locale-keysmith 0.1.0 → 0.2.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 +161 -22
- package/dist/cli.d.ts +0 -1
- package/dist/cli.js +108 -40
- package/dist/cli.js.map +1 -1
- package/dist/config.d.ts +3 -0
- package/dist/config.js +30 -20
- package/dist/config.js.map +1 -1
- package/dist/glob.d.ts +2 -0
- package/dist/glob.js +6 -0
- package/dist/glob.js.map +1 -0
- package/dist/index.js.map +1 -1
- package/dist/keys.d.ts +1 -0
- package/dist/keys.js +9 -3
- package/dist/keys.js.map +1 -1
- package/dist/parser.js +11 -3
- package/dist/parser.js.map +1 -1
- package/dist/scanner.js +3 -8
- package/dist/scanner.js.map +1 -1
- package/dist/translate.js +2 -1
- package/dist/translate.js.map +1 -1
- package/dist/types.d.ts +1 -0
- package/dist/usage.d.ts +1 -0
- package/dist/usage.js +22 -15
- package/dist/usage.js.map +1 -1
- package/package.json +43 -15
package/README.md
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
# locale-keysmith
|
|
2
2
|
|
|
3
|
-
Sort, audit, clean, and translate locale files from the command line.
|
|
3
|
+
Sort, audit, clean, and translate i18n locale files from the command line.
|
|
4
4
|
|
|
5
5
|
## Install
|
|
6
6
|
|
|
@@ -8,53 +8,192 @@ Sort, audit, clean, and translate locale files from the command line.
|
|
|
8
8
|
pnpm add -D locale-keysmith
|
|
9
9
|
```
|
|
10
10
|
|
|
11
|
+
## Quick start
|
|
12
|
+
|
|
13
|
+
```bash
|
|
14
|
+
# See which locale files are detected
|
|
15
|
+
pnpm exec locale-keysmith scan
|
|
16
|
+
|
|
17
|
+
# Get a full report: missing keys, unused keys, and unsorted files
|
|
18
|
+
pnpm exec locale-keysmith health
|
|
19
|
+
```
|
|
20
|
+
|
|
21
|
+
By default everything is scanned under the `src` folder. To look elsewhere, add a config
|
|
22
|
+
file (see [Configuration](#configuration)).
|
|
23
|
+
|
|
11
24
|
## Commands
|
|
12
25
|
|
|
26
|
+
Run a command with `pnpm exec locale-keysmith <command>` (or `npx locale-keysmith <command>`).
|
|
27
|
+
|
|
28
|
+
| Command | What it does |
|
|
29
|
+
| -------------------------- | ------------------------------------------------------------------------------- |
|
|
30
|
+
| `scan` | List the locale files that were found, with their inferred locale. |
|
|
31
|
+
| `health` | Report missing keys, unused keys, and unsorted files. Exits non-zero on issues. |
|
|
32
|
+
| `missing` | List keys present in the source locale but missing from the others. |
|
|
33
|
+
| `unused` | List source-locale keys that no source file references. |
|
|
34
|
+
| `sort` | Sort every locale file's keys alphabetically (nested too). |
|
|
35
|
+
| `remove-unused` | Delete unused keys from every locale file. |
|
|
36
|
+
| `translate --to <locales>` | Fill missing keys in target locales via Google Translate. |
|
|
37
|
+
|
|
38
|
+
### `scan`
|
|
39
|
+
|
|
13
40
|
```bash
|
|
14
41
|
pnpm exec locale-keysmith scan
|
|
15
|
-
|
|
42
|
+
```
|
|
43
|
+
|
|
44
|
+
Prints one line per detected locale file, e.g. `en src/locales/en.json`.
|
|
45
|
+
|
|
46
|
+
### `health`
|
|
47
|
+
|
|
48
|
+
```bash
|
|
49
|
+
pnpm exec locale-keysmith health
|
|
50
|
+
```
|
|
51
|
+
|
|
52
|
+
A one-shot audit that combines the checks below. It prints each problem it finds:
|
|
53
|
+
|
|
54
|
+
```
|
|
55
|
+
unsorted src/locales/de.json
|
|
56
|
+
missing de status.offline
|
|
57
|
+
unused legacy.oldButton
|
|
58
|
+
|
|
59
|
+
3 issues found.
|
|
60
|
+
```
|
|
61
|
+
|
|
62
|
+
It exits with a non-zero status when any issue is found, so it can gate CI. When everything
|
|
63
|
+
is fine it prints `All locale files are healthy.` and exits `0`.
|
|
64
|
+
|
|
65
|
+
### `missing`
|
|
66
|
+
|
|
67
|
+
```bash
|
|
16
68
|
pnpm exec locale-keysmith missing
|
|
69
|
+
```
|
|
70
|
+
|
|
71
|
+
Lists, per non-source locale, the keys that exist in the source locale but are absent.
|
|
72
|
+
|
|
73
|
+
### `unused`
|
|
74
|
+
|
|
75
|
+
```bash
|
|
17
76
|
pnpm exec locale-keysmith unused
|
|
18
|
-
|
|
77
|
+
```
|
|
78
|
+
|
|
79
|
+
Lists source-locale keys that are never referenced in your source files. See
|
|
80
|
+
[Key usage detection](#key-usage-detection) for exactly what counts as "referenced".
|
|
81
|
+
|
|
82
|
+
### `sort`
|
|
83
|
+
|
|
84
|
+
```bash
|
|
85
|
+
pnpm exec locale-keysmith sort # preview (no changes written)
|
|
86
|
+
pnpm exec locale-keysmith sort --write # write sorted files to disk
|
|
87
|
+
```
|
|
88
|
+
|
|
89
|
+
Sorts keys alphabetically at every nesting level. Without `--write` it only reports which
|
|
90
|
+
files would change.
|
|
91
|
+
|
|
92
|
+
### `remove-unused`
|
|
93
|
+
|
|
94
|
+
```bash
|
|
95
|
+
pnpm exec locale-keysmith remove-unused # preview
|
|
96
|
+
pnpm exec locale-keysmith remove-unused --dry-run # preview (explicit)
|
|
97
|
+
pnpm exec locale-keysmith remove-unused --write # delete unused keys and re-sort
|
|
98
|
+
```
|
|
99
|
+
|
|
100
|
+
Removes unused keys from **every** locale file (not just the source), then re-sorts them.
|
|
101
|
+
Without `--write` it reports how many keys would be removed.
|
|
102
|
+
|
|
103
|
+
### `translate`
|
|
104
|
+
|
|
105
|
+
```bash
|
|
106
|
+
export GOOGLE_TRANSLATE_API_KEY="your-api-key"
|
|
107
|
+
pnpm exec locale-keysmith translate --to de,fr # preview counts
|
|
19
108
|
pnpm exec locale-keysmith translate --from en --to de,fr --write
|
|
20
109
|
```
|
|
21
110
|
|
|
22
|
-
|
|
111
|
+
Translates the source locale's missing keys into each target locale using the Google
|
|
112
|
+
Translate API. A target locale that has no file yet is created next to the source file.
|
|
113
|
+
|
|
114
|
+
| Option | Default | Description |
|
|
115
|
+
| ----------------- | ------- | ----------------------------------------------- |
|
|
116
|
+
| `--to <locales>` | — | Comma-separated target locales (required). |
|
|
117
|
+
| `--from <locale>` | `en` | Source locale to translate from. |
|
|
118
|
+
| `--write` | off | Write results to disk (otherwise preview only). |
|
|
119
|
+
|
|
120
|
+
Requires the `GOOGLE_TRANSLATE_API_KEY` environment variable.
|
|
121
|
+
|
|
122
|
+
## Configuration
|
|
123
|
+
|
|
124
|
+
Configuration is **optional**. With no config file, locale-keysmith scans **only the `src`
|
|
125
|
+
folder** — it looks there for locale files (`.json`, `.yml`, `.yaml`) and for source usage,
|
|
126
|
+
and any writes are confined to it.
|
|
127
|
+
|
|
128
|
+
Create `locale-keysmith.config.json` in your project root to customise behaviour.
|
|
23
129
|
|
|
24
|
-
|
|
130
|
+
### Scanning other folders
|
|
131
|
+
|
|
132
|
+
The simplest knob is `roots` — the folders to scan for both locale files and source usage:
|
|
133
|
+
|
|
134
|
+
```json
|
|
135
|
+
{
|
|
136
|
+
"roots": ["src", "public/locales", "packages/ui"]
|
|
137
|
+
}
|
|
138
|
+
```
|
|
139
|
+
|
|
140
|
+
`translationFiles` and `src` are derived from `roots` automatically. For full control you can
|
|
141
|
+
set either explicitly, which overrides the derived globs:
|
|
25
142
|
|
|
26
143
|
```json
|
|
27
144
|
{
|
|
28
145
|
"sourceLocale": "en",
|
|
29
|
-
"
|
|
30
|
-
|
|
31
|
-
"public/locales/**/*.{json,yml,yaml}"
|
|
32
|
-
],
|
|
146
|
+
"roots": ["src"],
|
|
147
|
+
"translationFiles": ["src/locales/*.{json,yml,yaml}", "public/locales/**/*.{json,yml,yaml}"],
|
|
33
148
|
"src": ["src/**/*.{ts,tsx,js,jsx,vue}"],
|
|
34
149
|
"ignoreKeys": ["debug.*"]
|
|
35
150
|
}
|
|
36
151
|
```
|
|
37
152
|
|
|
38
|
-
|
|
153
|
+
### Fields and defaults
|
|
39
154
|
|
|
40
|
-
|
|
155
|
+
| Field | Default | Purpose |
|
|
156
|
+
| ------------------ | --------------------------------------------------------- | ----------------------------------------------------- |
|
|
157
|
+
| `sourceLocale` | `"en"` | Locale treated as the source of truth. |
|
|
158
|
+
| `roots` | `["src"]` | Folders to scan for locale files and source usage. |
|
|
159
|
+
| `translationFiles` | `<root>/**/*.{json,yml,yaml}` per root | Globs for locale files (overrides the derived globs). |
|
|
160
|
+
| `src` | `<root>/**/*.{ts,tsx,js,jsx,mjs,cjs,vue,svelte}` per root | Globs for source files (overrides the derived globs). |
|
|
161
|
+
| `ignoreKeys` | `[]` | Key patterns excluded from audits (`*` wildcard). |
|
|
41
162
|
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
pnpm exec locale-keysmith translate --from en --to de --write
|
|
45
|
-
```
|
|
163
|
+
`node_modules`, `dist`, and `.next` are always ignored. The locale of each file is inferred
|
|
164
|
+
from its filename (`en.json` → `en`, `pt-BR.yaml` → `pt-BR`).
|
|
46
165
|
|
|
47
|
-
|
|
166
|
+
### Key usage detection
|
|
48
167
|
|
|
49
|
-
|
|
168
|
+
`unused`, `remove-unused`, and `health` treat a key as used whether it is passed directly or
|
|
169
|
+
referenced indirectly. All of these are detected:
|
|
50
170
|
|
|
51
|
-
```
|
|
52
|
-
|
|
53
|
-
|
|
171
|
+
```ts
|
|
172
|
+
t("app.title"); // direct call (also i18n.t / $t / translate)
|
|
173
|
+
<Trans i18nKey="banner.welcome" />; // JSX i18nKey prop
|
|
174
|
+
t(online ? "status.online" : "status.offline"); // ternary branches
|
|
175
|
+
|
|
176
|
+
const priorityKey = { low: "priority.low", high: "priority.high" };
|
|
177
|
+
t(priorityKey[level]); // value from a lookup object
|
|
178
|
+
|
|
179
|
+
const tagKeys = ["tag.work", "tag.urgent"]; // keys in an array
|
|
180
|
+
const FOOTER = "footer.copyright"; // key in a constant
|
|
181
|
+
```
|
|
182
|
+
|
|
183
|
+
Any string literal shaped like a dotted key path (e.g. `"a.b.c"`) is counted as used. The one
|
|
184
|
+
thing that cannot be resolved statically is a **dynamically built** key, which is therefore
|
|
185
|
+
not detected:
|
|
186
|
+
|
|
187
|
+
```ts
|
|
188
|
+
t(`theme.${mode}`); // theme.dark / theme.light are NOT detected
|
|
54
189
|
```
|
|
55
190
|
|
|
56
|
-
|
|
191
|
+
## Development
|
|
57
192
|
|
|
58
193
|
```bash
|
|
59
|
-
pnpm
|
|
194
|
+
pnpm run lint # ESLint (typescript-eslint, flat config)
|
|
195
|
+
pnpm run format # Prettier --write
|
|
196
|
+
pnpm run test # Vitest
|
|
197
|
+
pnpm run coverage # Vitest with v8 coverage
|
|
198
|
+
pnpm run check # lint + format:check + build + test
|
|
60
199
|
```
|
package/dist/cli.d.ts
CHANGED
package/dist/cli.js
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
|
-
|
|
1
|
+
import { dirname, extname, join } from "node:path";
|
|
2
2
|
import chalk from "chalk";
|
|
3
3
|
import { Command } from "commander";
|
|
4
4
|
import { loadConfig } from "./config.js";
|
|
5
|
-
import { deleteValueByPath, filterIgnoredKeys, flattenKeys, sortObjectKeys } from "./keys.js";
|
|
5
|
+
import { deleteValueByPath, filterIgnoredKeys, flattenKeys, isSorted, sortObjectKeys } from "./keys.js";
|
|
6
6
|
import { writeLocaleFile } from "./parser.js";
|
|
7
7
|
import { loadLocaleFiles } from "./scanner.js";
|
|
8
8
|
import { translateMissingKeys } from "./translate.js";
|
|
@@ -12,7 +12,10 @@ program
|
|
|
12
12
|
.name("locale-keysmith")
|
|
13
13
|
.description("Sort, audit, clean, and translate locale files")
|
|
14
14
|
.version("0.1.0");
|
|
15
|
-
program
|
|
15
|
+
program
|
|
16
|
+
.command("scan")
|
|
17
|
+
.description("Find translation files")
|
|
18
|
+
.action(async () => {
|
|
16
19
|
const files = await loadLocaleFiles();
|
|
17
20
|
if (files.length === 0) {
|
|
18
21
|
console.log(chalk.yellow("No locale files found."));
|
|
@@ -30,46 +33,86 @@ program
|
|
|
30
33
|
const files = await loadLocaleFiles();
|
|
31
34
|
for (const file of files) {
|
|
32
35
|
file.data = sortObjectKeys(file.data);
|
|
33
|
-
if (options.write)
|
|
36
|
+
if (options.write) {
|
|
34
37
|
writeLocaleFile(file);
|
|
38
|
+
}
|
|
35
39
|
console.log(`${options.write ? "sorted" : "would sort"} ${file.path}`);
|
|
36
40
|
}
|
|
37
41
|
});
|
|
38
|
-
program
|
|
42
|
+
program
|
|
43
|
+
.command("missing")
|
|
44
|
+
.description("Find keys missing from non-source locales")
|
|
45
|
+
.action(async () => {
|
|
39
46
|
const config = loadConfig();
|
|
40
47
|
const files = await loadLocaleFiles();
|
|
41
|
-
const source = files
|
|
42
|
-
if (!source) {
|
|
43
|
-
throw new Error(`Source locale "${config.sourceLocale}" was not found.`);
|
|
44
|
-
}
|
|
48
|
+
const source = requireSourceLocale(files, config.sourceLocale);
|
|
45
49
|
const sourceKeys = filterIgnoredKeys(flattenKeys(source.data), config.ignoreKeys);
|
|
46
|
-
for (const file of files
|
|
47
|
-
|
|
48
|
-
|
|
50
|
+
for (const file of files) {
|
|
51
|
+
if (file.path === source.path) {
|
|
52
|
+
continue;
|
|
53
|
+
}
|
|
54
|
+
const missing = missingKeysFor(sourceKeys, file);
|
|
49
55
|
console.log(chalk.bold(file.locale));
|
|
50
56
|
if (missing.length === 0) {
|
|
51
57
|
console.log(chalk.green(" no missing keys"));
|
|
52
58
|
continue;
|
|
53
59
|
}
|
|
54
|
-
for (const key of missing)
|
|
60
|
+
for (const key of missing) {
|
|
55
61
|
console.log(` ${key}`);
|
|
62
|
+
}
|
|
56
63
|
}
|
|
57
64
|
});
|
|
58
|
-
program
|
|
65
|
+
program
|
|
66
|
+
.command("unused")
|
|
67
|
+
.description("Find translation keys not used in source files")
|
|
68
|
+
.action(async () => {
|
|
59
69
|
const config = loadConfig();
|
|
60
70
|
const files = await loadLocaleFiles();
|
|
61
|
-
const source = files
|
|
62
|
-
|
|
63
|
-
throw new Error(`Source locale "${config.sourceLocale}" was not found.`);
|
|
64
|
-
}
|
|
65
|
-
const used = await findUsedKeys();
|
|
66
|
-
const unused = filterIgnoredKeys(flattenKeys(source.data), config.ignoreKeys).filter((key) => !used.has(key));
|
|
71
|
+
const source = requireSourceLocale(files, config.sourceLocale);
|
|
72
|
+
const unused = await findUnusedKeys(source, config.ignoreKeys);
|
|
67
73
|
if (unused.length === 0) {
|
|
68
74
|
console.log(chalk.green("No unused keys found."));
|
|
69
75
|
return;
|
|
70
76
|
}
|
|
71
|
-
for (const key of unused)
|
|
77
|
+
for (const key of unused) {
|
|
72
78
|
console.log(key);
|
|
79
|
+
}
|
|
80
|
+
});
|
|
81
|
+
program
|
|
82
|
+
.command("health")
|
|
83
|
+
.description("Report missing keys, unused keys, and unsorted files (exits non-zero on any issue)")
|
|
84
|
+
.action(async () => {
|
|
85
|
+
const config = loadConfig();
|
|
86
|
+
const files = await loadLocaleFiles();
|
|
87
|
+
const source = requireSourceLocale(files, config.sourceLocale);
|
|
88
|
+
let issues = 0;
|
|
89
|
+
const unsorted = files.filter((file) => !isSorted(file.data));
|
|
90
|
+
for (const file of unsorted) {
|
|
91
|
+
console.log(`${chalk.yellow("unsorted")} ${file.path}`);
|
|
92
|
+
}
|
|
93
|
+
issues += unsorted.length;
|
|
94
|
+
const sourceKeys = filterIgnoredKeys(flattenKeys(source.data), config.ignoreKeys);
|
|
95
|
+
for (const file of files) {
|
|
96
|
+
if (file.path === source.path) {
|
|
97
|
+
continue;
|
|
98
|
+
}
|
|
99
|
+
const missing = missingKeysFor(sourceKeys, file);
|
|
100
|
+
for (const key of missing) {
|
|
101
|
+
console.log(`${chalk.red("missing")} ${file.locale} ${key}`);
|
|
102
|
+
}
|
|
103
|
+
issues += missing.length;
|
|
104
|
+
}
|
|
105
|
+
const unused = await findUnusedKeys(source, config.ignoreKeys);
|
|
106
|
+
for (const key of unused) {
|
|
107
|
+
console.log(`${chalk.red("unused")} ${key}`);
|
|
108
|
+
}
|
|
109
|
+
issues += unused.length;
|
|
110
|
+
if (issues === 0) {
|
|
111
|
+
console.log(chalk.green("All locale files are healthy."));
|
|
112
|
+
return;
|
|
113
|
+
}
|
|
114
|
+
console.log(chalk.bold(`\n${issues} issue${issues === 1 ? "" : "s"} found.`));
|
|
115
|
+
process.exitCode = 1;
|
|
73
116
|
});
|
|
74
117
|
program
|
|
75
118
|
.command("remove-unused")
|
|
@@ -79,22 +122,20 @@ program
|
|
|
79
122
|
.action(async (options) => {
|
|
80
123
|
const config = loadConfig();
|
|
81
124
|
const files = await loadLocaleFiles();
|
|
82
|
-
const source = files
|
|
83
|
-
|
|
84
|
-
throw new Error(`Source locale "${config.sourceLocale}" was not found.`);
|
|
85
|
-
}
|
|
86
|
-
const used = await findUsedKeys();
|
|
87
|
-
const unused = filterIgnoredKeys(flattenKeys(source.data), config.ignoreKeys).filter((key) => !used.has(key));
|
|
125
|
+
const source = requireSourceLocale(files, config.sourceLocale);
|
|
126
|
+
const unused = await findUnusedKeys(source, config.ignoreKeys);
|
|
88
127
|
if (unused.length === 0) {
|
|
89
128
|
console.log(chalk.green("No unused keys found."));
|
|
90
129
|
return;
|
|
91
130
|
}
|
|
92
131
|
for (const file of files) {
|
|
93
|
-
for (const key of unused)
|
|
132
|
+
for (const key of unused) {
|
|
94
133
|
deleteValueByPath(file.data, key);
|
|
134
|
+
}
|
|
95
135
|
file.data = sortObjectKeys(file.data);
|
|
96
|
-
if (options.write)
|
|
136
|
+
if (options.write) {
|
|
97
137
|
writeLocaleFile(file);
|
|
138
|
+
}
|
|
98
139
|
}
|
|
99
140
|
console.log(`${options.write ? "removed" : "would remove"} ${unused.length} unused keys`);
|
|
100
141
|
});
|
|
@@ -106,35 +147,62 @@ program
|
|
|
106
147
|
.option("--write", "Write changes to disk")
|
|
107
148
|
.action(async (options) => {
|
|
108
149
|
const files = await loadLocaleFiles();
|
|
109
|
-
const source = files
|
|
110
|
-
if (!source)
|
|
111
|
-
throw new Error(`Source locale "${options.from}" was not found.`);
|
|
150
|
+
const source = requireSourceLocale(files, options.from);
|
|
112
151
|
const sourceKeys = flattenKeys(source.data);
|
|
113
|
-
const
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
152
|
+
const targetLocales = new Set(options.to
|
|
153
|
+
.split(",")
|
|
154
|
+
.map((locale) => locale.trim())
|
|
155
|
+
.filter(Boolean));
|
|
156
|
+
for (const locale of targetLocales) {
|
|
157
|
+
if (locale === source.locale) {
|
|
158
|
+
continue;
|
|
159
|
+
}
|
|
160
|
+
const target = files.find((file) => file.locale === locale) ?? createEmptyLocaleFile(source, locale);
|
|
161
|
+
const missing = missingKeysFor(sourceKeys, target);
|
|
117
162
|
if (missing.length === 0) {
|
|
118
|
-
console.log(chalk.green(`${
|
|
163
|
+
console.log(chalk.green(`${locale}: no missing keys`));
|
|
119
164
|
continue;
|
|
120
165
|
}
|
|
121
166
|
if (!options.write) {
|
|
122
|
-
console.log(`${
|
|
167
|
+
console.log(`${locale}: would translate ${missing.length} keys`);
|
|
123
168
|
continue;
|
|
124
169
|
}
|
|
125
170
|
const changed = await translateMissingKeys({
|
|
126
171
|
source,
|
|
127
172
|
target,
|
|
128
|
-
targetLanguage:
|
|
173
|
+
targetLanguage: locale,
|
|
129
174
|
keys: missing
|
|
130
175
|
});
|
|
131
176
|
target.data = sortObjectKeys(target.data);
|
|
132
177
|
writeLocaleFile(target);
|
|
133
|
-
console.log(`${
|
|
178
|
+
console.log(`${locale}: translated ${changed} keys`);
|
|
134
179
|
}
|
|
135
180
|
});
|
|
136
181
|
program.parseAsync().catch((error) => {
|
|
137
182
|
console.error(chalk.red(error instanceof Error ? error.message : String(error)));
|
|
138
183
|
process.exitCode = 1;
|
|
139
184
|
});
|
|
185
|
+
function requireSourceLocale(files, locale) {
|
|
186
|
+
const source = files.find((file) => file.locale === locale);
|
|
187
|
+
if (!source) {
|
|
188
|
+
throw new Error(`Source locale "${locale}" was not found.`);
|
|
189
|
+
}
|
|
190
|
+
return source;
|
|
191
|
+
}
|
|
192
|
+
function missingKeysFor(sourceKeys, target) {
|
|
193
|
+
const present = new Set(flattenKeys(target.data));
|
|
194
|
+
return sourceKeys.filter((key) => !present.has(key));
|
|
195
|
+
}
|
|
196
|
+
async function findUnusedKeys(source, ignoreKeys) {
|
|
197
|
+
const used = await findUsedKeys();
|
|
198
|
+
return filterIgnoredKeys(flattenKeys(source.data), ignoreKeys).filter((key) => !used.has(key));
|
|
199
|
+
}
|
|
200
|
+
function createEmptyLocaleFile(source, locale) {
|
|
201
|
+
return {
|
|
202
|
+
path: join(dirname(source.path), `${locale}${extname(source.path)}`),
|
|
203
|
+
locale,
|
|
204
|
+
format: source.format,
|
|
205
|
+
data: {}
|
|
206
|
+
};
|
|
207
|
+
}
|
|
140
208
|
//# sourceMappingURL=cli.js.map
|
package/dist/cli.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"cli.js","sourceRoot":"","sources":["../src/cli.ts"],"names":[],"mappings":";
|
|
1
|
+
{"version":3,"file":"cli.js","sourceRoot":"","sources":["../src/cli.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,OAAO,EAAE,IAAI,EAAE,MAAM,WAAW,CAAC;AACnD,OAAO,KAAK,MAAM,OAAO,CAAC;AAC1B,OAAO,EAAE,OAAO,EAAE,MAAM,WAAW,CAAC;AACpC,OAAO,EAAE,UAAU,EAAE,MAAM,UAAU,CAAC;AACtC,OAAO,EAAE,iBAAiB,EAAE,iBAAiB,EAAE,WAAW,EAAE,QAAQ,EAAE,cAAc,EAAE,MAAM,QAAQ,CAAC;AACrG,OAAO,EAAE,eAAe,EAAE,MAAM,UAAU,CAAC;AAC3C,OAAO,EAAE,eAAe,EAAE,MAAM,WAAW,CAAC;AAC5C,OAAO,EAAE,oBAAoB,EAAE,MAAM,aAAa,CAAC;AAEnD,OAAO,EAAE,YAAY,EAAE,MAAM,SAAS,CAAC;AAEvC,MAAM,OAAO,GAAG,IAAI,OAAO,EAAE,CAAC;AAE9B,OAAO;KACJ,IAAI,CAAC,iBAAiB,CAAC;KACvB,WAAW,CAAC,gDAAgD,CAAC;KAC7D,OAAO,CAAC,OAAO,CAAC,CAAC;AAEpB,OAAO;KACJ,OAAO,CAAC,MAAM,CAAC;KACf,WAAW,CAAC,wBAAwB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CAAC,GAAG,CAAC,GAAG,CAAC,CAAC,CAAC;AACjG,CAAC;AAED,SAAS,qBAAqB,CAAC,MAAkB,EAAE,MAAc;IAC/D,OAAO;QACL,IAAI,EAAE,IAAI,CAAC,OAAO,CAAC,MAAM,CAAC,IAAI,CAAC,EAAE,GAAG,MAAM,GAAG,OAAO,CAAC,MAAM,CAAC,IAAI,CAAC,EAAE,CAAC;QACpE,MAAM;QACN,MAAM,EAAE,MAAM,CAAC,MAAM;QACrB,IAAI,EAAE,EAAE;KACT,CAAC;AACJ,CAAC"}
|
package/dist/config.d.ts
CHANGED
|
@@ -1,2 +1,5 @@
|
|
|
1
1
|
import type { LocaleLintConfig } from "./types.js";
|
|
2
|
+
export declare const CONFIG_FILENAME = "locale-keysmith.config.json";
|
|
3
|
+
export declare const LOCALE_EXTENSIONS: string[];
|
|
4
|
+
export declare const SOURCE_EXTENSIONS: string[];
|
|
2
5
|
export declare function loadConfig(cwd?: string): LocaleLintConfig;
|
package/dist/config.js
CHANGED
|
@@ -1,25 +1,35 @@
|
|
|
1
1
|
import { existsSync, readFileSync } from "node:fs";
|
|
2
2
|
import { join } from "node:path";
|
|
3
|
-
const
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
};
|
|
3
|
+
export const CONFIG_FILENAME = "locale-keysmith.config.json";
|
|
4
|
+
export const LOCALE_EXTENSIONS = ["json", "yml", "yaml"];
|
|
5
|
+
export const SOURCE_EXTENSIONS = ["ts", "tsx", "js", "jsx", "mjs", "cjs", "vue", "svelte"];
|
|
6
|
+
const DEFAULT_ROOTS = ["src"];
|
|
7
|
+
function rootGlob(root, extensions) {
|
|
8
|
+
const clean = root.replace(/^\.\/+/, "").replace(/\/+$/, "");
|
|
9
|
+
const prefix = clean === "" || clean === "." ? "" : `${clean}/`;
|
|
10
|
+
return `${prefix}**/*.{${extensions.join(",")}}`;
|
|
11
|
+
}
|
|
13
12
|
export function loadConfig(cwd = process.cwd()) {
|
|
14
|
-
const
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
13
|
+
const userConfig = readUserConfig(join(cwd, CONFIG_FILENAME));
|
|
14
|
+
const roots = userConfig.roots ?? DEFAULT_ROOTS;
|
|
15
|
+
return structuredClone({
|
|
16
|
+
sourceLocale: userConfig.sourceLocale ?? "en",
|
|
17
|
+
roots,
|
|
18
|
+
translationFiles: userConfig.translationFiles ?? roots.map((root) => rootGlob(root, LOCALE_EXTENSIONS)),
|
|
19
|
+
src: userConfig.src ?? roots.map((root) => rootGlob(root, SOURCE_EXTENSIONS)),
|
|
20
|
+
ignoreKeys: userConfig.ignoreKeys ?? []
|
|
21
|
+
});
|
|
22
|
+
}
|
|
23
|
+
function readUserConfig(path) {
|
|
24
|
+
if (!existsSync(path)) {
|
|
25
|
+
return {};
|
|
26
|
+
}
|
|
27
|
+
try {
|
|
28
|
+
return JSON.parse(readFileSync(path, "utf8"));
|
|
29
|
+
}
|
|
30
|
+
catch (error) {
|
|
31
|
+
const detail = error instanceof Error ? error.message : String(error);
|
|
32
|
+
throw new Error(`Failed to parse ${CONFIG_FILENAME}: ${detail}`, { cause: error });
|
|
33
|
+
}
|
|
24
34
|
}
|
|
25
35
|
//# sourceMappingURL=config.js.map
|
package/dist/config.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"config.js","sourceRoot":"","sources":["../src/config.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,YAAY,EAAE,MAAM,SAAS,CAAC;AACnD,OAAO,EAAE,IAAI,EAAE,MAAM,WAAW,CAAC;AAGjC,MAAM,
|
|
1
|
+
{"version":3,"file":"config.js","sourceRoot":"","sources":["../src/config.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,YAAY,EAAE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AC,CAAC;QACvG,GAAG,EAAE,UAAU,CAAC,GAAG,IAAI,KAAK,CAAC,GAAG,CAAC,CAAC,IAAI,EAAE,EAAE,CAAC,QAAQ,CAAC,IAAI,EAAE,iBAAiB,CAAC,CAAC;QAC7E,UAAU,EAAE,UAAU,CAAC,UAAU,IAAI,EAAE;KACxC,CAAC,CAAC;AACL,CAAC;AAED,SAAS,cAAc,CAAC,IAAY;IAClC,IAAI,CAAC,UAAU,CAAC,IAAI,CAAC,EAAE,CAAC;QACtB,OAAO,EAAE,CAAC;IACZ,CAAC;IAED,IAAI,CAAC;QACH,OAAO,IAAI,CAAC,KAAK,CAAC,YAAY,CAAC,IAAI,EAAE,MAAM,CAAC,CAA8B,CAAC;IAC7E,CAAC;IAAC,OAAO,KAAK,EAAE,CAAC;QACf,MAAM,MAAM,GAAG,KAAK,YAAY,KAAK,CAAC,CAAC,CAAC,KAAK,CAAC,OAAO,CAAC,CAAC,CAAC,MAAM,CAAC,KAAK,CAAC,CAAC;QACtE,MAAM,IAAI,KAAK,CAAC,mBAAmB,eAAe,KAAK,MAAM,EAAE,EAAE,EAAE,KAAK,EAAE,KAAK,EAAE,CAAC,CAAC;IACrF,CAAC;AACH,CAAC"}
|
package/dist/glob.d.ts
ADDED
package/dist/glob.js
ADDED
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import fg from "fast-glob";
|
|
2
|
+
export const IGNORED_DIRECTORIES = ["**/node_modules/**", "**/dist/**", "**/.next/**"];
|
|
3
|
+
export function globFiles(patterns, cwd = process.cwd(), extraIgnore = []) {
|
|
4
|
+
return fg(patterns, { cwd, absolute: true, ignore: [...IGNORED_DIRECTORIES, ...extraIgnore] });
|
|
5
|
+
}
|
|
6
|
+
//# sourceMappingURL=glob.js.map
|
package/dist/glob.js.map
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"glob.js","sourceRoot":"","sources":["../src/glob.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,WAAW,CAAC;AAE3B,MAAM,CAAC,MAAM,mBAAmB,GAAG,CAAC,oBAAoB,EAAE,YAAY,EAAE,aAAa,CAAC,CAAC;AAEvF,MAAM,UAAU,SAAS,CACvB,QAAkB,EAClB,GAAG,GAAG,OAAO,CAAC,GAAG,EAAE,EACnB,cAAwB,EAAE;IAE1B,OAAO,EAAE,CAAC,QAAQ,EAAE,EAAE,GAAG,EAAE,QAAQ,EAAE,IAAI,EAAE,MAAM,EAAE,CAAC,GAAG,mBAAmB,EAAE,GAAG,WAAW,CAAC,EAAE,CAAC,CAAC;AACjG,CAAC"}
|
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,QAAQ,CAAC;AACvB,cAAc,UAAU,CAAC;AACzB,cAAc,WAAW,CAAC;AAC1B,cAAc,SAAS,CAAC"}
|
package/dist/keys.d.ts
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import type { LocaleObject, LocaleValue } from "./types.js";
|
|
2
|
+
export declare function isSorted(value: LocaleObject): boolean;
|
|
2
3
|
export declare function sortObjectKeys<T extends LocaleValue>(value: T): T;
|
|
3
4
|
export declare function flattenKeys(value: LocaleObject, prefix?: string): string[];
|
|
4
5
|
export declare function filterIgnoredKeys(keys: string[], ignorePatterns: string[]): string[];
|
package/dist/keys.js
CHANGED
|
@@ -1,3 +1,6 @@
|
|
|
1
|
+
export function isSorted(value) {
|
|
2
|
+
return JSON.stringify(value) === JSON.stringify(sortObjectKeys(value));
|
|
3
|
+
}
|
|
1
4
|
export function sortObjectKeys(value) {
|
|
2
5
|
if (Array.isArray(value)) {
|
|
3
6
|
return value.map((item) => sortObjectKeys(item));
|
|
@@ -23,15 +26,17 @@ export function flattenKeys(value, prefix = "") {
|
|
|
23
26
|
});
|
|
24
27
|
}
|
|
25
28
|
export function filterIgnoredKeys(keys, ignorePatterns) {
|
|
26
|
-
if (ignorePatterns.length === 0)
|
|
29
|
+
if (ignorePatterns.length === 0) {
|
|
27
30
|
return keys;
|
|
31
|
+
}
|
|
28
32
|
const matchers = ignorePatterns.map(patternToRegExp);
|
|
29
33
|
return keys.filter((key) => !matchers.some((matcher) => matcher.test(key)));
|
|
30
34
|
}
|
|
31
35
|
export function getValueByPath(value, path) {
|
|
32
36
|
return path.split(".").reduce((current, segment) => {
|
|
33
|
-
if (!isPlainObject(current))
|
|
37
|
+
if (!isPlainObject(current)) {
|
|
34
38
|
return undefined;
|
|
39
|
+
}
|
|
35
40
|
return current[segment];
|
|
36
41
|
}, value);
|
|
37
42
|
}
|
|
@@ -53,8 +58,9 @@ export function deleteValueByPath(value, path) {
|
|
|
53
58
|
const parents = [];
|
|
54
59
|
for (const segment of segments.slice(0, -1)) {
|
|
55
60
|
const child = current[segment];
|
|
56
|
-
if (!isPlainObject(child))
|
|
61
|
+
if (!isPlainObject(child)) {
|
|
57
62
|
return;
|
|
63
|
+
}
|
|
58
64
|
parents.push({ object: current, key: segment });
|
|
59
65
|
current = child;
|
|
60
66
|
}
|
package/dist/keys.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"keys.js","sourceRoot":"","sources":["../src/keys.ts"],"names":[],"mappings":"AAEA,MAAM,UAAU,cAAc,CAAwB,KAAQ;IAC5D,IAAI,KAAK,CAAC,OAAO,CAAC,KAAK,CAAC,EAAE,CAAC;QACzB,OAAO,KAAK,CAAC,GAAG,CAAC,CAAC,IAAI,EAAE,EAAE,CAAC,cAAc,CAAC,IAAI,CAAC,CAAM,CAAC;IACxD,CAAC;IAED,IAAI,aAAa,CAAC,KAAK,CAAC,EAAE,CAAC;QACzB,MAAM,MAAM,GAAG,MAAM,CAAC,IAAI,CAAC,KAAK,CAAC;aAC9B,IAAI,CAAC,CAAC,CAAC,EAAE,C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CAAC,GAAG,CAAC,CAAC;QAExC,IAAI,aAAa,CAAC,KAAK,CAAC,IAAI,MAAM,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC,MAAM,KAAK,CAAC,EAAE,CAAC;YAC5D,OAAO,MAAM,CAAC,MAAM,CAAC,MAAM,CAAC,GAAG,CAAC,CAAC;QACnC,CAAC;IACH,CAAC;AACH,CAAC;AAED,SAAS,aAAa,CAAC,KAAc;IACnC,OAAO,OAAO,CAAC,KAAK,CAAC,IAAI,OAAO,KAAK,KAAK,QAAQ,IAAI,CAAC,KAAK,CAAC,OAAO,CAAC,KAAK,CAAC,CAAC;AAC9E,CAAC;AAED,SAAS,eAAe,CAAC,OAAe;IACtC,MAAM,OAAO,GAAG,OAAO,CAAC,OAAO,CAAC,oBAAoB,EAAE,MAAM,CAAC,CAAC,UAAU,CAAC,GAAG,EAAE,IAAI,CAAC,CAAC;IAEpF,OAAO,IAAI,MAAM,CAAC,IAAI,OAAO,GAAG,CAAC,CAAC;AACpC,CAAC"}
|
package/dist/parser.js
CHANGED
|
@@ -2,10 +2,18 @@ import { extname } from "node:path";
|
|
|
2
2
|
import { readFileSync, writeFileSync } from "node:fs";
|
|
3
3
|
import YAML from "yaml";
|
|
4
4
|
export function readLocaleFile(path) {
|
|
5
|
-
const
|
|
5
|
+
const format = extname(path).toLowerCase() === ".json" ? "json" : "yaml";
|
|
6
6
|
const raw = readFileSync(path, "utf8");
|
|
7
|
-
|
|
8
|
-
|
|
7
|
+
let parsed = {};
|
|
8
|
+
if (raw.trim() !== "") {
|
|
9
|
+
try {
|
|
10
|
+
parsed = format === "json" ? JSON.parse(raw) : YAML.parse(raw);
|
|
11
|
+
}
|
|
12
|
+
catch (error) {
|
|
13
|
+
const detail = error instanceof Error ? error.message : String(error);
|
|
14
|
+
throw new Error(`Failed to parse ${path}: ${detail}`, { cause: error });
|
|
15
|
+
}
|
|
16
|
+
}
|
|
9
17
|
return {
|
|
10
18
|
path,
|
|
11
19
|
locale: inferLocale(path),
|
package/dist/parser.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"parser.js","sourceRoot":"","sources":["../src/parser.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,MAAM,WAAW,CAAC;AACpC,OAAO,EAAE,YAAY,EAAE,aAAa,EAAE,MAAM,SAAS,CAAC;AACtD,OAAO,IAAI,MAAM,MAAM,CAAC;AAGxB,MAAM,UAAU,cAAc,CAAC,IAAY;IACzC,MAAM,
|
|
1
|
+
{"version":3,"file":"parser.js","sourceRoot":"","sources":["../src/parser.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,MAAM,WAAW,CAAC;AACpC,OAAO,EAAE,YAAY,EAAE,aAAa,EAAE,MAAM,SAAS,CAAC;AACtD,OAAO,IAAI,MAAM,MAAM,CAAC;AAGxB,MAAM,UAAU,cAAc,CAAC,IAAY;IACzC,MAAM,MAAM,GAAyB,OAAO,CAAC,IAAI,CAAC,CAAC,WAAW,EAAE,KAAK,OAAO,CAAC,CAAC,CAAC,MAAM,CAAC,CAAC,CAAC,MAAM,CAAC;IAC/F,MAAM,GAAG,GAAG,YAAY,CAAC,IAAI,EAAE,MAAM,CAAC,CAAC;IAEvC,IAAI,MAAM,GAAY,EAAE,CAAC;IAEzB,IAAI,GAAG,CAAC,IAAI,EAAE,KAAK,EAAE,EAAE,CAAC;QACtB,IAAI,CAAC;YACH,MAAM,GAAG,MAAM,KAAK,MAAM,CAAC,CAAC,CAAC,IAAI,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,IAAI,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC;QACjE,CAAC;QAAC,OAAO,KAAK,EAAE,CAAC;YACf,MAAM,MAAM,GAAG,KAAK,YAAY,KAAK,CAAC,CAAC,CAAC,KAAK,CAAC,OAAO,CAAC,CAAC,CAAC,MAAM,CAAC,KAAK,CAAC,CAAC;YACtE,MAAM,IAAI,KAAK,CAAC,mBAAmB,IAAI,KAAK,MAAM,EAAE,EAAE,EAAE,KAAK,EAAE,KAAK,EAAE,CAAC,CAAC;QAC1E,CAAC;IACH,CAAC;IAED,OAAO;QACL,IAAI;QACJ,MAAM,EAAE,WAAW,CAAC,IAAI,CAAC;QACzB,MAAM;QACN,IAAI,EAAE,CAAC,MAAM,IAAI,EAAE,CAAiB;KACrC,CAAC;AACJ,CAAC;AAED,MAAM,UAAU,eAAe,CAAC,IAAgB;IAC9C,MAAM,OAAO,GACX,IAAI,CAAC,MAAM,KAAK,MAAM;QACpB,CAAC,CAAC,GAAG,IAAI,CAAC,SAAS,CAAC,IAAI,CAAC,IAAI,EAAE,IAAI,EAAE,CAAC,CAAC,IAAI;QAC3C,CAAC,CAAC,IAAI,CAAC,SAAS,CAAC,IAAI,CAAC,IAAI,EAAE,EAAE,cAAc,EAAE,KAAK,EAAE,CAAC,CAAC;IAE3D,aAAa,CAAC,IAAI,CAAC,IAAI,EAAE,OAAO,CAAC,CAAC;AACpC,CAAC;AAED,MAAM,UAAU,WAAW,CAAC,IAAY;IACtC,MAAM,QAAQ,GAAG,IAAI,CAAC,KAAK,CAAC,OAAO,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,CAAC,IAAI,EAAE,CAAC;IAElD,OAAO,QAAQ,CAAC,OAAO,CAAC,kBAAkB,EAAE,EAAE,CAAC,CAAC;AAClD,CAAC"}
|
package/dist/scanner.js
CHANGED
|
@@ -1,13 +1,8 @@
|
|
|
1
|
-
import
|
|
2
|
-
import {
|
|
1
|
+
import { CONFIG_FILENAME, loadConfig } from "./config.js";
|
|
2
|
+
import { globFiles } from "./glob.js";
|
|
3
3
|
import { readLocaleFile } from "./parser.js";
|
|
4
4
|
export async function findLocaleFiles(cwd = process.cwd()) {
|
|
5
|
-
|
|
6
|
-
return fg(config.translationFiles, {
|
|
7
|
-
cwd,
|
|
8
|
-
absolute: true,
|
|
9
|
-
ignore: ["**/node_modules/**", "**/dist/**", "**/.next/**"]
|
|
10
|
-
});
|
|
5
|
+
return globFiles(loadConfig(cwd).translationFiles, cwd, [`**/${CONFIG_FILENAME}`]);
|
|
11
6
|
}
|
|
12
7
|
export async function loadLocaleFiles(cwd = process.cwd()) {
|
|
13
8
|
const paths = await findLocaleFiles(cwd);
|
package/dist/scanner.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"scanner.js","sourceRoot":"","sources":["../src/scanner.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,
|
|
1
|
+
{"version":3,"file":"scanner.js","sourceRoot":"","sources":["../src/scanner.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,eAAe,EAAE,UAAU,EAAE,MAAM,UAAU,CAAC;AACvD,OAAO,EAAE,SAAS,EAAE,MAAM,QAAQ,CAAC;AACnC,OAAO,EAAE,cAAc,EAAE,MAAM,UAAU,CAAC;AAG1C,MAAM,CAAC,KAAK,UAAU,eAAe,CAAC,GAAG,GAAG,OAAO,CAAC,GAAG,EAAE;IACvD,OAAO,SAAS,CAAC,UAAU,CAAC,GAAG,CAAC,CAAC,gBAAgB,EAAE,GAAG,EAAE,CAAC,MAAM,eAAe,EAAE,CAAC,CAAC,CAAC;AACrF,CAAC;AAED,MAAM,CAAC,KAAK,UAAU,eAAe,CAAC,GAAG,GAAG,OAAO,CAAC,GAAG,EAAE;IACvD,MAAM,KAAK,GAAG,MAAM,eAAe,CAAC,GAAG,CAAC,CAAC;IAEzC,OAAO,KAAK,CAAC,GAAG,CAAC,cAAc,CAAC,CAAC;AACnC,CAAC"}
|
package/dist/translate.js
CHANGED
|
@@ -7,8 +7,9 @@ export async function translateMissingKeys(options) {
|
|
|
7
7
|
let changed = 0;
|
|
8
8
|
for (const key of options.keys) {
|
|
9
9
|
const sourceValue = getValueByPath(options.source.data, key);
|
|
10
|
-
if (typeof sourceValue !== "string" || sourceValue.trim() === "")
|
|
10
|
+
if (typeof sourceValue !== "string" || sourceValue.trim() === "") {
|
|
11
11
|
continue;
|
|
12
|
+
}
|
|
12
13
|
const translated = await translateText(sourceValue, options.targetLanguage, apiKey);
|
|
13
14
|
setValueByPath(options.target.data, key, translated);
|
|
14
15
|
changed += 1;
|
package/dist/translate.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"translate.js","sourceRoot":"","sources":["../src/translate.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,cAAc,EAAE,cAAc,EAAE,MAAM,
|
|
1
|
+
{"version":3,"file":"translate.js","sourceRoot":"","sources":["../src/translate.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,cAAc,EAAE,cAAc,EAAE,MAAM,QAAQ,CAAC;AAGxD,MAAM,CAAC,KAAK,UAAU,oBAAoB,CAAC,OAK1C;IACC,MAAM,MAAM,GAAG,OAAO,CAAC,GAAG,CAAC,wBAAwB,CAAC;IAEpD,IAAI,CAAC,MAAM,EAAE,CAAC;QACZ,MAAM,IAAI,KAAK,CAAC,iEAAiE,CAAC,CAAC;IACrF,CAAC;IAED,IAAI,OAAO,GAAG,CAAC,CAAC;IAEhB,KAAK,MAAM,GAAG,IAAI,OAAO,CAAC,IAAI,EAAE,CAAC;QAC/B,MAAM,WAAW,GAAG,cAAc,CAAC,OAAO,CAAC,MAAM,CAAC,IAAI,EAAE,GAAG,CAAC,CAAC;QAE7D,IAAI,OAAO,WAAW,KAAK,QAAQ,IAAI,WAAW,CAAC,IAAI,EAAE,KAAK,EAAE,EAAE,CAAC;YACjE,SAAS;QACX,CAAC;QAED,MAAM,UAAU,GAAG,MAAM,aAAa,CAAC,WAAW,EAAE,OAAO,CAAC,cAAc,EAAE,MAAM,CAAC,CAAC;QACpF,cAAc,CAAC,OAAO,CAAC,MAAM,CAAC,IAAI,EAAE,GAAG,EAAE,UAAU,CAAC,CAAC;QACrD,OAAO,IAAI,CAAC,CAAC;IACf,CAAC;IAED,OAAO,OAAO,CAAC;AACjB,CAAC;AAED,KAAK,UAAU,aAAa,CAAC,IAAY,EAAE,MAAc,EAAE,MAAc;IACvE,MAAM,QAAQ,GAAG,MAAM,KAAK,CAAC,gEAAgE,MAAM,EAAE,EAAE;QACrG,MAAM,EAAE,MAAM;QACd,OAAO,EAAE;YACP,cAAc,EAAE,kBAAkB;SACnC;QACD,IAAI,EAAE,IAAI,CAAC,SAAS,CAAC;YACnB,CAAC,EAAE,IAAI;YACP,MAAM;YACN,MAAM,EAAE,MAAM;SACf,CAAC;KACH,CAAC,CAAC;IAEH,IAAI,CAAC,QAAQ,CAAC,EAAE,EAAE,CAAC;QACjB,MAAM,IAAI,KAAK,CAAC,+CAA+C,QAAQ,CAAC,MAAM,GAAG,CAAC,CAAC;IACrF,CAAC;IAED,MAAM,OAAO,GAAG,CAAC,MAAM,QAAQ,CAAC,IAAI,EAAE,CAErC,CAAC;IAEF,OAAO,OAAO,CAAC,IAAI,EAAE,YAAY,EAAE,CAAC,CAAC,CAAC,EAAE,cAAc,IAAI,IAAI,CAAC;AACjE,CAAC"}
|
package/dist/types.d.ts
CHANGED
package/dist/usage.d.ts
CHANGED
package/dist/usage.js
CHANGED
|
@@ -1,27 +1,34 @@
|
|
|
1
1
|
import { readFileSync } from "node:fs";
|
|
2
|
-
import fg from "fast-glob";
|
|
3
2
|
import { loadConfig } from "./config.js";
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
/\b(?:
|
|
3
|
+
import { globFiles } from "./glob.js";
|
|
4
|
+
const callPatterns = [
|
|
5
|
+
/\b(?:t|i18n\.t|\$t|translate)\(\s*["'`]([^"'`]+)["'`]/g, // t("key"), i18n.t('key'), $t(`key`), translate("key")
|
|
6
|
+
/\bi18nKey\s*=\s*["'`]([^"'`]+)["'`]/g // <Trans i18nKey="key" />, useTranslation-style i18nKey props
|
|
7
7
|
];
|
|
8
|
+
const stringLiteralPattern = /(["'`])((?:\\.|(?!\1)[^\\])*)\1/g;
|
|
9
|
+
const keyShape = /^[A-Za-z0-9_$-]+(?:\.[A-Za-z0-9_$-]+)+$/;
|
|
8
10
|
export async function findUsedKeys(cwd = process.cwd()) {
|
|
9
|
-
const
|
|
10
|
-
const files = await fg(config.src, {
|
|
11
|
-
cwd,
|
|
12
|
-
absolute: true,
|
|
13
|
-
ignore: ["**/node_modules/**", "**/dist/**", "**/.next/**"]
|
|
14
|
-
});
|
|
11
|
+
const files = await globFiles(loadConfig(cwd).src, cwd);
|
|
15
12
|
const used = new Set();
|
|
16
13
|
for (const file of files) {
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
14
|
+
collectUsedKeys(readFileSync(file, "utf8"), used);
|
|
15
|
+
}
|
|
16
|
+
return used;
|
|
17
|
+
}
|
|
18
|
+
export function collectUsedKeys(content, used = new Set()) {
|
|
19
|
+
for (const pattern of callPatterns) {
|
|
20
|
+
for (const match of content.matchAll(pattern)) {
|
|
21
|
+
if (match[1] && !match[1].includes("${")) {
|
|
22
|
+
used.add(match[1]);
|
|
22
23
|
}
|
|
23
24
|
}
|
|
24
25
|
}
|
|
26
|
+
for (const match of content.matchAll(stringLiteralPattern)) {
|
|
27
|
+
const literal = match[2];
|
|
28
|
+
if (keyShape.test(literal)) {
|
|
29
|
+
used.add(literal);
|
|
30
|
+
}
|
|
31
|
+
}
|
|
25
32
|
return used;
|
|
26
33
|
}
|
|
27
34
|
//# sourceMappingURL=usage.js.map
|
package/dist/usage.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"usage.js","sourceRoot":"","sources":["../src/usage.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAAE,MAAM,SAAS,CAAC;AACvC,OAAO,EAAE,MAAM,
|
|
1
|
+
{"version":3,"file":"usage.js","sourceRoot":"","sources":["../src/usage.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAAE,MAAM,SAAS,CAAC;AACvC,OAAO,EAAE,UAAU,EAAE,MAAM,UAAU,CAAC;AACtC,OAAO,EAAE,SAAS,EAAE,MAAM,QAAQ,CAAC;AAEnC,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ACpB,CAAC;IACH,CAAC;IAED,OAAO,IAAI,CAAC;AACd,CAAC"}
|
package/package.json
CHANGED
|
@@ -1,8 +1,9 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "locale-keysmith",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.2.0",
|
|
4
4
|
"description": "CLI helper for sorting, auditing, cleaning, and translating i18n locale keys.",
|
|
5
5
|
"type": "module",
|
|
6
|
+
"packageManager": "pnpm@10.4.0",
|
|
6
7
|
"bin": {
|
|
7
8
|
"locale-keysmith": "./dist/cli.js"
|
|
8
9
|
},
|
|
@@ -17,6 +18,19 @@
|
|
|
17
18
|
"README.md",
|
|
18
19
|
"LICENSE"
|
|
19
20
|
],
|
|
21
|
+
"scripts": {
|
|
22
|
+
"dev": "tsx src/cli.ts",
|
|
23
|
+
"build": "tsc && tsc-alias --resolve-full-paths",
|
|
24
|
+
"test": "vitest run",
|
|
25
|
+
"test:watch": "vitest",
|
|
26
|
+
"coverage": "vitest run --coverage",
|
|
27
|
+
"lint": "eslint .",
|
|
28
|
+
"lint:fix": "eslint . --fix",
|
|
29
|
+
"format": "prettier --write .",
|
|
30
|
+
"format:check": "prettier --check .",
|
|
31
|
+
"check": "pnpm run lint && pnpm run format:check && pnpm run build && pnpm run test",
|
|
32
|
+
"prepublishOnly": "pnpm run check"
|
|
33
|
+
},
|
|
20
34
|
"keywords": [
|
|
21
35
|
"i18n",
|
|
22
36
|
"l10n",
|
|
@@ -26,25 +40,39 @@
|
|
|
26
40
|
],
|
|
27
41
|
"author": "",
|
|
28
42
|
"license": "MIT",
|
|
43
|
+
"repository": {
|
|
44
|
+
"type": "git",
|
|
45
|
+
"url": "git+https://github.com/faysalakash/locale-keysmith.git"
|
|
46
|
+
},
|
|
47
|
+
"homepage": "https://github.com/faysalakash/locale-keysmith#readme",
|
|
48
|
+
"bugs": {
|
|
49
|
+
"url": "https://github.com/faysalakash/locale-keysmith/issues"
|
|
50
|
+
},
|
|
29
51
|
"dependencies": {
|
|
30
|
-
"chalk": "^
|
|
31
|
-
"commander": "^
|
|
32
|
-
"fast-glob": "^3.3.
|
|
33
|
-
"yaml": "^2.
|
|
52
|
+
"chalk": "^6.0.0",
|
|
53
|
+
"commander": "^15.0.0",
|
|
54
|
+
"fast-glob": "^3.3.3",
|
|
55
|
+
"yaml": "^2.9.0"
|
|
34
56
|
},
|
|
35
57
|
"devDependencies": {
|
|
36
|
-
"@
|
|
37
|
-
"
|
|
38
|
-
"
|
|
39
|
-
"
|
|
58
|
+
"@eslint/js": "^10.0.1",
|
|
59
|
+
"@types/node": "^26.1.2",
|
|
60
|
+
"@vitest/coverage-v8": "^4.1.10",
|
|
61
|
+
"eslint": "^10.8.0",
|
|
62
|
+
"eslint-config-prettier": "^10.1.8",
|
|
63
|
+
"prettier": "^3.9.6",
|
|
64
|
+
"tsc-alias": "^1.9.1",
|
|
65
|
+
"tsx": "^4.23.7",
|
|
66
|
+
"typescript": "^6.0.3",
|
|
67
|
+
"typescript-eslint": "^8.66.0",
|
|
68
|
+
"vitest": "^4.1.10"
|
|
40
69
|
},
|
|
41
70
|
"engines": {
|
|
42
71
|
"node": ">=18.18"
|
|
43
72
|
},
|
|
44
|
-
"
|
|
45
|
-
"
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
"check": "pnpm run build && pnpm run test"
|
|
73
|
+
"pnpm": {
|
|
74
|
+
"ignoredBuiltDependencies": [
|
|
75
|
+
"esbuild"
|
|
76
|
+
]
|
|
49
77
|
}
|
|
50
|
-
}
|
|
78
|
+
}
|