This repository has been archived by the owner on Apr 18, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 184
Doc: i18n Service
Benoit Tigeot edited this page Dec 11, 2015
·
7 revisions
Many pieces of ember-i18n rely on the service:i18n
. Ask for it wherever you need (likely in Routes and Components):
// app/routes/post.js
export default Ember.Object.extend({
i18n: Ember.inject.service(),
afterModel: function(post) {
document.title = this.get('i18n').t('title.post', { post: post });
}
});
Please note that Ember.inject.service()
is lazy, so you won't be able to observe things (e.g. i18n.locale
) until you cause it to be looked up via this.get('i18n')
. See #299.
If you find yourself needing it in many places, you can declare an injection:
// app/initializers/i18n.js
export default {
name: 'i18n',
after: 'ember-i18n',
initialize: function(app) {
app.inject('model', 'i18n', 'service:i18n')
}
};
If you want the service injected into everything, you can avoid the initializer code by installing ember-i18n-inject.
To get a list of available locales:
var locales = this.get('i18n.locales');
This can be useful if you want to create a menu of alternate locales to the user.