I'm trying to achieve asynchronous fetching of translations. I set up the publicOnly to true as docs say:
// config/ember-intl.js
module.exports = function() {
return {
publicOnly: true
}
};
Skipped the step of setting up the locales key, because translations are stored in /translations folder.
Next, I should modify beforeModel hook to asynchronously fetch the translations, and that's where docs are pretty vague:
// app/routes/application.js
export default Ember.Route.extend({
intl: Ember.inject.service(),
async beforeModel() {
let translations = await fetch('/api/translations.json');
this.get('intl').addTranslations('en-us', translations);
this.get('intl').setLocale('en-us');
}
});
How these lines supposed to work:
let translations = await fetch('/api/translations.json');
this.get('intl').addTranslations('en-us', translations);
In runtime I have no translations.json file anywhere in the dist folder. I've got dist/translations/en-us.json only for my one and only translation and no clue how to make it work.
Service API misses documentation of addTranslations method.
Would appreciate any help.
This is what I was using back when I was doing async translations (and I may bring this back as my application grows)
This is in
services/intl.tsI believe it's inspired by one of the github issues on the ember-intl repository, and I modified it to work with my setup. (like, the config.hostUrl stuff -- this is just set to my domain at the moment, but it may be handy if your site isn't deployed at the root of your domain).
Usage in my application route:
Something I haven't yet figured out is how to best manage async translations with a progressive web app. In the current version of my app, I've removed the async behavior and just bundle the translation file (just one) with my app.