@el-j/google-sheet-translations 2.1.1 → 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
@@ -773,6 +773,9 @@ function isDataJsonNewer(dataJsonPath, translationsOutputDir) {
773
773
  if (!mostRecentTranslationMtime) return true;
774
774
  return dataJsonMtime > mostRecentTranslationMtime;
775
775
  } catch (error) {
776
+ if (error.code === "ENOENT") {
777
+ return true;
778
+ }
776
779
  console.warn("Error comparing file modification times:", error);
777
780
  return false;
778
781
  }
@@ -830,6 +833,20 @@ function readDataJson(dataJsonPath) {
830
833
  }
831
834
 
832
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
+ }
833
850
  async function handleBidirectionalSync(doc, dataJsonPath, translationsOutputDir, syncLocalChanges, autoTranslate, spreadsheetData, waitSeconds, localeMapping = {}, override = false, cleanPush = false) {
834
851
  const result = {
835
852
  shouldRefresh: false,
@@ -837,12 +854,15 @@ async function handleBidirectionalSync(doc, dataJsonPath, translationsOutputDir,
837
854
  };
838
855
  const localData = readDataJson(dataJsonPath);
839
856
  const dataJsonExists = localData !== null;
840
- const shouldSyncToSheet = dataJsonExists && (cleanPush || syncLocalChanges && isDataJsonNewer(dataJsonPath, translationsOutputDir));
857
+ const hasMissingSheets = syncLocalChanges && localData !== null && hasSheetsMissingFromSpreadsheet(localData, spreadsheetData);
858
+ const shouldSyncToSheet = dataJsonExists && (cleanPush || syncLocalChanges && isDataJsonNewer(dataJsonPath, translationsOutputDir) || hasMissingSheets);
841
859
  if (!shouldSyncToSheet || !localData) {
842
860
  return result;
843
861
  }
844
862
  if (cleanPush) {
845
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...");
846
866
  } else {
847
867
  console.log("Local languageData.json is newer than translation files. Checking for changes...");
848
868
  }
package/dist/index.js CHANGED
@@ -838,6 +838,9 @@ function isDataJsonNewer(dataJsonPath, translationsOutputDir) {
838
838
  if (!mostRecentTranslationMtime) return true;
839
839
  return dataJsonMtime > mostRecentTranslationMtime;
840
840
  } catch (error) {
841
+ if (error.code === "ENOENT") {
842
+ return true;
843
+ }
841
844
  console.warn("Error comparing file modification times:", error);
842
845
  return false;
843
846
  }
@@ -895,6 +898,20 @@ function readDataJson(dataJsonPath) {
895
898
  }
896
899
 
897
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
+ }
898
915
  async function handleBidirectionalSync(doc, dataJsonPath, translationsOutputDir, syncLocalChanges, autoTranslate, spreadsheetData, waitSeconds, localeMapping = {}, override = false, cleanPush = false) {
899
916
  const result = {
900
917
  shouldRefresh: false,
@@ -902,12 +919,15 @@ async function handleBidirectionalSync(doc, dataJsonPath, translationsOutputDir,
902
919
  };
903
920
  const localData = readDataJson(dataJsonPath);
904
921
  const dataJsonExists = localData !== null;
905
- const shouldSyncToSheet = dataJsonExists && (cleanPush || syncLocalChanges && isDataJsonNewer(dataJsonPath, translationsOutputDir));
922
+ const hasMissingSheets = syncLocalChanges && localData !== null && hasSheetsMissingFromSpreadsheet(localData, spreadsheetData);
923
+ const shouldSyncToSheet = dataJsonExists && (cleanPush || syncLocalChanges && isDataJsonNewer(dataJsonPath, translationsOutputDir) || hasMissingSheets);
906
924
  if (!shouldSyncToSheet || !localData) {
907
925
  return result;
908
926
  }
909
927
  if (cleanPush) {
910
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...");
911
931
  } else {
912
932
  console.log("Local languageData.json is newer than translation files. Checking for changes...");
913
933
  }
@@ -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,CA2B5F"}
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;AAMhD;;GAEG;AACH,MAAM,WAAW,UAAU;IAC1B,aAAa,EAAE,OAAO,CAAC;IACvB,UAAU,EAAE,OAAO,CAAC;CACpB;AAED;;;;;;;;;;;;;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,CA4DrB"}
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.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
  }