mirror of
https://github.com/sharevb/it-tools.git
synced 2026-11-21 21:44:40 +03:00
fix(Scripts): translate only if missing + handle '
This commit is contained in:
1 parent
aab0e2eb18
commit
7516aae2c1
1 file changed
+3
-2
@@ -34,7 +34,8 @@ async function translateText(text, targetLang) {
|
|||||||
key: GOOGLE_TRANSLATE_API_KEY,
|
key: GOOGLE_TRANSLATE_API_KEY,
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
return response.data.data.translations[0].translatedText;
|
return response.data.data.translations[0].translatedText
|
||||||
|
.replace(/\{'/, '{\'').replace(/'\}/, '}\'');
|
||||||
}
|
}
|
||||||
|
|
||||||
function flattenYaml(obj, prefix = '') {
|
function flattenYaml(obj, prefix = '') {
|
||||||
@@ -85,7 +86,7 @@ async function syncTranslations(englishFile, targetFiles, dryRun = false) {
|
|||||||
let langCharCount = 0;
|
let langCharCount = 0;
|
||||||
|
|
||||||
for (const [key, englishText] of Object.entries(englishFlat)) {
|
for (const [key, englishText] of Object.entries(englishFlat)) {
|
||||||
const needsTranslation = !targetFlat[key] || targetFlat[key] === englishText;
|
const needsTranslation = !targetFlat[key];
|
||||||
if (needsTranslation) {
|
if (needsTranslation) {
|
||||||
if (dryRun) {
|
if (dryRun) {
|
||||||
langCharCount += englishText.length;
|
langCharCount += englishText.length;
|
||||||
|
|||||||
Reference in new issue
Block a user