Ember and Moment - change locale


#1

Hi there!
How do i change locale in all app? I mean, user clicks on switch language, and all components in my app, will change names of month.


#2

Boris, try check it https://github.com/jamesarosen/ember-i18n


#3

Yes, ember-i18n is the way to go.

With it it’s pretty easy to hook up an action that will change the language, which will reflect everywhere.

In this action you’ll do two things:

  1. this.get('i18n').set('locale', newLocale)
  2. moment.locale(newLocale)

Just make sure your computed properties using moment etc. bind to i18n.locale.

// ... inside a controller/route/etc
i18n: Ember.inject.service(),

myComputed: function() {
  // ...
  return moment().format();
}.property('i18n.locale'),

#4

https://github.com/stefanpenner/ember-moment recomputes helpers on locale change. Just be sure to use the service API to trigger the locale change.