From b3ef2c179a376d2142ae484b4606a84aec1967ac Mon Sep 17 00:00:00 2001 From: Michael Telatynski <7t3chguy@gmail.com> Date: Tue, 17 May 2022 17:44:30 +0100 Subject: [PATCH] Update weblateToCounterpart to be more resilient (#22247) * Update i18n check CI to ignore RiotTranslateBot * Update `weblateToCounterpart` to be more resilient --- .github/workflows/static_analysis.yaml | 5 ++++- scripts/copy-res.js | 10 ++++++++-- 2 files changed, 12 insertions(+), 3 deletions(-) diff --git a/.github/workflows/static_analysis.yaml b/.github/workflows/static_analysis.yaml index 93f83956eb..d191ecd6b1 100644 --- a/.github/workflows/static_analysis.yaml +++ b/.github/workflows/static_analysis.yaml @@ -44,7 +44,10 @@ jobs: files_ignore: | src/i18n/strings/en_EN.json - name: "Assert only en_EN was modified" - if: github.event_name == 'pull_request' && steps.changed_files.outputs.any_modified == 'true' + if: | + github.event_name == 'pull_request' && + github.actor != 'RiotTranslateBot' && + steps.changed_files.outputs.any_modified == 'true' run: | echo "You can only modify en_EN.json, do not touch any of the other i18n files as Weblate will be confused" exit 1 diff --git a/scripts/copy-res.js b/scripts/copy-res.js index 8d91092fdb..58a9885134 100755 --- a/scripts/copy-res.js +++ b/scripts/copy-res.js @@ -232,8 +232,14 @@ function weblateToCounterpart(inTrs) { if (keyParts.length === 2) { let obj = outTrs[keyParts[0]]; if (obj === undefined) { - obj = {}; - outTrs[keyParts[0]] = obj; + 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 {