Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

lowercase locale name (ja-jp) with i18next is not working, while ja-JP works

I am using i18next with aurelia using the i18next aurelia plugin.

The problem I am facing is in locale case sensitivity.

When I set my url to http://localhost/ja-JP everything works fine, but changing the url to http://localhost/ja-jp throws this error

Possible Unhandled Promise Rejection: ["failed loading locales/ja-JP/translation.json"]

I thought that i18next is by default looking into case sensitive directory, so I tried keeping two directories ja-JP and ja-jp too, but still same problem.

Any idea why would it be a problem?

http://localhost/ja/ and http://localhost/en both work perfectly fine though

if it is relevant, here is the webpack conf section

 "aurelia-i18n": [
        { name: "locales/ja-jp/translation.json" },
        { name: "locales/en-us/translation.json" }
      ]

and the aurelia configuration for i18next

export function configure(aurelia: Aurelia) {
  aurelia.use
    .standardConfiguration()
    .plugin(PLATFORM.moduleName('aurelia-validation'))
    .plugin(PLATFORM.moduleName('au-table'))
    .plugin(PLATFORM.moduleName("aurelia-i18n"), (instance) => {
      let aliases = ["t", "i18n"];
      TCustomAttribute.configureAliases(aliases);

      instance.i18next.use(Backend.with(aurelia.loader));

      return instance.setup({
        backend: {
          loadPath: "./locales/{{lng}}/{{ns}}.json"
        },
        attributes: aliases,
        lng: "en-us",
        fallbackLng: "en-us",
        load: "currentOnly",
        debug: false
      });
    })
  .feature(PLATFORM.moduleName('resources/index'))
  .developmentLogging(environment.debug ? 'debug' : 'warn');

  if (environment.testing) {
    aurelia.use.plugin(PLATFORM.moduleName('aurelia-testing'))
  }

  aurelia.start().then(() => aurelia.setRoot(PLATFORM.moduleName('app')));
}
like image 707
user728650 Avatar asked Dec 12 '25 19:12

user728650


1 Answers

There is lowerCaseLng Option that will help you. https://www.i18next.com/overview/configuration-options

i18next
  .init({
    ...
    lowerCaseLng: true
  });
like image 175
Allen Wong Avatar answered Dec 14 '25 09:12

Allen Wong



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!