Skip to content

Commit

Permalink
add embroider reproduction
Browse files Browse the repository at this point in the history
  • Loading branch information
amk221 committed Apr 29, 2024
1 parent 22debaf commit 61bb48f
Show file tree
Hide file tree
Showing 10 changed files with 2,627 additions and 15 deletions.
29 changes: 29 additions & 0 deletions app/formats.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
export default {
time: {
hhmmss: {
hour: 'numeric',
minute: 'numeric',
second: 'numeric',
},
},
date: {
hhmmss: {
hour: 'numeric',
minute: 'numeric',
second: 'numeric',
},
},
number: {
compact: {
notation: 'compact',
},
EUR: {
style: 'currency',
currency: 'EUR',
},
USD: {
style: 'currency',
currency: 'USD',
},
},
};
34 changes: 34 additions & 0 deletions app/routes/application.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
import Route from '@ember/routing/route';
import { service } from '@ember/service';

export default class ApplicationRoute extends Route {
@service intl;

async beforeModel() {
const locale = 'en-gb';

// Path to fingerprinted asset map is dealt with at build time by broccoli-asset-rev
const map = await load('/assets/assetMap.json');

// Dynamic path to translation file, broccoli-asset-rev can't deal with this,
// hence the need to look up the real (fingerprinted) path in the asset map.
const path = `translations/${locale}.json`;
const fingerprintedPath = map.assets[path];

const translations = await load(fingerprintedPath);

await wait(500);

this.intl.addTranslations(locale, translations);

this.intl.setLocale([locale]);
}
}

function load(url) {
return fetch(url).then((response) => response.json());
}

function wait(ms) {
return new Promise((resolve) => setTimeout(resolve, ms));
}
1 change: 1 addition & 0 deletions app/templates/application-loading.hbs
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Loading...
8 changes: 1 addition & 7 deletions app/templates/application.hbs
Original file line number Diff line number Diff line change
@@ -1,7 +1 @@
{{page-title "Example"}}

{{! The following component displays Ember's default welcome message. }}
<WelcomePage />
{{! Feel free to remove this! }}

{{outlet}}
Translated string: {{t "greeting"}}
95 changes: 95 additions & 0 deletions config/ember-intl.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,95 @@
/* jshint node:true */

module.exports = function (/* environment */) {
return {
/**
* Merges the fallback locale's translations into all other locales as a
* build-time fallback strategy.
*
* This will **not** prevent missing translation warnings or errors from occurring.
* It's meant as safety net when warnings are enabled.
* When enabled along with `errorOnMissingTranslations` any fallback attempts will result in an error.
*
* @property fallbackLocale
* @type {String?}
* @default "null"
*/
fallbackLocale: null,

/**
* Path where translations are stored. This is relative to the project root.
* For example, if your translations are an npm dependency, set this to:
*`'./node_modules/path/to/translations'`
*
* @property inputPath
* @type {String}
* @default "'translations'"
*/
inputPath: 'translations',

/**
* Prevents the translations from being bundled with the application code.
* This enables asynchronously loading the translations for the active locale
* by fetching them from the asset folder of the build.
*
* See: https://ember-intl.github.io/ember-intl/docs/guide/asynchronously-loading-translations
*
* @property publicOnly
* @type {Boolean}
* @default "false"
*/
publicOnly: true,

/**
* Add the subdirectories of the translations as a namespace for all keys.
*
* @property wrapTranslationsWithNamespace
* @type {Boolean}
* @default "false"
*/
wrapTranslationsWithNamespace: false,

/**
* Cause a build error if ICU argument mismatches are detected between translations
* with the same key across all locales.
*
* @property errorOnNamedArgumentMismatch
* @type {Boolean}
* @default "false"
*/
errorOnNamedArgumentMismatch: false,

/**
* Cause a build error if missing translations are detected.
*
* See https://ember-intl.github.io/ember-intl/docs/guide/missing-translations#throwing-a-build-error-on-missing-when-required-translations
*
* @property errorOnMissingTranslations
* @type {Boolean}
* @default "false"
*/
errorOnMissingTranslations: false,

/**
* Removes empty translations from the build output.
*
* @property stripEmptyTranslations
* @type {Boolean}
* @default "false"
*/
stripEmptyTranslations: false,

/**
* A function that is called whenever any translation key, from any locale, is missing at build time.
*
* See https://ember-intl.github.io/ember-intl/docs/guide/missing-translations#requiring-translations
*
* @property requiresTranslation
* @type {Function}
* @default "function(key,locale) { return true }"
*/
requiresTranslation(/* key, locale */) {
return true;
},
};
};
30 changes: 24 additions & 6 deletions ember-cli-build.js
Original file line number Diff line number Diff line change
@@ -1,11 +1,29 @@
'use strict';

const EmberApp = require('ember-cli/lib/broccoli/ember-app');
const { Webpack } = require('@embroider/webpack');
const exampleAssetHost = 'http://localhost:4211';
const embroiderBuild = false;

module.exports = function (defaults) {
const app = new EmberApp(defaults, {
// Add options here
});
if (embroiderBuild) {
module.exports = function (defaults) {
const app = new EmberApp(defaults, {});

return app.toTree();
};
return require('@embroider/compat').compatBuild(app, Webpack);
};
} else {
module.exports = function (defaults) {
const app = new EmberApp(defaults, {
fingerprint: {
enabled: true,
exclude: ['testem.js'],
extensions: ['js', 'json', 'css'],
prepend: `${exampleAssetHost}/`,
generateAssetMap: true,
fingerprintAssetMap: true,
},
});

return app.toTree();
};
}
Loading

0 comments on commit 61bb48f

Please sign in to comment.