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