@@ -213,6 +213,24 @@ async function coreAiTranslate(stringsToTranslate, lang) {
213213 return translationForLanguage ;
214214}
215215
216+ function shallowEqual ( obj1 , obj2 ) {
217+ // Check if both have the same number of keys:
218+ const keys1 = Object . keys ( obj1 ) ;
219+ const keys2 = Object . keys ( obj2 ) ;
220+ if ( keys1 . length !== keys2 . length ) {
221+ return false ;
222+ }
223+
224+ // Check if all corresponding values match:
225+ for ( const key of keys1 ) {
226+ if ( obj1 [ key ] !== obj2 [ key ] ) {
227+ return false ;
228+ }
229+ }
230+
231+ return true ;
232+ }
233+
216234/**
217235 * Auto translations scans the following files to determine which strings have changed and needs to be translated:
218236 * 1. nls/<lang>/lastTranslated.json holds the last root english strings that was automatically translated. This will be
@@ -304,8 +322,12 @@ async function _processLang(lang) {
304322
305323 let translatedStringsJSON = JSON . stringify ( translations , null , 2 ) ;
306324 let fileToWrite = `${ FILE_HEADER } ${ translatedStringsJSON } ${ FILE_FOOTER } ` ;
307- fs . writeFileSync ( `src/nls/${ lang } /strings.js` , fileToWrite ) ;
308- fs . writeFileSync ( `src/nls/${ lang } /lastTranslated.json` , JSON . stringify ( updatedLastTranslatedJSON , null , 2 ) ) ;
325+ if ( ! shallowEqual ( translations , localeStringsJS ) ) {
326+ fs . writeFileSync ( `src/nls/${ lang } /strings.js` , fileToWrite ) ;
327+ }
328+ if ( ! shallowEqual ( updatedLastTranslatedJSON , lastTranslated ) ) {
329+ fs . writeFileSync ( `src/nls/${ lang } /lastTranslated.json` , JSON . stringify ( updatedLastTranslatedJSON , null , 2 ) ) ;
330+ }
309331}
310332
311333async function translate ( ) {
0 commit comments