ember.jsember-i18n

how to remember ember-i18n language choice on browser refresh


I tried first something like this in my application controller:

init123: function() {
  var locale;
  if (this.session.get('lang') === null || this.session.get('lang') === undefined)
    locale = ENV.i18n.defaultLocale;
  else
    locale = this.session.get('lang');

  this.get('i18n').set('locale', locale);
}.on('init'),

but this only works when the user is logged in. If not, always the default is set.

Then I tried stuff with the initalizer like on this answer.

How to set the i18n.locale from within an initializer from Artych

But how do I remember the last choice done in the browser?

Thx


Solution

  • You need to persist the preference somewhere. Take a look at the ember-localforage-adapter or ember-local-storage packages.