i18next / i18next-http-backend

i18next-http-backend is a backend layer for i18next using in Node.js, in the browser and for Deno.
MIT License
450 stars 69 forks source link

Allow editing the languages to load if loadpath is a function #78

Closed jasperfirecai2 closed 3 years ago

jasperfirecai2 commented 3 years ago

https://github.com/i18next/i18next-http-backend/blob/82498bd0b4dbb687a5fada5f9ce91492e1759927/i18nextHttpBackend.js#L118

It's nice that a function or promise can be passed to manage the languages and the path generation on load, but in the end all it can return is a path that will be interpolated. I would like to be able to use a function, or a path interpolation, where i can for example remove -us at the end of en-us. Since i only have a /en folder but browser language is set to en-us, and thus it tries to fetch a file that i know won't exist

adrai commented 3 years ago

You can use the fallback feature of i18next: https://www.i18next.com/principles/fallback#fallback-language image

...and/or use a different load option: https://www.i18next.com/overview/configuration-options image

...or simply change the served path on server side

jasperfirecai2 commented 3 years ago

except the fallback only applies after the failed fetch.. image with config

{
    backend: {
      loadPath: './locales/{{lng}}/{{ns}}.json'
    },
    fallbackLng: 'en'
}
adrai commented 3 years ago

You may need to change the load option to "languageOnly": https://www.i18next.com/overview/configuration-options

jasperfirecai2 commented 3 years ago

could've sworn I tried that before.. that works now. thanks