Search code examples
reactjsinternationalizationtranslationi18nextreact-i18next

i18next not detecting language variation, eg: en-us


When I set in my browser a language variation, for example: English (United States) / en-us. The i18next library doesn't detect that variation and just loads the next language in the list, for example: Spanish or plain English.

enter image description here


Solution

  • In order to make i18Next detect language variations, you have to add: nonExplicitSupportedLngs: true, in the i18next config file, for example:

    i18next
        ...
        .use(LanguageDetector)
        .init({
            supportedLngs: ['en', 'es'],
            nonExplicitSupportedLngs: true, //support language variation
            ...
        });
    

    Reference: https://www.i18next.com/overview/configuration-options > nonExplicitSupportedLngs