Skip to content

Commit 8a89a78

Browse files
committed
fix(Scripts): remove target languages unused + keep line break
1 parent 3ba3b22 commit 8a89a78

File tree

1 file changed

+14
-1
lines changed

1 file changed

+14
-1
lines changed

scripts/translate-missings.mjs

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,12 +26,25 @@ program
2626

2727
const options = program.opts();
2828

29+
function removeUnusedKeys(targetFlat, englishFlat) {
30+
const cleaned = {};
31+
for (const key of Object.keys(targetFlat)) {
32+
if (englishFlat[key] !== undefined) {
33+
cleaned[key] = targetFlat[key];
34+
} else {
35+
console.log(`Removed unused key: ${key}`);
36+
}
37+
}
38+
return cleaned;
39+
}
40+
2941
async function translateText(text, targetLang) {
3042
const response = await axios.post(TRANSLATE_ENDPOINT, null, {
3143
params: {
3244
q: text,
3345
target: targetLang,
3446
key: GOOGLE_TRANSLATE_API_KEY,
47+
format: 'text',
3548
},
3649
});
3750
return response.data.data.translations[0].translatedText
@@ -80,7 +93,7 @@ async function syncTranslations(englishFile, targetFiles, dryRun = false) {
8093
continue;
8194
}
8295
const targetYaml = yaml.parse(await fs.readFile(file, 'utf8')) || {};
83-
const targetFlat = flattenYaml(targetYaml);
96+
const targetFlat = removeUnusedKeys(flattenYaml(targetYaml), englishFlat);
8497

8598
const updatedFlat = { ...targetFlat };
8699
let langCharCount = 0;

0 commit comments

Comments
 (0)