badguardhome/client/src/i18n.js

39 lines
1000 B
JavaScript
Raw Normal View History

import i18n from 'i18next';
import XHR from 'i18next-xhr-backend';
import { reactI18nextModule } from 'react-i18next';
2018-11-06 02:51:00 +00:00
import { initReactI18n } from 'react-i18next/hooks';
import langDetect from 'i18next-browser-languagedetector';
import { LANGUAGES, BASE_LOCALE } from './helpers/twosky';
const availableLanguages = Object.keys(LANGUAGES);
i18n
.use(langDetect)
.use(XHR)
2018-11-06 02:51:00 +00:00
.use(initReactI18n)
.use(reactI18nextModule)
.init({
2019-10-21 13:03:17 +00:00
lowerCaseLng: true,
fallbackLng: BASE_LOCALE,
keySeparator: false,
nsSeparator: false,
returnEmptyString: false,
interpolation: {
escapeValue: false,
},
react: {
wait: true,
},
whitelist: availableLanguages,
backend: {
loadPath: '/__locales/{{lng}}.json',
},
2019-10-21 13:03:17 +00:00
}, () => {
if (!availableLanguages.includes(i18n.language)) {
i18n.changeLanguage(BASE_LOCALE);
2019-10-21 13:03:17 +00:00
}
});
export default i18n;