mirror of
https://github.com/sharevb/it-tools.git
synced 2026-11-20 21:23:08 +03:00
fix(Scripts): remove target languages unused + keep line break
This commit is contained in:
1 parent
3ba3b222ad
commit
8a89a78830
1 file changed
+14
-1
@@ -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;
|
||||
|
||||
Reference in new issue
Block a user