@el-j/google-sheet-translations 2.1.4 → 2.1.5-beta.1

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/README.md CHANGED
@@ -245,18 +245,19 @@ When enabled, the auto-translation feature automatically adds Google Translate f
245
245
 
246
246
  The formula follows this format:
247
247
  ```
248
- =GOOGLETRANSLATE(INDIRECT(sourceColumn&ROW());$sourceColumn$1;targetColumn$1)
248
+ =GOOGLETRANSLATE(INDIRECT(srcCol&ROW()); langCodeFormula($srcCol$1); langCodeFormula(tgtCol$1))
249
249
  ```
250
250
 
251
- For example, if you add a new key with an English translation in column B but no German translation in column C, the system will automatically add:
251
+ The `langCodeFormula` dynamically extracts the GOOGLETRANSLATE-compatible language code from the header cell stripping region qualifiers (e.g. `"tr-TR"` `"tr"`) while preserving Chinese variants (`zh-TW` / `zh-CN`). All formula separators are automatically matched to the spreadsheet's locale.
252
+
253
+ For example, if you add a new key with an English translation in column B but no Turkish translation (header `tr-TR`) in column C, the system will automatically add:
252
254
  ```
253
- =GOOGLETRANSLATE(INDIRECT("B"&ROW());$B$1;C$1)
255
+ =GOOGLETRANSLATE(INDIRECT("B"&ROW());IF(LOWER(LEFT($B$1;3))="zh-";LOWER($B$1);LOWER(IFERROR(LEFT($B$1;FIND("-";$B$1)-1);$B$1)));IF(LOWER(LEFT(C$1;3))="zh-";LOWER(C$1);LOWER(IFERROR(LEFT(C$1;FIND("-";C$1)-1);C$1))))
254
256
  ```
255
257
 
256
258
  Where:
257
259
  - `INDIRECT("B"&ROW())` dynamically references the source text cell in the same row
258
- - `$B$1` references the header cell containing the source language code
259
- - `C$1` references the header cell containing the target language code
260
+ - Each `IF(…)` wrapper extracts the language code from the header cell (`$B$1` / `C$1`), producing `"en"` and `"tr"` respectively at evaluation time
260
261
 
261
262
  [View the complete Auto-Translation Guide](docs/auto-translation-guide.md) for more details and best practices.
262
263
 
package/dist/esm/index.js CHANGED
@@ -169,6 +169,14 @@ function filterValidLocales(headerRow, keyColumn) {
169
169
  function getLanguagePrefix(locale) {
170
170
  return locale.toLowerCase().split(/[-_]/)[0];
171
171
  }
172
+ var GOOGLE_TRANSLATE_CODES_REQUIRING_REGION = /* @__PURE__ */ new Set(["zh-tw", "zh-cn"]);
173
+ function getGoogleTranslateCode(locale) {
174
+ const normalized = locale.toLowerCase().trim().replace("_", "-");
175
+ if (GOOGLE_TRANSLATE_CODES_REQUIRING_REGION.has(normalized)) {
176
+ return normalized;
177
+ }
178
+ return normalized.split(/[-_]/)[0];
179
+ }
172
180
  var LANGUAGE_TO_COUNTRY_MAP = {
173
181
  "en": "en-GB",
174
182
  "de": "de-DE",
@@ -531,12 +539,23 @@ function columnIndexToLetter(index) {
531
539
  } while (i >= 0);
532
540
  return result;
533
541
  }
534
- function langCodeFormula(cellRef) {
535
- return `LOWER(IFERROR(LEFT(${cellRef},FIND("-",${cellRef})-1),${cellRef}))`;
542
+ function getFormulaSeparator(doc) {
543
+ try {
544
+ const locale = doc._rawProperties?.locale || "";
545
+ if (/^(en|ja|ko|zh|th|id|ms)/i.test(locale)) return ",";
546
+ } catch {
547
+ }
548
+ return ";";
549
+ }
550
+ function langCodeFormula(cellRef, sep) {
551
+ const prefix = `LOWER(IFERROR(LEFT(${cellRef}${sep}FIND("-"${sep}${cellRef})-1)${sep}${cellRef}))`;
552
+ const full = `LOWER(${cellRef})`;
553
+ return `IF(LOWER(LEFT(${cellRef}${sep}3))="zh-"${sep}${full}${sep}${prefix})`;
536
554
  }
537
555
  async function updateSpreadsheetWithLocalChanges(doc, changes, waitSeconds, autoTranslate = false, localeMapping = {}, override = false) {
538
556
  console.log("Updating spreadsheet with local changes...");
539
557
  const baseDelayMs = waitSeconds * 1e3;
558
+ const sep = getFormulaSeparator(doc);
540
559
  for (const sheetTitle of new Set(
541
560
  Object.values(changes).flatMap((locale) => Object.keys(locale))
542
561
  )) {
@@ -680,7 +699,7 @@ async function updateSpreadsheetWithLocalChanges(doc, changes, waitSeconds, auto
680
699
  const targetColumnLetter = columnIndexToLetter(targetHeaderIndex);
681
700
  row.set(
682
701
  exactTargetHeader,
683
- `=GOOGLETRANSLATE(INDIRECT("${sourceColumnLetter}"&ROW());${langCodeFormula(`$${sourceColumnLetter}$1`)};${langCodeFormula(`${targetColumnLetter}$1`)})`
702
+ `=GOOGLETRANSLATE(INDIRECT("${sourceColumnLetter}"&ROW())${sep}${langCodeFormula(`$${sourceColumnLetter}$1`, sep)}${sep}${langCodeFormula(`${targetColumnLetter}$1`, sep)})`
684
703
  );
685
704
  }
686
705
  }
@@ -729,7 +748,7 @@ async function updateSpreadsheetWithLocalChanges(doc, changes, waitSeconds, auto
729
748
  }
730
749
  const sourceColumnLetter = columnIndexToLetter(sourceHeaderIndex);
731
750
  const targetColumnLetter = columnIndexToLetter(targetHeaderIndex);
732
- rowData[exactHeaderName] = `=GOOGLETRANSLATE(INDIRECT("${sourceColumnLetter}"&ROW());${langCodeFormula(`$${sourceColumnLetter}$1`)};${langCodeFormula(`${targetColumnLetter}$1`)})`;
751
+ rowData[exactHeaderName] = `=GOOGLETRANSLATE(INDIRECT("${sourceColumnLetter}"&ROW())${sep}${langCodeFormula(`$${sourceColumnLetter}$1`, sep)}${sep}${langCodeFormula(`${targetColumnLetter}$1`, sep)})`;
733
752
  }
734
753
  }
735
754
  }
@@ -985,8 +1004,18 @@ function colLetter(index) {
985
1004
  } while (i >= 0);
986
1005
  return result;
987
1006
  }
988
- function langCodeFormula2(cellRef) {
989
- return `LOWER(IFERROR(LEFT(${cellRef},FIND("-",${cellRef})-1),${cellRef}))`;
1007
+ function getFormulaSeparator2(doc) {
1008
+ try {
1009
+ const locale = doc._rawProperties?.locale || "";
1010
+ if (/^(en|ja|ko|zh|th|id|ms)/i.test(locale)) return ",";
1011
+ } catch {
1012
+ }
1013
+ return ";";
1014
+ }
1015
+ function langCodeFormula2(cellRef, sep) {
1016
+ const prefix = `LOWER(IFERROR(LEFT(${cellRef}${sep}FIND("-"${sep}${cellRef})-1)${sep}${cellRef}))`;
1017
+ const full = `LOWER(${cellRef})`;
1018
+ return `IF(LOWER(LEFT(${cellRef}${sep}3))="zh-"${sep}${full}${sep}${prefix})`;
990
1019
  }
991
1020
  var DEFAULT_TARGET_LOCALES = ["de", "fr", "es", "it", "pt", "ja", "zh"];
992
1021
  var STARTER_KEYS = {
@@ -1068,11 +1097,12 @@ async function createSpreadsheet(authClient, options = {}) {
1068
1097
  "setHeaderRow"
1069
1098
  );
1070
1099
  const sourceColLetter = colLetter(1);
1100
+ const sep = getFormulaSeparator2(doc);
1071
1101
  const rows = Object.entries(seedKeys).map(([key, sourceValue]) => {
1072
1102
  const row = { key, [sourceLocale]: sourceValue };
1073
1103
  targetLocales.forEach((locale, idx) => {
1074
1104
  const targetColLetter = colLetter(2 + idx);
1075
- row[locale] = `=GOOGLETRANSLATE(INDIRECT("${sourceColLetter}"&ROW());${langCodeFormula2(`$${sourceColLetter}$1`)};${langCodeFormula2(`${targetColLetter}$1`)})`;
1105
+ row[locale] = `=GOOGLETRANSLATE(INDIRECT("${sourceColLetter}"&ROW())${sep}${langCodeFormula2(`$${sourceColLetter}$1`, sep)}${sep}${langCodeFormula2(`${targetColLetter}$1`, sep)})`;
1076
1106
  });
1077
1107
  return row;
1078
1108
  });
@@ -1299,6 +1329,7 @@ export {
1299
1329
  index_default as default,
1300
1330
  filterValidLocales,
1301
1331
  findLocalChanges,
1332
+ getGoogleTranslateCode,
1302
1333
  getLanguagePrefix,
1303
1334
  getLocaleDisplayName,
1304
1335
  getNormalizedLocaleForHeader,
package/dist/index.d.ts CHANGED
@@ -16,7 +16,7 @@ export { readPublicSheet } from './utils/publicSheetReader';
16
16
  export { createSpreadsheet } from './utils/spreadsheetCreator';
17
17
  export { validateCredentials } from './utils/validateEnv';
18
18
  export { isValidLocale, filterValidLocales } from './utils/localeFilter';
19
- export { getLanguagePrefix, normalizeLocaleCode, createLocaleMapping, getOriginalHeaderForLocale, getNormalizedLocaleForHeader, resolveLocaleWithFallback, } from './utils/localeNormalizer';
19
+ export { getLanguagePrefix, getGoogleTranslateCode, normalizeLocaleCode, createLocaleMapping, getOriginalHeaderForLocale, getNormalizedLocaleForHeader, resolveLocaleWithFallback, } from './utils/localeNormalizer';
20
20
  export { processRawRows } from './utils/sheetProcessor';
21
21
  export type { SheetProcessingResult } from './utils/sheetProcessor';
22
22
  export { getTranslationSummary, getLocaleDisplayName, mergeSheets } from './utils/translationHelpers';
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAGH,OAAO,EAAE,kBAAkB,EAAE,oBAAoB,EAAE,MAAM,sBAAsB,CAAC;AAGhF,YAAY,EAAE,kBAAkB,EAAE,MAAM,8BAA8B,CAAC;AAGvE,OAAO,EAAE,IAAI,EAAE,MAAM,cAAc,CAAC;AACpC,OAAO,EAAE,SAAS,EAAE,MAAM,qBAAqB,CAAC;AAChD,OAAO,EAAE,WAAW,EAAE,MAAM,qBAAqB,CAAC;AAClD,OAAO,EAAE,gBAAgB,EAAE,MAAM,cAAc,CAAC;AAChD,OAAO,EAAE,uBAAuB,EAAE,MAAM,+CAA+C,CAAC;AACxF,OAAO,EAAE,yBAAyB,EAAE,MAAM,iDAAiD,CAAC;AAC5F,OAAO,EAAE,gBAAgB,EAAE,MAAM,wCAAwC,CAAC;AAC1E,OAAO,EAAE,iCAAiC,EAAE,MAAM,4BAA4B,CAAC;AAG/E,OAAO,EAAE,eAAe,EAAE,MAAM,2BAA2B,CAAC;AAG5D,OAAO,EAAE,iBAAiB,EAAE,MAAM,4BAA4B,CAAC;AAC/D,OAAO,EAAE,mBAAmB,EAAE,MAAM,qBAAqB,CAAC;AAG1D,OAAO,EAAE,aAAa,EAAE,kBAAkB,EAAE,MAAM,sBAAsB,CAAC;AAGzE,OAAO,EACL,iBAAiB,EACjB,mBAAmB,EACnB,mBAAmB,EACnB,0BAA0B,EAC1B,4BAA4B,EAC5B,yBAAyB,GAC1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4BAA4B,CAAC;AAG/E,OAAO,EAAE,eAAe,EAAE,MAAM,2BAA2B,CAAC;AAG5D,OAAO,EAAE,iBAAiB,EAAE,MAAM,4BAA4B,CAAC;AAC/D,OAAO,EAAE,mBAAmB,EAAE,MAAM,qBAAqB,CAAC;AAG1D,OAAO,EAAE,aAAa,EAAE,kBAAkB,EAAE,MAAM,sBAAsB,CAAC;AAGzE,OAAO,EACL,iBAAiB,EACjB,sBAAsB,EACtB,mBAAmB,EACnB,mBAAmB,EACnB,0BAA0B,EAC1B,4BAA4B,EAC5B,yBAAyB,GAC1B,MAAM,0BAA0B,CAAC;AAGlC,OAAO,EAAE,cAAc,EAAE,MAAM,wBAAwB,CAAC;AACxD,YAAY,EAAE,qBAAqB,EAAE,MAAM,wBAAwB,CAAC;AAGpE,OAAO,EAAE,qBAAqB,EAAE,oBAAoB,EAAE,WAAW,EAAE,MAAM,4BAA4B,CAAC;AACtG,YAAY,EAAE,kBAAkB,EAAE,YAAY,EAAE,MAAM,4BAA4B,CAAC;AAGnF,OAAO,EAAE,qBAAqB,EAAE,gBAAgB,EAAE,qBAAqB,EAAE,MAAM,oBAAoB,CAAC;AAGpG,OAAO,EAAE,uBAAuB,EAAE,MAAM,qBAAqB,CAAC;AAC9D,YAAY,EAAE,UAAU,EAAE,MAAM,qBAAqB,CAAC;AAGtD,YAAY,EACV,eAAe,EACf,gBAAgB,EAChB,QAAQ,EACR,aAAa,GACd,MAAM,SAAS,CAAC;AAGjB,OAAO,EAAE,kBAAkB,EAAE,MAAM,sBAAsB,CAAC;AAC1D,eAAe,kBAAkB,CAAC"}
package/dist/index.js CHANGED
@@ -39,6 +39,7 @@ __export(index_exports, {
39
39
  default: () => index_default,
40
40
  filterValidLocales: () => filterValidLocales,
41
41
  findLocalChanges: () => findLocalChanges,
42
+ getGoogleTranslateCode: () => getGoogleTranslateCode,
42
43
  getLanguagePrefix: () => getLanguagePrefix,
43
44
  getLocaleDisplayName: () => getLocaleDisplayName,
44
45
  getNormalizedLocaleForHeader: () => getNormalizedLocaleForHeader,
@@ -234,6 +235,14 @@ function filterValidLocales(headerRow, keyColumn) {
234
235
  function getLanguagePrefix(locale) {
235
236
  return locale.toLowerCase().split(/[-_]/)[0];
236
237
  }
238
+ var GOOGLE_TRANSLATE_CODES_REQUIRING_REGION = /* @__PURE__ */ new Set(["zh-tw", "zh-cn"]);
239
+ function getGoogleTranslateCode(locale) {
240
+ const normalized = locale.toLowerCase().trim().replace("_", "-");
241
+ if (GOOGLE_TRANSLATE_CODES_REQUIRING_REGION.has(normalized)) {
242
+ return normalized;
243
+ }
244
+ return normalized.split(/[-_]/)[0];
245
+ }
237
246
  var LANGUAGE_TO_COUNTRY_MAP = {
238
247
  "en": "en-GB",
239
248
  "de": "de-DE",
@@ -596,12 +605,23 @@ function columnIndexToLetter(index) {
596
605
  } while (i >= 0);
597
606
  return result;
598
607
  }
599
- function langCodeFormula(cellRef) {
600
- return `LOWER(IFERROR(LEFT(${cellRef},FIND("-",${cellRef})-1),${cellRef}))`;
608
+ function getFormulaSeparator(doc) {
609
+ try {
610
+ const locale = doc._rawProperties?.locale || "";
611
+ if (/^(en|ja|ko|zh|th|id|ms)/i.test(locale)) return ",";
612
+ } catch {
613
+ }
614
+ return ";";
615
+ }
616
+ function langCodeFormula(cellRef, sep) {
617
+ const prefix = `LOWER(IFERROR(LEFT(${cellRef}${sep}FIND("-"${sep}${cellRef})-1)${sep}${cellRef}))`;
618
+ const full = `LOWER(${cellRef})`;
619
+ return `IF(LOWER(LEFT(${cellRef}${sep}3))="zh-"${sep}${full}${sep}${prefix})`;
601
620
  }
602
621
  async function updateSpreadsheetWithLocalChanges(doc, changes, waitSeconds, autoTranslate = false, localeMapping = {}, override = false) {
603
622
  console.log("Updating spreadsheet with local changes...");
604
623
  const baseDelayMs = waitSeconds * 1e3;
624
+ const sep = getFormulaSeparator(doc);
605
625
  for (const sheetTitle of new Set(
606
626
  Object.values(changes).flatMap((locale) => Object.keys(locale))
607
627
  )) {
@@ -745,7 +765,7 @@ async function updateSpreadsheetWithLocalChanges(doc, changes, waitSeconds, auto
745
765
  const targetColumnLetter = columnIndexToLetter(targetHeaderIndex);
746
766
  row.set(
747
767
  exactTargetHeader,
748
- `=GOOGLETRANSLATE(INDIRECT("${sourceColumnLetter}"&ROW());${langCodeFormula(`$${sourceColumnLetter}$1`)};${langCodeFormula(`${targetColumnLetter}$1`)})`
768
+ `=GOOGLETRANSLATE(INDIRECT("${sourceColumnLetter}"&ROW())${sep}${langCodeFormula(`$${sourceColumnLetter}$1`, sep)}${sep}${langCodeFormula(`${targetColumnLetter}$1`, sep)})`
749
769
  );
750
770
  }
751
771
  }
@@ -794,7 +814,7 @@ async function updateSpreadsheetWithLocalChanges(doc, changes, waitSeconds, auto
794
814
  }
795
815
  const sourceColumnLetter = columnIndexToLetter(sourceHeaderIndex);
796
816
  const targetColumnLetter = columnIndexToLetter(targetHeaderIndex);
797
- rowData[exactHeaderName] = `=GOOGLETRANSLATE(INDIRECT("${sourceColumnLetter}"&ROW());${langCodeFormula(`$${sourceColumnLetter}$1`)};${langCodeFormula(`${targetColumnLetter}$1`)})`;
817
+ rowData[exactHeaderName] = `=GOOGLETRANSLATE(INDIRECT("${sourceColumnLetter}"&ROW())${sep}${langCodeFormula(`$${sourceColumnLetter}$1`, sep)}${sep}${langCodeFormula(`${targetColumnLetter}$1`, sep)})`;
798
818
  }
799
819
  }
800
820
  }
@@ -1050,8 +1070,18 @@ function colLetter(index) {
1050
1070
  } while (i >= 0);
1051
1071
  return result;
1052
1072
  }
1053
- function langCodeFormula2(cellRef) {
1054
- return `LOWER(IFERROR(LEFT(${cellRef},FIND("-",${cellRef})-1),${cellRef}))`;
1073
+ function getFormulaSeparator2(doc) {
1074
+ try {
1075
+ const locale = doc._rawProperties?.locale || "";
1076
+ if (/^(en|ja|ko|zh|th|id|ms)/i.test(locale)) return ",";
1077
+ } catch {
1078
+ }
1079
+ return ";";
1080
+ }
1081
+ function langCodeFormula2(cellRef, sep) {
1082
+ const prefix = `LOWER(IFERROR(LEFT(${cellRef}${sep}FIND("-"${sep}${cellRef})-1)${sep}${cellRef}))`;
1083
+ const full = `LOWER(${cellRef})`;
1084
+ return `IF(LOWER(LEFT(${cellRef}${sep}3))="zh-"${sep}${full}${sep}${prefix})`;
1055
1085
  }
1056
1086
  var DEFAULT_TARGET_LOCALES = ["de", "fr", "es", "it", "pt", "ja", "zh"];
1057
1087
  var STARTER_KEYS = {
@@ -1133,11 +1163,12 @@ async function createSpreadsheet(authClient, options = {}) {
1133
1163
  "setHeaderRow"
1134
1164
  );
1135
1165
  const sourceColLetter = colLetter(1);
1166
+ const sep = getFormulaSeparator2(doc);
1136
1167
  const rows = Object.entries(seedKeys).map(([key, sourceValue]) => {
1137
1168
  const row = { key, [sourceLocale]: sourceValue };
1138
1169
  targetLocales.forEach((locale, idx) => {
1139
1170
  const targetColLetter = colLetter(2 + idx);
1140
- row[locale] = `=GOOGLETRANSLATE(INDIRECT("${sourceColLetter}"&ROW());${langCodeFormula2(`$${sourceColLetter}$1`)};${langCodeFormula2(`${targetColLetter}$1`)})`;
1171
+ row[locale] = `=GOOGLETRANSLATE(INDIRECT("${sourceColLetter}"&ROW())${sep}${langCodeFormula2(`$${sourceColLetter}$1`, sep)}${sep}${langCodeFormula2(`${targetColLetter}$1`, sep)})`;
1141
1172
  });
1142
1173
  return row;
1143
1174
  });
@@ -1364,6 +1395,7 @@ var index_default = getSpreadSheetData;
1364
1395
  createSpreadsheet,
1365
1396
  filterValidLocales,
1366
1397
  findLocalChanges,
1398
+ getGoogleTranslateCode,
1367
1399
  getLanguagePrefix,
1368
1400
  getLocaleDisplayName,
1369
1401
  getNormalizedLocaleForHeader,
@@ -14,6 +14,28 @@
14
14
  * Used for language-family matching when an exact locale code is not found.
15
15
  */
16
16
  export declare function getLanguagePrefix(locale: string): string;
17
+ /**
18
+ * Converts a spreadsheet locale header (e.g. `"tr-TR"`, `"en-US"`, `"zh-TW"`)
19
+ * into the language code accepted by Google Sheets' `GOOGLETRANSLATE` function.
20
+ *
21
+ * Rules:
22
+ * - Chinese variants (`zh-TW`, `zh-CN`) keep their region qualifier because
23
+ * `GOOGLETRANSLATE` distinguishes between Simplified and Traditional Chinese.
24
+ * - All other locales are stripped to their ISO 639-1 two-letter prefix
25
+ * (e.g. `"tr-TR"` → `"tr"`, `"en-US"` → `"en"`).
26
+ *
27
+ * @param locale - A locale string from a spreadsheet header or config option.
28
+ * @returns A lowercased language code suitable for `GOOGLETRANSLATE`.
29
+ *
30
+ * @example
31
+ * ```ts
32
+ * getGoogleTranslateCode('tr-TR'); // → 'tr'
33
+ * getGoogleTranslateCode('en-US'); // → 'en'
34
+ * getGoogleTranslateCode('zh-TW'); // → 'zh-tw'
35
+ * getGoogleTranslateCode('de'); // → 'de'
36
+ * ```
37
+ */
38
+ export declare function getGoogleTranslateCode(locale: string): string;
17
39
  /**
18
40
  * Normalizes a language code to include country code if missing
19
41
  * @param locale The original locale code from spreadsheet header
@@ -1 +1 @@
1
- {"version":3,"file":"localeNormalizer.d.ts","sourceRoot":"","sources":["../../src/utils/localeNormalizer.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH;;;;;;;;;;GAUG;AACH,wBAAgB,iBAAiB,CAAC,MAAM,EAAE,MAAM,GAAG,MAAM,CAExD;AA4CD;;;;GAIG;AACH,wBAAgB,mBAAmB,CAAC,MAAM,EAAE,MAAM,GAAG,MAAM,CA0B1D;AAED;;;;;GAKG;AACH,wBAAgB,mBAAmB,CAClC,eAAe,EAAE,MAAM,EAAE,EACzB,SAAS,EAAE,MAAM,GACf;IACF,iBAAiB,EAAE,MAAM,EAAE,CAAC;IAC5B,aAAa,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;IACtC,eAAe,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;CACxC,CA+BA;AAED;;;;;;;;;;;;;GAaG;AACH,wBAAgB,0BAA0B,CACzC,gBAAgB,EAAE,MAAM,EACxB,aAA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AAE,MAAM,EACtB,eAAe,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,GACrC,MAAM,GAAG,SAAS,CAEpB;AAED;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA6BG;AACH,wBAAgB,yBAAyB,CACxC,MAAM,EAAE,MAAM,EACd,gBAAgB,EAAE,MAAM,EAAE,GACxB,MAAM,GAAG,SAAS,CAUpB"}
@@ -1 +1 @@
1
- {"version":3,"file":"spreadsheetCreator.d.ts","sourceRoot":"","sources":["../../src/utils/spreadsheetCreator.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,GAAG,EAAE,MAAM,qBAAqB,CAAC;AA8B/C,MAAM,WAAW,wBAAwB;IACxC,+DAA+D;IAC/D,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,8FAA8F;IAC9F,YAAY,CAAC,EAAE,MAAM,CAAC;IACtB,mGAAmG;IACnG,aAAa,CAAC,EAAE,MAAM,EAAE,CAAC;IACzB,mFAAmF;IACnF,QAAQ,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;CAClC;AAED,MAAM,WAAW,sBAAsB;IACtC,aAAa,EAAE,MAAM,CAAC;IACtB,GAAG,EAAE,MAAM,CAAC;CACZ;AAiBD;;;;;GAKG;AACH,wBAAsB,iBAAiB,CACtC,UAAU,EAAE,GAAG,EACf,OAAO,GAAE,wBAA6B,GACpC,OAAO,CAAC,sBAAsB,CAAC,CAgHjC"}
1
+ {"version":3,"file":"spreadsheetCreator.d.ts","sourceRoot":"","sources":["../../src/utils/spreadsheetCreator.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,GAAG,EAAE,MAAM,qBAAqB,CAAC;AA2C/C,MAAM,WAAW,wBAAwB;IACxC,+DAA+D;IAC/D,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,8FAA8F;IAC9F,YAAY,CAAC,EAAE,MAAM,CAAC;IACtB,mGAAmG;IACnG,aAAa,CAAC,EAAE,MAAM,EAAE,CAAC;IACzB,mFAAmF;IACnF,QAAQ,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;CAClC;AAED,MAAM,WAAW,sBAAsB;IACtC,aAAa,EAAE,MAAM,CAAC;IACtB,GAAG,EAAE,MAAM,CAAC;CACZ;AAiBD;;;;;GAKG;AACH,wBAAsB,iBAAiB,CACtC,UAAU,EAAE,GAAG,EACf,OAAO,GAAE,wBAA6B,GACpC,OAAO,CAAC,sBAAsB,CAAC,CAmHjC"}
@@ -6,11 +6,12 @@ import type { TranslationData } from "../types";
6
6
  * When autoTranslate is enabled:
7
7
  * - For each new key added to the spreadsheet, the system checks which languages have translations
8
8
  * - For languages missing translations, it automatically adds Google Translate formulas
9
- * - The formula extracts the language prefix from the header cell (e.g. "tr-TR" → "tr") because
10
- * GOOGLETRANSLATE only accepts ISO 639-1 codes for most languages
9
+ * - The formula dynamically extracts the GOOGLETRANSLATE-compatible language code from the header
10
+ * cell at spreadsheet-evaluation time (e.g. header "tr-TR" "tr") and also preserves Chinese
11
+ * variants (zh-TW, zh-CN) where the region is meaningful
11
12
  * - The formula format is:
12
- * =GOOGLETRANSLATE(INDIRECT(sourceColumn&ROW());LOWER(IFERROR(LEFT($sourceColumn$1,FIND("-",$sourceColumn$1)-1),$sourceColumn$1));LOWER(IFERROR(LEFT(targetColumn$1,FIND("-",targetColumn$1)-1),targetColumn$1)))
13
- * - This dynamic formula uses cell references for language codes and automatically adapts to the correct row
13
+ * =GOOGLETRANSLATE(INDIRECT(srcCol&ROW()); langCodeFormula($srcCol$1); langCodeFormula(tgtCol$1))
14
+ * - All formula separators are set to match the spreadsheet's locale (`;` or `,`)
14
15
  * - For **existing** keys the same logic applies: empty cells in other language columns receive a
15
16
  * formula; cells that already contain a translation are only overwritten when `override` is true.
16
17
  *
@@ -1 +1 @@
1
- {"version":3,"file":"spreadsheetUpdater.d.ts","sourceRoot":"","sources":["../../src/utils/spreadsheetUpdater.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,iBAAiB,EAA8B,MAAM,oBAAoB,CAAC;AACxF,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,UAAU,CAAC;AAiChD;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAsCG;AACH,wBAAsB,iCAAiC,CACnD,GAAG,EAAE,iBAAiB,EACtB,OAAO,EAAE,eAAe,EACxB,WAAW,EAAE,MAAM,EACnB,aAAa,UAAQ,EACrB,aAAa,GAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAM,EAC1C,QAAQ,UAAQ,GACjB,OAAO,CAAC,IAAI,CAAC,CAiVf"}
1
+ {"version":3,"file":"spreadsheetUpdater.d.ts","sourceRoot":"","sources":["../../src/utils/spreadsheetUpdater.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,iBAAiB,EAA8B,MAAM,oBAAoB,CAAC;AACxF,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,UAAU,CAAC;AAqEhD;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAuCG;AACH,wBAAsB,iCAAiC,CACnD,GAAG,EAAE,iBAAiB,EACtB,OAAO,EAAE,eAAe,EACxB,WAAW,EAAE,MAAM,EACnB,aAAa,UAAQ,EACrB,aAAa,GAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAM,EAC1C,QAAQ,UAAQ,GACjB,OAAO,CAAC,IAAI,CAAC,CAgVf"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@el-j/google-sheet-translations",
3
- "version": "2.1.4",
3
+ "version": "2.1.5-beta.1",
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",