@el-j/google-sheet-translations 2.1.0 → 2.1.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/esm/index.js
CHANGED
|
@@ -394,11 +394,8 @@ function convertToDataJsonFormat(translationObj, locales) {
|
|
|
394
394
|
projectData[sheetTitle] = {};
|
|
395
395
|
for (const locale of locales) {
|
|
396
396
|
if (translationObj?.[locale]?.[sheetTitle]) {
|
|
397
|
-
projectData[sheetTitle][locale] = {};
|
|
398
397
|
const translations = translationObj[locale][sheetTitle];
|
|
399
|
-
|
|
400
|
-
projectData[sheetTitle][locale][key] = translations[key];
|
|
401
|
-
}
|
|
398
|
+
projectData[sheetTitle][locale] = { ...translations };
|
|
402
399
|
console.log(
|
|
403
400
|
`Found ${Object.keys(translations).length} keys for locale ${locale} in sheet ${sheetTitle}`
|
|
404
401
|
);
|
|
@@ -776,6 +773,9 @@ function isDataJsonNewer(dataJsonPath, translationsOutputDir) {
|
|
|
776
773
|
if (!mostRecentTranslationMtime) return true;
|
|
777
774
|
return dataJsonMtime > mostRecentTranslationMtime;
|
|
778
775
|
} catch (error) {
|
|
776
|
+
if (error.code === "ENOENT") {
|
|
777
|
+
return true;
|
|
778
|
+
}
|
|
779
779
|
console.warn("Error comparing file modification times:", error);
|
|
780
780
|
return false;
|
|
781
781
|
}
|
|
@@ -833,6 +833,20 @@ function readDataJson(dataJsonPath) {
|
|
|
833
833
|
}
|
|
834
834
|
|
|
835
835
|
// src/utils/syncManager.ts
|
|
836
|
+
function hasSheetsMissingFromSpreadsheet(localData, spreadsheetData) {
|
|
837
|
+
const spreadsheetLocales = Object.keys(spreadsheetData);
|
|
838
|
+
for (const locale of Object.keys(localData)) {
|
|
839
|
+
if (!localData[locale]) continue;
|
|
840
|
+
const resolvedLocale = resolveLocaleWithFallback(locale, spreadsheetLocales);
|
|
841
|
+
for (const sheet of Object.keys(localData[locale])) {
|
|
842
|
+
if (sheet === I18N_SHEET_NAME) continue;
|
|
843
|
+
if (!resolvedLocale || !spreadsheetData[resolvedLocale]?.[sheet]) {
|
|
844
|
+
return true;
|
|
845
|
+
}
|
|
846
|
+
}
|
|
847
|
+
}
|
|
848
|
+
return false;
|
|
849
|
+
}
|
|
836
850
|
async function handleBidirectionalSync(doc, dataJsonPath, translationsOutputDir, syncLocalChanges, autoTranslate, spreadsheetData, waitSeconds, localeMapping = {}, override = false, cleanPush = false) {
|
|
837
851
|
const result = {
|
|
838
852
|
shouldRefresh: false,
|
|
@@ -840,12 +854,15 @@ async function handleBidirectionalSync(doc, dataJsonPath, translationsOutputDir,
|
|
|
840
854
|
};
|
|
841
855
|
const localData = readDataJson(dataJsonPath);
|
|
842
856
|
const dataJsonExists = localData !== null;
|
|
843
|
-
const
|
|
857
|
+
const hasMissingSheets = syncLocalChanges && localData !== null && hasSheetsMissingFromSpreadsheet(localData, spreadsheetData);
|
|
858
|
+
const shouldSyncToSheet = dataJsonExists && (cleanPush || syncLocalChanges && isDataJsonNewer(dataJsonPath, translationsOutputDir) || hasMissingSheets);
|
|
844
859
|
if (!shouldSyncToSheet || !localData) {
|
|
845
860
|
return result;
|
|
846
861
|
}
|
|
847
862
|
if (cleanPush) {
|
|
848
863
|
console.log("Clean push enabled \u2013 pushing ALL keys from languageData.json to the spreadsheet...");
|
|
864
|
+
} else if (hasMissingSheets) {
|
|
865
|
+
console.log("Spreadsheet is missing one or more local sheets. Syncing missing sheets...");
|
|
849
866
|
} else {
|
|
850
867
|
console.log("Local languageData.json is newer than translation files. Checking for changes...");
|
|
851
868
|
}
|
package/dist/index.js
CHANGED
|
@@ -459,11 +459,8 @@ function convertToDataJsonFormat(translationObj, locales) {
|
|
|
459
459
|
projectData[sheetTitle] = {};
|
|
460
460
|
for (const locale of locales) {
|
|
461
461
|
if (translationObj?.[locale]?.[sheetTitle]) {
|
|
462
|
-
projectData[sheetTitle][locale] = {};
|
|
463
462
|
const translations = translationObj[locale][sheetTitle];
|
|
464
|
-
|
|
465
|
-
projectData[sheetTitle][locale][key] = translations[key];
|
|
466
|
-
}
|
|
463
|
+
projectData[sheetTitle][locale] = { ...translations };
|
|
467
464
|
console.log(
|
|
468
465
|
`Found ${Object.keys(translations).length} keys for locale ${locale} in sheet ${sheetTitle}`
|
|
469
466
|
);
|
|
@@ -841,6 +838,9 @@ function isDataJsonNewer(dataJsonPath, translationsOutputDir) {
|
|
|
841
838
|
if (!mostRecentTranslationMtime) return true;
|
|
842
839
|
return dataJsonMtime > mostRecentTranslationMtime;
|
|
843
840
|
} catch (error) {
|
|
841
|
+
if (error.code === "ENOENT") {
|
|
842
|
+
return true;
|
|
843
|
+
}
|
|
844
844
|
console.warn("Error comparing file modification times:", error);
|
|
845
845
|
return false;
|
|
846
846
|
}
|
|
@@ -898,6 +898,20 @@ function readDataJson(dataJsonPath) {
|
|
|
898
898
|
}
|
|
899
899
|
|
|
900
900
|
// src/utils/syncManager.ts
|
|
901
|
+
function hasSheetsMissingFromSpreadsheet(localData, spreadsheetData) {
|
|
902
|
+
const spreadsheetLocales = Object.keys(spreadsheetData);
|
|
903
|
+
for (const locale of Object.keys(localData)) {
|
|
904
|
+
if (!localData[locale]) continue;
|
|
905
|
+
const resolvedLocale = resolveLocaleWithFallback(locale, spreadsheetLocales);
|
|
906
|
+
for (const sheet of Object.keys(localData[locale])) {
|
|
907
|
+
if (sheet === I18N_SHEET_NAME) continue;
|
|
908
|
+
if (!resolvedLocale || !spreadsheetData[resolvedLocale]?.[sheet]) {
|
|
909
|
+
return true;
|
|
910
|
+
}
|
|
911
|
+
}
|
|
912
|
+
}
|
|
913
|
+
return false;
|
|
914
|
+
}
|
|
901
915
|
async function handleBidirectionalSync(doc, dataJsonPath, translationsOutputDir, syncLocalChanges, autoTranslate, spreadsheetData, waitSeconds, localeMapping = {}, override = false, cleanPush = false) {
|
|
902
916
|
const result = {
|
|
903
917
|
shouldRefresh: false,
|
|
@@ -905,12 +919,15 @@ async function handleBidirectionalSync(doc, dataJsonPath, translationsOutputDir,
|
|
|
905
919
|
};
|
|
906
920
|
const localData = readDataJson(dataJsonPath);
|
|
907
921
|
const dataJsonExists = localData !== null;
|
|
908
|
-
const
|
|
922
|
+
const hasMissingSheets = syncLocalChanges && localData !== null && hasSheetsMissingFromSpreadsheet(localData, spreadsheetData);
|
|
923
|
+
const shouldSyncToSheet = dataJsonExists && (cleanPush || syncLocalChanges && isDataJsonNewer(dataJsonPath, translationsOutputDir) || hasMissingSheets);
|
|
909
924
|
if (!shouldSyncToSheet || !localData) {
|
|
910
925
|
return result;
|
|
911
926
|
}
|
|
912
927
|
if (cleanPush) {
|
|
913
928
|
console.log("Clean push enabled \u2013 pushing ALL keys from languageData.json to the spreadsheet...");
|
|
929
|
+
} else if (hasMissingSheets) {
|
|
930
|
+
console.log("Spreadsheet is missing one or more local sheets. Syncing missing sheets...");
|
|
914
931
|
} else {
|
|
915
932
|
console.log("Local languageData.json is newer than translation files. Checking for changes...");
|
|
916
933
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"convertToDataJsonFormat.d.ts","sourceRoot":"","sources":["../../../src/utils/dataConverter/convertToDataJsonFormat.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,eAAe,EAAoB,MAAM,aAAa,CAAC;AAErE;;;;;GAKG;AACH,wBAAgB,uBAAuB,CACtC,cAAc,EAAE,eAAe,EAC/B,OAAO,EAAE,MAAM,EAAE,GACf,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,EAAE,
|
|
1
|
+
{"version":3,"file":"convertToDataJsonFormat.d.ts","sourceRoot":"","sources":["../../../src/utils/dataConverter/convertToDataJsonFormat.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,eAAe,EAAoB,MAAM,aAAa,CAAC;AAErE;;;;;GAKG;AACH,wBAAgB,uBAAuB,CACtC,cAAc,EAAE,eAAe,EAC/B,OAAO,EAAE,MAAM,EAAE,GACf,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,EAAE,CAmD3B;AAED,eAAe,uBAAuB,CAAC"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"isDataJsonNewer.d.ts","sourceRoot":"","sources":["../../src/utils/isDataJsonNewer.ts"],"names":[],"mappings":"AAIA;;;;;GAKG;AACH,wBAAgB,eAAe,CAAC,YAAY,EAAE,MAAM,EAAE,qBAAqB,EAAE,MAAM,GAAG,OAAO,
|
|
1
|
+
{"version":3,"file":"isDataJsonNewer.d.ts","sourceRoot":"","sources":["../../src/utils/isDataJsonNewer.ts"],"names":[],"mappings":"AAIA;;;;;GAKG;AACH,wBAAgB,eAAe,CAAC,YAAY,EAAE,MAAM,EAAE,qBAAqB,EAAE,MAAM,GAAG,OAAO,CAgC5F"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"syncManager.d.ts","sourceRoot":"","sources":["../../src/utils/syncManager.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,oBAAoB,CAAC;AAC5D,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,UAAU,CAAC;
|
|
1
|
+
{"version":3,"file":"syncManager.d.ts","sourceRoot":"","sources":["../../src/utils/syncManager.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,oBAAoB,CAAC;AAC5D,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,UAAU,CAAC;AAQhD;;GAEG;AACH,MAAM,WAAW,UAAU;IAC1B,aAAa,EAAE,OAAO,CAAC;IACvB,UAAU,EAAE,OAAO,CAAC;CACpB;AA2BD;;;;;;;;;;;;;GAaG;AACH,wBAAsB,uBAAuB,CAC5C,GAAG,EAAE,iBAAiB,EACtB,YAAY,EAAE,MAAM,EACpB,qBAAqB,EAAE,MAAM,EAC7B,gBAAgB,EAAE,OAAO,EACzB,aAAa,EAAE,OAAO,EACtB,eAAe,EAAE,eAAe,EAChC,WAAW,EAAE,MAAM,EACnB,aAAa,GAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAM,EAC1C,QAAQ,UAAQ,EAChB,SAAS,UAAQ,GACf,OAAO,CAAC,UAAU,CAAC,CA2ErB"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@el-j/google-sheet-translations",
|
|
3
|
-
"version": "2.1.
|
|
3
|
+
"version": "2.1.2",
|
|
4
4
|
"description": "A package to manage translations stored in Google Spreadsheets",
|
|
5
5
|
"main": "dist/index.js",
|
|
6
6
|
"module": "dist/esm/index.js",
|
|
@@ -97,6 +97,9 @@
|
|
|
97
97
|
"overrides": {
|
|
98
98
|
"google-spreadsheet": {
|
|
99
99
|
"google-auth-library": "^10.6.1"
|
|
100
|
+
},
|
|
101
|
+
"vite": {
|
|
102
|
+
"esbuild": "^0.25.0"
|
|
100
103
|
}
|
|
101
104
|
}
|
|
102
105
|
}
|