@scoutello/i18n-magic 0.15.2 → 0.18.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 (63) hide show
  1. package/README.md +178 -17
  2. package/dist/cli.d.ts +2 -0
  3. package/dist/cli.d.ts.map +1 -0
  4. package/dist/cli.js +101 -0
  5. package/dist/cli.js.map +1 -0
  6. package/dist/commands/check-missing.d.ts +1 -0
  7. package/dist/commands/check-missing.d.ts.map +1 -0
  8. package/dist/commands/check-missing.js +13 -0
  9. package/dist/commands/check-missing.js.map +1 -0
  10. package/dist/commands/clean.d.ts +3 -0
  11. package/dist/commands/clean.d.ts.map +1 -0
  12. package/dist/commands/clean.js +81 -0
  13. package/dist/commands/clean.js.map +1 -0
  14. package/dist/commands/create-pruned-namespace-automated.d.ts +20 -0
  15. package/dist/commands/create-pruned-namespace-automated.d.ts.map +1 -0
  16. package/dist/commands/create-pruned-namespace-automated.js +98 -0
  17. package/dist/commands/create-pruned-namespace-automated.js.map +1 -0
  18. package/dist/commands/create-pruned-namespace.d.ts +3 -0
  19. package/dist/commands/create-pruned-namespace.d.ts.map +1 -0
  20. package/dist/commands/create-pruned-namespace.js +122 -0
  21. package/dist/commands/create-pruned-namespace.js.map +1 -0
  22. package/dist/commands/replace.d.ts +1 -0
  23. package/dist/commands/replace.d.ts.map +1 -0
  24. package/dist/commands/replace.js +58 -0
  25. package/dist/commands/replace.js.map +1 -0
  26. package/dist/commands/scan.d.ts +1 -0
  27. package/dist/commands/scan.d.ts.map +1 -0
  28. package/dist/commands/scan.js +70 -0
  29. package/dist/commands/scan.js.map +1 -0
  30. package/dist/commands/sync-locales.d.ts +1 -0
  31. package/dist/commands/sync-locales.d.ts.map +1 -0
  32. package/dist/commands/sync-locales.js +78 -0
  33. package/dist/commands/sync-locales.js.map +1 -0
  34. package/dist/i18n-magic.cjs.development.js +458 -126
  35. package/dist/i18n-magic.cjs.development.js.map +1 -1
  36. package/dist/i18n-magic.cjs.production.min.js +1 -1
  37. package/dist/i18n-magic.cjs.production.min.js.map +1 -1
  38. package/dist/i18n-magic.esm.js +449 -126
  39. package/dist/i18n-magic.esm.js.map +1 -1
  40. package/dist/index.d.ts +11 -1
  41. package/dist/index.d.ts.map +1 -0
  42. package/dist/index.js +22 -9
  43. package/dist/index.js.map +1 -0
  44. package/dist/lib/languges.d.ts +1 -0
  45. package/dist/lib/languges.d.ts.map +1 -0
  46. package/dist/lib/languges.js +146 -0
  47. package/dist/lib/languges.js.map +1 -0
  48. package/dist/lib/types.d.ts +8 -0
  49. package/dist/lib/types.d.ts.map +1 -0
  50. package/dist/lib/types.js +3 -0
  51. package/dist/lib/types.js.map +1 -0
  52. package/dist/lib/utils.d.ts +1 -0
  53. package/dist/lib/utils.d.ts.map +1 -0
  54. package/dist/lib/utils.js +220 -0
  55. package/dist/lib/utils.js.map +1 -0
  56. package/package.json +37 -14
  57. package/src/cli.ts +117 -0
  58. package/src/commands/clean.ts +105 -0
  59. package/src/commands/create-pruned-namespace-automated.ts +165 -0
  60. package/src/commands/create-pruned-namespace.ts +165 -0
  61. package/src/commands/scan.ts +12 -0
  62. package/src/index.ts +23 -106
  63. package/src/lib/types.ts +8 -0
@@ -0,0 +1,122 @@
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.createPrunedNamespace = void 0;
7
+ const fast_glob_1 = __importDefault(require("fast-glob"));
8
+ const i18next_scanner_1 = require("i18next-scanner");
9
+ const node_fs_1 = __importDefault(require("node:fs"));
10
+ const prompts_1 = __importDefault(require("prompts"));
11
+ const utils_1 = require("../lib/utils");
12
+ const createPrunedNamespace = async (config) => {
13
+ const { namespaces, loadPath, savePath, locales, defaultNamespace } = config;
14
+ // Step 1: Ask for source namespace
15
+ const sourceNamespaceResponse = await (0, prompts_1.default)({
16
+ type: "select",
17
+ name: "value",
18
+ message: "Select source namespace to create pruned version from:",
19
+ choices: namespaces.map((namespace) => ({
20
+ title: namespace,
21
+ value: namespace,
22
+ })),
23
+ onState: (state) => {
24
+ if (state.aborted) {
25
+ process.nextTick(() => {
26
+ process.exit(0);
27
+ });
28
+ }
29
+ },
30
+ });
31
+ const sourceNamespace = sourceNamespaceResponse.value;
32
+ // Step 2: Ask for new namespace name
33
+ const newNamespaceResponse = await (0, prompts_1.default)({
34
+ type: "text",
35
+ name: "value",
36
+ message: "Enter the name for the new namespace:",
37
+ validate: (value) => {
38
+ if (!value)
39
+ return "Namespace name cannot be empty";
40
+ if (namespaces.includes(value))
41
+ return "Namespace already exists";
42
+ return true;
43
+ },
44
+ onState: (state) => {
45
+ if (state.aborted) {
46
+ process.nextTick(() => {
47
+ process.exit(0);
48
+ });
49
+ }
50
+ },
51
+ });
52
+ const newNamespace = newNamespaceResponse.value;
53
+ // Step 3: Ask for glob patterns to find relevant keys
54
+ const globPatternsResponse = await (0, prompts_1.default)({
55
+ type: "list",
56
+ name: "value",
57
+ message: "Enter glob patterns to find relevant keys (comma separated):",
58
+ initial: config.globPatterns.join(","),
59
+ separator: ",",
60
+ onState: (state) => {
61
+ if (state.aborted) {
62
+ process.nextTick(() => {
63
+ process.exit(0);
64
+ });
65
+ }
66
+ },
67
+ });
68
+ const selectedGlobPatterns = globPatternsResponse.value;
69
+ console.log(`Finding keys used in files matching: ${selectedGlobPatterns.join(", ")}`);
70
+ // Extract keys from files matching the glob patterns
71
+ const parser = new i18next_scanner_1.Parser({
72
+ nsSeparator: false,
73
+ keySeparator: false,
74
+ });
75
+ const files = await (0, fast_glob_1.default)([...selectedGlobPatterns, "!**/node_modules/**"]);
76
+ console.log(`Found ${files.length} files to scan`);
77
+ const extractedKeys = [];
78
+ for (const file of files) {
79
+ const content = node_fs_1.default.readFileSync(file, "utf-8");
80
+ parser.parseFuncFromString(content, { list: ["t"] }, (key) => {
81
+ extractedKeys.push(key);
82
+ });
83
+ }
84
+ const uniqueExtractedKeys = (0, utils_1.removeDuplicatesFromArray)(extractedKeys);
85
+ console.log(`Found ${uniqueExtractedKeys.length} unique translation keys`);
86
+ // Filter keys that belong to the source namespace
87
+ const relevantKeys = [];
88
+ for (const key of uniqueExtractedKeys) {
89
+ const pureKey = (0, utils_1.getPureKey)(key, sourceNamespace, sourceNamespace === defaultNamespace);
90
+ if (pureKey) {
91
+ relevantKeys.push(pureKey);
92
+ }
93
+ }
94
+ console.log(`Found ${relevantKeys.length} keys from namespace '${sourceNamespace}'`);
95
+ if (relevantKeys.length === 0) {
96
+ console.log("No relevant keys found. Exiting...");
97
+ return;
98
+ }
99
+ // Get translations from source namespace and create new namespace files
100
+ for (const locale of locales) {
101
+ try {
102
+ // Load source namespace translations
103
+ const sourceTranslations = await (0, utils_1.loadLocalesFile)(loadPath, locale, sourceNamespace);
104
+ // Create new namespace with only the keys used in the glob pattern files
105
+ const newNamespaceTranslations = {};
106
+ for (const key of relevantKeys) {
107
+ if (sourceTranslations[key]) {
108
+ newNamespaceTranslations[key] = sourceTranslations[key];
109
+ }
110
+ }
111
+ // Write the new namespace file
112
+ await (0, utils_1.writeLocalesFile)(savePath, locale, newNamespace, newNamespaceTranslations);
113
+ console.log(`Created pruned namespace '${newNamespace}' for locale '${locale}' with ${Object.keys(newNamespaceTranslations).length} keys`);
114
+ }
115
+ catch (error) {
116
+ console.error(`Error creating pruned namespace for locale '${locale}':`, error);
117
+ }
118
+ }
119
+ console.log(`✅ Successfully created pruned namespace '${newNamespace}'`);
120
+ };
121
+ exports.createPrunedNamespace = createPrunedNamespace;
122
+ //# sourceMappingURL=create-pruned-namespace.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"create-pruned-namespace.js","sourceRoot":"","sources":["../../src/commands/create-pruned-namespace.ts"],"names":[],"mappings":";;;;;;AAAA,0DAA4B;AAC5B,qDAAwC;AACxC,sDAAwB;AACxB,sDAA6B;AAE7B,wCAKqB;AAEd,MAAM,qBAAqB,GAAG,KAAK,EAAE,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;gBACzD,CAAC;YACH,CAAC;YAED,+BAA+B;YAC/B,MAAM,IAAA,wBAAgB,EACpB,QAAQ,EACR,MAAM,EACN,YAAY,EACZ,wBAAwB,CACzB,CAAA;YAED,OAAO,CAAC,GAAG,CACT,6BAA6B,YAAY,iBAAiB,MAAM,UAC9D,MAAM,CAAC,IAAI,CAAC,wBAAwB,CAAC,CAAC,MACxC,OAAO,CACR,CAAA;QACH,CAAC;QAAC,OAAO,KAAK,EAAE,CAAC;YACf,OAAO,CAAC,KAAK,CACX,+CAA+C,MAAM,IAAI,EACzD,KAAK,CACN,CAAA;QACH,CAAC;IACH,CAAC;IAED,OAAO,CAAC,GAAG,CAAC,4CAA4C,YAAY,GAAG,CAAC,CAAA;AAC1E,CAAC,CAAA;AAxJY,QAAA,qBAAqB,yBAwJjC"}
@@ -1,2 +1,3 @@
1
1
  import type { Configuration } from "../lib/types";
2
2
  export declare const replaceTranslation: (config: Configuration, key?: string) => Promise<void>;
3
+ //# sourceMappingURL=replace.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"replace.d.ts","sourceRoot":"","sources":["../../src/commands/replace.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,cAAc,CAAA;AAsBjD,eAAO,MAAM,kBAAkB,GAC7B,QAAQ,aAAa,EACrB,MAAM,MAAM,kBAyEb,CAAA"}
@@ -0,0 +1,58 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.replaceTranslation = void 0;
4
+ const utils_1 = require("../lib/utils");
5
+ const getKeyToReplace = async (keys) => {
6
+ const keyToReplace = await (0, utils_1.getTextInput)("Enter the key to replace the translation for: ");
7
+ if (!keys[keyToReplace]) {
8
+ console.log(`The key "${keyToReplace}" does not exist.`);
9
+ return await getKeyToReplace(keys);
10
+ }
11
+ console.log(`The key "${keyToReplace}" exists.`);
12
+ return keyToReplace;
13
+ };
14
+ const replaceTranslation = async (config, key) => {
15
+ const { loadPath, savePath, defaultLocale, defaultNamespace, namespaces, locales, globPatterns, context, openai, } = config;
16
+ const keys = await (0, utils_1.loadLocalesFile)(config.loadPath, config.defaultLocale, config.defaultNamespace);
17
+ let keyToReplace;
18
+ if (key) {
19
+ if (keys[key]) {
20
+ keyToReplace = key;
21
+ console.log(`The key "${keyToReplace}" exists.`);
22
+ }
23
+ else {
24
+ console.log(`The key "${key}" does not exist.`);
25
+ keyToReplace = await getKeyToReplace(keys);
26
+ }
27
+ }
28
+ else {
29
+ keyToReplace = await getKeyToReplace(keys);
30
+ }
31
+ console.log(`The current translation in ${defaultLocale} for "${keyToReplace}" is "${keys[keyToReplace]}".`);
32
+ const newTranslation = await (0, utils_1.getTextInput)("Enter the new translation: ");
33
+ for (const locale of locales) {
34
+ let newValue = "";
35
+ if (locale === defaultLocale) {
36
+ newValue = newTranslation;
37
+ }
38
+ else {
39
+ const translation = await (0, utils_1.translateKey)({
40
+ context,
41
+ inputLanguage: defaultLocale,
42
+ outputLanguage: locale,
43
+ object: {
44
+ [keyToReplace]: newTranslation,
45
+ },
46
+ openai,
47
+ model: config.model,
48
+ });
49
+ newValue = translation[keyToReplace];
50
+ }
51
+ const existingKeys = await (0, utils_1.loadLocalesFile)(loadPath, locale, defaultNamespace);
52
+ existingKeys[keyToReplace] = newValue;
53
+ (0, utils_1.writeLocalesFile)(savePath, locale, defaultNamespace, existingKeys);
54
+ console.log(`The new translation for "${keyToReplace}" in ${locale} is "${newValue}".`);
55
+ }
56
+ };
57
+ exports.replaceTranslation = replaceTranslation;
58
+ //# sourceMappingURL=replace.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"replace.js","sourceRoot":"","sources":["../../src/commands/replace.ts"],"names":[],"mappings":";;;AACA,wCAKqB;AAErB,MAAM,eAAe,GAAG,KAAK,EAAE,IAA4B,EAAE,EAAE;IAC7D,MAAM,YAAY,GAAG,MAAM,IAAA,oBAAY,EACrC,gDAAgD,CACjD,CAAA;IAED,IAAI,CAAC,IAAI,CA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AAE,CAAC;QAC7B,IAAI,QAAQ,GAAG,EAAE,CAAA;QACjB,IAAI,MAAM,KAAK,aAAa,EAAE,CAAC;YAC7B,QAAQ,GAAG,cAAc,CAAA;QAC3B,CAAC;aAAM,CAAC;YACN,MAAM,WAAW,GAAG,MAAM,IAAA,oBAAY,EAAC;gBACrC,OAAO;gBACP,aAAa,EAAE,aAAa;gBAC5B,cAAc,EAAE,MAAM;gBACtB,MAAM,EAAE;oBACN,CAAC,YAAY,CAAC,EAAE,cAAc;iBAC/B;gBACD,MAAM;gBACN,KAAK,EAAE,MAAM,CAAC,KAAK;aACpB,CAAC,CAAA;YAEF,QAAQ,GAAG,WAAW,CAAC,YAAY,CAAC,CAAA;QACtC,CAAC;QAED,MAAM,YAAY,GAAG,MAAM,IAAA,uBAAe,EACxC,QAAQ,EACR,MAAM,EACN,gBAAgB,CACjB,CAAA;QAED,YAAY,CAAC,YAAY,CAAC,GAAG,QAAQ,CAAA;QAErC,IAAA,wBAAgB,EAAC,QAAQ,EAAE,MAAM,EAAE,gBAAgB,EAAE,YAAY,CAAC,CAAA;QAElE,OAAO,CAAC,GAAG,CACT,4BAA4B,YAAY,QAAQ,MAAM,QAAQ,QAAQ,IAAI,CAC3E,CAAA;IACH,CAAC;AACH,CAAC,CAAA;AA3EY,QAAA,kBAAkB,sBA2E9B"}
@@ -1,2 +1,3 @@
1
1
  import type { Configuration } from "../lib/types";
2
2
  export declare const translateMissing: (config: Configuration) => Promise<void>;
3
+ //# sourceMappingURL=scan.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"scan.d.ts","sourceRoot":"","sources":["../../src/commands/scan.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,cAAc,CAAA;AAWjD,eAAO,MAAM,gBAAgB,GAAU,QAAQ,aAAa,kBA8F3D,CAAA"}
@@ -0,0 +1,70 @@
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.translateMissing = void 0;
7
+ const console_1 = __importDefault(require("console"));
8
+ const utils_1 = require("../lib/utils");
9
+ const clean_1 = require("./clean");
10
+ const translateMissing = async (config) => {
11
+ const { loadPath, savePath, defaultLocale, namespaces, locales, context, openai, disableTranslation, autoClear, } = config;
12
+ // Run clean command first if autoClear is enabled
13
+ if (autoClear) {
14
+ console_1.default.log("🧹 Auto-clearing unused translations before scanning...");
15
+ await (0, clean_1.removeUnusedKeys)(config);
16
+ console_1.default.log("✅ Auto-clear completed. Now scanning for missing translations...\n");
17
+ }
18
+ const newKeys = await (0, utils_1.getMissingKeys)(config);
19
+ if (newKeys.length === 0) {
20
+ console_1.default.log("No new keys found.");
21
+ await (0, utils_1.checkAllKeysExist)(config);
22
+ return;
23
+ }
24
+ console_1.default.log(`${newKeys.length} keys are missing. Please provide the values for the following keys in ${defaultLocale}:`);
25
+ const newKeysWithDefaultLocale = [];
26
+ for (const newKey of newKeys) {
27
+ const answer = await (0, utils_1.getTextInput)(newKey.key);
28
+ newKeysWithDefaultLocale.push({
29
+ key: newKey.key,
30
+ namespace: newKey.namespace,
31
+ value: answer,
32
+ });
33
+ }
34
+ const newKeysObject = newKeysWithDefaultLocale.reduce((prev, next) => {
35
+ prev[next.key] = next.value;
36
+ return prev;
37
+ }, {});
38
+ const allLocales = disableTranslation ? [defaultLocale] : locales;
39
+ for (const locale of allLocales) {
40
+ let translatedValues = {};
41
+ if (locale === defaultLocale) {
42
+ translatedValues = newKeysObject;
43
+ }
44
+ else {
45
+ translatedValues = await (0, utils_1.translateKey)({
46
+ inputLanguage: defaultLocale,
47
+ outputLanguage: locale,
48
+ context,
49
+ object: newKeysObject,
50
+ openai,
51
+ model: config.model,
52
+ });
53
+ }
54
+ for (const namespace of namespaces) {
55
+ const existingKeys = await (0, utils_1.loadLocalesFile)(loadPath, locale, namespace);
56
+ const relevantKeys = newKeysWithDefaultLocale.filter((key) => key.namespace === namespace);
57
+ if (relevantKeys.length === 0) {
58
+ continue;
59
+ }
60
+ for (const key of relevantKeys) {
61
+ existingKeys[key.key] = translatedValues[key.key];
62
+ }
63
+ (0, utils_1.writeLocalesFile)(savePath, locale, namespace, existingKeys);
64
+ }
65
+ }
66
+ await (0, utils_1.checkAllKeysExist)(config);
67
+ console_1.default.log(`Successfully translated ${newKeys.length} keys.`);
68
+ };
69
+ exports.translateMissing = translateMissing;
70
+ //# sourceMappingURL=scan.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"scan.js","sourceRoot":"","sources":["../../src/commands/scan.ts"],"names":[],"mappings":";;;;;;AAAA,sDAA6B;AAE7B,wCAOqB;AACrB,mCAA0C;AAEnC,MAAM,gBAAgB,GAAG,KAAK,EAAE,MAAqB,EAAE,EAAE;IAC9D,MAAM,EACJ,QAAQ,EACR,QAAQ,EACR,aAAa,EACb,UAAU,EACV,OAAO,EACP,OAAO,EACP,MAAM,EACN,kBAAkB,EAClB,SAAS,GACV,GAAG,MAAM,CAAA;IAEV,kDAAkD;IAClD,IAAI,SAAS,EAAE,CAAC;QACd,iBAAO,CAAC,GAAG,CAAC,yDAAyD,CAAC,CAAA;QACtE,MAAM,IAAA,wBAAgB,EAAC,MAAM,CAAC,CAAA;QAC9B,iBAAO,CAAC,GAAG,CACT,oEAAoE,CACrE,CAAA;IACH,CAAC;IAED,MAAM,OAAO,GAAG,MAAM,IAAA,sBAAc,EAAC,MAAM,CAAC,CAAA;IAE5C,IAAI,OAAO,CAAC,MAAM,KAAK,CAAC,EAAE,CAAC;QACzB,iBAAO,CAAC,GAAG,CAAC,oBAAoB,CAAC,CAAA;QAEjC,MAAM,IAAA,yBAAiB,EAAC,MAAM,CAAC,CAAA;QAE/B,OAAM;IACR,CAAC;IAED,iBAAO,CAAC,GAAG,CACT,GAAG,OAAO,CAAC,MAAM,0EAA0E,aAAa,GAAG,CAC5G,CAAA;IAED,MAAM,wBAAwB,GAAG,EAAE,C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C,GAAG,CAAC,SAAS,KAAK,SAAS,CACrC,CAAA;YAED,IAAI,YAAY,CAAC,MAAM,KAAK,CAAC,EAAE,CAAC;gBAC9B,SAAQ;YACV,CAAC;YAED,KAAK,MAAM,GAAG,IAAI,YAAY,EAAE,CAAC;gBAC/B,YAAY,CAAC,GAAG,CAAC,GAAG,CAAC,GAAG,gBAAgB,CAAC,GAAG,CAAC,GAAG,CAAC,CAAA;YACnD,CAAC;YAED,IAAA,wBAAgB,EAAC,QAAQ,EAAE,MAAM,EAAE,SAAS,EAAE,YAAY,CAAC,CAAA;QAC7D,CAAC;IACH,CAAC;IAED,MAAM,IAAA,yBAAiB,EAAC,MAAM,CAAC,CAAA;IAE/B,iBAAO,CAAC,GAAG,CAAC,2BAA2B,OAAO,CAAC,MAAM,QAAQ,CAAC,CAAA;AAChE,CAAC,CAAA;AA9FY,QAAA,gBAAgB,oBA8F5B"}
@@ -1,2 +1,3 @@
1
1
  import type { Configuration } from "../lib/types";
2
2
  export declare const syncLocales: (config: Configuration) => Promise<void>;
3
+ //# sourceMappingURL=sync-locales.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"sync-locales.d.ts","sourceRoot":"","sources":["../../src/commands/sync-locales.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,cAAc,CAAA;AAQjD,eAAO,MAAM,WAAW,GAAU,QAAQ,aAAa,kBAwHtD,CAAA"}
@@ -0,0 +1,78 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.syncLocales = void 0;
4
+ const utils_1 = require("../lib/utils");
5
+ const syncLocales = async (config) => {
6
+ const { loadPath, savePath, defaultLocale, namespaces, locales, context, openai, } = config;
7
+ try {
8
+ for (const namespace of namespaces) {
9
+ let defaultLocaleKeys;
10
+ try {
11
+ defaultLocaleKeys = await (0, utils_1.loadLocalesFile)(loadPath, defaultLocale, namespace);
12
+ }
13
+ catch (error) {
14
+ throw new utils_1.TranslationError(`Failed to load default locale file for namespace "${namespace}"`, defaultLocale, namespace, error instanceof Error ? error : undefined);
15
+ }
16
+ for (const locale of locales) {
17
+ if (locale === defaultLocale)
18
+ continue;
19
+ let localeKeys;
20
+ try {
21
+ localeKeys = await (0, utils_1.loadLocalesFile)(loadPath, locale, namespace);
22
+ }
23
+ catch (error) {
24
+ console.warn(`Warning: Could not load locale file for ${locale} (namespace: ${namespace}). Creating new file.`);
25
+ localeKeys = {};
26
+ }
27
+ const missingKeys = {};
28
+ // Check which keys from default locale are missing in current locale
29
+ for (const [key, value] of Object.entries(defaultLocaleKeys)) {
30
+ if (!localeKeys[key]) {
31
+ missingKeys[key] = value;
32
+ }
33
+ }
34
+ // If there are missing keys, translate them
35
+ if (Object.keys(missingKeys).length > 0) {
36
+ console.log(`Found ${Object.keys(missingKeys).length} missing keys in ${locale} (namespace: ${namespace})`);
37
+ let translatedValues;
38
+ try {
39
+ translatedValues = await (0, utils_1.translateKey)({
40
+ inputLanguage: defaultLocale,
41
+ outputLanguage: locale,
42
+ context,
43
+ object: missingKeys,
44
+ openai,
45
+ model: config.model,
46
+ });
47
+ }
48
+ catch (error) {
49
+ throw new utils_1.TranslationError(`Failed to translate keys for locale "${locale}" (namespace: ${namespace})`, locale, namespace, error instanceof Error ? error : undefined);
50
+ }
51
+ // Merge translated values with existing ones
52
+ const updatedLocaleKeys = {
53
+ ...localeKeys,
54
+ ...translatedValues,
55
+ };
56
+ try {
57
+ await (0, utils_1.writeLocalesFile)(savePath, locale, namespace, updatedLocaleKeys);
58
+ }
59
+ catch (error) {
60
+ throw new utils_1.TranslationError(`Failed to save translations for locale "${locale}" (namespace: ${namespace})`, locale, namespace, error instanceof Error ? error : undefined);
61
+ }
62
+ console.log(`Successfully translated and saved ${Object.keys(missingKeys).length} keys for ${locale} (namespace: ${namespace})`);
63
+ }
64
+ else {
65
+ console.log(`No missing keys found for ${locale} (namespace: ${namespace})`);
66
+ }
67
+ }
68
+ }
69
+ }
70
+ catch (error) {
71
+ if (error instanceof utils_1.TranslationError) {
72
+ throw error;
73
+ }
74
+ throw new utils_1.TranslationError("An unexpected error occurred during translation", undefined, undefined, error instanceof Error ? error : undefined);
75
+ }
76
+ };
77
+ exports.syncLocales = syncLocales;
78
+ //# sourceMappingURL=sync-locales.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"sync-locales.js","sourceRoot":"","sources":["../../src/commands/sync-locales.ts"],"names":[],"mappings":";;;AACA,wCAKqB;AAEd,MAAM,WAAW,GAAG,KAAK,EAAE,MAAqB,EAAE,EAAE;IACzD,MAAM,EACJ,QAAQ,EACR,QAAQ,EACR,aAAa,EACb,UAAU,EACV,OAAO,EACP,OAAO,EACP,MAAM,GACP,GAAG,MAAM,CAAA;IAEV,IAAI,CAAC;QACH,KAAK,MAAM,SAAS,IAAI,UAAU,EAAE,CAAC;YACnC,IAAI,iBAAyC,CAAA;YAE7C,IAAI,CAAC;gBACH,iBAAiB,GAAG,MAAM,IAAA,uBAAe,EACvC,QAAQ,EACR,aAAa,EACb,SAAS,CACV,CAAA;YACH,CAAC;YAAC,OAAO,KAAK,EAAE,CAAC;gBACf,MAAM,IAAI,wBAAgB,CACxB,qDAAqD,SAAS,GAAG,EACjE,aAAa,EACb,SAAS,EACT,KAAK,YAAY,KAAK,CAAC,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC,SAAS,CAC3C,CAAA;YACH,CAAC;YAED,KAAK,MAAM,MAAM,IAAI,OAAO,EAAE,CAAC;gBAC7B,IAAI,MAAM,KAAK,aAAa;oBAAE,SAAQ;gBAEtC,IAAI,UAAkC,CAAA;gBACtC,IAAI,CAAC;oBACH,UAAU,GAAG,MAAM,IAAA,uBAAe,EAAC,QAAQ,EAAE,MAAM,EAAE,SAAS,CAAC,CAAA;gBACjE,CAAC;gBAAC,OAAO,KAAK,EAAE,CAAC;oBACf,OAAO,CAAC,IAAI,CACV,2CAA2C,MAAM,gBAAgB,SAAS,uBAAuB,CAClG,CAAA;oBACD,UAAU,G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