Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions app/routes/application.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -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);
}
}
18 changes: 17 additions & 1 deletion app/services/locale.js
Original file line number Diff line number Diff line change
@@ -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.
Expand All @@ -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);
}
}
2 changes: 1 addition & 1 deletion config/ember-intl.js
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
4 changes: 4 additions & 0 deletions ember-cli-build.js
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down