-
-
Notifications
You must be signed in to change notification settings - Fork 21
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add first i18n infrastructure and translate utils and about-dialog
- Loading branch information
Showing
29 changed files
with
680 additions
and
62 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
const messagesDe = { | ||
"about-dialog": { | ||
"header": `Über FacilMap {{version}}`, | ||
"license-text": `{{facilmap}} is unter der {{license}} verfügbar.`, | ||
"license-text-facilmap": `FacilMap`, | ||
"license-text-license": `GNU Affero General Public License, Version 3`, | ||
"issues-text": `Bitte melden Sie Fehler und Verbesserungsvorschläge auf {{tracker}}.`, | ||
"issues-text-tracker": `GitHub`, | ||
"help-text": `Wenn Sie Fragen haben, schauen Sie sich die {{documentation}} an, schreiben Sie ins {{discussions}} oder fragen im {{chat}}.`, | ||
"help-text-documentation": `Dokumentation`, | ||
"help-text-discussions": `Forum`, | ||
"help-text-chat": `Matrix-Chat`, | ||
"privacy-information": `Informationen zum Datenschutz`, | ||
"map-data": `Kartendaten`, | ||
"map-data-search": `Suche`, | ||
"map-data-pois": `POIs`, | ||
"map-data-directions": `Routenberechnung`, | ||
"map-data-geoip": `GeoIP`, | ||
"map-data-geoip-description": `Dieses Produkt enthält GeoLine2-Daten von Maxmind, verfügbar unter {{maxmind}}.`, | ||
"attribution-osm-contributors": `OSM-Mitwirkende`, | ||
"programs-libraries": `Programme/Bibliotheken`, | ||
"icons": `Symbole` | ||
}, | ||
|
||
"modal-dialog": { | ||
"close": "Schließen", | ||
"cancel": "Abbrechen", | ||
"save": "Speichern" | ||
} | ||
}; | ||
|
||
export default messagesDe; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
const messagesEn = { | ||
"about-dialog": { | ||
"header": `About FacilMap {{version}}`, | ||
"license-text": `{{facilmap}} is available under the {{license}}.`, | ||
"license-text-facilmap": `FacilMap`, | ||
"license-text-license": `GNU Affero General Public License, Version 3`, | ||
"issues-text": `If something does not work or you have a suggestion for improvement, please report on the {{tracker}}.`, | ||
"issues-text-tracker": `issue tracker`, | ||
"help-text": `If you have a question, please have a look at the {{documentation}}, raise a question in the {{discussions}} or ask in the {{chat}}.`, | ||
"help-text-documentation": `documentation`, | ||
"help-text-discussions": `discussion forum`, | ||
"help-text-chat": `Matrix chat`, | ||
"privacy-information": `Privacy information`, | ||
"map-data": `Map data`, | ||
"map-data-search": `Search`, | ||
"map-data-pois": `POIs`, | ||
"map-data-directions": `Directions`, | ||
"map-data-geoip": `GeoIP`, | ||
"map-data-geoip-description": `This product includes GeoLite2 data created by MaxMind, available from {{maxmind}}.`, | ||
"attribution-osm-contributors": `OSM Contributors`, | ||
"programs-libraries": `Programs/libraries`, | ||
"icons": `Icons` | ||
}, | ||
|
||
"modal-dialog": { | ||
"close": "Close", | ||
"cancel": "Cancel", | ||
"save": "Save" | ||
} | ||
}; | ||
|
||
export default messagesEn; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,73 @@ | ||
/// <reference types="vite/client" /> | ||
import { type i18n } from "i18next"; | ||
import { defineComponent, ref } from "vue"; | ||
import messagesEn from "../../i18n/en"; | ||
import messagesDe from "../../i18n/de"; | ||
import { getRawI18n, onI18nReady } from "facilmap-utils"; | ||
|
||
const namespace = "facilmap-frontend"; | ||
|
||
onI18nReady((i18n) => { | ||
i18n.addResourceBundle("en", namespace, messagesEn); | ||
i18n.addResourceBundle("de", namespace, messagesDe); | ||
}); | ||
|
||
if (import.meta.hot) { | ||
import.meta.hot.accept("../../i18n/en", (m) => { | ||
onI18nReady((i18n) => { | ||
i18n.addResourceBundle("en", namespace, m!.default); | ||
}); | ||
}); | ||
|
||
import.meta.hot.accept("../../i18n/de", (m) => { | ||
onI18nReady((i18n) => { | ||
i18n.addResourceBundle("de", namespace, m!.default); | ||
}); | ||
}); | ||
} | ||
|
||
const rerenderCounter = ref(0); | ||
const rerender = () => { | ||
rerenderCounter.value++; | ||
}; | ||
|
||
onI18nReady((i18n) => { | ||
i18n.store.on("added", rerender); | ||
i18n.store.on("removed", rerender); | ||
i18n.on("languageChanged", rerender); | ||
i18n.on("loaded", rerender); | ||
}); | ||
|
||
export function useI18n(): Pick<i18n, "t"> { | ||
return { | ||
t: new Proxy(getRawI18n().getFixedT(null, namespace), { | ||
apply: (target, thisArg, argumentsList) => { | ||
rerenderCounter.value; | ||
return target.apply(thisArg, argumentsList as any); | ||
} | ||
}) | ||
}; | ||
} | ||
|
||
export const T = defineComponent({ | ||
props: { | ||
k: { type: String, required: true } | ||
}, | ||
setup(props, { slots }) { | ||
const i18n = useI18n(); | ||
|
||
return () => { | ||
const mappedSlots = Object.entries(slots).map(([name, slot], i) => ({ name, placeholder: `%___SLOT_${i}___%`, slot })); | ||
const placeholderByName = Object.fromEntries(mappedSlots.map(({ name, placeholder }) => [name, placeholder])); | ||
const slotByPlaceholder = Object.fromEntries(mappedSlots.map(({ placeholder, slot }) => [placeholder, slot])); | ||
const message = i18n.t(props.k, placeholderByName); | ||
return message.split(/(%___SLOT_\d+___%)/g).map((v, i) => { | ||
if (i % 2 === 0) { | ||
return v; | ||
} else { | ||
return slotByPlaceholder[v]!(); | ||
} | ||
}); | ||
}; | ||
} | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.