Skip to content

Commit 84833ec

Browse files
committed
fix: sorting last translated json for it to be eazier to review in pull req
1 parent 095d46e commit 84833ec

File tree

1 file changed

+18
-1
lines changed

1 file changed

+18
-1
lines changed

gulpfile.js/translateStrings.js

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -231,6 +231,22 @@ function shallowEqual(obj1, obj2) {
231231
return true;
232232
}
233233

234+
/**
235+
* Returns a new object whose keys are sorted in ascending order.
236+
*
237+
* @param {Object} obj - The object to sort by keys.
238+
* @returns {Object} sortedObj - A new object with sorted keys.
239+
*/
240+
function getSortedObject(obj) {
241+
const sortedObj = {};
242+
// Gather all keys, sort them, then build the new object in that order
243+
const sortedKeys = Object.keys(obj).sort();
244+
for (const key of sortedKeys) {
245+
sortedObj[key] = obj[key];
246+
}
247+
return sortedObj;
248+
}
249+
234250
/**
235251
* Auto translations scans the following files to determine which strings have changed and needs to be translated:
236252
* 1. nls/<lang>/lastTranslated.json holds the last root english strings that was automatically translated. This will be
@@ -326,7 +342,8 @@ async function _processLang(lang) {
326342
fs.writeFileSync(`src/nls/${lang}/strings.js`, fileToWrite);
327343
}
328344
if(!shallowEqual(updatedLastTranslatedJSON, lastTranslated)){
329-
fs.writeFileSync(`src/nls/${lang}/lastTranslated.json`, JSON.stringify(updatedLastTranslatedJSON, null, 2));
345+
const sortedList = getSortedObject(updatedLastTranslatedJSON);
346+
fs.writeFileSync(`src/nls/${lang}/lastTranslated.json`, JSON.stringify(sortedList, null, 2));
330347
}
331348
}
332349

0 commit comments

Comments
 (0)