diff --git a/app/routes/application.ts b/app/routes/application.ts index 8af0ab02..697c58bd 100644 --- a/app/routes/application.ts +++ b/app/routes/application.ts @@ -6,11 +6,13 @@ import hljs from 'highlight.js'; import { setup } from 'highlightjs-glimmer'; import type RouterService from '@ember/routing/router-service'; +import type IntlService from 'ember-intl/services/intl'; setup(hljs); export default class Application extends Route { @service declare router: RouterService; + @service declare intl: IntlService; constructor(...args: EmberConstructorArgs) { super(...args); @@ -32,4 +34,11 @@ export default class Application extends Route { this.router.on('routeDidChange', highlight); }); } + + async beforeModel() { + let translations = await fetch('/translations/en-us.json'); + let translationsAsJson = await translations.json(); + + this.intl.addTranslations('en-US', translationsAsJson); + } } diff --git a/app/services/locale.js b/app/services/locale.js index e5336f11..08bf8f66 100644 --- a/app/services/locale.js +++ b/app/services/locale.js @@ -1,5 +1,7 @@ import Service, { inject as service } from '@ember/service'; +import ENV from 'ember-cheat-sheet/config/environment'; + /* To help with maintenance, please list the supported locales in alphabetical order. @@ -25,11 +27,25 @@ export default class LocaleService extends Service { return 0; }); - updateSiteLocale(locale) { + async updateSiteLocale(locale) { if (!supportedLocales.has(locale)) { return; } + let translationPath = `translations/${locale.toLowerCase()}.json`; + + if (ENV.environment === 'production') { + let assetMap = await fetch('/assets/assetMap.json'); + let assetMapJson = await assetMap.json(); + + translationPath = assetMapJson.assets[translationPath]; + } + + let translations = await fetch(`/${translationPath}`); + let translationsJson = await translations.json(); + + this.intl.addTranslations(locale, translationsJson); + this.intl.setLocale(locale); } } diff --git a/config/ember-intl.js b/config/ember-intl.js index b52aa95e..b16d0da4 100644 --- a/config/ember-intl.js +++ b/config/ember-intl.js @@ -38,7 +38,7 @@ module.exports = function (/* environment */) { * @type {Boolean} * @default "false" */ - publicOnly: false, + publicOnly: true, /** * Add the subdirectories of the translations as a namespace for all keys. diff --git a/ember-cli-build.js b/ember-cli-build.js index 184ccc73..27478201 100644 --- a/ember-cli-build.js +++ b/ember-cli-build.js @@ -7,6 +7,10 @@ const { LEGACY } = process.env; module.exports = function (defaults) { let app = new EmberApp(defaults, { // custom options here + fingerprint: { + generateAssetMap: true, + fingerprintAssetMap: true, + }, }); if (LEGACY) {