Closed eharrow closed 6 years ago
@eharrow can't you use it in the service itself? Why do you need to do it in an initializer?
ember-18n add-on exposes itself as a service and suggests initialising in an instance initialiser see https://github.com/jamesarosen/ember-i18n/wiki/Doc:-Setting-the-Locale
thx
Ah I see. In this case I would suggest that you use the first approach in the application route:
// app/routes/application.js
export default Ember.Route.extend({
i18n: Ember.inject.service(),
userSettings: storageFor('userSettings'),
// You can use beforeModel as you don't depend on the model hook
beforeModel: function() {
this.set('i18n.locale', this.get('userSettings.locale'));
}
});
Yes that works fine. Ta
I wish to read from a storage object in an initialiser and then do something for the service being initialised. This is to support I18N where a user saved their preferred locale to local-storage and on the next app start the value will be read and the i18n add-on initiliased with it.
The issue I have is that using storageFor() in the way the docs work in an initialiser ends up with an error to do with the storage factory. How can I look up the storage instance in this case?