Home > front end >  i18next - REACT - Firefox returns "de" - Chrome returns "de-DE"
i18next - REACT - Firefox returns "de" - Chrome returns "de-DE"

Time:08-09

using

    "i18next": "^21.6.6",
    "i18next-browser-languagedetector": "^6.1.2",
    "i18next-http-backend": "^1.3.2"

I got the following folder & files:

"public/locales/de-DE/*.json"
"public/locales/en-US/*.json"

Problem:

In Chrome, first visiting the website, the navigator.language returns "de-DE". The language is found correctly. But default of Firefox returns "de" without the region. So, i18next does not find the matching folder.

Whats the best way to map "non-region" codes to an "default-region" for a language, e.g. de -> de-DE or en -> en-US

Is there something specified by i18next or shall I just copy all from de-DE to de folder?

Configuration:

i18n
.use(Backend)
.use(LanguageDetector)
.use(initReactI18next)
.init({
    fallbackLng: 'en-US',
    debug: true,

    interpolation: {
        escapeValue: false,
    },
    react: {
        useSuspense: false,
    },
});

CodePudding user response:

Rename your folders to en and de, and set the load option to languageOnly.

  • Related