FEATURE: Support i18n in Ember CLI plugin tests

This commit is contained in:
Robin Ward 2021-11-24 14:51:23 -05:00
parent de3680eb5c
commit c27e324bd1
3 changed files with 22 additions and 7 deletions

View File

@ -4,6 +4,8 @@ const fs = require("fs");
const concat = require("broccoli-concat"); const concat = require("broccoli-concat");
const mergeTrees = require("broccoli-merge-trees"); const mergeTrees = require("broccoli-merge-trees");
const MessageFormat = require("messageformat"); const MessageFormat = require("messageformat");
const deepmerge = require("deepmerge");
const glob = require("glob");
let built = false; let built = false;
@ -40,10 +42,14 @@ class TranslationPlugin extends Plugin {
return; return;
} }
let file = this.inputPaths[0] + "/" + this.inputFile; let parsed = {};
let yaml = fs.readFileSync(file, { encoding: "UTF-8" }); this.inputPaths.forEach((path) => {
let parsed = Yaml.load(yaml); let file = path + "/" + this.inputFile;
let yaml = fs.readFileSync(file, { encoding: "UTF-8" });
let loaded = Yaml.load(yaml);
parsed = deepmerge(parsed, loaded);
});
let extras = { let extras = {
en: { en: {
@ -82,11 +88,14 @@ module.exports = function translatePlugin(...params) {
}; };
module.exports.createI18nTree = function (discourseRoot, vendorJs) { module.exports.createI18nTree = function (discourseRoot, vendorJs) {
let en = new TranslationPlugin( let translations = [discourseRoot + "/config/locales"].concat(
[discourseRoot + "/config/locales"], glob
"client.en.yml" .sync(discourseRoot + "/plugins/*/config/locales/client.en.yml")
.map((f) => f.replace(/\/client\.en\.yml$/, ""))
); );
let en = new TranslationPlugin(translations, "client.en.yml");
return concat( return concat(
mergeTrees([ mergeTrees([
vendorJs, vendorJs,

View File

@ -22,15 +22,16 @@
"@ember/test-helpers": "^2.2.0", "@ember/test-helpers": "^2.2.0",
"@glimmer/component": "^1.0.0", "@glimmer/component": "^1.0.0",
"@popperjs/core": "2.10.2", "@popperjs/core": "2.10.2",
"@uppy/utils": "^4.0.3",
"@uppy/aws-s3": "^2.0.4", "@uppy/aws-s3": "^2.0.4",
"@uppy/aws-s3-multipart": "^2.1.0", "@uppy/aws-s3-multipart": "^2.1.0",
"@uppy/core": "^2.1.0", "@uppy/core": "^2.1.0",
"@uppy/drop-target": "^1.1.0", "@uppy/drop-target": "^1.1.0",
"@uppy/utils": "^4.0.3",
"@uppy/xhr-upload": "^2.0.4", "@uppy/xhr-upload": "^2.0.4",
"admin": "^1.0.0", "admin": "^1.0.0",
"bent": "^7.3.12", "bent": "^7.3.12",
"broccoli-asset-rev": "^3.0.0", "broccoli-asset-rev": "^3.0.0",
"deepmerge": "^4.2.2",
"discourse-common": "^1.0.0", "discourse-common": "^1.0.0",
"discourse-hbr": "^1.0.0", "discourse-hbr": "^1.0.0",
"discourse-widget-hbs": "^1.0.0", "discourse-widget-hbs": "^1.0.0",

View File

@ -4526,6 +4526,11 @@ deep-is@^0.1.3, deep-is@~0.1.3:
resolved "https://registry.yarnpkg.com/deep-is/-/deep-is-0.1.3.tgz#b369d6fb5dbc13eecf524f91b070feedc357cf34" resolved "https://registry.yarnpkg.com/deep-is/-/deep-is-0.1.3.tgz#b369d6fb5dbc13eecf524f91b070feedc357cf34"
integrity sha1-s2nW+128E+7PUk+RsHD+7cNXzzQ= integrity sha1-s2nW+128E+7PUk+RsHD+7cNXzzQ=
deepmerge@^4.2.2:
version "4.2.2"
resolved "https://registry.yarnpkg.com/deepmerge/-/deepmerge-4.2.2.tgz#44d2ea3679b8f4d4ffba33f03d865fc1e7bf4955"
integrity sha512-FJ3UgI4gIl+PHZm53knsuSFpE+nESMr7M4v9QcgB7S63Kj/6WqMiFQJpBBYz1Pt+66bZpP3Q7Lye0Oo9MPKEdg==
defaults@^1.0.3: defaults@^1.0.3:
version "1.0.3" version "1.0.3"
resolved "https://registry.yarnpkg.com/defaults/-/defaults-1.0.3.tgz#c656051e9817d9ff08ed881477f3fe4019f3ef7d" resolved "https://registry.yarnpkg.com/defaults/-/defaults-1.0.3.tgz#c656051e9817d9ff08ed881477f3fe4019f3ef7d"