From c27e324bd1cafa627e196c36ce669bd29c15f543 Mon Sep 17 00:00:00 2001 From: Robin Ward Date: Wed, 24 Nov 2021 14:51:23 -0500 Subject: [PATCH] FEATURE: Support i18n in Ember CLI plugin tests --- .../discourse/lib/translation-plugin.js | 21 +++++++++++++------ app/assets/javascripts/discourse/package.json | 3 ++- app/assets/javascripts/yarn.lock | 5 +++++ 3 files changed, 22 insertions(+), 7 deletions(-) diff --git a/app/assets/javascripts/discourse/lib/translation-plugin.js b/app/assets/javascripts/discourse/lib/translation-plugin.js index ca907b69dd2..0fb923c52ed 100644 --- a/app/assets/javascripts/discourse/lib/translation-plugin.js +++ b/app/assets/javascripts/discourse/lib/translation-plugin.js @@ -4,6 +4,8 @@ const fs = require("fs"); const concat = require("broccoli-concat"); const mergeTrees = require("broccoli-merge-trees"); const MessageFormat = require("messageformat"); +const deepmerge = require("deepmerge"); +const glob = require("glob"); let built = false; @@ -40,10 +42,14 @@ class TranslationPlugin extends Plugin { return; } - let file = this.inputPaths[0] + "/" + this.inputFile; + let parsed = {}; - let yaml = fs.readFileSync(file, { encoding: "UTF-8" }); - let parsed = Yaml.load(yaml); + this.inputPaths.forEach((path) => { + let file = path + "/" + this.inputFile; + let yaml = fs.readFileSync(file, { encoding: "UTF-8" }); + let loaded = Yaml.load(yaml); + parsed = deepmerge(parsed, loaded); + }); let extras = { en: { @@ -82,11 +88,14 @@ module.exports = function translatePlugin(...params) { }; module.exports.createI18nTree = function (discourseRoot, vendorJs) { - let en = new TranslationPlugin( - [discourseRoot + "/config/locales"], - "client.en.yml" + let translations = [discourseRoot + "/config/locales"].concat( + glob + .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( mergeTrees([ vendorJs, diff --git a/app/assets/javascripts/discourse/package.json b/app/assets/javascripts/discourse/package.json index a294e751173..c3886f25b21 100644 --- a/app/assets/javascripts/discourse/package.json +++ b/app/assets/javascripts/discourse/package.json @@ -22,15 +22,16 @@ "@ember/test-helpers": "^2.2.0", "@glimmer/component": "^1.0.0", "@popperjs/core": "2.10.2", - "@uppy/utils": "^4.0.3", "@uppy/aws-s3": "^2.0.4", "@uppy/aws-s3-multipart": "^2.1.0", "@uppy/core": "^2.1.0", "@uppy/drop-target": "^1.1.0", + "@uppy/utils": "^4.0.3", "@uppy/xhr-upload": "^2.0.4", "admin": "^1.0.0", "bent": "^7.3.12", "broccoli-asset-rev": "^3.0.0", + "deepmerge": "^4.2.2", "discourse-common": "^1.0.0", "discourse-hbr": "^1.0.0", "discourse-widget-hbs": "^1.0.0", diff --git a/app/assets/javascripts/yarn.lock b/app/assets/javascripts/yarn.lock index 2d0667d1766..9c5b9bd4181 100644 --- a/app/assets/javascripts/yarn.lock +++ b/app/assets/javascripts/yarn.lock @@ -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" 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: version "1.0.3" resolved "https://registry.yarnpkg.com/defaults/-/defaults-1.0.3.tgz#c656051e9817d9ff08ed881477f3fe4019f3ef7d"