diff --git a/package.json b/package.json index 8649c44..0f145ad 100644 --- a/package.json +++ b/package.json @@ -105,7 +105,7 @@ "fs-extra": "^11.0.0", "glob": "^10.0.0", "jest": "^29.0.0", - "matrix-web-i18n": "^1.3.0", + "matrix-web-i18n": "^2.0.0", "mkdirp": "^3.0.0", "node-pre-gyp": "^0.17.0", "pacote": "^15.0.0", diff --git a/scripts/copy-res.ts b/scripts/copy-res.ts index 913e9cf..67af7ab 100755 --- a/scripts/copy-res.ts +++ b/scripts/copy-res.ts @@ -28,11 +28,11 @@ fs.mkdirSync("lib/i18n/strings", { recursive: true }); type Translations = Record | string>; function genLangFile(file: string, dest: string): void { - const inTrs: Record = {}; + const translations: Translations = {}; [file].forEach(function (f) { if (fs.existsSync(f)) { try { - Object.assign(inTrs, JSON.parse(fs.readFileSync(f).toString())); + Object.assign(translations, JSON.parse(fs.readFileSync(f).toString())); } catch (e) { console.error("Failed: " + f, e); throw e; @@ -40,7 +40,6 @@ function genLangFile(file: string, dest: string): void { } }); - const translations = weblateToCounterpart(inTrs); const json = JSON.stringify(translations, null, 4); const filename = path.basename(file); @@ -50,46 +49,6 @@ function genLangFile(file: string, dest: string): void { } } -/* - * 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: Record): Translations { - const outTrs: Translations = {}; - - 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, and regenerating languages.json with the new filename diff --git a/src/i18n/strings/basefile.json b/src/i18n/strings/basefile.json index 9e26dfe..0967ef4 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 9a842bd..4ccc3db 100644 --- a/yarn.lock +++ b/yarn.lock @@ -5564,10 +5564,10 @@ matcher@^3.0.0: dependencies: escape-string-regexp "^4.0.0" -matrix-web-i18n@^1.3.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"