From 96c652ef08b29ee10a7f6fb5b7f0165f904de099 Mon Sep 17 00:00:00 2001 From: Michael Telatynski <7t3chguy@gmail.com> Date: Thu, 17 Aug 2023 09:37:59 +0100 Subject: [PATCH] Switch to nested object pluralisation format for i18n files (#25970) --- package.json | 2 +- scripts/copy-res.js | 45 +--------------------------------- src/i18n/strings/basefile.json | 2 +- yarn.lock | 8 +++--- 4 files changed, 7 insertions(+), 50 deletions(-) diff --git a/package.json b/package.json index d64c353697..e3c8dd67eb 100644 --- a/package.json +++ b/package.json @@ -145,7 +145,7 @@ "json-loader": "^0.5.7", "loader-utils": "^3.0.0", "matrix-mock-request": "^2.5.0", - "matrix-web-i18n": "^1.4.0", + "matrix-web-i18n": "^2.0.0", "mini-css-extract-plugin": "^1", "minimist": "^1.2.6", "mkdirp": "^3.0.0", diff --git a/scripts/copy-res.js b/scripts/copy-res.js index 5969048e6d..d713accfd1 100755 --- a/scripts/copy-res.js +++ b/scripts/copy-res.js @@ -81,7 +81,6 @@ const parseArgs = require("minimist"); const Cpx = require("cpx"); const chokidar = require("chokidar"); const fs = require("fs"); -const rimraf = require("rimraf"); const argv = parseArgs(process.argv.slice(2), {}); @@ -158,7 +157,7 @@ function genLangFile(lang, dest) { const reactSdkFile = "node_modules/matrix-react-sdk/src/i18n/strings/" + lang + ".json"; const riotWebFile = "src/i18n/strings/" + lang + ".json"; - let translations = {}; + const translations = {}; [reactSdkFile, riotWebFile].forEach(function (f) { if (fs.existsSync(f)) { try { @@ -170,8 +169,6 @@ function genLangFile(lang, dest) { } }); - translations = weblateToCounterpart(translations); - const json = JSON.stringify(translations, null, 4); const jsonBuffer = Buffer.from(json); const digest = loaderUtils.getHashDigest(jsonBuffer, null, null, 7); @@ -207,46 +204,6 @@ function genLangList(langFileMap) { } } -/** - * Convert translation key from weblate format - * (which only supports a single level) to counterpart - * which requires object values for 'count' translations. - * - * eg. - * "there are %(count)s badgers|one": "a badger", - * "there are %(count)s badgers|other": "%(count)s badgers" - * becomes - * "there are %(count)s badgers": { - * "one": "a badger", - * "other": "%(count)s badgers" - * } - */ -function weblateToCounterpart(inTrs) { - const outTrs = {}; - - for (const key of Object.keys(inTrs)) { - const keyParts = key.split("|", 2); - if (keyParts.length === 2) { - let obj = outTrs[keyParts[0]]; - if (obj === undefined) { - obj = outTrs[keyParts[0]] = {}; - } else if (typeof obj === "string") { - // This is a transitional edge case if a string went from singular to pluralised and both still remain - // in the translation json file. Use the singular translation as `other` and merge pluralisation atop. - obj = outTrs[keyParts[0]] = { - other: inTrs[key], - }; - console.warn("Found entry in i18n file in both singular and pluralised form", keyParts[0]); - } - obj[keyParts[1]] = inTrs[key]; - } else { - outTrs[key] = inTrs[key]; - } - } - - return outTrs; -} - /** watch the input files for a given language, regenerate the file, adding its content-hashed filename to langFileMap diff --git a/src/i18n/strings/basefile.json b/src/i18n/strings/basefile.json index 9e26dfeeb6..0967ef424b 100644 --- a/src/i18n/strings/basefile.json +++ b/src/i18n/strings/basefile.json @@ -1 +1 @@ -{} \ No newline at end of file +{} diff --git a/yarn.lock b/yarn.lock index 9430e26444..6bb3dbb18f 100644 --- a/yarn.lock +++ b/yarn.lock @@ -8576,10 +8576,10 @@ matrix-mock-request@^2.5.0: what-input "^5.2.10" zxcvbn "^4.4.2" -matrix-web-i18n@^1.4.0: - version "1.4.0" - resolved "https://registry.yarnpkg.com/matrix-web-i18n/-/matrix-web-i18n-1.4.0.tgz#f383a3ebc29d3fd6eb137d38cc4c3198771cc073" - integrity sha512-+NP2h4zdft+2H/6oFQ0i2PBm00Ei6HpUHke8rklgpe/yCABBG5Q7gIQdZoxazi0DXWWtcvvIfgamPZmkg6oRwA== +matrix-web-i18n@^2.0.0: + version "2.0.0" + resolved "https://registry.yarnpkg.com/matrix-web-i18n/-/matrix-web-i18n-2.0.0.tgz#fe43c9e4061410cef4b8663527ee692296ce023b" + integrity sha512-bMn4MsWKnzzfQPVAfgmlMXa1rqVS1kUuTQ//d+Zsze2hGX8pTB1y3qFLYhkgAgVcx89FxiVL7Kw9dUzllvwgOg== dependencies: "@babel/parser" "^7.18.5" "@babel/traverse" "^7.18.5"