-
Notifications
You must be signed in to change notification settings - Fork 0
/
i18n_init.mjs
34 lines (31 loc) · 1.07 KB
/
i18n_init.mjs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
function i18n_init(language_code="en", onInitialized=null, onLanguageChanged=null){
const translationsBackendOptions = { // these are options to i18nextHttpBackend plugin of i18next
loadPath: './translations/{{lng}}.json'
};
i18next
.use(window.i18nextHttpBackend)
.use(ReactI18next.initReactI18next) // passes i18n down to react-i18next
.init(
{
lng: language_code,
debug: true,
supportedLngs: ["en", "fr"],
fallbackLng: { // In order to not download the fallback language translation file when it won't be needed, languages in which the application is fully translated should have an empty array for their key here
"fr": [],
"en": [],
"default": ["en"]
},
load: "currentOnly",
backend: translationsBackendOptions,
interpolation: {
escapeValue: false // React already safes from XSS
}
},
onInitialized
);
if(onLanguageChanged){
i18next.on('languageChanged', onLanguageChanged);
}
}
export { i18n_init };
export default i18n_init;