Skip to content

Commit

Permalink
fix: reordering of translations keys in json shouldnt cause pull request
Browse files Browse the repository at this point in the history
  • Loading branch information
abose committed Jan 18, 2025
1 parent fd93b77 commit 095d46e
Showing 1 changed file with 24 additions and 2 deletions.
26 changes: 24 additions & 2 deletions gulpfile.js/translateStrings.js
Original file line number Diff line number Diff line change
Expand Up @@ -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/<lang>/lastTranslated.json holds the last root english strings that was automatically translated. This will be
Expand Down Expand Up @@ -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() {
Expand Down

0 comments on commit 095d46e

Please sign in to comment.