Reputation: 71
In which route/component should I inject the "i18n" service for it to be used in application.hbs? I'm trying to use it in other HBS files, and if I inject "i18n" into the route/component - I'm able to use it.
But it's just not working in application.hbs
Upvotes: 0
Views: 212
Reputation: 18240
Generally you dont have to inject the i18n
service to use the t
helper, which is what you usually do from a template.
But in generally a service needs to be injected to the controller if you want to use it in the routes template. So you need to inject the service to the application
controller to use it on your application
template.
Upvotes: 1
Reputation: 6915
You can do it by using an instance initializer and inject i18n service to your all routes and components by using this code:
/instance-initializers/component-route-i18n-injector.js
import Ember from 'ember';
export function initialize(appInstance) {
let i18n = appInstance.lookup('service:i18n');
Ember.Component.reopen({
i18n: i18n
});
Ember.Controller.reopen({
i18n: i18n
});
}
export default {
name: 'component-route-i18n-injector',
initialize
};
You can take a look at this twiddle.
Upvotes: 0