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 in app/initializers folder as follows:
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.
@broerse Thank you very much, really appreciated for such a detailed example with real use cases! Special thanks for the link to BabelEdit, - I’ve never heard about this tool. Really cool.