Reputation: 126
i have the following Problem with ember-i18n:
Error: Attempting to inject an unknown injection: 'service:i18n'
at Registry.validateInjections (ember.debug.js:2303)
at ember.debug.js:1538
at runInDebug (ember.debug.js:5813)
at Object.runInDebug (ember.debug.js:17396)
at instantiate (ember.debug.js:1532)
at lookup (ember.debug.js:1385)
at Container.lookup (ember.debug.js:1304)
at Class.lookup (ember.debug.js:32564)
at Class._internalGetHandler (router-ext.js:107)
at Class._getHandlerForEngine (router-ext.js:84)
I use the ember-i18n plugin in an ember engine. My i18n initializers addon/instance-initializers/i18n.js
:
export default {
name: 'i18n',
initialize: function(applicationInstance) {
const i18nService = applicationInstance.lookup('service:i18n');
i18nService.set('defaultLocale', window.I18n.defaultLocale);
i18nService.set('locale', window.I18n.locale);
}
};
In my index route (routes/index.js
) i have the following code:
import Ember from 'ember';
export default Ember.Route.extend({
i18n: Ember.inject.service(),
actions: {
didTransition() {
Ember.run.scheduleOnce('afterRender', this, function() {
console.log(this.get('i18n').t('error_empty_user_data'));
// ....
});
}
}
});
How can I declare the i18n service?
I use the ember-18n 4.5.0 Version and the 2.10.0 ember-cli Version.
Upvotes: 1
Views: 2676
Reputation: 9406
The initializer should run after i18n
one.
export default {
name: 'i18n',
after: ['ember-i18n'],
initialize: function(applicationInstance) {
const i18nService = applicationInstance.lookup('service:i18n');
i18nService.set('defaultLocale', window.I18n.defaultLocale);
i18nService.set('locale', window.I18n.locale);
}
};
Upvotes: 1