@el-j/google-sheet-translations 1.0.0

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.
Files changed (83) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +258 -0
  3. package/dist/constants.d.ts +6 -0
  4. package/dist/constants.d.ts.map +1 -0
  5. package/dist/constants.js +9 -0
  6. package/dist/constants.js.map +1 -0
  7. package/dist/getSpreadSheetData.d.ts +7 -0
  8. package/dist/getSpreadSheetData.d.ts.map +1 -0
  9. package/dist/getSpreadSheetData.js +121 -0
  10. package/dist/getSpreadSheetData.js.map +1 -0
  11. package/dist/index.d.ts +18 -0
  12. package/dist/index.d.ts.map +1 -0
  13. package/dist/index.js +34 -0
  14. package/dist/index.js.map +1 -0
  15. package/dist/types.d.ts +22 -0
  16. package/dist/types.d.ts.map +1 -0
  17. package/dist/types.js +3 -0
  18. package/dist/types.js.map +1 -0
  19. package/dist/utils/auth.d.ts +8 -0
  20. package/dist/utils/auth.d.ts.map +1 -0
  21. package/dist/utils/auth.js +19 -0
  22. package/dist/utils/auth.js.map +1 -0
  23. package/dist/utils/configurationHandler.d.ts +29 -0
  24. package/dist/utils/configurationHandler.d.ts.map +1 -0
  25. package/dist/utils/configurationHandler.js +23 -0
  26. package/dist/utils/configurationHandler.js.map +1 -0
  27. package/dist/utils/dataConverter/convertFromDataJsonFormat.d.ts +8 -0
  28. package/dist/utils/dataConverter/convertFromDataJsonFormat.d.ts.map +1 -0
  29. package/dist/utils/dataConverter/convertFromDataJsonFormat.js +47 -0
  30. package/dist/utils/dataConverter/convertFromDataJsonFormat.js.map +1 -0
  31. package/dist/utils/dataConverter/convertToDataJsonFormat.d.ts +10 -0
  32. package/dist/utils/dataConverter/convertToDataJsonFormat.d.ts.map +1 -0
  33. package/dist/utils/dataConverter/convertToDataJsonFormat.js +51 -0
  34. package/dist/utils/dataConverter/convertToDataJsonFormat.js.map +1 -0
  35. package/dist/utils/dataConverter/findLocalChanges.d.ts +9 -0
  36. package/dist/utils/dataConverter/findLocalChanges.d.ts.map +1 -0
  37. package/dist/utils/dataConverter/findLocalChanges.js +39 -0
  38. package/dist/utils/dataConverter/findLocalChanges.js.map +1 -0
  39. package/dist/utils/fileWriter.d.ts +23 -0
  40. package/dist/utils/fileWriter.d.ts.map +1 -0
  41. package/dist/utils/fileWriter.js +119 -0
  42. package/dist/utils/fileWriter.js.map +1 -0
  43. package/dist/utils/getFileLastModified.d.ts +7 -0
  44. package/dist/utils/getFileLastModified.d.ts.map +1 -0
  45. package/dist/utils/getFileLastModified.js +23 -0
  46. package/dist/utils/getFileLastModified.js.map +1 -0
  47. package/dist/utils/isDataJsonNewer.d.ts +8 -0
  48. package/dist/utils/isDataJsonNewer.d.ts.map +1 -0
  49. package/dist/utils/isDataJsonNewer.js +40 -0
  50. package/dist/utils/isDataJsonNewer.js.map +1 -0
  51. package/dist/utils/localeFilter.d.ts +17 -0
  52. package/dist/utils/localeFilter.d.ts.map +1 -0
  53. package/dist/utils/localeFilter.js +49 -0
  54. package/dist/utils/localeFilter.js.map +1 -0
  55. package/dist/utils/localeNormalizer.d.ts +37 -0
  56. package/dist/utils/localeNormalizer.d.ts.map +1 -0
  57. package/dist/utils/localeNormalizer.js +145 -0
  58. package/dist/utils/localeNormalizer.js.map +1 -0
  59. package/dist/utils/readDataJson.d.ts +8 -0
  60. package/dist/utils/readDataJson.d.ts.map +1 -0
  61. package/dist/utils/readDataJson.js +29 -0
  62. package/dist/utils/readDataJson.js.map +1 -0
  63. package/dist/utils/sheetProcessor.d.ts +22 -0
  64. package/dist/utils/sheetProcessor.d.ts.map +1 -0
  65. package/dist/utils/sheetProcessor.js +86 -0
  66. package/dist/utils/sheetProcessor.js.map +1 -0
  67. package/dist/utils/spreadsheetUpdater.d.ts +25 -0
  68. package/dist/utils/spreadsheetUpdater.d.ts.map +1 -0
  69. package/dist/utils/spreadsheetUpdater.js +196 -0
  70. package/dist/utils/spreadsheetUpdater.js.map +1 -0
  71. package/dist/utils/syncManager.d.ts +23 -0
  72. package/dist/utils/syncManager.d.ts.map +1 -0
  73. package/dist/utils/syncManager.js +62 -0
  74. package/dist/utils/syncManager.js.map +1 -0
  75. package/dist/utils/validateEnv.d.ts +9 -0
  76. package/dist/utils/validateEnv.d.ts.map +1 -0
  77. package/dist/utils/validateEnv.js +29 -0
  78. package/dist/utils/validateEnv.js.map +1 -0
  79. package/dist/utils/wait.d.ts +9 -0
  80. package/dist/utils/wait.d.ts.map +1 -0
  81. package/dist/utils/wait.js +21 -0
  82. package/dist/utils/wait.js.map +1 -0
  83. package/package.json +91 -0
@@ -0,0 +1,145 @@
1
+ "use strict";
2
+ /**
3
+ * Locale normalization utilities for converting simple language codes to full locale codes
4
+ * and maintaining mappings between normalized codes and original spreadsheet headers
5
+ */
6
+ Object.defineProperty(exports, "__esModule", { value: true });
7
+ exports.normalizeLocaleCode = normalizeLocaleCode;
8
+ exports.createLocaleMapping = createLocaleMapping;
9
+ exports.getOriginalHeaderForLocale = getOriginalHeaderForLocale;
10
+ exports.getNormalizedLocaleForHeader = getNormalizedLocaleForHeader;
11
+ /**
12
+ * Common language to country mappings for normalization
13
+ * Maps language codes to their most common country variants
14
+ */
15
+ const LANGUAGE_TO_COUNTRY_MAP = {
16
+ 'en': 'en-GB',
17
+ 'de': 'de-DE',
18
+ 'fr': 'fr-FR',
19
+ 'es': 'es-ES',
20
+ 'it': 'it-IT',
21
+ 'pt': 'pt-PT',
22
+ 'pl': 'pl-PL',
23
+ 'ru': 'ru-RU',
24
+ 'zh': 'zh-CN',
25
+ 'ja': 'ja-JP',
26
+ 'ko': 'ko-KR',
27
+ 'ar': 'ar-SA',
28
+ 'hi': 'hi-IN',
29
+ 'th': 'th-TH',
30
+ 'vi': 'vi-VN',
31
+ 'tr': 'tr-TR',
32
+ 'nl': 'nl-NL',
33
+ 'sv': 'sv-SE',
34
+ 'da': 'da-DK',
35
+ 'no': 'no-NO',
36
+ 'fi': 'fi-FI',
37
+ 'cs': 'cs-CZ',
38
+ 'sk': 'sk-SK',
39
+ 'hu': 'hu-HU',
40
+ 'ro': 'ro-RO',
41
+ 'bg': 'bg-BG',
42
+ 'hr': 'hr-HR',
43
+ 'sl': 'sl-SI',
44
+ 'et': 'et-EE',
45
+ 'lv': 'lv-LV',
46
+ 'lt': 'lt-LT',
47
+ 'el': 'el-GR',
48
+ 'he': 'he-IL',
49
+ 'uk': 'uk-UA',
50
+ 'be': 'be-BY',
51
+ };
52
+ /**
53
+ * Normalizes a language code to include country code if missing
54
+ * @param locale The original locale code from spreadsheet header
55
+ * @returns Normalized locale with country code
56
+ */
57
+ function normalizeLocaleCode(locale) {
58
+ if (!locale || typeof locale !== 'string') {
59
+ return '';
60
+ }
61
+ const normalized = locale.toLowerCase().trim();
62
+ // If already has country code, return as is
63
+ if (normalized.includes('-') || normalized.includes('_')) {
64
+ return normalized;
65
+ }
66
+ // Look up the language in our mapping first
67
+ const withCountry = LANGUAGE_TO_COUNTRY_MAP[normalized];
68
+ if (withCountry) {
69
+ return withCountry;
70
+ }
71
+ // If not in mapping and it's a 2-letter code, append the same code in uppercase
72
+ // This handles cases like "pl" -> "pl-PL"
73
+ if (normalized.length === 2 && /^[a-z]{2}$/.test(normalized)) {
74
+ return `${normalized}-${normalized.toUpperCase()}`;
75
+ }
76
+ // Return original if we can't normalize it
77
+ return normalized;
78
+ }
79
+ /**
80
+ * Creates a mapping between normalized locale codes and their original spreadsheet headers
81
+ * @param originalHeaders Array of original header names from spreadsheet
82
+ * @param keyColumn The key column name to exclude
83
+ * @returns Object with normalized locales and header mapping
84
+ */
85
+ function createLocaleMapping(originalHeaders, keyColumn) {
86
+ const localeMapping = {}; // normalized -> original
87
+ const originalMapping = {}; // original -> normalized
88
+ const normalizedLocales = [];
89
+ for (const header of originalHeaders) {
90
+ const headerLower = header.toLowerCase();
91
+ // Skip key column and non-locale headers
92
+ if (headerLower === keyColumn.toLowerCase()) {
93
+ continue;
94
+ }
95
+ // Check if this looks like a locale
96
+ const isLocale = /^[a-z]{2}([_-][a-z]{2})?([_-][a-z]+)?$/.test(headerLower);
97
+ if (!isLocale) {
98
+ continue;
99
+ }
100
+ const normalized = normalizeLocaleCode(headerLower);
101
+ localeMapping[normalized] = header; // Store original case
102
+ originalMapping[headerLower] = normalized;
103
+ normalizedLocales.push(normalized);
104
+ }
105
+ return {
106
+ normalizedLocales: [...new Set(normalizedLocales)], // Remove duplicates
107
+ localeMapping, // normalized -> original header
108
+ originalMapping // original header (lowercase) -> normalized
109
+ };
110
+ }
111
+ /**
112
+ * Finds the original header name for a given normalized locale
113
+ * @param normalizedLocale The normalized locale code (e.g., 'pl-PL')
114
+ * @param localeMapping Mapping from normalized locales to original headers
115
+ * @returns Original header name or undefined if not found
116
+ */
117
+ function getOriginalHeaderForLocale(normalizedLocale, localeMapping) {
118
+ // Try direct lookup first
119
+ let result = localeMapping[normalizedLocale];
120
+ if (result)
121
+ return result;
122
+ // Try lowercase lookup if direct lookup fails
123
+ const lowercaseLocale = normalizedLocale.toLowerCase();
124
+ result = localeMapping[lowercaseLocale];
125
+ if (result)
126
+ return result;
127
+ // Try finding by case-insensitive key comparison
128
+ for (const [key, value] of Object.entries(localeMapping)) {
129
+ if (key.toLowerCase() === lowercaseLocale) {
130
+ return value;
131
+ }
132
+ }
133
+ return undefined;
134
+ }
135
+ /**
136
+ * Finds the normalized locale for a given original header
137
+ * @public
138
+ * @param originalHeader The original header name (e.g., 'pl')
139
+ * @param originalMapping Mapping from original headers to normalized locales
140
+ * @returns Normalized locale code or undefined if not found
141
+ */
142
+ function getNormalizedLocaleForHeader(originalHeader, originalMapping) {
143
+ return originalMapping[originalHeader.toLowerCase()];
144
+ }
145
+ //# sourceMappingURL=localeNormalizer.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"localeNormalizer.js","sourceRoot":"","sources":["../../src/utils/localeNormalizer.ts"],"names":[],"mappings":";AAAA;;;GAGG;;AAiDH,kDA0BC;AAQD,kDAsCC;AAQD,gEAqBC;AASD,oEAKC;A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AG,CAAC,iBAAiB,CAAC,CAAC,EAAE,oBAAoB;QACxE,aAAa,EAAE,gCAAgC;QAC/C,eAAe,CAAC,4CAA4C;KAC5D,CAAC;AACH,CAAC;AAED;;;;;GAKG;AACH,SAAgB,0BAA0B,CACzC,gBAAwB,EACxB,aAAqC;IAErC,0BAA0B;IAC1B,IAAI,MAAM,GAAG,aAAa,CAAC,gBAAgB,CAAC,CAAC;IAC7C,IAAI,MAAM;QAAE,OAAO,MAAM,CAAC;IAE1B,8CAA8C;IAC9C,MAAM,eAAe,GAAG,gBAAgB,CAAC,WAAW,EAAE,CAAC;IACvD,MAAM,GAAG,aAAa,CAAC,eAAe,CAAC,CAAC;IACxC,IAAI,MAAM;QAAE,OAAO,MAAM,CAAC;IAE1B,iDAAiD;IACjD,KAAK,MAAM,CAAC,GAAG,EAAE,KAAK,CAAC,IAAI,MAAM,CAAC,OAAO,CAAC,aAAa,CAAC,EAAE,CAAC;QAC1D,IAAI,GAAG,CAAC,WAAW,EAAE,KAAK,eAAe,EAAE,CAAC;YAC3C,OAAO,KAAK,CAAC;QACd,CAAC;IACF,CAAC;IAED,OAAO,SAAS,CAAC;AAClB,CAAC;AAED;;;;;;GAMG;AACH,SAAgB,4BAA4B,CAC3C,cAAsB,EACtB,eAAuC;IAEvC,OAAO,eAAe,CAAC,cAAc,CAAC,WAAW,EAAE,CAAC,CAAC;AACtD,CAAC"}
@@ -0,0 +1,8 @@
1
+ import type { TranslationData } from "../types";
2
+ /**
3
+ * Reads and parses the languageData.json file
4
+ * @param dataJsonPath - Path to languageData.json
5
+ * @returns Parsed languageData.json contents, or null if file doesn't exist or is invalid
6
+ */
7
+ export declare function readDataJson(dataJsonPath: string): TranslationData | null;
8
+ //# sourceMappingURL=readDataJson.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"readDataJson.d.ts","sourceRoot":"","sources":["../../src/utils/readDataJson.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,UAAU,CAAC;AAGhD;;;;GAIG;AACH,wBAAgB,YAAY,CAAC,YAAY,EAAE,MAAM,GAAG,eAAe,GAAG,IAAI,CAezE"}
@@ -0,0 +1,29 @@
1
+ "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ exports.readDataJson = readDataJson;
7
+ const node_fs_1 = __importDefault(require("node:fs"));
8
+ const convertFromDataJsonFormat_1 = require("../utils/dataConverter/convertFromDataJsonFormat");
9
+ /**
10
+ * Reads and parses the languageData.json file
11
+ * @param dataJsonPath - Path to languageData.json
12
+ * @returns Parsed languageData.json contents, or null if file doesn't exist or is invalid
13
+ */
14
+ function readDataJson(dataJsonPath) {
15
+ try {
16
+ if (!node_fs_1.default.existsSync(dataJsonPath)) {
17
+ return null;
18
+ }
19
+ const dataJsonContent = node_fs_1.default.readFileSync(dataJsonPath, 'utf8');
20
+ const dataJson = JSON.parse(dataJsonContent);
21
+ // Convert from languageData.json format to TranslationData
22
+ return (0, convertFromDataJsonFormat_1.convertFromDataJsonFormat)(dataJson);
23
+ }
24
+ catch (error) {
25
+ console.warn("Error reading or parsing languageData.json:", error);
26
+ return null;
27
+ }
28
+ }
29
+ //# sourceMappingURL=readDataJson.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"readDataJson.js","sourceRoot":"","sources":["../../src/utils/readDataJson.ts"],"names":[],"mappings":";;;;;AASA,oCAeC;AAxBD,sDAAyB;AAEzB,gGAA6F;AAE7F;;;;GAIG;AACH,SAAgB,YAAY,CAAC,YAAoB;IAChD,IAAI,CAAC;QACJ,IAAI,CAAC,iBAAE,CAAC,UAAU,CAAC,YAAY,CAAC,EAAE,CAAC;YAClC,OAAO,IAAI,CAAC;QACb,CAAC;QAED,MAAM,eAAe,GAAG,iBAAE,CAAC,YAAY,CAAC,YAAY,EAAE,MAAM,CAAC,CAAC;QAC9D,MAAM,QAAQ,GAAG,IAAI,CAAC,KAAK,CAAC,eAAe,CAAC,CAAC;QAE7C,2DAA2D;QAC3D,OAAO,IAAA,qDAAyB,EAAC,QAAQ,CAAC,CAAC;IAC5C,CAAC;IAAC,OAAO,KAAK,EAAE,CAAC;QAChB,OAAO,CAAC,IAAI,CAAC,6CAA6C,EAAE,KAAK,CAAC,CAAC;QACnE,OAAO,IAAI,CAAC;IACb,CAAC;AACF,CAAC"}
@@ -0,0 +1,22 @@
1
+ import type { GoogleSpreadsheetWorksheet } from "google-spreadsheet";
2
+ import type { TranslationData } from "../types";
3
+ /**
4
+ * Result of processing a single sheet
5
+ */
6
+ export interface SheetProcessingResult {
7
+ translations: TranslationData;
8
+ locales: string[];
9
+ localeMapping: Record<string, string>;
10
+ originalMapping: Record<string, string>;
11
+ success: boolean;
12
+ }
13
+ /**
14
+ * Processes a single Google Sheet and extracts translation data
15
+ * @param sheet The Google Spreadsheet worksheet to process
16
+ * @param sheetTitle The title of the sheet being processed
17
+ * @param rowLimit Maximum number of rows to fetch
18
+ * @param waitSeconds Time to wait after processing
19
+ * @returns Processing result containing translations and locales
20
+ */
21
+ export declare function processSheet(sheet: GoogleSpreadsheetWorksheet, sheetTitle: string, rowLimit: number, waitSeconds: number): Promise<SheetProcessingResult>;
22
+ //# sourceMappingURL=sheetProcessor.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"sheetProcessor.d.ts","sourceRoot":"","sources":["../../src/utils/sheetProcessor.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,0BAA0B,EAAE,MAAM,oBAAoB,CAAC;AACrE,OAAO,KAAK,EAAY,eAAe,EAAE,MAAM,UAAU,CAAC;AAK1D;;GAEG;AACH,MAAM,WAAW,qBAAqB;IACrC,YAAY,EAAE,eAAe,CAAC;IAC9B,OAAO,EAAE,MAAM,EAAE,CAAC;IAClB,aAAa,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;IACtC,eAAe,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;IACxC,OAAO,EAAE,OAAO,CAAC;CACjB;AAED;;;;;;;GAOG;AACH,wBAAsB,YAAY,CACjC,KAAK,EAAE,0BAA0B,EACjC,UAAU,EAAE,MAAM,EAClB,QAAQ,EAAE,MAAM,EAChB,WAAW,EAAE,MAAM,GACjB,OAAO,CAAC,qBAAqB,CAAC,CA6FhC"}
@@ -0,0 +1,86 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.processSheet = processSheet;
4
+ const wait_1 = require("./wait");
5
+ const localeFilter_1 = require("./localeFilter");
6
+ const localeNormalizer_1 = require("./localeNormalizer");
7
+ /**
8
+ * Processes a single Google Sheet and extracts translation data
9
+ * @param sheet The Google Spreadsheet worksheet to process
10
+ * @param sheetTitle The title of the sheet being processed
11
+ * @param rowLimit Maximum number of rows to fetch
12
+ * @param waitSeconds Time to wait after processing
13
+ * @returns Processing result containing translations and locales
14
+ */
15
+ async function processSheet(sheet, sheetTitle, rowLimit, waitSeconds) {
16
+ const result = {
17
+ translations: {},
18
+ locales: [],
19
+ localeMapping: {},
20
+ originalMapping: {},
21
+ success: false
22
+ };
23
+ try {
24
+ const rows = await sheet.getRows({ limit: rowLimit });
25
+ if (!rows || rows.length === 0) {
26
+ console.warn(`No rows found in sheet "${sheetTitle}"`);
27
+ return result;
28
+ }
29
+ // Extract header information
30
+ const rowObject = rows[0].toObject();
31
+ const headerRow = Object.keys(rowObject).map(key => key.toLowerCase());
32
+ console.log(`Header row for sheet "${sheetTitle}":`, headerRow);
33
+ const keyColumn = headerRow[0];
34
+ const validLocales = (0, localeFilter_1.filterValidLocales)(headerRow, keyColumn);
35
+ if (validLocales.length === 0) {
36
+ console.warn(`No valid locale columns found in sheet "${sheetTitle}"`);
37
+ return result;
38
+ }
39
+ // Create locale mapping for normalization
40
+ const originalHeaders = Object.keys(rowObject); // Keep original case
41
+ const { normalizedLocales, localeMapping, originalMapping } = (0, localeNormalizer_1.createLocaleMapping)(originalHeaders, keyColumn);
42
+ // Store the mappings in the result
43
+ result.localeMapping = localeMapping;
44
+ result.originalMapping = originalMapping;
45
+ // Convert rows to data objects
46
+ const cells = rows.map(row => row.toObject());
47
+ // Process each normalized locale
48
+ for (const normalizedLocale of normalizedLocales) {
49
+ // Find the original header for this normalized locale
50
+ const originalHeader = localeMapping[normalizedLocale];
51
+ if (!originalHeader)
52
+ continue;
53
+ const languageCells = cells.map((row) => {
54
+ // Look for the key column (case-insensitive)
55
+ const keyField = Object.keys(row).find(k => k.toLowerCase() === keyColumn);
56
+ if (!keyField || !row[keyField] || !row[originalHeader]) {
57
+ return {}; // Skip rows without key or translation
58
+ }
59
+ const rowLocal = {};
60
+ // Convert key to lowercase
61
+ rowLocal[row[keyField].toString().toLowerCase()] = row[originalHeader];
62
+ return rowLocal;
63
+ });
64
+ // Filter out empty objects before combining
65
+ const nonEmptyLanguageCells = languageCells.filter(cell => Object.keys(cell).length > 0);
66
+ // Combine all keys into one object
67
+ const prepareObj = {};
68
+ prepareObj[sheetTitle] = nonEmptyLanguageCells.reduce((acc, cell) => Object.assign(acc, cell), {});
69
+ // Use normalized locale as the key in translations
70
+ if (result.translations[normalizedLocale]) {
71
+ result.translations[normalizedLocale] = { ...result.translations[normalizedLocale], ...prepareObj };
72
+ }
73
+ else {
74
+ result.translations[normalizedLocale] = { ...prepareObj };
75
+ }
76
+ }
77
+ result.locales = normalizedLocales;
78
+ result.success = true;
79
+ await (0, wait_1.wait)(waitSeconds, `after processing sheet: ${sheetTitle}`);
80
+ }
81
+ catch (error) {
82
+ console.error(`Error processing sheet "${sheetTitle}":`, error);
83
+ }
84
+ return result;
85
+ }
86
+ //# sourceMappingURL=sheetProcessor.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"sheetProcessor.js","sourceRoot":"","sources":["../../src/utils/sheetProcessor.ts"],"names":[],"mappings":";;AAyBA,oCAkGC;AAzHD,iCAA8B;AAC9B,iDAAoD;AACpD,yD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CAAC,MAAM,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC,MAAM,GAAG,CAAC,CACpC,CAAC;YAEF,mCAAmC;YACnC,MAAM,UAAU,GAA2C,EAAE,CAAC;YAC9D,UAAU,CAAC,UAAU,CAAC,GAAG,qBAAqB,CAAC,MAAM,CACpD,CAAC,GAAG,EAAE,IAAI,EAAE,EAAE,CAAC,MAAM,CAAC,MAAM,CAAC,GAAG,EAAE,IAAI,CAAC,EACvC,EAAE,CACF,CAAC;YAEF,mDAAmD;YACnD,IAAI,MAAM,CAAC,YAAY,CAAC,gBAAgB,CAAC,EAAE,CAAC;gBAC3C,MAAM,CAAC,YAAY,CAAC,gBAAgB,CAAC,GAAG,EAAE,GAAG,MAAM,CAAC,YAAY,CAAC,gBAAgB,CAAC,EAAE,GAAG,UAAU,EAAE,CAAC;YACrG,CAAC;iBAAM,CAAC;gBACP,MAAM,CAAC,YAAY,CAAC,gBAAgB,CAAC,GAAG,EAAE,GAAG,UAAU,EAAE,CAAC;YAC3D,CAAC;QACF,CAAC;QAED,MAAM,CAAC,OAAO,GAAG,iBAAiB,CAAC;QACnC,MAAM,CAAC,OAAO,GAAG,IAAI,CAAC;QAEtB,MAAM,IAAA,WAAI,EAAC,WAAW,EAAE,2BAA2B,UAAU,EAAE,CAAC,CAAC;IAElE,CAAC;IAAC,OAAO,KAAK,EAAE,CAAC;QAChB,OAAO,CAAC,KAAK,CAAC,2BAA2B,UAAU,IAAI,EAAE,KAAK,CAAC,CAAC;IACjE,CAAC;IAED,OAAO,MAAM,CAAC;AACf,CAAC"}
@@ -0,0 +1,25 @@
1
+ import type { GoogleSpreadsheet } from "google-spreadsheet";
2
+ import type { TranslationData } from "../types";
3
+ /**
4
+ * Updates the Google Spreadsheet with new keys from local data
5
+ *
6
+ * When autoTranslate is enabled:
7
+ * - For each new key added to the spreadsheet, the system checks which languages have translations
8
+ * - For languages missing translations, it automatically adds Google Translate formulas
9
+ * - The formula format is: =GOOGLETRANSLATE(INDIRECT(sourceColumn&ROW());$sourceColumn$1;targetColumn$1)
10
+ * - This dynamic formula uses cell references for language codes and automatically adapts to the correct row
11
+ *
12
+ * Example:
13
+ * If a new key "welcome" has an English translation in column B but no German translation in column C,
14
+ * and autoTranslate is enabled, the system will add:
15
+ * =GOOGLETRANSLATE(INDIRECT("B"&ROW());$B$1;C$1) to the German column
16
+ *
17
+ * @param doc - The Google Spreadsheet instance
18
+ * @param changes - Object containing new keys to add to the spreadsheet
19
+ * @param waitSeconds - Number of seconds to wait between API calls
20
+ * @param autoTranslate - Whether to add Google Translate formulas for missing translations (default: false)
21
+ * @param localeMapping - Mapping from normalized locale codes to original spreadsheet headers
22
+ * @returns Promise that resolves when the update is complete
23
+ */
24
+ export declare function updateSpreadsheetWithLocalChanges(doc: GoogleSpreadsheet, changes: TranslationData, waitSeconds: number, autoTranslate?: boolean, localeMapping?: Record<string, string>): Promise<void>;
25
+ //# sourceMappingURL=spreadsheetUpdater.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"spreadsheetUpdater.d.ts","sourceRoot":"","sources":["../../src/utils/spreadsheetUpdater.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,oBAAoB,CAAC;AAC5D,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,UAAU,CAAC;AAehD;;;;;;;;;;;;;;;;;;;;GAoBG;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,GAC3C,OAAO,CAAC,IAAI,CAAC,CA2Mf"}
@@ -0,0 +1,196 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.updateSpreadsheetWithLocalChanges = updateSpreadsheetWithLocalChanges;
4
+ const wait_1 = require("./wait");
5
+ const localeNormalizer_1 = require("./localeNormalizer");
6
+ /** Converts a 0-based column index to a spreadsheet column letter (A, B, ..., Z, AA, AB, ...) */
7
+ function columnIndexToLetter(index) {
8
+ let result = '';
9
+ let i = index;
10
+ do {
11
+ result = String.fromCharCode(65 + (i % 26)) + result;
12
+ i = Math.floor(i / 26) - 1;
13
+ } while (i >= 0);
14
+ return result;
15
+ }
16
+ /**
17
+ * Updates the Google Spreadsheet with new keys from local data
18
+ *
19
+ * When autoTranslate is enabled:
20
+ * - For each new key added to the spreadsheet, the system checks which languages have translations
21
+ * - For languages missing translations, it automatically adds Google Translate formulas
22
+ * - The formula format is: =GOOGLETRANSLATE(INDIRECT(sourceColumn&ROW());$sourceColumn$1;targetColumn$1)
23
+ * - This dynamic formula uses cell references for language codes and automatically adapts to the correct row
24
+ *
25
+ * Example:
26
+ * If a new key "welcome" has an English translation in column B but no German translation in column C,
27
+ * and autoTranslate is enabled, the system will add:
28
+ * =GOOGLETRANSLATE(INDIRECT("B"&ROW());$B$1;C$1) to the German column
29
+ *
30
+ * @param doc - The Google Spreadsheet instance
31
+ * @param changes - Object containing new keys to add to the spreadsheet
32
+ * @param waitSeconds - Number of seconds to wait between API calls
33
+ * @param autoTranslate - Whether to add Google Translate formulas for missing translations (default: false)
34
+ * @param localeMapping - Mapping from normalized locale codes to original spreadsheet headers
35
+ * @returns Promise that resolves when the update is complete
36
+ */
37
+ async function updateSpreadsheetWithLocalChanges(doc, changes, waitSeconds, autoTranslate = false, localeMapping = {}) {
38
+ console.log("Updating spreadsheet with local changes...");
39
+ // Process each sheet in the changes object
40
+ for (const sheetTitle of new Set(Object.values(changes).flatMap(locale => Object.keys(locale)))) {
41
+ console.log(`Processing sheet: ${sheetTitle}`);
42
+ const sheet = doc.sheetsByTitle[sheetTitle];
43
+ if (!sheet) {
44
+ console.warn(`Sheet "${sheetTitle}" not found in the document, cannot update`);
45
+ continue;
46
+ }
47
+ // Get all rows from the sheet
48
+ await (0, wait_1.wait)(waitSeconds, `before getting rows for sheet: ${sheetTitle}`);
49
+ const rows = await sheet.getRows();
50
+ if (!rows || rows.length === 0) {
51
+ console.warn(`No rows found in sheet "${sheetTitle}", cannot update`);
52
+ continue;
53
+ }
54
+ // Extract header information
55
+ const rowObject = rows[0].toObject();
56
+ const headerRow = Object.keys(rowObject).map(key => key.toLowerCase());
57
+ const keyColumn = headerRow[0]; // First column is the key
58
+ // Get all locales from the headerRow except the key column
59
+ const locales = headerRow.filter(key => key !== keyColumn);
60
+ // Map of existing keys to their row indices
61
+ const existingKeys = new Map();
62
+ rows.forEach((row, index) => {
63
+ const rowData = row.toObject();
64
+ const keyField = Object.keys(rowData).find(k => k.toLowerCase() === keyColumn);
65
+ if (keyField && rowData[keyField]) {
66
+ // Store the key in lowercase for case-insensitive comparison
67
+ existingKeys.set(rowData[keyField].toString().toLowerCase(), index);
68
+ }
69
+ });
70
+ // New keys to add to the sheet
71
+ const newKeys = new Map();
72
+ // Track which locales have values for each new key (for auto-translation)
73
+ const keyLocalesMap = new Map();
74
+ // Collect all new keys and their translations
75
+ for (const locale of Object.keys(changes)) {
76
+ if (!changes[locale]?.[sheetTitle])
77
+ continue;
78
+ const localeData = changes[locale][sheetTitle];
79
+ for (const key of Object.keys(localeData)) {
80
+ const keyLower = key.toLowerCase();
81
+ if (!existingKeys.has(keyLower)) {
82
+ if (!newKeys.has(keyLower)) {
83
+ newKeys.set(keyLower, { [keyColumn]: key });
84
+ // Initialize map for this key's locale values
85
+ keyLocalesMap.set(keyLower, new Map());
86
+ }
87
+ // Find the exact header for this locale using the mapping
88
+ let localeHeader = (0, localeNormalizer_1.getOriginalHeaderForLocale)(locale, localeMapping);
89
+ // Fallback to case-insensitive search in headerRow if mapping lookup fails
90
+ if (!localeHeader) {
91
+ localeHeader = headerRow.find(h => h.toLowerCase() === locale.toLowerCase());
92
+ }
93
+ if (localeHeader) {
94
+ const theKey = newKeys.get(keyLower);
95
+ if (!theKey) {
96
+ console.warn(`Key "${key}" not found in newKeys map, skipping...`);
97
+ continue;
98
+ }
99
+ const value = String(localeData[key]);
100
+ // Use the correct header name for the locale value
101
+ theKey[localeHeader] = value;
102
+ // Store this locale value for potential auto-translation
103
+ const localesForKey = keyLocalesMap.get(keyLower);
104
+ if (localesForKey) {
105
+ localesForKey.set(locale.toLowerCase(), localeHeader);
106
+ }
107
+ }
108
+ }
109
+ else {
110
+ // Update existing key with new translation
111
+ const rowIndex = existingKeys.get(keyLower);
112
+ const row = rows[rowIndex];
113
+ // Find the exact header for this locale using the mapping
114
+ let localeHeader = (0, localeNormalizer_1.getOriginalHeaderForLocale)(locale, localeMapping);
115
+ // Fallback to case-insensitive search if mapping lookup fails
116
+ if (!localeHeader) {
117
+ localeHeader = Object.keys(row.toObject()).find(h => h.toLowerCase() === locale.toLowerCase());
118
+ }
119
+ if (localeHeader) {
120
+ // Use set() method instead of direct property assignment to avoid TS errors
121
+ row.set(localeHeader, String(localeData[key]));
122
+ await (0, wait_1.wait)(waitSeconds / 2, `before updating row ${rowIndex}`);
123
+ try {
124
+ await row.save();
125
+ }
126
+ catch (err) {
127
+ console.error(`Failed to save row for key "${keyLower}" in sheet "${sheetTitle}":`, err);
128
+ }
129
+ }
130
+ }
131
+ }
132
+ }
133
+ // Add new keys to the sheet
134
+ if (newKeys.size > 0) {
135
+ console.log(`Adding ${newKeys.size} new keys to sheet ${sheetTitle}...`);
136
+ // Apply auto-translation for new keys if enabled
137
+ if (autoTranslate) {
138
+ // Process each new key
139
+ for (const [keyLower, rowData] of newKeys.entries()) {
140
+ const localesWithValues = keyLocalesMap.get(keyLower);
141
+ if (localesWithValues && localesWithValues.size > 0) {
142
+ // Pick the first locale with a value as the source for translation
143
+ const [, sourceHeader] = [...localesWithValues.entries()][0];
144
+ // Find the cell reference for the source value
145
+ // In Google Sheets formulas, we need to use column letters (A, B, C...) and row numbers
146
+ // For each locale that doesn't have a value, add a GOOGLETRANSLATE formula
147
+ for (const localeHeader of locales) {
148
+ const localeLower = localeHeader.toLowerCase();
149
+ // Skip if this locale already has a value
150
+ if (localesWithValues.has(localeLower) || rowData[localeHeader]) {
151
+ continue;
152
+ }
153
+ // Find the exact case-preserved header name
154
+ const exactHeaderName = headerRow.find(h => h.toLowerCase() === localeLower);
155
+ if (exactHeaderName) {
156
+ // Create Google Translate formula referring to the source column
157
+ // Since we don't know the exact row number yet, we'll use a special placeholder
158
+ // that will be replaced with the actual cell reference after the rows are added
159
+ // Get the column index for the source locale to build the reference
160
+ const sourceHeaderIndex = headerRow.indexOf(sourceHeader);
161
+ // Get the column index for the target locale
162
+ const targetHeaderIndex = headerRow.indexOf(exactHeaderName);
163
+ // Guard against unexpected out-of-range indices
164
+ if (sourceHeaderIndex < 0 || targetHeaderIndex < 0) {
165
+ continue;
166
+ }
167
+ const sourceColumnLetter = columnIndexToLetter(sourceHeaderIndex);
168
+ const targetColumnLetter = columnIndexToLetter(targetHeaderIndex);
169
+ // Create improved Google Translate formula using INDIRECT and cell references
170
+ // This formula dynamically references:
171
+ // - INDIRECT(sourceColumn&ROW()) for the source text
172
+ // - $sourceColumn$1 for the source language code from header
173
+ // - targetColumn$1 for the target language code from header
174
+ rowData[exactHeaderName] = `=GOOGLETRANSLATE(INDIRECT("${sourceColumnLetter}"&ROW());$${sourceColumnLetter}$1;${targetColumnLetter}$1)`;
175
+ }
176
+ }
177
+ }
178
+ }
179
+ }
180
+ const newRows = Array.from(newKeys.values());
181
+ await (0, wait_1.wait)(waitSeconds, `before adding ${newRows.length} new rows`);
182
+ // Add new rows in chunks to avoid rate limiting
183
+ const CHUNK_SIZE = 5;
184
+ for (let i = 0; i < newRows.length; i += CHUNK_SIZE) {
185
+ const chunk = newRows.slice(i, i + CHUNK_SIZE);
186
+ await sheet.addRows(chunk);
187
+ if (i + CHUNK_SIZE < newRows.length) {
188
+ await (0, wait_1.wait)(waitSeconds, `after adding ${chunk.length} rows (chunk ${i / CHUNK_SIZE + 1})`);
189
+ }
190
+ }
191
+ }
192
+ await (0, wait_1.wait)(waitSeconds, `after updating sheet: ${sheetTitle}`);
193
+ }
194
+ console.log("Finished updating spreadsheet with local changes.");
195
+ }
196
+ //# sourceMappingURL=spreadsheetUpdater.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"spreadsheetUpdater.js","sourceRoot":"","sources":["../../src/utils/spreadsheetUpdater.ts"],"names":[],"mappings":";;AAqCA,8EAiNC;AApPD,iCAA8B;AAC9B,yDAAgE;AAEhE,iGAAiG;AACjG,SAAS,mBAAmB,CAAC,KAAa;IACtC,IAAI,MAAM,GAAG,EAAE,CAAC;IAChB,IAAI,CAAC,GAAG,KAAK,CAAC;IACd,GAAG,CAAC;QACA,MAAM,GAAG,MAAM,CAAC,YAAY,CAAC,EAAE,GAAG,CAAC,CAAC,GAAG,EAAE,CAAC,CAAC,GAAG,MAAM,CAAC;QACrD,CAAC,GAAG,IAAI,CAAC,KAAK,CAAC,CAAC,GAAG,EAAE,CAAC,GAAG,CAAC,CAAC;IAC/B,CAAC,QAAQ,CAAC,IAAI,CAAC,EAAE;IACjB,OAAO,MAAM,CAAC;AAClB,CAAC;AAED;;;;;;;;;;;;;;;;;;;;GAoBG;AACI,KAAK,UAAU,iCAAiC,CACnD,GAAsB,EACtB,OAAwB,EACxB,WAAmB,EACnB,aAAa,GAAG,KAAK,EACrB,gBAAwC,EAAE;IAE1C,OAAO,CAAC,GAAG,CAAC,4CAA4C,CAAC,CAAC;IAE1D,2CAA2C;IAC3C,KAAK,MAAM,UAAU,IAAI,IAAI,GAAG,CAC5B,MAAM,CAAC,MAAM,CAAC,OAAO,CAAC,CAAC,OAAO,CAAC,MAAM,CAAC,EAAE,CAAC,MAAM,CAAC,IAAI,CAAC,MAAM,CAAC,CAAC,CAChE,EAAE,CAAC;QACA,OAAO,CAAC,GAAG,CAAC,qBAAqB,UAAU,EAAE,CAAC,CAAC;QAC/C,MAAM,KAAK,GAAG,GAAG,CAAC,aAAa,CAAC,UAAU,CAAC,CAAC;QAE5C,IAAI,CAAC,KAAK,EAAE,CAAC;YACT,OAAO,CAAC,IAAI,C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AE,CAAC;gBAClD,MAAM,KAAK,GAAG,OAAO,CAAC,KAAK,CAAC,CAAC,EAAE,CAAC,GAAG,UAAU,CAAC,CAAC;gBAE/C,MAAM,KAAK,CAAC,OAAO,CAAC,KAAK,CAAC,CAAC;gBAE3B,IAAI,CAAC,GAAG,UAAU,GAAG,OAAO,CAAC,MAAM,EAAE,CAAC;oBAClC,MAAM,IAAA,WAAI,EAAC,WAAW,EAAE,gBAAgB,KAAK,CAAC,MAAM,gBAAgB,CAAC,GAAG,UAAU,GAAG,CAAC,GAAG,CAAC,CAAC;gBAC/F,CAAC;YACL,CAAC;QACL,CAAC;QAED,MAAM,IAAA,WAAI,EAAC,WAAW,EAAE,yBAAyB,UAAU,EAAE,CAAC,CAAC;IACnE,CAAC;IAED,OAAO,CAAC,GAAG,CAAC,mDAAmD,CAAC,CAAC;AACrE,CAAC"}
@@ -0,0 +1,23 @@
1
+ import type { GoogleSpreadsheet } from "google-spreadsheet";
2
+ import type { TranslationData } from "../types";
3
+ /**
4
+ * Sync operation result
5
+ */
6
+ export interface SyncResult {
7
+ shouldRefresh: boolean;
8
+ hasChanges: boolean;
9
+ }
10
+ /**
11
+ * Checks if local changes need to be synced to the spreadsheet and performs the sync if needed
12
+ * @param doc Google Spreadsheet document
13
+ * @param dataJsonPath Path to the languageData.json file
14
+ * @param translationsOutputDir Directory containing translation output files
15
+ * @param syncLocalChanges Whether sync is enabled
16
+ * @param autoTranslate Whether to auto-generate Google Translate formulas
17
+ * @param spreadsheetData Current data from the spreadsheet
18
+ * @param waitSeconds Time to wait between API calls
19
+ * @param localeMapping Mapping from normalized locale codes to original spreadsheet headers
20
+ * @returns Sync operation result
21
+ */
22
+ export declare function handleBidirectionalSync(doc: GoogleSpreadsheet, dataJsonPath: string, translationsOutputDir: string, syncLocalChanges: boolean, autoTranslate: boolean, spreadsheetData: TranslationData, waitSeconds: number, localeMapping?: Record<string, string>): Promise<SyncResult>;
23
+ //# sourceMappingURL=syncManager.d.ts.map
@@ -0,0 +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;;;;;;;;;;;GAWG;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,GACxC,OAAO,CAAC,UAAU,CAAC,CAoDrB"}