@scoutello/i18n-magic 0.19.0 → 0.20.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/README.md +15 -31
- package/dist/cli.js +0 -6
- package/dist/cli.js.map +1 -1
- package/dist/commands/clean.d.ts.map +1 -1
- package/dist/commands/clean.js +16 -29
- package/dist/commands/clean.js.map +1 -1
- package/dist/commands/replace.d.ts.map +1 -1
- package/dist/commands/replace.js +79 -32
- package/dist/commands/replace.js.map +1 -1
- package/dist/index.d.ts +0 -3
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +1 -5
- package/dist/index.js.map +1 -1
- package/dist/lib/utils.d.ts +10 -2
- package/dist/lib/utils.d.ts.map +1 -1
- package/dist/lib/utils.js +50 -15
- package/dist/lib/utils.js.map +1 -1
- package/package.json +1 -1
- package/src/cli.ts +1 -6
- package/src/commands/clean.ts +19 -32
- package/src/commands/replace.ts +97 -46
- package/src/index.ts +2 -7
- package/src/lib/utils.ts +70 -19
- package/src/commands/create-pruned-namespace-automated.ts +0 -165
- package/src/commands/create-pruned-namespace.ts +0 -168
package/README.md
CHANGED
|
@@ -49,7 +49,7 @@ module.exports = {
|
|
|
49
49
|
'./components/**/*.tsx',
|
|
50
50
|
'./pages/**/*.tsx',
|
|
51
51
|
'./lib/**/*.ts',
|
|
52
|
-
// Namespace-specific patterns for
|
|
52
|
+
// Namespace-specific patterns for automatic namespace assignment
|
|
53
53
|
{
|
|
54
54
|
pattern: './apps/dashboard/**/*.tsx',
|
|
55
55
|
namespaces: ['dashboard'],
|
|
@@ -94,7 +94,7 @@ The `globPatterns` array supports two formats:
|
|
|
94
94
|
'./components/**/*.tsx';
|
|
95
95
|
```
|
|
96
96
|
|
|
97
|
-
2. **Object patterns**: Patterns with namespace-specific configuration for
|
|
97
|
+
2. **Object patterns**: Patterns with namespace-specific configuration for automatic namespace assignment
|
|
98
98
|
```js
|
|
99
99
|
{
|
|
100
100
|
pattern: './apps/dashboard/**/*.tsx',
|
|
@@ -102,7 +102,7 @@ The `globPatterns` array supports two formats:
|
|
|
102
102
|
}
|
|
103
103
|
```
|
|
104
104
|
|
|
105
|
-
When using object patterns, translation keys found in files matching that pattern will be
|
|
105
|
+
When using object patterns, translation keys found in files matching that pattern will be automatically saved to the specified namespaces. This enables automatic creation of namespace-specific translation files based on where the keys are used in your codebase.
|
|
106
106
|
|
|
107
107
|
### 4. Start using i18n Magic
|
|
108
108
|
|
|
@@ -179,16 +179,18 @@ Scan your codebase for missing translations and automatically generate them. Thi
|
|
|
179
179
|
The command will:
|
|
180
180
|
|
|
181
181
|
1. Scan all files matching your glob patterns for translation usage
|
|
182
|
-
2.
|
|
183
|
-
3.
|
|
184
|
-
4.
|
|
185
|
-
5.
|
|
182
|
+
2. Automatically determine which namespaces each key belongs to based on the file location
|
|
183
|
+
3. Identify missing translation keys in your default locale
|
|
184
|
+
4. Prompt you to provide translations for each missing key
|
|
185
|
+
5. Automatically translate to all other configured locales using AI
|
|
186
|
+
6. Save the new translations to the appropriate namespace files
|
|
186
187
|
|
|
187
188
|
This is useful for:
|
|
188
189
|
|
|
189
190
|
- Adding new translations during development
|
|
190
191
|
- Ensuring all translation keys have corresponding values
|
|
191
192
|
- Maintaining translation consistency across locales
|
|
193
|
+
- Automatically organizing translations into the correct namespaces
|
|
192
194
|
|
|
193
195
|
### `replace`
|
|
194
196
|
|
|
@@ -196,10 +198,11 @@ Update an existing translation key with a new value and automatically translate
|
|
|
196
198
|
|
|
197
199
|
The command will:
|
|
198
200
|
|
|
199
|
-
1.
|
|
200
|
-
2.
|
|
201
|
-
3.
|
|
202
|
-
4.
|
|
201
|
+
1. Automatically detect which namespaces the key is used in based on your codebase
|
|
202
|
+
2. Prompt you to select or specify the translation key to replace
|
|
203
|
+
3. Ask for the new translation value in your default locale
|
|
204
|
+
4. Automatically translate the new value to all other configured locales using AI
|
|
205
|
+
5. Update all relevant namespace files with the new values
|
|
203
206
|
|
|
204
207
|
You can specify the key in two ways:
|
|
205
208
|
|
|
@@ -213,6 +216,7 @@ This is useful for:
|
|
|
213
216
|
- Updating existing translations that need changes
|
|
214
217
|
- Fixing translation errors across all locales
|
|
215
218
|
- Maintaining consistency when modifying content
|
|
219
|
+
- Automatically updating translations in all relevant namespaces
|
|
216
220
|
|
|
217
221
|
### `check-missing`
|
|
218
222
|
|
|
@@ -253,26 +257,6 @@ This is useful for:
|
|
|
253
257
|
|
|
254
258
|
**Note**: This command works best when used with `disableTranslation: true` in your config to separate the scanning and translation phases.
|
|
255
259
|
|
|
256
|
-
### `prune`
|
|
257
|
-
|
|
258
|
-
Create a pruned namespace from an existing namespace, containing only the translation keys that are actually used in specific files. This is useful for creating optimized translation bundles for different parts of your application (e.g., dashboard, mobile app, etc.).
|
|
259
|
-
|
|
260
|
-
The command will:
|
|
261
|
-
|
|
262
|
-
1. Prompt you to select a source namespace to prune from
|
|
263
|
-
2. Ask for a name for the new namespace
|
|
264
|
-
3. Ask for glob patterns to scan for translation usage
|
|
265
|
-
4. Extract all translation keys used in the matched files
|
|
266
|
-
5. Create new translation files for all locales containing only the used keys
|
|
267
|
-
|
|
268
|
-
This is particularly useful for:
|
|
269
|
-
|
|
270
|
-
- Creating namespace-specific translation bundles
|
|
271
|
-
- Reducing bundle size by including only necessary translations
|
|
272
|
-
- Optimizing performance in micro-frontends or modular applications
|
|
273
|
-
|
|
274
|
-
You can also automate this process using the `pruneNamespaces` configuration in your `i18n-magic.js` file (see configuration example above).
|
|
275
|
-
|
|
276
260
|
### `clean`
|
|
277
261
|
|
|
278
262
|
Remove unused translation keys from all locales. This command scans your codebase to find which translation keys are actually being used and removes any keys that are no longer referenced in your code.
|
package/dist/cli.js
CHANGED
|
@@ -9,7 +9,6 @@ const dotenv_1 = __importDefault(require("dotenv"));
|
|
|
9
9
|
const openai_1 = __importDefault(require("openai"));
|
|
10
10
|
const check_missing_1 = require("./commands/check-missing");
|
|
11
11
|
const clean_1 = require("./commands/clean");
|
|
12
|
-
const create_pruned_namespace_1 = require("./commands/create-pruned-namespace");
|
|
13
12
|
const replace_1 = require("./commands/replace");
|
|
14
13
|
const scan_1 = require("./commands/scan");
|
|
15
14
|
const sync_locales_1 = require("./commands/sync-locales");
|
|
@@ -47,11 +46,6 @@ const commands = [
|
|
|
47
46
|
description: "Remove unused translations from all locales. Useful for a CI/CD pipeline or husky hook.",
|
|
48
47
|
action: clean_1.removeUnusedKeys,
|
|
49
48
|
},
|
|
50
|
-
{
|
|
51
|
-
name: "prune",
|
|
52
|
-
description: "Create a pruned namespace from the other namespaces.",
|
|
53
|
-
action: create_pruned_namespace_1.createPrunedNamespace,
|
|
54
|
-
},
|
|
55
49
|
];
|
|
56
50
|
for (const command of commands) {
|
|
57
51
|
const cmd = program.command(command.name).description(command.description);
|
package/dist/cli.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"cli.js","sourceRoot":"","sources":["../src/cli.ts"],"names":[],"mappings":";;;;;AAAA,yCAAmC;AACnC,oDAA2B;AAC3B,oDAA2B;AAC3B,4DAAuD;AACvD,4CAAmD;
|
|
1
|
+
{"version":3,"file":"cli.js","sourceRoot":"","sources":["../src/cli.ts"],"names":[],"mappings":";;;;;AAAA,yCAAmC;AACnC,oDAA2B;AAC3B,oDAA2B;AAC3B,4DAAuD;AACvD,4CAAmD;AAEnD,gDAAuD;AACvD,0CAAkD;AAClD,0DAAqD;AAErD,uCAAwC;AAExC,MAAM,OAAO,GAAG,IAAI,mBAAO,EAAE,CAAA;AAE7B,OAAO;KACJ,IAAI,CAAC,YAAY,CAAC;KAClB,WAAW,CACV,6FAA6F,CAC9F;KACA,OAAO,CAAC,OAAO,CAAC;KAChB,MAAM,CAAC,qBAAqB,EAAE,qBAAqB,CAAC;KACpD,MAAM,CAAC,kBAAkB,EAAE,mBAAmB,CAAC,CAAA;AAElD,MAAM,QAAQ,GAAkB;IAC9B;QACE,IAAI,EAAE,MAAM;QACZ,WAAW,EACT,uHAAuH;QACzH,MAAM,EAAE,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{"version":3,"file":"clean.d.ts","sourceRoot":"","sources":["../../src/commands/clean.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"clean.d.ts","sourceRoot":"","sources":["../../src/commands/clean.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,cAAc,CAAA;AAQjD,eAAO,MAAM,gBAAgB,GAAU,QAAQ,aAAa,kBAsF3D,CAAA"}
|
package/dist/commands/clean.js
CHANGED
|
@@ -1,48 +1,35 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
-
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
-
};
|
|
5
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
3
|
exports.removeUnusedKeys = 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
4
|
const utils_1 = require("../lib/utils");
|
|
11
5
|
const removeUnusedKeys = async (config) => {
|
|
12
6
|
const { globPatterns, namespaces, defaultNamespace, locales, loadPath, savePath, } = config;
|
|
13
|
-
//
|
|
14
|
-
const
|
|
15
|
-
|
|
16
|
-
|
|
7
|
+
// Get all keys with their associated namespaces from the codebase
|
|
8
|
+
const keysWithNamespaces = await (0, utils_1.getKeysWithNamespaces)({
|
|
9
|
+
globPatterns,
|
|
10
|
+
defaultNamespace,
|
|
17
11
|
});
|
|
18
|
-
// Find all files to scan
|
|
19
|
-
const allPatterns = globPatterns.map((pattern) => typeof pattern === "string" ? pattern : pattern.pattern);
|
|
20
|
-
const files = await (0, fast_glob_1.default)([...allPatterns, "!**/node_modules/**"]);
|
|
21
|
-
// Extract all translation keys from the codebase
|
|
22
|
-
const extractedKeys = [];
|
|
23
|
-
for (const file of files) {
|
|
24
|
-
const content = node_fs_1.default.readFileSync(file, "utf-8");
|
|
25
|
-
parser.parseFuncFromString(content, { list: ["t"] }, (key) => {
|
|
26
|
-
extractedKeys.push(key);
|
|
27
|
-
});
|
|
28
|
-
}
|
|
29
|
-
// Remove duplicates
|
|
30
|
-
const uniqueExtractedKeys = (0, utils_1.removeDuplicatesFromArray)(extractedKeys);
|
|
31
12
|
// Track stats for reporting
|
|
32
13
|
const stats = {
|
|
33
14
|
total: 0,
|
|
34
15
|
removed: 0,
|
|
35
16
|
};
|
|
36
|
-
//
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
const
|
|
40
|
-
|
|
17
|
+
// Group keys by namespace
|
|
18
|
+
const keysByNamespace = {};
|
|
19
|
+
for (const { key, namespaces: keyNamespaces } of keysWithNamespaces) {
|
|
20
|
+
for (const namespace of keyNamespaces) {
|
|
21
|
+
if (!keysByNamespace[namespace]) {
|
|
22
|
+
keysByNamespace[namespace] = new Set();
|
|
23
|
+
}
|
|
41
24
|
const pureKey = (0, utils_1.getPureKey)(key, namespace, namespace === defaultNamespace);
|
|
42
25
|
if (pureKey) {
|
|
43
|
-
|
|
26
|
+
keysByNamespace[namespace].add(pureKey);
|
|
44
27
|
}
|
|
45
28
|
}
|
|
29
|
+
}
|
|
30
|
+
// Process each namespace and locale
|
|
31
|
+
for (const namespace of namespaces) {
|
|
32
|
+
const usedKeysSet = keysByNamespace[namespace] || new Set();
|
|
46
33
|
// Process each locale
|
|
47
34
|
for (const locale of locales) {
|
|
48
35
|
// Load existing keys for this locale and namespace
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"clean.js","sourceRoot":"","sources":["../../src/commands/clean.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"clean.js","sourceRoot":"","sources":["../../src/commands/clean.ts"],"names":[],"mappings":";;;AACA,wCAKqB;AAEd,MAAM,gBAAgB,GAAG,KAAK,EAAE,MAAqB,EAAE,EAAE;IAC9D,MAAM,EACJ,YAAY,EACZ,UAAU,EACV,gBAAgB,EAChB,OAAO,EACP,Q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src/commands/replace.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,cAAc,CAAA;
|
|
1
|
+
{"version":3,"file":"replace.d.ts","sourceRoot":"","sources":["../../src/commands/replace.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,cAAc,CAAA;AA6BjD,eAAO,MAAM,kBAAkB,GAC7B,QAAQ,aAAa,EACrB,MAAM,MAAM,kBAqHb,CAAA"}
|
package/dist/commands/replace.js
CHANGED
|
@@ -2,56 +2,103 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.replaceTranslation = void 0;
|
|
4
4
|
const utils_1 = require("../lib/utils");
|
|
5
|
-
const getKeyToReplace = async (
|
|
5
|
+
const getKeyToReplace = async (allAvailableKeys) => {
|
|
6
6
|
const keyToReplace = await (0, utils_1.getTextInput)("Enter the key to replace the translation for: ");
|
|
7
|
-
if (!
|
|
7
|
+
if (!allAvailableKeys[keyToReplace]) {
|
|
8
8
|
console.log(`The key "${keyToReplace}" does not exist.`);
|
|
9
|
-
return await getKeyToReplace(
|
|
9
|
+
return await getKeyToReplace(allAvailableKeys);
|
|
10
10
|
}
|
|
11
|
-
|
|
12
|
-
|
|
11
|
+
const namespaces = allAvailableKeys[keyToReplace].map((k) => k.namespace);
|
|
12
|
+
console.log(`The key "${keyToReplace}" exists in namespaces: ${namespaces.join(", ")}.`);
|
|
13
|
+
return { key: keyToReplace, namespaces };
|
|
13
14
|
};
|
|
14
15
|
const replaceTranslation = async (config, key) => {
|
|
15
16
|
const { loadPath, savePath, defaultLocale, defaultNamespace, namespaces, locales, globPatterns, context, openai, } = config;
|
|
16
|
-
|
|
17
|
+
// Find all keys with their namespaces from the codebase
|
|
18
|
+
const keysWithNamespaces = await (0, utils_1.getKeysWithNamespaces)({
|
|
19
|
+
globPatterns,
|
|
20
|
+
defaultNamespace,
|
|
21
|
+
});
|
|
22
|
+
// Build a map of all available keys across all namespaces
|
|
23
|
+
const allAvailableKeys = {};
|
|
24
|
+
for (const namespace of namespaces) {
|
|
25
|
+
const keys = await (0, utils_1.loadLocalesFile)(loadPath, defaultLocale, namespace);
|
|
26
|
+
for (const [keyName, value] of Object.entries(keys)) {
|
|
27
|
+
if (!allAvailableKeys[keyName]) {
|
|
28
|
+
allAvailableKeys[keyName] = [];
|
|
29
|
+
}
|
|
30
|
+
allAvailableKeys[keyName].push({ namespace, value });
|
|
31
|
+
}
|
|
32
|
+
}
|
|
17
33
|
let keyToReplace;
|
|
34
|
+
let targetNamespaces = [];
|
|
18
35
|
if (key) {
|
|
19
|
-
if (
|
|
36
|
+
if (allAvailableKeys[key]) {
|
|
20
37
|
keyToReplace = key;
|
|
21
|
-
|
|
38
|
+
// Determine which namespaces this key should be updated in based on usage
|
|
39
|
+
const keyUsage = keysWithNamespaces.filter((k) => {
|
|
40
|
+
const pureKey = (0, utils_1.getPureKey)(k.key, defaultNamespace, true);
|
|
41
|
+
return pureKey === key || k.key === key;
|
|
42
|
+
});
|
|
43
|
+
if (keyUsage.length > 0) {
|
|
44
|
+
// Use namespaces from actual usage
|
|
45
|
+
const allNamespaces = [];
|
|
46
|
+
for (const k of keyUsage) {
|
|
47
|
+
allNamespaces.push(...k.namespaces);
|
|
48
|
+
}
|
|
49
|
+
targetNamespaces = [...new Set(allNamespaces)];
|
|
50
|
+
}
|
|
51
|
+
else {
|
|
52
|
+
// Fallback to all namespaces where the key exists
|
|
53
|
+
targetNamespaces = allAvailableKeys[key].map((k) => k.namespace);
|
|
54
|
+
}
|
|
55
|
+
console.log(`The key "${keyToReplace}" exists in namespaces: ${targetNamespaces.join(", ")}.`);
|
|
22
56
|
}
|
|
23
57
|
else {
|
|
24
58
|
console.log(`The key "${key}" does not exist.`);
|
|
25
|
-
|
|
59
|
+
const result = await getKeyToReplace(allAvailableKeys);
|
|
60
|
+
keyToReplace = result.key;
|
|
61
|
+
targetNamespaces = result.namespaces;
|
|
26
62
|
}
|
|
27
63
|
}
|
|
28
64
|
else {
|
|
29
|
-
|
|
65
|
+
const result = await getKeyToReplace(allAvailableKeys);
|
|
66
|
+
keyToReplace = result.key;
|
|
67
|
+
targetNamespaces = result.namespaces;
|
|
30
68
|
}
|
|
31
|
-
|
|
32
|
-
const
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
newValue = newTranslation;
|
|
69
|
+
// Show current translations across namespaces
|
|
70
|
+
for (const namespace of targetNamespaces) {
|
|
71
|
+
const keys = await (0, utils_1.loadLocalesFile)(loadPath, defaultLocale, namespace);
|
|
72
|
+
if (keys[keyToReplace]) {
|
|
73
|
+
console.log(`Current translation in ${defaultLocale} (${namespace}): "${keys[keyToReplace]}"`);
|
|
37
74
|
}
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
75
|
+
}
|
|
76
|
+
const newTranslation = await (0, utils_1.getTextInput)("Enter the new translation: ");
|
|
77
|
+
// Update the key in all relevant namespaces and locales
|
|
78
|
+
for (const namespace of targetNamespaces) {
|
|
79
|
+
for (const locale of locales) {
|
|
80
|
+
let newValue = "";
|
|
81
|
+
if (locale === defaultLocale) {
|
|
82
|
+
newValue = newTranslation;
|
|
83
|
+
}
|
|
84
|
+
else {
|
|
85
|
+
const translation = await (0, utils_1.translateKey)({
|
|
86
|
+
context,
|
|
87
|
+
inputLanguage: defaultLocale,
|
|
88
|
+
outputLanguage: locale,
|
|
89
|
+
object: {
|
|
90
|
+
[keyToReplace]: newTranslation,
|
|
91
|
+
},
|
|
92
|
+
openai,
|
|
93
|
+
model: config.model,
|
|
94
|
+
});
|
|
95
|
+
newValue = translation[keyToReplace];
|
|
96
|
+
}
|
|
97
|
+
const existingKeys = await (0, utils_1.loadLocalesFile)(loadPath, locale, namespace);
|
|
98
|
+
existingKeys[keyToReplace] = newValue;
|
|
99
|
+
await (0, utils_1.writeLocalesFile)(savePath, locale, namespace, existingKeys);
|
|
100
|
+
console.log(`Updated "${keyToReplace}" in ${locale} (${namespace}): "${newValue}"`);
|
|
50
101
|
}
|
|
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
102
|
}
|
|
56
103
|
};
|
|
57
104
|
exports.replaceTranslation = replaceTranslation;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"replace.js","sourceRoot":"","sources":["../../src/commands/replace.ts"],"names":[],"mappings":";;;AACA,
|
|
1
|
+
{"version":3,"file":"replace.js","sourceRoot":"","sources":["../../src/commands/replace.ts"],"names":[],"mappings":";;;AACA,wCAOqB;AAErB,MAAM,eAAe,GAAG,KAAK,EAC3B,gBAAwE,EACxB,EAAE;IAClD,MAAM,YAAY,GAAG,MAAM,IAAA,oBAAY,EACrC,gDAAgD,CACjD,CAAA;IAED,IAAI,CAAC,gBAAgB,CAAC,YAAY,CAAC,EAAE,CAAC;QACpC,OAAO,CAAC,GAAG,CAAC,YAAY,YAAY,mBAAmB,CAAC,CAAA;QACxD,OAAO,MAAM,eAAe,CAAC,gBAAgB,CAAC,CAAA;IAChD,CAAC;IAED,MAAM,UAAU,GAAG,gBAAgB,CAAC,YAAY,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,SAAS,CAAC,CAAA;IACzE,OAAO,CAAC,GAAG,CACT,YAAY,YAAY,2BAA2B,UAAU,CAAC,IAAI,CAAC,IAAI,CAAC,GAAG,CAC5E,CAAA;IACD,OAAO,EAAE,GAAG,EAAE,YAAY,EAAE,UAAU,EAAE,CAAA;AAC1C,CAAC,CAAA;AA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uH9B"}
|
package/dist/index.d.ts
CHANGED
|
@@ -1,11 +1,8 @@
|
|
|
1
1
|
export { checkMissing } from "./commands/check-missing";
|
|
2
2
|
export { removeUnusedKeys } from "./commands/clean";
|
|
3
|
-
export { createPrunedNamespace } from "./commands/create-pruned-namespace";
|
|
4
|
-
export { createPrunedNamespaceAutomated } from "./commands/create-pruned-namespace-automated";
|
|
5
3
|
export { replaceTranslation } from "./commands/replace";
|
|
6
4
|
export { translateMissing } from "./commands/scan";
|
|
7
5
|
export { syncLocales } from "./commands/sync-locales";
|
|
8
6
|
export { loadConfig } from "./lib/utils";
|
|
9
|
-
export type { PruneOptions, PruneResponse, PruneResult, } from "./commands/create-pruned-namespace-automated";
|
|
10
7
|
export type { CommandType, Configuration, GlobPatternConfig, } from "./lib/types";
|
|
11
8
|
//# sourceMappingURL=index.d.ts.map
|
package/dist/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,YAAY,EAAE,MAAM,0BAA0B,CAAA;AACvD,OAAO,EAAE,gBAAgB,EAAE,MAAM,kBAAkB,CAAA;
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,YAAY,EAAE,MAAM,0BAA0B,CAAA;AACvD,OAAO,EAAE,gBAAgB,EAAE,MAAM,kBAAkB,CAAA;AAEnD,OAAO,EAAE,kBAAkB,EAAE,MAAM,oBAAoB,CAAA;AACvD,OAAO,EAAE,gBAAgB,EAAE,MAAM,iBAAiB,CAAA;AAClD,OAAO,EAAE,WAAW,EAAE,MAAM,yBAAyB,CAAA;AAGrD,OAAO,EAAE,UAAU,EAAE,MAAM,aAAa,CAAA;AAIxC,YAAY,EACV,WAAW,EACX,aAAa,EACb,iBAAiB,GAClB,MAAM,aAAa,CAAA"}
|
package/dist/index.js
CHANGED
|
@@ -1,15 +1,11 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.loadConfig = exports.syncLocales = exports.translateMissing = exports.replaceTranslation = exports.
|
|
3
|
+
exports.loadConfig = exports.syncLocales = exports.translateMissing = exports.replaceTranslation = exports.removeUnusedKeys = exports.checkMissing = void 0;
|
|
4
4
|
// Export command functions for programmatic usage
|
|
5
5
|
var check_missing_1 = require("./commands/check-missing");
|
|
6
6
|
Object.defineProperty(exports, "checkMissing", { enumerable: true, get: function () { return check_missing_1.checkMissing; } });
|
|
7
7
|
var clean_1 = require("./commands/clean");
|
|
8
8
|
Object.defineProperty(exports, "removeUnusedKeys", { enumerable: true, get: function () { return clean_1.removeUnusedKeys; } });
|
|
9
|
-
var create_pruned_namespace_1 = require("./commands/create-pruned-namespace");
|
|
10
|
-
Object.defineProperty(exports, "createPrunedNamespace", { enumerable: true, get: function () { return create_pruned_namespace_1.createPrunedNamespace; } });
|
|
11
|
-
var create_pruned_namespace_automated_1 = require("./commands/create-pruned-namespace-automated");
|
|
12
|
-
Object.defineProperty(exports, "createPrunedNamespaceAutomated", { enumerable: true, get: function () { return create_pruned_namespace_automated_1.createPrunedNamespaceAutomated; } });
|
|
13
9
|
var replace_1 = require("./commands/replace");
|
|
14
10
|
Object.defineProperty(exports, "replaceTranslation", { enumerable: true, get: function () { return replace_1.replaceTranslation; } });
|
|
15
11
|
var scan_1 = require("./commands/scan");
|
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";;;AAAA,kDAAkD;AAClD,0DAAuD;AAA9C,6GAAA,YAAY,OAAA;AACrB,0CAAmD;AAA1C,yGAAA,gBAAgB,OAAA;
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";;;AAAA,kDAAkD;AAClD,0DAAuD;AAA9C,6GAAA,YAAY,OAAA;AACrB,0CAAmD;AAA1C,yGAAA,gBAAgB,OAAA;AAEzB,8CAAuD;AAA9C,6GAAA,kBAAkB,OAAA;AAC3B,wCAAkD;AAAzC,wGAAA,gBAAgB,OAAA;AACzB,wDAAqD;AAA5C,2GAAA,WAAW,OAAA;AAEpB,2BAA2B;AAC3B,qCAAwC;AAA/B,mGAAA,UAAU,OAAA"}
|
package/dist/lib/utils.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import type OpenAI from "openai";
|
|
2
|
-
import type {
|
|
2
|
+
import type { Configuration, GlobPatternConfig } from "./types";
|
|
3
3
|
export declare const loadConfig: ({ configPath, }: {
|
|
4
4
|
configPath: string;
|
|
5
5
|
}) => any;
|
|
@@ -25,7 +25,7 @@ export declare const extractGlobPatterns: (globPatterns: (string | GlobPatternCo
|
|
|
25
25
|
export declare const getNamespacesForFile: (filePath: string, globPatterns: (string | {
|
|
26
26
|
pattern: string;
|
|
27
27
|
namespaces: string[];
|
|
28
|
-
})[]) => string[];
|
|
28
|
+
})[], defaultNamespace: string) => string[];
|
|
29
29
|
/**
|
|
30
30
|
* Gets all glob patterns that should be used for a specific namespace
|
|
31
31
|
*/
|
|
@@ -33,6 +33,14 @@ export declare const getGlobPatternsForNamespace: (namespace: string, globPatter
|
|
|
33
33
|
pattern: string;
|
|
34
34
|
namespaces: string[];
|
|
35
35
|
})[]) => string[];
|
|
36
|
+
/**
|
|
37
|
+
* Extracts keys with their associated namespaces based on the files they're found in
|
|
38
|
+
*/
|
|
39
|
+
export declare const getKeysWithNamespaces: ({ globPatterns, defaultNamespace, }: Pick<Configuration, "globPatterns" | "defaultNamespace">) => Promise<{
|
|
40
|
+
key: string;
|
|
41
|
+
namespaces: string[];
|
|
42
|
+
file: string;
|
|
43
|
+
}[]>;
|
|
36
44
|
export declare const getMissingKeys: ({ globPatterns, namespaces, defaultNamespace, defaultLocale, loadPath, }: Configuration) => Promise<any[]>;
|
|
37
45
|
export declare const getTextInput: (prompt: string) => Promise<string>;
|
|
38
46
|
export declare const checkAllKeysExist: ({ namespaces, defaultLocale, loadPath, locales, context, openai, savePath, disableTranslation, model, }: Configuration) => Promise<void>;
|
package/dist/lib/utils.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"utils.d.ts","sourceRoot":"","sources":["../../src/lib/utils.ts"],"names":[],"mappings":"AAIA,OAAO,KAAK,MAAM,MAAM,QAAQ,CAAA;AAGhC,OAAO,KAAK,EAAE,
|
|
1
|
+
{"version":3,"file":"utils.d.ts","sourceRoot":"","sources":["../../src/lib/utils.ts"],"names":[],"mappings":"AAIA,OAAO,KAAK,MAAM,MAAM,QAAQ,CAAA;AAGhC,OAAO,KAAK,EAAE,aAAa,EAAE,iBAAiB,EAAE,MAAM,SAAS,CAAA;AAE/D,eAAO,MAAM,UAAU,GAAI,iBAExB;IAAE,UAAU,EAAE,MAAM,CAAA;CAAE,QAgBxB,CAAA;AAED,wBAAgB,yBAAyB,CAAC,CAAC,EAAE,GAAG,EAAE,CAAC,EAAE,GAAG,CAAC,EAAE,CAE1D;AAED,eAAO,MAAM,YAAY,GAAU,oEAOhC;IACD,MAAM,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAA;IAC9B,OAAO,EAAE,MAAM,CAAA;IACf,aAAa,EAAE,MAAM,CAAA;IACrB,cAAc,EAAE,MAAM,CAAA;IACtB,KAAK,EAAE,MAAM,CAAA;IACb,MAAM,EAAE,MAAM,CAAA;CACf,oCAyDA,CAAA;AAED,eAAO,MAAM,eAAe,GAC1B,UACI,MAAM,GACN,CAAC,CAAC,MAAM,EAAE,MAAM,EAAE,SAAS,EAAE,MAAM,KAAK,OAAO,CAAC,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC,CAAC,EAC5E,QAAQ,MAAM,EACd,WAAW,MAAM,oCAsBlB,CAAA;AAED,eAAO,MAAM,gBAAgB,GAC3B,UACI,MAAM,GACN,CAA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CAAC,EAAE,MAAM;IACf,SAAS,CAAC,EAAE,MAAM;IAClB,KAAK,CAAC,EAAE,KAAK;gBAHpB,OAAO,EAAE,MAAM,EACR,MAAM,CAAC,EAAE,MAAM,EACf,SAAS,CAAC,EAAE,MAAM,EAClB,KAAK,CAAC,EAAE,KAAK;CAKvB"}
|
package/dist/lib/utils.js
CHANGED
|
@@ -3,7 +3,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
3
3
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
4
|
};
|
|
5
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
-
exports.TranslationError = exports.checkAllKeysExist = exports.getTextInput = exports.getMissingKeys = exports.getGlobPatternsForNamespace = exports.getNamespacesForFile = exports.extractGlobPatterns = exports.getPureKey = exports.writeLocalesFile = exports.loadLocalesFile = exports.translateKey = exports.loadConfig = void 0;
|
|
6
|
+
exports.TranslationError = exports.checkAllKeysExist = exports.getTextInput = exports.getMissingKeys = exports.getKeysWithNamespaces = exports.getGlobPatternsForNamespace = exports.getNamespacesForFile = exports.extractGlobPatterns = exports.getPureKey = exports.writeLocalesFile = exports.loadLocalesFile = exports.translateKey = exports.loadConfig = void 0;
|
|
7
7
|
exports.removeDuplicatesFromArray = removeDuplicatesFromArray;
|
|
8
8
|
const fast_glob_1 = __importDefault(require("fast-glob"));
|
|
9
9
|
const i18next_scanner_1 = require("i18next-scanner");
|
|
@@ -129,7 +129,7 @@ exports.extractGlobPatterns = extractGlobPatterns;
|
|
|
129
129
|
/**
|
|
130
130
|
* Gets the namespaces associated with a specific file path based on glob pattern configuration
|
|
131
131
|
*/
|
|
132
|
-
const getNamespacesForFile = (filePath, globPatterns) => {
|
|
132
|
+
const getNamespacesForFile = (filePath, globPatterns, defaultNamespace) => {
|
|
133
133
|
const matchingNamespaces = [];
|
|
134
134
|
for (const pattern of globPatterns) {
|
|
135
135
|
if (typeof pattern === "object") {
|
|
@@ -141,7 +141,10 @@ const getNamespacesForFile = (filePath, globPatterns) => {
|
|
|
141
141
|
}
|
|
142
142
|
}
|
|
143
143
|
}
|
|
144
|
-
|
|
144
|
+
// If no specific namespaces found, use default namespace
|
|
145
|
+
return matchingNamespaces.length > 0
|
|
146
|
+
? [...new Set(matchingNamespaces)]
|
|
147
|
+
: [defaultNamespace];
|
|
145
148
|
};
|
|
146
149
|
exports.getNamespacesForFile = getNamespacesForFile;
|
|
147
150
|
/**
|
|
@@ -162,32 +165,64 @@ const getGlobPatternsForNamespace = (namespace, globPatterns) => {
|
|
|
162
165
|
return patterns;
|
|
163
166
|
};
|
|
164
167
|
exports.getGlobPatternsForNamespace = getGlobPatternsForNamespace;
|
|
165
|
-
|
|
168
|
+
/**
|
|
169
|
+
* Extracts keys with their associated namespaces based on the files they're found in
|
|
170
|
+
*/
|
|
171
|
+
const getKeysWithNamespaces = async ({ globPatterns, defaultNamespace, }) => {
|
|
166
172
|
const parser = new i18next_scanner_1.Parser({
|
|
167
173
|
nsSeparator: false,
|
|
168
174
|
keySeparator: false,
|
|
169
175
|
});
|
|
170
176
|
const allPatterns = (0, exports.extractGlobPatterns)(globPatterns);
|
|
171
177
|
const files = await (0, fast_glob_1.default)([...allPatterns, "!**/node_modules/**"]);
|
|
172
|
-
const
|
|
178
|
+
const keysWithNamespaces = [];
|
|
173
179
|
for (const file of files) {
|
|
174
180
|
const content = node_fs_1.default.readFileSync(file, "utf-8");
|
|
181
|
+
const fileKeys = [];
|
|
175
182
|
parser.parseFuncFromString(content, { list: ["t"] }, (key) => {
|
|
176
|
-
|
|
183
|
+
fileKeys.push(key);
|
|
177
184
|
});
|
|
185
|
+
// Get namespaces for this file
|
|
186
|
+
const fileNamespaces = (0, exports.getNamespacesForFile)(file, globPatterns, defaultNamespace);
|
|
187
|
+
// Add each key with its associated namespaces
|
|
188
|
+
for (const key of fileKeys) {
|
|
189
|
+
keysWithNamespaces.push({
|
|
190
|
+
key,
|
|
191
|
+
namespaces: fileNamespaces,
|
|
192
|
+
file,
|
|
193
|
+
});
|
|
194
|
+
}
|
|
178
195
|
}
|
|
179
|
-
|
|
196
|
+
return keysWithNamespaces;
|
|
197
|
+
};
|
|
198
|
+
exports.getKeysWithNamespaces = getKeysWithNamespaces;
|
|
199
|
+
const getMissingKeys = async ({ globPatterns, namespaces, defaultNamespace, defaultLocale, loadPath, }) => {
|
|
200
|
+
const keysWithNamespaces = await (0, exports.getKeysWithNamespaces)({
|
|
201
|
+
globPatterns,
|
|
202
|
+
defaultNamespace,
|
|
203
|
+
});
|
|
180
204
|
const newKeys = [];
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
for (const
|
|
205
|
+
// Group keys by namespace
|
|
206
|
+
const keysByNamespace = {};
|
|
207
|
+
for (const { key, namespaces: keyNamespaces } of keysWithNamespaces) {
|
|
208
|
+
for (const namespace of keyNamespaces) {
|
|
209
|
+
if (!keysByNamespace[namespace]) {
|
|
210
|
+
keysByNamespace[namespace] = new Set();
|
|
211
|
+
}
|
|
185
212
|
const pureKey = (0, exports.getPureKey)(key, namespace, namespace === defaultNamespace);
|
|
186
|
-
if (
|
|
187
|
-
|
|
213
|
+
if (pureKey) {
|
|
214
|
+
keysByNamespace[namespace].add(pureKey);
|
|
188
215
|
}
|
|
189
|
-
|
|
190
|
-
|
|
216
|
+
}
|
|
217
|
+
}
|
|
218
|
+
// Check for missing keys in each namespace
|
|
219
|
+
for (const namespace of namespaces) {
|
|
220
|
+
const existingKeys = await (0, exports.loadLocalesFile)(loadPath, defaultLocale, namespace);
|
|
221
|
+
console.log(Object.keys(existingKeys).length, "existing keys in", namespace);
|
|
222
|
+
const keysForNamespace = keysByNamespace[namespace] || new Set();
|
|
223
|
+
for (const key of keysForNamespace) {
|
|
224
|
+
if (!existingKeys[key]) {
|
|
225
|
+
newKeys.push({ key, namespace });
|
|
191
226
|
}
|
|
192
227
|
}
|
|
193
228
|
}
|