mirror of
https://github.com/maputnik/editor.git
synced 2026-02-10 06:30:00 +00:00
- add german translation (following the changes in https://github.com/maplibre/maputnik/pull/929) - using an alphabecial order for the languages - update the documentation with a step-by-step guide - add myself as a helping person for german - move the helping-users list to the implementation of new features - update CHANGELOG.md - add a link to the l18n README in the root README 
43 lines
1.4 KiB
TypeScript
43 lines
1.4 KiB
TypeScript
import i18n from "i18next";
|
|
import detector from "i18next-browser-languagedetector";
|
|
import resourcesToBackend from "i18next-resources-to-backend";
|
|
import { initReactI18next } from "react-i18next";
|
|
|
|
export const supportedLanguages = {
|
|
"de": "Deutsch",
|
|
"en": "English",
|
|
"fr": "Français",
|
|
"he": "עברית",
|
|
"ja": "日本語",
|
|
"zh": "简体中文"
|
|
} as const;
|
|
|
|
i18n
|
|
.use(detector) // detect user language from browser settings
|
|
.use(
|
|
resourcesToBackend((lang: string, ns: string) => {
|
|
if (lang === "en") {
|
|
// English is the default language, so we don't need to load any resources for it.
|
|
return {};
|
|
}
|
|
return import(`./locales/${lang}/${ns}.json`);
|
|
})
|
|
)
|
|
.use(initReactI18next) // required to initialize react-i18next
|
|
.init({
|
|
supportedLngs: Object.keys(supportedLanguages),
|
|
keySeparator: false, // we do not use keys in form messages.welcome
|
|
nsSeparator: false,
|
|
interpolation: {
|
|
escapeValue: false // React already escapes for us
|
|
},
|
|
saveMissing: true, // this needs to be set for missingKeyHandler to work
|
|
fallbackLng: false, // we set the fallback to false so we can get the correct language in the missingKeyHandler
|
|
missingKeyHandler: (lngs, _ns, key) => {
|
|
if (lngs[0] === "en") { return; }
|
|
console.warn(`Missing translation for "${key}" in "${lngs.join(", ")}"`);
|
|
}
|
|
});
|
|
|
|
export default i18n;
|