'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 1:[1]

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

Solution 2:[2]

Either remove the supportedLngs option or add nonExplicitSupportedLngs: true.

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Juanma Menendez
Solution 2 adrai