PowPi
PowPi

Reputation: 163

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

Upvotes: 1

Views: 612

Answers (2)

lpinto.eu
lpinto.eu

Reputation: 2127

If you are using ember-simple-auth you can save it into the session.

Upvotes: 0

brian
brian

Reputation: 167

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

Upvotes: 1

Related Questions