From 095d46ea88ac1ef932922bbac8bf799297fa4a41 Mon Sep 17 00:00:00 2001 From: abose Date: Sun, 19 Jan 2025 02:24:16 +0530 Subject: [PATCH] fix: reordering of translations keys in json shouldnt cause pull request --- gulpfile.js/translateStrings.js | 26 ++++++++++++++++++++++++-- 1 file changed, 24 insertions(+), 2 deletions(-) diff --git a/gulpfile.js/translateStrings.js b/gulpfile.js/translateStrings.js index b1078a645..0cba58819 100644 --- a/gulpfile.js/translateStrings.js +++ b/gulpfile.js/translateStrings.js @@ -213,6 +213,24 @@ async function coreAiTranslate(stringsToTranslate, lang) { return translationForLanguage; } +function shallowEqual(obj1, obj2) { + // Check if both have the same number of keys: + const keys1 = Object.keys(obj1); + const keys2 = Object.keys(obj2); + if (keys1.length !== keys2.length) { + return false; + } + + // Check if all corresponding values match: + for (const key of keys1) { + if (obj1[key] !== obj2[key]) { + return false; + } + } + + return true; +} + /** * Auto translations scans the following files to determine which strings have changed and needs to be translated: * 1. nls//lastTranslated.json holds the last root english strings that was automatically translated. This will be @@ -304,8 +322,12 @@ async function _processLang(lang) { let translatedStringsJSON = JSON.stringify(translations, null, 2); let fileToWrite = `${FILE_HEADER}${translatedStringsJSON}${FILE_FOOTER}`; - fs.writeFileSync(`src/nls/${lang}/strings.js`, fileToWrite); - fs.writeFileSync(`src/nls/${lang}/lastTranslated.json`, JSON.stringify(updatedLastTranslatedJSON, null, 2)); + if(!shallowEqual(translations, localeStringsJS)){ + fs.writeFileSync(`src/nls/${lang}/strings.js`, fileToWrite); + } + if(!shallowEqual(updatedLastTranslatedJSON, lastTranslated)){ + fs.writeFileSync(`src/nls/${lang}/lastTranslated.json`, JSON.stringify(updatedLastTranslatedJSON, null, 2)); + } } async function translate() {