You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
28 lines
1.1 KiB
28 lines
1.1 KiB
1 year ago
|
import { initReactI18next } from 'react-i18next';
|
||
|
import i18n from 'i18next';
|
||
|
import resources from './assets/locales/resources.js';
|
||
|
// the translations
|
||
|
// (tip move them in a JSON file and import them,
|
||
|
// or even better, manage them via a UI: https://react.i18next.com/guides/multiple-translation-files#manage-your-translations-with-a-management-gui)
|
||
|
|
||
|
let localLang = sessionStorage.getItem('lang');
|
||
|
const browserLang = navigator.language;
|
||
|
if (!localLang) {
|
||
|
localLang = browserLang === 'zh-CN' ? 'zh-CN' : 'en-US';
|
||
|
}
|
||
|
|
||
|
i18n
|
||
|
.use(initReactI18next) // passes i18n down to react-i18next
|
||
|
.init({
|
||
|
resources,
|
||
|
lng: localLang, // language to use, more information here: https://www.i18next.com/overview/configuration-options#languages-namespaces-resources
|
||
|
// you can use the i18n.changeLanguage function to change the language manually: https://www.i18next.com/overview/api#changelanguage
|
||
|
// if you're using a language detector, do not define the lng option
|
||
|
|
||
|
interpolation: {
|
||
|
escapeValue: false, // react already safes from xss
|
||
|
},
|
||
|
});
|
||
|
|
||
|
export default i18n;
|