@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.
- package/LICENSE +21 -0
- package/README.md +258 -0
- package/dist/constants.d.ts +6 -0
- package/dist/constants.d.ts.map +1 -0
- package/dist/constants.js +9 -0
- package/dist/constants.js.map +1 -0
- package/dist/getSpreadSheetData.d.ts +7 -0
- package/dist/getSpreadSheetData.d.ts.map +1 -0
- package/dist/getSpreadSheetData.js +121 -0
- package/dist/getSpreadSheetData.js.map +1 -0
- package/dist/index.d.ts +18 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +34 -0
- package/dist/index.js.map +1 -0
- package/dist/types.d.ts +22 -0
- package/dist/types.d.ts.map +1 -0
- package/dist/types.js +3 -0
- package/dist/types.js.map +1 -0
- package/dist/utils/auth.d.ts +8 -0
- package/dist/utils/auth.d.ts.map +1 -0
- package/dist/utils/auth.js +19 -0
- package/dist/utils/auth.js.map +1 -0
- package/dist/utils/configurationHandler.d.ts +29 -0
- package/dist/utils/configurationHandler.d.ts.map +1 -0
- package/dist/utils/configurationHandler.js +23 -0
- package/dist/utils/configurationHandler.js.map +1 -0
- package/dist/utils/dataConverter/convertFromDataJsonFormat.d.ts +8 -0
- package/dist/utils/dataConverter/convertFromDataJsonFormat.d.ts.map +1 -0
- package/dist/utils/dataConverter/convertFromDataJsonFormat.js +47 -0
- package/dist/utils/dataConverter/convertFromDataJsonFormat.js.map +1 -0
- package/dist/utils/dataConverter/convertToDataJsonFormat.d.ts +10 -0
- package/dist/utils/dataConverter/convertToDataJsonFormat.d.ts.map +1 -0
- package/dist/utils/dataConverter/convertToDataJsonFormat.js +51 -0
- package/dist/utils/dataConverter/convertToDataJsonFormat.js.map +1 -0
- package/dist/utils/dataConverter/findLocalChanges.d.ts +9 -0
- package/dist/utils/dataConverter/findLocalChanges.d.ts.map +1 -0
- package/dist/utils/dataConverter/findLocalChanges.js +39 -0
- package/dist/utils/dataConverter/findLocalChanges.js.map +1 -0
- package/dist/utils/fileWriter.d.ts +23 -0
- package/dist/utils/fileWriter.d.ts.map +1 -0
- package/dist/utils/fileWriter.js +119 -0
- package/dist/utils/fileWriter.js.map +1 -0
- package/dist/utils/getFileLastModified.d.ts +7 -0
- package/dist/utils/getFileLastModified.d.ts.map +1 -0
- package/dist/utils/getFileLastModified.js +23 -0
- package/dist/utils/getFileLastModified.js.map +1 -0
- package/dist/utils/isDataJsonNewer.d.ts +8 -0
- package/dist/utils/isDataJsonNewer.d.ts.map +1 -0
- package/dist/utils/isDataJsonNewer.js +40 -0
- package/dist/utils/isDataJsonNewer.js.map +1 -0
- package/dist/utils/localeFilter.d.ts +17 -0
- package/dist/utils/localeFilter.d.ts.map +1 -0
- package/dist/utils/localeFilter.js +49 -0
- package/dist/utils/localeFilter.js.map +1 -0
- package/dist/utils/localeNormalizer.d.ts +37 -0
- package/dist/utils/localeNormalizer.d.ts.map +1 -0
- package/dist/utils/localeNormalizer.js +145 -0
- package/dist/utils/localeNormalizer.js.map +1 -0
- package/dist/utils/readDataJson.d.ts +8 -0
- package/dist/utils/readDataJson.d.ts.map +1 -0
- package/dist/utils/readDataJson.js +29 -0
- package/dist/utils/readDataJson.js.map +1 -0
- package/dist/utils/sheetProcessor.d.ts +22 -0
- package/dist/utils/sheetProcessor.d.ts.map +1 -0
- package/dist/utils/sheetProcessor.js +86 -0
- package/dist/utils/sheetProcessor.js.map +1 -0
- package/dist/utils/spreadsheetUpdater.d.ts +25 -0
- package/dist/utils/spreadsheetUpdater.d.ts.map +1 -0
- package/dist/utils/spreadsheetUpdater.js +196 -0
- package/dist/utils/spreadsheetUpdater.js.map +1 -0
- package/dist/utils/syncManager.d.ts +23 -0
- package/dist/utils/syncManager.d.ts.map +1 -0
- package/dist/utils/syncManager.js +62 -0
- package/dist/utils/syncManager.js.map +1 -0
- package/dist/utils/validateEnv.d.ts +9 -0
- package/dist/utils/validateEnv.d.ts.map +1 -0
- package/dist/utils/validateEnv.js +29 -0
- package/dist/utils/validateEnv.js.map +1 -0
- package/dist/utils/wait.d.ts +9 -0
- package/dist/utils/wait.d.ts.map +1 -0
- package/dist/utils/wait.js +21 -0
- package/dist/utils/wait.js.map +1 -0
- package/package.json +91 -0
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import type { TranslationData } from "../../types";
|
|
2
|
+
/**
|
|
3
|
+
* Converts languageData.json format back to the translation object structure
|
|
4
|
+
* @param dataJson - Data in the languageData.json format
|
|
5
|
+
* @returns Converted data in the TranslationData format
|
|
6
|
+
*/
|
|
7
|
+
export declare function convertFromDataJsonFormat(dataJson: Record<string, unknown>[]): TranslationData;
|
|
8
|
+
//# sourceMappingURL=convertFromDataJsonFormat.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"convertFromDataJsonFormat.d.ts","sourceRoot":"","sources":["../../../src/utils/dataConverter/convertFromDataJsonFormat.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,eAAe,EAAoB,MAAM,aAAa,CAAC;AAYrE;;;;GAIG;AACH,wBAAgB,yBAAyB,CACxC,QAAQ,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,EAAE,GACjC,eAAe,CAqCjB"}
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.convertFromDataJsonFormat = convertFromDataJsonFormat;
|
|
4
|
+
/**
|
|
5
|
+
* Type-guard: checks that a value has the shape of sheet data
|
|
6
|
+
* (an object mapping locale → translation record)
|
|
7
|
+
*/
|
|
8
|
+
function isSheetData(v) {
|
|
9
|
+
return typeof v === 'object' && v !== null && !Array.isArray(v);
|
|
10
|
+
}
|
|
11
|
+
/**
|
|
12
|
+
* Converts languageData.json format back to the translation object structure
|
|
13
|
+
* @param dataJson - Data in the languageData.json format
|
|
14
|
+
* @returns Converted data in the TranslationData format
|
|
15
|
+
*/
|
|
16
|
+
function convertFromDataJsonFormat(dataJson) {
|
|
17
|
+
const result = {};
|
|
18
|
+
for (const projectData of dataJson) {
|
|
19
|
+
for (const sheetTitle of Object.keys(projectData)) {
|
|
20
|
+
const raw = projectData[sheetTitle];
|
|
21
|
+
if (!isSheetData(raw)) {
|
|
22
|
+
console.warn(`Skipping malformed entry for sheet "${sheetTitle}"`);
|
|
23
|
+
continue;
|
|
24
|
+
}
|
|
25
|
+
for (const locale of Object.keys(raw)) {
|
|
26
|
+
// Initialize locale if it doesn't exist
|
|
27
|
+
if (!result[locale]) {
|
|
28
|
+
result[locale] = {};
|
|
29
|
+
}
|
|
30
|
+
// Initialize sheet if it doesn't exist
|
|
31
|
+
if (!result[locale][sheetTitle]) {
|
|
32
|
+
result[locale][sheetTitle] = {};
|
|
33
|
+
}
|
|
34
|
+
const localeData = raw[locale];
|
|
35
|
+
if (typeof localeData !== 'object' || localeData === null) {
|
|
36
|
+
continue;
|
|
37
|
+
}
|
|
38
|
+
// Add all translations
|
|
39
|
+
for (const key of Object.keys(localeData)) {
|
|
40
|
+
result[locale][sheetTitle][key] = localeData[key];
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
return result;
|
|
46
|
+
}
|
|
47
|
+
//# sourceMappingURL=convertFromDataJsonFormat.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"convertFromDataJsonFormat.js","sourceRoot":"","sources":["../../../src/utils/dataConverter/convertFromDataJsonFormat.ts"],"names":[],"mappings":";;AAiBA,8DAuCC;AAtDD;;;GAGG;AACH,SAAS,WAAW,CACnB,CAAU;IAEV,OAAO,OAAO,CAAC,KAAK,QAAQ,IAAI,CAAC,KAAK,IAAI,IAAI,CAAC,KAAK,CAAC,OAAO,CAAC,CAAC,CAAC,CAAC;AACjE,CAAC;AAED;;;;GAIG;AACH,SAAgB,yBAAyB,CACxC,QAAmC;IAEnC,MAAM,MAAM,GAAoB,EAAE,CAAC;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the translation object to the expected languageData.json format
|
|
4
|
+
* @param translationObj - The translation object with locale->sheet->key->value structure
|
|
5
|
+
* @param locales - Array of locale identifiers
|
|
6
|
+
* @returns Converted data in the format expected for languageData.json
|
|
7
|
+
*/
|
|
8
|
+
export declare function convertToDataJsonFormat(translationObj: TranslationData, locales: string[]): Record<string, unknown>[];
|
|
9
|
+
export default convertToDataJsonFormat;
|
|
10
|
+
//# sourceMappingURL=convertToDataJsonFormat.d.ts.map
|
|
@@ -0,0 +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,CAuD3B;AAED,eAAe,uBAAuB,CAAC"}
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.convertToDataJsonFormat = convertToDataJsonFormat;
|
|
4
|
+
/**
|
|
5
|
+
* Converts the translation object to the expected languageData.json format
|
|
6
|
+
* @param translationObj - The translation object with locale->sheet->key->value structure
|
|
7
|
+
* @param locales - Array of locale identifiers
|
|
8
|
+
* @returns Converted data in the format expected for languageData.json
|
|
9
|
+
*/
|
|
10
|
+
function convertToDataJsonFormat(translationObj, locales) {
|
|
11
|
+
const result = [];
|
|
12
|
+
console.log("Converting translation object to languageData.json format...");
|
|
13
|
+
// Get all sheet names from all locales to make sure we don't miss any
|
|
14
|
+
const allSheets = new Set();
|
|
15
|
+
for (const locale of Object.keys(translationObj)) {
|
|
16
|
+
if (translationObj[locale]) {
|
|
17
|
+
for (const sheet of Object.keys(translationObj[locale])) {
|
|
18
|
+
allSheets.add(sheet);
|
|
19
|
+
}
|
|
20
|
+
}
|
|
21
|
+
}
|
|
22
|
+
console.log(`Found ${allSheets.size} sheets across all locales`);
|
|
23
|
+
// Process each sheet
|
|
24
|
+
for (const sheetTitle of allSheets) {
|
|
25
|
+
// Create a new project object with the sheet title as the main key
|
|
26
|
+
const projectData = {};
|
|
27
|
+
projectData[sheetTitle] = {};
|
|
28
|
+
// For each locale, add all key-value pairs
|
|
29
|
+
for (const locale of locales) {
|
|
30
|
+
if (translationObj?.[locale]?.[sheetTitle]) { // Use original locale case for lookup
|
|
31
|
+
// Create the locale object
|
|
32
|
+
projectData[sheetTitle][locale] = {};
|
|
33
|
+
// Add all translations for this locale
|
|
34
|
+
const translations = translationObj[locale][sheetTitle];
|
|
35
|
+
for (const key of Object.keys(translations)) {
|
|
36
|
+
projectData[sheetTitle][locale][key] = translations[key];
|
|
37
|
+
}
|
|
38
|
+
// Log how many translations we found for debugging
|
|
39
|
+
console.log(`Found ${Object.keys(translations).length} keys for locale ${locale} in sheet ${sheetTitle}`);
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
// Only add non-empty projects
|
|
43
|
+
if (Object.keys(projectData[sheetTitle]).length > 0) {
|
|
44
|
+
result.push(projectData);
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
console.log(`Created ${result.length} sheet entries for languageData.json`);
|
|
48
|
+
return result;
|
|
49
|
+
}
|
|
50
|
+
exports.default = convertToDataJsonFormat;
|
|
51
|
+
//# sourceMappingURL=convertToDataJsonFormat.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"convertToDataJsonFormat.js","sourceRoot":"","sources":["../../../src/utils/dataConverter/convertToDataJsonFormat.ts"],"names":[],"mappings":";;AAQA,0DA0DC;AAhED;;;;;GAKG;AACH,SAAgB,uBAAuB,CACtC,cAA+B,EAC/B,OAAiB;IAEjB,MAAM,MAAM,GAA8B,EAAE,CAAC;IAC7C,OAAO,CAAC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IAAI,CAAC,YAAY,CAAC,CAAC,MAC3B,oBAAoB,MAAM,aAAa,UAAU,EAAE,CACnD,CAAC;YACH,CAAC;QACF,CAAC;QAED,8BAA8B;QAC9B,IAAI,MAAM,CAAC,IAAI,CAAC,WAAW,CAAC,UAAU,CAAC,CAAC,CAAC,MAAM,GAAG,CAAC,EAAE,CAAC;YACrD,MAAM,CAAC,IAAI,CAAC,WAAW,CAAC,CAAC;QAC1B,CAAC;IACF,CAAC;IAED,OAAO,CAAC,GAAG,CAAC,WAAW,MAAM,CAAC,MAAM,sCAAsC,CAAC,CAAC;IAC5E,OAAO,MAAM,CAAC;AACf,CAAC;AAED,kBAAe,uBAAuB,CAAC"}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import type { TranslationData } from "../../types";
|
|
2
|
+
/**
|
|
3
|
+
* Compares local languageData.json with spreadsheet data to find new keys
|
|
4
|
+
* @param localData - Data from local languageData.json file
|
|
5
|
+
* @param spreadsheetData - Data fetched from the spreadsheet
|
|
6
|
+
* @returns Object with new keys that are in localData but not in spreadsheetData
|
|
7
|
+
*/
|
|
8
|
+
export declare function findLocalChanges(localData: TranslationData, spreadsheetData: TranslationData): TranslationData;
|
|
9
|
+
//# sourceMappingURL=findLocalChanges.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"findLocalChanges.d.ts","sourceRoot":"","sources":["../../../src/utils/dataConverter/findLocalChanges.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,aAAa,CAAC;AAEnD;;;;;GAKG;AAEH,wBAAgB,gBAAgB,CAC/B,SAAS,EAAE,eAAe,EAC1B,eAAe,EAAE,eAAe,GAC9B,eAAe,CA6BjB"}
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.findLocalChanges = findLocalChanges;
|
|
4
|
+
/**
|
|
5
|
+
* Compares local languageData.json with spreadsheet data to find new keys
|
|
6
|
+
* @param localData - Data from local languageData.json file
|
|
7
|
+
* @param spreadsheetData - Data fetched from the spreadsheet
|
|
8
|
+
* @returns Object with new keys that are in localData but not in spreadsheetData
|
|
9
|
+
*/
|
|
10
|
+
function findLocalChanges(localData, spreadsheetData) {
|
|
11
|
+
const changes = {};
|
|
12
|
+
// Check each locale in local data
|
|
13
|
+
for (const locale of Object.keys(localData)) {
|
|
14
|
+
if (!localData[locale])
|
|
15
|
+
continue;
|
|
16
|
+
// Check each sheet in local data
|
|
17
|
+
for (const sheet of Object.keys(localData[locale])) {
|
|
18
|
+
if (!localData[locale][sheet])
|
|
19
|
+
continue;
|
|
20
|
+
// Check each key in local data
|
|
21
|
+
for (const key of Object.keys(localData[locale][sheet])) {
|
|
22
|
+
// If the spreadsheet doesn't have this locale, sheet, or key, it's a new key
|
|
23
|
+
const isNewKey = !spreadsheetData[locale] ||
|
|
24
|
+
!spreadsheetData[locale][sheet] ||
|
|
25
|
+
!spreadsheetData[locale][sheet][key];
|
|
26
|
+
// If it's a new key, add it to changes
|
|
27
|
+
if (isNewKey) {
|
|
28
|
+
if (!changes[locale])
|
|
29
|
+
changes[locale] = {};
|
|
30
|
+
if (!changes[locale][sheet])
|
|
31
|
+
changes[locale][sheet] = {};
|
|
32
|
+
changes[locale][sheet][key] = localData[locale][sheet][key];
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
return changes;
|
|
38
|
+
}
|
|
39
|
+
//# sourceMappingURL=findLocalChanges.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"findLocalChanges.js","sourceRoot":"","sources":["../../../src/utils/dataConverter/findLocalChanges.ts"],"names":[],"mappings":";;AASA,4CAgCC;AAvCD;;;;;GAKG;AAEH,SAAgB,gBAAgB,CAC/B,SAA0B,EAC1B,eAAgC;IAEhC,MAAM,OAAO,GAAoB,EAAE,CAAC;IAEpC,kCA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|
3
|
+
* Writes locale files to the translations directory
|
|
4
|
+
* @param translations Translation data organized by locale
|
|
5
|
+
* @param locales Array of locale identifiers
|
|
6
|
+
* @param translationsOutputDir Directory to write translation files to
|
|
7
|
+
*/
|
|
8
|
+
export declare function writeTranslationFiles(translations: TranslationData, locales: string[], translationsOutputDir: string): void;
|
|
9
|
+
/**
|
|
10
|
+
* Writes the locales.ts file containing the array of available locales and header mapping
|
|
11
|
+
* @param locales Array of normalized locale identifiers (filtered to only include valid locales)
|
|
12
|
+
* @param localeMapping Mapping from normalized locales to original spreadsheet headers
|
|
13
|
+
* @param localesOutputPath Path to write the locales.ts file
|
|
14
|
+
*/
|
|
15
|
+
export declare function writeLocalesFile(locales: string[], localeMapping: Record<string, string>, localesOutputPath: string): void;
|
|
16
|
+
/**
|
|
17
|
+
* Writes the languageData.json file containing all translation data
|
|
18
|
+
* @param translations Translation data organized by locale
|
|
19
|
+
* @param locales Array of locale identifiers
|
|
20
|
+
* @param dataJsonPath Path to write the languageData.json file
|
|
21
|
+
*/
|
|
22
|
+
export declare function writeLanguageDataFile(translations: TranslationData, locales: string[], dataJsonPath: string): void;
|
|
23
|
+
//# sourceMappingURL=fileWriter.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"fileWriter.d.ts","sourceRoot":"","sources":["../../src/utils/fileWriter.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,UAAU,CAAC;AAGhD;;;;;GAKG;AACH,wBAAgB,qBAAqB,CACpC,YAAY,EAAE,eAAe,EAC7B,OAAO,EAAE,MAAM,EAAE,EACjB,qBAAqB,EAAE,MAAM,GAC3B,IAAI,CAqCN;AAED;;;;;GAKG;AACH,wBAAgB,gBAAgB,CAC/B,OAAO,EAAE,MAAM,EAAE,EACjB,aAAa,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,EACrC,iBAAiB,EAAE,MAAM,GACvB,IAAI,CAqCN;AAED;;;;;GAKG;AACH,wBAAgB,qBAAqB,CACpC,YAAY,EAAE,eAAe,EAC7B,OAAO,EAAE,MAAM,EAAE,EACjB,YAAY,EAAE,MAAM,GAClB,IAAI,CAwBN"}
|
|
@@ -0,0 +1,119 @@
|
|
|
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.writeTranslationFiles = writeTranslationFiles;
|
|
7
|
+
exports.writeLocalesFile = writeLocalesFile;
|
|
8
|
+
exports.writeLanguageDataFile = writeLanguageDataFile;
|
|
9
|
+
const node_fs_1 = __importDefault(require("node:fs"));
|
|
10
|
+
const node_path_1 = __importDefault(require("node:path"));
|
|
11
|
+
const convertToDataJsonFormat_1 = require("./dataConverter/convertToDataJsonFormat");
|
|
12
|
+
/**
|
|
13
|
+
* Writes locale files to the translations directory
|
|
14
|
+
* @param translations Translation data organized by locale
|
|
15
|
+
* @param locales Array of locale identifiers
|
|
16
|
+
* @param translationsOutputDir Directory to write translation files to
|
|
17
|
+
*/
|
|
18
|
+
function writeTranslationFiles(translations, locales, translationsOutputDir) {
|
|
19
|
+
// Make sure the translations directory exists
|
|
20
|
+
if (!node_fs_1.default.existsSync(translationsOutputDir)) {
|
|
21
|
+
try {
|
|
22
|
+
node_fs_1.default.mkdirSync(translationsOutputDir, { recursive: true });
|
|
23
|
+
}
|
|
24
|
+
catch (err) {
|
|
25
|
+
throw new Error(`Failed to create translations directory "${translationsOutputDir}"`, { cause: err });
|
|
26
|
+
}
|
|
27
|
+
}
|
|
28
|
+
// Write files for all locales
|
|
29
|
+
for (const locale of locales) {
|
|
30
|
+
if (!translations[locale] || Object.keys(translations[locale]).length === 0) {
|
|
31
|
+
console.warn(`No translations found for locale "${locale}"`);
|
|
32
|
+
continue;
|
|
33
|
+
}
|
|
34
|
+
// Sanitize locale to prevent path traversal attacks
|
|
35
|
+
const safeName = locale.toLowerCase().replace(/[^a-z0-9_-]/g, '_');
|
|
36
|
+
if (safeName !== locale.toLowerCase()) {
|
|
37
|
+
console.warn(`Locale "${locale}" contained unsafe characters; sanitised to "${safeName}"`);
|
|
38
|
+
}
|
|
39
|
+
try {
|
|
40
|
+
node_fs_1.default.writeFileSync(node_path_1.default.join(translationsOutputDir, `${safeName}.json`), JSON.stringify(translations[locale], null, 2), "utf8");
|
|
41
|
+
console.log(`Successfully wrote translations for ${locale}`);
|
|
42
|
+
}
|
|
43
|
+
catch (err) {
|
|
44
|
+
console.error(`Failed to write translation file for locale "${locale}" at "${node_path_1.default.join(translationsOutputDir, `${safeName}.json`)}":`, err);
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
/**
|
|
49
|
+
* Writes the locales.ts file containing the array of available locales and header mapping
|
|
50
|
+
* @param locales Array of normalized locale identifiers (filtered to only include valid locales)
|
|
51
|
+
* @param localeMapping Mapping from normalized locales to original spreadsheet headers
|
|
52
|
+
* @param localesOutputPath Path to write the locales.ts file
|
|
53
|
+
*/
|
|
54
|
+
function writeLocalesFile(locales, localeMapping, localesOutputPath) {
|
|
55
|
+
// Create locales.ts file directory if it doesn't exist
|
|
56
|
+
const localesOutputDir = node_path_1.default.dirname(localesOutputPath);
|
|
57
|
+
if (!node_fs_1.default.existsSync(localesOutputDir)) {
|
|
58
|
+
try {
|
|
59
|
+
node_fs_1.default.mkdirSync(localesOutputDir, { recursive: true });
|
|
60
|
+
}
|
|
61
|
+
catch (err) {
|
|
62
|
+
throw new Error(`Failed to create directory "${localesOutputDir}"`, { cause: err });
|
|
63
|
+
}
|
|
64
|
+
}
|
|
65
|
+
const validLocales = locales.filter(locale => locale && locale.trim().length > 0);
|
|
66
|
+
// Create the content with both locales and header mapping
|
|
67
|
+
const content = `/**
|
|
68
|
+
* This file is auto-generated from the Google Spreadsheet package.
|
|
69
|
+
* It contains the list of available locales and their mappings to original spreadsheet headers.
|
|
70
|
+
* Do not edit this file manually, it will be overwritten by the package.
|
|
71
|
+
*/
|
|
72
|
+
|
|
73
|
+
export const locales = ${JSON.stringify(validLocales)};
|
|
74
|
+
|
|
75
|
+
/**
|
|
76
|
+
* Mapping from normalized locale codes to original spreadsheet headers
|
|
77
|
+
* Used for syncing changes back to the spreadsheet
|
|
78
|
+
*/
|
|
79
|
+
export const localeHeaderMapping = ${JSON.stringify(localeMapping, null, 2)};
|
|
80
|
+
|
|
81
|
+
export default locales;
|
|
82
|
+
`;
|
|
83
|
+
try {
|
|
84
|
+
node_fs_1.default.writeFileSync(localesOutputPath, content, "utf8");
|
|
85
|
+
}
|
|
86
|
+
catch (err) {
|
|
87
|
+
throw new Error(`Failed to write locales file at "${localesOutputPath}"`, { cause: err });
|
|
88
|
+
}
|
|
89
|
+
console.log(`Successfully wrote locales file with ${validLocales.length} locales:`, validLocales);
|
|
90
|
+
console.log('Header mapping includes:', Object.keys(localeMapping).length, 'mappings');
|
|
91
|
+
}
|
|
92
|
+
/**
|
|
93
|
+
* Writes the languageData.json file containing all translation data
|
|
94
|
+
* @param translations Translation data organized by locale
|
|
95
|
+
* @param locales Array of locale identifiers
|
|
96
|
+
* @param dataJsonPath Path to write the languageData.json file
|
|
97
|
+
*/
|
|
98
|
+
function writeLanguageDataFile(translations, locales, dataJsonPath) {
|
|
99
|
+
// Create languageData.json directory if it doesn't exist
|
|
100
|
+
const dataJsonDir = node_path_1.default.dirname(dataJsonPath);
|
|
101
|
+
if (!node_fs_1.default.existsSync(dataJsonDir)) {
|
|
102
|
+
try {
|
|
103
|
+
node_fs_1.default.mkdirSync(dataJsonDir, { recursive: true });
|
|
104
|
+
}
|
|
105
|
+
catch (err) {
|
|
106
|
+
throw new Error(`Failed to create directory "${dataJsonDir}"`, { cause: err });
|
|
107
|
+
}
|
|
108
|
+
}
|
|
109
|
+
// Convert the object format to the array format expected in languageData.json
|
|
110
|
+
const dataJsonContent = (0, convertToDataJsonFormat_1.convertToDataJsonFormat)(translations, locales);
|
|
111
|
+
try {
|
|
112
|
+
node_fs_1.default.writeFileSync(dataJsonPath, JSON.stringify(dataJsonContent, null, 2), "utf8");
|
|
113
|
+
}
|
|
114
|
+
catch (err) {
|
|
115
|
+
throw new Error(`Failed to write language data file at "${dataJsonPath}"`, { cause: err });
|
|
116
|
+
}
|
|
117
|
+
console.log("Successfully updated languageData.json with fresh spreadsheet data");
|
|
118
|
+
}
|
|
119
|
+
//# sourceMappingURL=fileWriter.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"fileWriter.js","sourceRoot":"","sources":["../../src/utils/fileWriter.ts"],"names":[],"mappings":";;;;;AAWA,sDAyCC;AAQD,4CAyCC;AAQD,sDA4BC;AAzID,sDAAyB;AACzB,0DAA6B;AAE7B,qFAAkF;AAElF;;;;;GAKG;AACH,SAAgB,qBAAqB,CACpC,YAA6B,EAC7B,OAAiB,EACjB,qBAA6B;IAE7B,8CAA8C;IAC9C,IAAI,CAAC,iBAAE,CAAC,UAAU,CAAC,qBAAqB,CAAC,EAAE,CAAC;QAC3C,IAAI,CAAC;YACJ,iBAAE,CAAC,SAAS,CAAC,qBAAqB,EAAE,EAAE,SAAS,EAAE,IAAI,EAAE,CAAC,CAAC;QAC1D,CAAC;QAAC,OAAO,GAAG,EAAE,CAAC;YACd,MAAM,IAAI,KAAK,CAAC,4CAA4C,qBAAqB,GAAG,EAAE,EAAE,KAAK,EAAE,GAAG,EAAE,CAAC,CAAC;QACvG,CAAC;IACF,CAAC;IAED,8BAA8B;IAC9B,KAAK,MAAM,MAAM,IAAI,OAAO,EAAE,CAAC;QAC9B,IAAI,CAAC,YAAY,CAAC,MAAM,CAAC,IAAI,MAAM,CAAC,IAAI,CAAC,YAAY,CAAC,MAAM,CAAC,CAAC,CAAC,MAAM,KAAK,CAAC,EAAE,CAAC;YAC7E,OAAO,CAAC,IAAI,CAAC,qCAAqC,MAAM,GAAG,CAAC,CAAC;YAC7D,SAAS;Q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,+BAA+B,WAAW,GAAG,EAAE,EAAE,KAAK,EAAE,GAAG,EAAE,CAAC,CAAC;QAChF,CAAC;IACF,CAAC;IAED,8EAA8E;IAC9E,MAAM,eAAe,GAAG,IAAA,iDAAuB,EAAC,YAAY,EAAE,OAAO,CAAC,CAAC;IAEvE,IAAI,CAAC;QACJ,iBAAE,CAAC,aAAa,CACf,YAAY,EACZ,IAAI,CAAC,SAAS,CAAC,eAAe,EAAE,IAAI,EAAE,CAAC,CAAC,EACxC,MAAM,CACN,CAAC;IACH,CAAC;IAAC,OAAO,GAAG,EAAE,CAAC;QACd,MAAM,IAAI,KAAK,CAAC,0CAA0C,YAAY,GAAG,EAAE,EAAE,KAAK,EAAE,GAAG,EAAE,CAAC,CAAC;IAC5F,CAAC;IACD,OAAO,CAAC,GAAG,CAAC,oEAAoE,CAAC,CAAC;AACnF,CAAC"}
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Gets the last modified time of a file
|
|
3
|
+
* @param filePath - Path to the file
|
|
4
|
+
* @returns The last modified time as a Date object, or null if file doesn't exist
|
|
5
|
+
*/
|
|
6
|
+
export declare function getFileLastModified(filePath: string): Date | null;
|
|
7
|
+
//# sourceMappingURL=getFileLastModified.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"getFileLastModified.d.ts","sourceRoot":"","sources":["../../src/utils/getFileLastModified.ts"],"names":[],"mappings":"AAEA;;;;GAIG;AACH,wBAAgB,mBAAmB,CAAC,QAAQ,EAAE,MAAM,GAAG,IAAI,GAAG,IAAI,CAQjE"}
|
|
@@ -0,0 +1,23 @@
|
|
|
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.getFileLastModified = getFileLastModified;
|
|
7
|
+
const node_fs_1 = __importDefault(require("node:fs"));
|
|
8
|
+
/**
|
|
9
|
+
* Gets the last modified time of a file
|
|
10
|
+
* @param filePath - Path to the file
|
|
11
|
+
* @returns The last modified time as a Date object, or null if file doesn't exist
|
|
12
|
+
*/
|
|
13
|
+
function getFileLastModified(filePath) {
|
|
14
|
+
try {
|
|
15
|
+
const stats = node_fs_1.default.statSync(filePath);
|
|
16
|
+
return stats.mtime;
|
|
17
|
+
}
|
|
18
|
+
catch (error) {
|
|
19
|
+
console.warn(`Could not read file stats for "${filePath}":`, error);
|
|
20
|
+
return null;
|
|
21
|
+
}
|
|
22
|
+
}
|
|
23
|
+
//# sourceMappingURL=getFileLastModified.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"getFileLastModified.js","sourceRoot":"","sources":["../../src/utils/getFileLastModified.ts"],"names":[],"mappings":";;;;;AAOA,kDAQC;AAfD,sDAAyB;AAEzB;;;;GAIG;AACH,SAAgB,mBAAmB,CAAC,QAAgB;IACnD,IAAI,CAAC;QACJ,MAAM,KAAK,GAAG,iBAAE,CAAC,QAAQ,CAAC,QAAQ,CAAC,CAAC;QACpC,OAAO,KAAK,CAAC,KAAK,CAAC;IACpB,CAAC;IAAC,OAAO,KAAK,EAAE,CAAC;QAChB,OAAO,CAAC,IAAI,CAAC,kCAAkC,QAAQ,IAAI,EAAE,KAAK,CAAC,CAAC;QACpE,OAAO,IAAI,CAAC;IACb,CAAC;AACF,CAAC"}
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Checks if languageData.json has been modified more recently than the translation files
|
|
3
|
+
* @param dataJsonPath - Path to languageData.json
|
|
4
|
+
* @param translationsOutputDir - Directory containing translation files
|
|
5
|
+
* @returns True if languageData.json is newer than the translation files
|
|
6
|
+
*/
|
|
7
|
+
export declare function isDataJsonNewer(dataJsonPath: string, translationsOutputDir: string): boolean;
|
|
8
|
+
//# sourceMappingURL=isDataJsonNewer.d.ts.map
|
|
@@ -0,0 +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"}
|
|
@@ -0,0 +1,40 @@
|
|
|
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.isDataJsonNewer = isDataJsonNewer;
|
|
7
|
+
const node_fs_1 = __importDefault(require("node:fs"));
|
|
8
|
+
const node_path_1 = __importDefault(require("node:path"));
|
|
9
|
+
const getFileLastModified_1 = require("./getFileLastModified");
|
|
10
|
+
/**
|
|
11
|
+
* Checks if languageData.json has been modified more recently than the translation files
|
|
12
|
+
* @param dataJsonPath - Path to languageData.json
|
|
13
|
+
* @param translationsOutputDir - Directory containing translation files
|
|
14
|
+
* @returns True if languageData.json is newer than the translation files
|
|
15
|
+
*/
|
|
16
|
+
function isDataJsonNewer(dataJsonPath, translationsOutputDir) {
|
|
17
|
+
const dataJsonMtime = (0, getFileLastModified_1.getFileLastModified)(dataJsonPath);
|
|
18
|
+
if (!dataJsonMtime)
|
|
19
|
+
return false;
|
|
20
|
+
// Get the most recent translation file modification time
|
|
21
|
+
try {
|
|
22
|
+
const files = node_fs_1.default.readdirSync(translationsOutputDir)
|
|
23
|
+
.filter(file => file.endsWith('.json'))
|
|
24
|
+
.map(file => node_path_1.default.join(translationsOutputDir, file));
|
|
25
|
+
if (files.length === 0)
|
|
26
|
+
return true;
|
|
27
|
+
const mostRecentTranslationMtime = files
|
|
28
|
+
.map(file => (0, getFileLastModified_1.getFileLastModified)(file))
|
|
29
|
+
.filter((d) => d !== null)
|
|
30
|
+
.reduce((max, d) => (max === null || d > max ? d : max), null);
|
|
31
|
+
if (!mostRecentTranslationMtime)
|
|
32
|
+
return true;
|
|
33
|
+
return dataJsonMtime > mostRecentTranslationMtime;
|
|
34
|
+
}
|
|
35
|
+
catch (error) {
|
|
36
|
+
console.warn("Error comparing file modification times:", error);
|
|
37
|
+
return false;
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
//# sourceMappingURL=isDataJsonNewer.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"isDataJsonNewer.js","sourceRoot":"","sources":["../../src/utils/isDataJsonNewer.ts"],"names":[],"mappings":";;;;;AAUA,0CA2BC;AArCD,sDAAyB;AACzB,0DAA6B;AAC7B,+DAA4D;AAE5D;;;;;GAKG;AACH,SAAgB,eAAe,CAAC,YAAoB,EAAE,qBAA6B;IAClF,MAAM,aAAa,GAAG,IAAA,yCAAmB,EAAC,YAAY,CAAC,CAAC;IAExD,IAAI,CAAC,aAAa;QAAE,OAAO,KAAK,CAAC;IAEjC,yDAAyD;IACzD,IAAI,CAAC;QACJ,MAAM,KAAK,GAAG,iBAAE,CAAC,WAAW,CAAC,qBAAqB,CAAC;aACjD,MAAM,CAAC,IAAI,CAAC,EAAE,CAAC,IAAI,CAAC,QAAQ,CAAC,OAAO,CAAC,CAAC;aACtC,GAAG,CAAC,IAAI,CAAC,EAAE,CAAC,mBAAI,CAAC,IAAI,CAAC,qBAAqB,EAAE,IAAI,CAAC,CAAC,CAAC;QAEtD,IAAI,KAAK,CAAC,MAAM,KAAK,CAAC;YAAE,OAAO,IAAI,CAAC;QAEpC,MAAM,0BAA0B,GAAG,KAAK;aACtC,GAAG,CAAC,IAAI,CAAC,EAAE,CAAC,IAAA,yCAAmB,EAAC,IAAI,CAAC,CAAC;aACtC,MAAM,CAAC,CAAC,CAAC,EAAa,EAAE,CAAC,CAAC,KAAK,IAAI,CAAC;aACpC,MAAM,CACN,CAAC,GAAG,EAAE,CAAC,EAAE,EAAE,CAAC,CAAC,GAAG,KAAK,IAAI,IAAI,CAAC,GAAG,GAAG,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,GAAG,CAAC,EAC/C,IAAI,CACJ,CAAC;QAEH,IAAI,CAAC,0BAA0B;YAAE,OAAO,IAAI,CAAC;QAC7C,OAAO,aAAa,GAAG,0BAA0B,CAAC;IACnD,CAAC;IAAC,OAAO,KAAK,EAAE,CAAC;QAChB,OAAO,CAAC,IAAI,CAAC,0CAA0C,EAAE,KAAK,CAAC,CAAC;QAChE,OAAO,KAAK,CAAC;IACd,CAAC;AACF,CAAC"}
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Locale validation utilities
|
|
3
|
+
*/
|
|
4
|
+
/**
|
|
5
|
+
* Determines if a string represents a valid locale identifier
|
|
6
|
+
* @param value The string to test
|
|
7
|
+
* @returns true if the string appears to be a locale identifier
|
|
8
|
+
*/
|
|
9
|
+
export declare function isValidLocale(value: string): boolean;
|
|
10
|
+
/**
|
|
11
|
+
* Filters header row to only include valid locale columns, excluding the key column
|
|
12
|
+
* @param headerRow Array of column names from the sheet header
|
|
13
|
+
* @param keyColumn The name of the key column to exclude
|
|
14
|
+
* @returns Array of valid locale identifiers
|
|
15
|
+
*/
|
|
16
|
+
export declare function filterValidLocales(headerRow: string[], keyColumn: string): string[];
|
|
17
|
+
//# sourceMappingURL=localeFilter.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"localeFilter.d.ts","sourceRoot":"","sources":["../../src/utils/localeFilter.ts"],"names":[],"mappings":"AAAA;;GAEG;AAgBH;;;;GAIG;AACH,wBAAgB,aAAa,CAAC,KAAK,EAAE,MAAM,GAAG,OAAO,CAcpD;AAED;;;;;GAKG;AACH,wBAAgB,kBAAkB,CAAC,SAAS,EAAE,MAAM,EAAE,EAAE,SAAS,EAAE,MAAM,GAAG,MAAM,EAAE,CAKnF"}
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* Locale validation utilities
|
|
4
|
+
*/
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports.isValidLocale = isValidLocale;
|
|
7
|
+
exports.filterValidLocales = filterValidLocales;
|
|
8
|
+
const COMMON_LOCALE_PATTERNS = [
|
|
9
|
+
/^[a-z]{2}$/, // en, de, fr
|
|
10
|
+
/^[a-z]{2}-[a-z]{2}$/, // en-us, de-de
|
|
11
|
+
/^[a-z]{2}_[a-z]{2}$/, // en_us, de_de
|
|
12
|
+
/^[a-z]{2}-[a-z]{2}-[a-z]+$/, // en-us-traditional
|
|
13
|
+
];
|
|
14
|
+
const NON_LOCALE_KEYWORDS = [
|
|
15
|
+
'key', 'keys', 'id', 'identifier', 'name', 'title', 'label',
|
|
16
|
+
'description', 'comment', 'note', 'context', 'category', 'type',
|
|
17
|
+
'status', 'updated', 'created', 'modified', 'version', 'source',
|
|
18
|
+
'i18n', 'translation', 'namespace', 'section'
|
|
19
|
+
];
|
|
20
|
+
/**
|
|
21
|
+
* Determines if a string represents a valid locale identifier
|
|
22
|
+
* @param value The string to test
|
|
23
|
+
* @returns true if the string appears to be a locale identifier
|
|
24
|
+
*/
|
|
25
|
+
function isValidLocale(value) {
|
|
26
|
+
if (!value || typeof value !== 'string') {
|
|
27
|
+
return false;
|
|
28
|
+
}
|
|
29
|
+
const normalized = value.toLowerCase().trim();
|
|
30
|
+
// Check if it's a common non-locale keyword
|
|
31
|
+
if (NON_LOCALE_KEYWORDS.includes(normalized)) {
|
|
32
|
+
return false;
|
|
33
|
+
}
|
|
34
|
+
// Check if it matches common locale patterns (only accept lowercase patterns)
|
|
35
|
+
return COMMON_LOCALE_PATTERNS.some(pattern => pattern.test(normalized));
|
|
36
|
+
}
|
|
37
|
+
/**
|
|
38
|
+
* Filters header row to only include valid locale columns, excluding the key column
|
|
39
|
+
* @param headerRow Array of column names from the sheet header
|
|
40
|
+
* @param keyColumn The name of the key column to exclude
|
|
41
|
+
* @returns Array of valid locale identifiers
|
|
42
|
+
*/
|
|
43
|
+
function filterValidLocales(headerRow, keyColumn) {
|
|
44
|
+
return headerRow
|
|
45
|
+
.filter(column => column.toLowerCase() !== keyColumn.toLowerCase())
|
|
46
|
+
.filter(column => isValidLocale(column)) // Use original case for validation
|
|
47
|
+
.map(locale => locale.toLowerCase()); // Then normalize to lowercase
|
|
48
|
+
}
|
|
49
|
+
//# sourceMappingURL=localeFilter.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"localeFilter.js","sourceRoot":"","sources":["../../src/utils/localeFilter.ts"],"names":[],"mappings":";AAAA;;GAEG;;AAqBH,sCAcC;AAQD,gDAKC;AA9CD,MAAM,sBAAsB,GAAG;IAC9B,YAAY,EAAqB,aAAa;IAC9C,qBAAqB,EAAW,eAAe;IAC/C,qBAAqB,EAAW,eAAe;IAC/C,4BAA4B,EAAI,oBAAoB;CACpD,CAAC;AAEF,MAAM,mBAAmB,GAAG;IAC3B,KAAK,EAAE,MAAM,EAAE,IAAI,EAAE,YAAY,EAAE,MAAM,EAAE,OAAO,EAAE,OAAO;IAC3D,aAAa,EAAE,SAAS,EAAE,MAAM,EAAE,SAAS,EAAE,UAAU,EAAE,MAAM;IAC/D,QAAQ,EAAE,SAAS,EAAE,SAAS,EAAE,UAAU,EAAE,SAAS,EAAE,QAAQ;IAC/D,MAAM,EAAE,aAAa,EAAE,WAAW,EAAE,SAAS;CAC7C,CAAC;AAEF;;;;GAIG;AACH,SAAgB,aAAa,CAAC,KAAa;IAC1C,IAAI,CAAC,KAAK,IAAI,OAAO,KAAK,KAAK,QAAQ,EAAE,CAAC;QACzC,OAAO,KAAK,CAAC;IACd,CAAC;IAED,MAAM,UAAU,GAAG,KAAK,CAAC,WAAW,EAAE,CAAC,IAAI,EAAE,CAAC;IAE9C,4CAA4C;IAC5C,IAAI,mBAAmB,CAAC,QAAQ,CAAC,UAAU,CAAC,EAAE,CAAC;QAC9C,OAAO,KAAK,CAAC;IACd,CAAC;IAED,8EAA8E;IAC9E,OAAO,sBAAsB,CAAC,IAAI,CAAC,OAAO,CAAC,EAAE,CAAC,OAAO,CAAC,IAAI,CAAC,UAAU,CAAC,CAAC,CAAC;AACzE,CAAC;AAED;;;;;GAKG;AACH,SAAgB,kBAAkB,CAAC,SAAmB,EAAE,SAAiB;IACxE,OAAO,SAAS;SACd,MAAM,CAAC,MAAM,CAAC,EAAE,CAAC,MAAM,CAAC,WAAW,EAAE,KAAK,SAAS,CAAC,WAAW,EAAE,CAAC;SAClE,MAAM,CAAC,MAAM,CAAC,EAAE,CAAC,aAAa,CAAC,MAAM,CAAC,CAAC,CAAC,mCAAmC;SAC3E,GAAG,CAAC,MAAM,CAAC,EAAE,CAAC,MAAM,CAAC,WAAW,EAAE,CAAC,CAAC,CAAC,8BAA8B;AACtE,CAAC"}
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Locale normalization utilities for converting simple language codes to full locale codes
|
|
3
|
+
* and maintaining mappings between normalized codes and original spreadsheet headers
|
|
4
|
+
*/
|
|
5
|
+
/**
|
|
6
|
+
* Normalizes a language code to include country code if missing
|
|
7
|
+
* @param locale The original locale code from spreadsheet header
|
|
8
|
+
* @returns Normalized locale with country code
|
|
9
|
+
*/
|
|
10
|
+
export declare function normalizeLocaleCode(locale: string): string;
|
|
11
|
+
/**
|
|
12
|
+
* Creates a mapping between normalized locale codes and their original spreadsheet headers
|
|
13
|
+
* @param originalHeaders Array of original header names from spreadsheet
|
|
14
|
+
* @param keyColumn The key column name to exclude
|
|
15
|
+
* @returns Object with normalized locales and header mapping
|
|
16
|
+
*/
|
|
17
|
+
export declare function createLocaleMapping(originalHeaders: string[], keyColumn: string): {
|
|
18
|
+
normalizedLocales: string[];
|
|
19
|
+
localeMapping: Record<string, string>;
|
|
20
|
+
originalMapping: Record<string, string>;
|
|
21
|
+
};
|
|
22
|
+
/**
|
|
23
|
+
* Finds the original header name for a given normalized locale
|
|
24
|
+
* @param normalizedLocale The normalized locale code (e.g., 'pl-PL')
|
|
25
|
+
* @param localeMapping Mapping from normalized locales to original headers
|
|
26
|
+
* @returns Original header name or undefined if not found
|
|
27
|
+
*/
|
|
28
|
+
export declare function getOriginalHeaderForLocale(normalizedLocale: string, localeMapping: Record<string, string>): string | undefined;
|
|
29
|
+
/**
|
|
30
|
+
* Finds the normalized locale for a given original header
|
|
31
|
+
* @public
|
|
32
|
+
* @param originalHeader The original header name (e.g., 'pl')
|
|
33
|
+
* @param originalMapping Mapping from original headers to normalized locales
|
|
34
|
+
* @returns Normalized locale code or undefined if not found
|
|
35
|
+
*/
|
|
36
|
+
export declare function getNormalizedLocaleForHeader(originalHeader: string, originalMapping: Record<string, string>): string | undefined;
|
|
37
|
+
//# sourceMappingURL=localeNormalizer.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"localeNormalizer.d.ts","sourceRoot":"","sources":["../../src/utils/localeNormalizer.ts"],"names":[],"mappings":"AAAA;;;GAGG;AA4CH;;;;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;;;;;GAKG;AACH,wBAAgB,0BAA0B,CACzC,gBAAgB,EAAE,MAAM,EACxB,aAAa,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,GACnC,MAAM,GAAG,SAAS,CAkBpB;AAED;;;;;;GAMG;AACH,wBAAgB,4BAA4B,CAC3C,cAAc,EAAE,MAAM,EACtB,eAAe,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,GACrC,MAAM,GAAG,SAAS,CAEpB"}
|