Tanner Summers
Tanner Summers

Reputation: 663

i18next mapping en-US locale to en namespace folder/file

Sorry if I am not asking this question correctly, currently, our system uses i18next with the i18next-http-backend and i18next-browser-languagedetector. The browser, using i18next-browser-languagedetector returns en-US when the browser is using an English locale setting. However the nodejs app is set up with the i18next-http-backend in a way where the translations are set up in english for /public/locales/en/language.json. Now the problem is, the i18next package relies on the fallback language because, en-US does not map to the en (/public/locales/en/) namespace/folder location.

I know, it would be very simple enough to just rename the folder or simple enough to change the fallback language to en.

But I feel like there is a way to map this or an alternative way that i can't figure out and can't find in the docs so I am wondering if its possible, that when the languagedetector detects en-US locale, it will map to the /public/locales/en/ location

any help is appreciated, thanks in advance!

Upvotes: 2

Views: 1090

Answers (2)

adrai
adrai

Reputation: 3168

Alternatively, set the load option to 'languageOnly': https://www.i18next.com/overview/configuration-options#languages-namespaces-resources enter image description here

Upvotes: 0

Juanma Menendez
Juanma Menendez

Reputation: 20089

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
        ...
    });

Upvotes: 1

Related Questions