@belgoros wrote:
I decided to migrate from deprecated ember-i18 to a new ember-intl. After transforming the old translation files with a provided migrator, I’m still stuck with initialization of the locale. Previously, I used an initializer
i18n.js
defined inapp/initializers
folder as follows:export default { name: 'i18n', after: 'ember-i18n', initialize: function(app) { app.inject('model', 'i18n', 'service:i18n'); app.inject('controller', 'i18n', 'service:i18n'); app.inject('route', 'i18n', 'service:i18n'); } };
and I set up the default locale based on the User browser settings in
app/instance-initializers/i18n.js
as follows:export function initialize(applicationInstance) { let i18n = applicationInstance.lookup('service:i18n'); let moment = applicationInstance.lookup('service:moment'); let locale = calculateLocale(i18n.get('locales')); i18n.set('locale', locale); moment.setLocale(locale); } function calculateLocale(locales) { // whatever you do to pick a locale for the user: const language = navigator.languages[0] || navigator.language || navigator.userLanguage; return locales.includes(language.toLowerCase()) ? language : 'en-GB'; } export default { name: 'i18n', initialize };
Unfortunately,
ember-intl
is missing clear docs explaining how to do that. Do you have any ideas or tips? Thank you.
Posts: 1
Participants: 1