BOD-38 Added Browser Detection for i18n. Uses local storage to store user language preferences.

This commit is contained in:
Patrick Fic
2020-04-20 15:45:09 -07:00
parent b3eb6fe91d
commit 64f3f727e4
5 changed files with 26 additions and 15 deletions

View File

@@ -1,5 +1,6 @@
import i18n from "i18next";
import { initReactI18next } from "react-i18next";
import LanguageDetector from "i18next-browser-languagedetector";
import en_Translation from "./en_us/common.json";
import fr_Translation from "./fr/common.json";
import es_Translation from "./es/common.json";
@@ -7,23 +8,25 @@ import es_Translation from "./es/common.json";
// the translations
// (tip move them in a JSON file and import them)
const resources = {
en_us: en_Translation,
fr: fr_Translation,
es: es_Translation
"en-US": en_Translation,
"fr-CA": fr_Translation,
"es-MX": es_Translation,
};
i18n
.use(initReactI18next) // passes i18n down to react-i18next
.use(initReactI18next)
.use(LanguageDetector) // passes i18n down to react-i18next
.init({
resources,
lng: "en_us",
fallbackLng: "en-us",
//lng: "en",
detection: {},
fallbackLng: "en-US",
debug: true,
//keySeparator: false, // we do not use keys in form messages.welcome
interpolation: {
escapeValue: false // react already safes from xss
}
escapeValue: false, // react already safes from xss
},
});
export default i18n;