From 8a89a78830205209bc78dbf3828388c83a100826 Mon Sep 17 00:00:00 2001 From: ShareVB Date: Sun, 19 Oct 2025 21:32:01 +0200 Subject: [PATCH] fix(Scripts): remove target languages unused + keep line break --- scripts/translate-missings.mjs | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/scripts/translate-missings.mjs b/scripts/translate-missings.mjs index e7cb55d7..1185ec7b 100644 --- a/scripts/translate-missings.mjs +++ b/scripts/translate-missings.mjs @@ -26,12 +26,25 @@ program const options = program.opts(); +function removeUnusedKeys(targetFlat, englishFlat) { + const cleaned = {}; + for (const key of Object.keys(targetFlat)) { + if (englishFlat[key] !== undefined) { + cleaned[key] = targetFlat[key]; + } else { + console.log(`Removed unused key: ${key}`); + } + } + return cleaned; +} + async function translateText(text, targetLang) { const response = await axios.post(TRANSLATE_ENDPOINT, null, { params: { q: text, target: targetLang, key: GOOGLE_TRANSLATE_API_KEY, + format: 'text', }, }); return response.data.data.translations[0].translatedText @@ -80,7 +93,7 @@ async function syncTranslations(englishFile, targetFiles, dryRun = false) { continue; } const targetYaml = yaml.parse(await fs.readFile(file, 'utf8')) || {}; - const targetFlat = flattenYaml(targetYaml); + const targetFlat = removeUnusedKeys(flattenYaml(targetYaml), englishFlat); const updatedFlat = { ...targetFlat }; let langCharCount = 0;