Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Incorrectly forcing the selection of a language #254

Closed
wmansfield opened this issue Jan 26, 2018 · 7 comments
Closed

Incorrectly forcing the selection of a language #254

wmansfield opened this issue Jan 26, 2018 · 7 comments
Labels

Comments

@wmansfield
Copy link

if (options && !options.lng) {

The plugin should not force a lng option. When using a detector, this would be dynamically resolved, by forcing this option, it prevents the detector from doing its job. If anything, the fallback language should be forced.

@zewa666
Copy link
Member

zewa666 commented Jan 31, 2018

Yeah I see i've introduced a regression when fixing the RT feature. Will have a look at how to so it differently

@zewa666 zewa666 added the bug label Jan 31, 2018
@Jule-
Copy link

Jule- commented Feb 16, 2018

As said in #234 :
Maybe a better solution should be to enforce a fallbackLng and use it for relative-time when lng is missing!

It is a blocking issue for browser language detection, which I guess everyone who wants to internationalize its app wants too...

@Jule-
Copy link

Jule- commented Feb 17, 2018

A workaround is:

.plugin('aurelia-i18n', instance => {
  let aliases = ['t', 'i18n'];
  TCustomAttribute.configureAliases(aliases);

  instance.i18next
    .use(Backend)
    .use(LngDetector);

  return instance.setup({
    backend: {
      loadPath: './locales/{{lng}}/{{ns}}.json'
    },
    lng: 'en',
    detection: {
      order: ['navigator'], // Enforce navigator language detection
      lookupCookie: 'i18next',
      lookupLocalStorage: 'i18nextLng',
      caches: ['localStorage', 'cookie']
    },
    attributes: aliases,
    fallbackLng: 'en',
    debug: environment.debug
  })
    .then(() => {
      // Enforce language detection
      instance.i18next.changeLanguage();
    });
})

Calling changeLanguage() without lng argument trigger language detection mechanism. Side effect is that setting lng in setup() options cache the selected language in localStorage and cookie so I have to enforce navigator language detection in order to get it, if not language detection find obviously what you set at first in lng... With this specific workaround you cannot allow users to set language differently than the navigator one, at least at every app startup.

Alternatively, and I think it is a better workaround, you can change detection options to:

detection: {
  order: ['localStorage', 'cookie', 'navigator'],
  lookupCookie: 'i18next',
  lookupLocalStorage: 'i18nextLng',
  caches: [] // Enforce no detection caching
}

In that case detection reads cached language but do not writes in cache so you have to set it by yourself in localStorage or cookie when user wants to change its default language.

HTH

zewa666 added a commit that referenced this issue Feb 19, 2018
stops forcing the lng option in favor of relativetime and uses the fallbackLng instead

Related issue #254
@zewa666
Copy link
Member

zewa666 commented Feb 19, 2018

Alright sorry for taking me so long to fix this but I think I got it with the recent PR #259. Just waiting for it to properly build and after merge we'll hopefully get a quick release out.

zewa666 added a commit that referenced this issue Feb 19, 2018
stops forcing the lng option in favor of relativetime and uses the fallbackLng instead

Related issue #254
@zewa666
Copy link
Member

zewa666 commented Feb 24, 2018

The new Release has been pushed, may I ask you guys to check out whether now everything runs as expected?

@Jule-
Copy link

Jule- commented Feb 24, 2018

Thanks @zewa666! All seems ok for me! 😃

@zewa666
Copy link
Member

zewa666 commented Feb 24, 2018

Thanks for the quick response. Im gonna close this for now and we can reopen the issues If any other troubles occur.

@zewa666 zewa666 closed this as completed Feb 24, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

3 participants