ai-localize-validators 2.0.5 → 2.0.6
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/CHANGELOG.md +7 -0
- package/README.md +83 -0
- package/package.json +2 -2
package/CHANGELOG.md
CHANGED
package/README.md
ADDED
|
@@ -0,0 +1,83 @@
|
|
|
1
|
+
# ai-localize-validators
|
|
2
|
+
|
|
3
|
+
> Locale file validation — missing keys, duplicate values, placeholder mismatches, and unused keys — for the [ai-localize-core](https://github.com/ai-localize/ai-localize-core) platform.
|
|
4
|
+
|
|
5
|
+
[](https://www.npmjs.com/package/ai-localize-validators)
|
|
6
|
+
[](LICENSE)
|
|
7
|
+
|
|
8
|
+
---
|
|
9
|
+
|
|
10
|
+
## What it does
|
|
11
|
+
|
|
12
|
+
| Validator | Type | Description |
|
|
13
|
+
|---|---|---|
|
|
14
|
+
| `MissingKeyValidator` | Error | Finds keys absent in target languages **or** where the translated value still equals the English source placeholder |
|
|
15
|
+
| `DuplicateKeyValidator` | Error | Finds keys sharing the same translated value within a namespace |
|
|
16
|
+
| `PlaceholderValidator` | Error | Detects `{{var}}` / `{var}` / `%(var)s` / `%var` mismatches between source and target |
|
|
17
|
+
| `UnusedKeyValidator` | Warning | Finds locale keys not referenced anywhere in source code |
|
|
18
|
+
|
|
19
|
+
## Installation
|
|
20
|
+
|
|
21
|
+
```bash
|
|
22
|
+
npm install ai-localize-validators
|
|
23
|
+
```
|
|
24
|
+
|
|
25
|
+
## Usage
|
|
26
|
+
|
|
27
|
+
```ts
|
|
28
|
+
import { LocaleValidator } from 'ai-localize-validators';
|
|
29
|
+
|
|
30
|
+
const validator = new LocaleValidator({
|
|
31
|
+
localesDir: './locales',
|
|
32
|
+
sourceDir: './src',
|
|
33
|
+
defaultLanguage: 'en',
|
|
34
|
+
targetLanguages: ['fr', 'de'],
|
|
35
|
+
checkUnused: true,
|
|
36
|
+
checkDuplicates: true,
|
|
37
|
+
checkPlaceholders: true,
|
|
38
|
+
});
|
|
39
|
+
|
|
40
|
+
const result = validator.validate();
|
|
41
|
+
// result.valid — boolean
|
|
42
|
+
// result.errors — ValidationError[]
|
|
43
|
+
// result.warnings — ValidationWarning[]
|
|
44
|
+
```
|
|
45
|
+
|
|
46
|
+
## Missing key detection (v2.0.5+)
|
|
47
|
+
|
|
48
|
+
A translation key is flagged as **missing** when ANY of these is true:
|
|
49
|
+
|
|
50
|
+
1. The key is absent from the target language file
|
|
51
|
+
2. The target value is an empty string `""`
|
|
52
|
+
3. **The target value equals the source (English) value** — indicating it was auto-seeded by the extractor and not yet translated
|
|
53
|
+
|
|
54
|
+
This third condition correctly catches keys seeded by `ai-localize extract` which copies the English value into target files as a placeholder. Error message:
|
|
55
|
+
|
|
56
|
+
```
|
|
57
|
+
[missing-key] Missing translation for "common.save" in "fr" (value equals source)
|
|
58
|
+
```
|
|
59
|
+
|
|
60
|
+
> **Intentionally identical values:** If a key is supposed to be the same across all languages (brand names, units, etc.), use `staticKeys` in your config instead of hardcoding the value. Static keys bypass the validator entirely.
|
|
61
|
+
|
|
62
|
+
## Individual validators
|
|
63
|
+
|
|
64
|
+
```ts
|
|
65
|
+
import {
|
|
66
|
+
MissingKeyValidator,
|
|
67
|
+
DuplicateKeyValidator,
|
|
68
|
+
PlaceholderValidator,
|
|
69
|
+
UnusedKeyValidator,
|
|
70
|
+
} from 'ai-localize-validators';
|
|
71
|
+
|
|
72
|
+
const { errors, missingByLanguage } = new MissingKeyValidator(
|
|
73
|
+
'./locales', 'en', ['fr', 'de']
|
|
74
|
+
).validate();
|
|
75
|
+
```
|
|
76
|
+
|
|
77
|
+
---
|
|
78
|
+
|
|
79
|
+
## Part of ai-localize-core
|
|
80
|
+
|
|
81
|
+
Install the CLI for the complete toolset: `npm install -g ai-localize-cli`
|
|
82
|
+
|
|
83
|
+
MIT © ai-localize-core contributors
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "ai-localize-validators",
|
|
3
|
-
"version": "2.0.
|
|
3
|
+
"version": "2.0.6",
|
|
4
4
|
"description": "Locale file validation engine — missing, duplicate, placeholder and unused key validators",
|
|
5
5
|
"main": "./dist/index.js",
|
|
6
6
|
"module": "./dist/index.mjs",
|
|
@@ -33,7 +33,7 @@
|
|
|
33
33
|
"node": ">=18.0.0"
|
|
34
34
|
},
|
|
35
35
|
"dependencies": {
|
|
36
|
-
"ai-localize-shared": "2.0.
|
|
36
|
+
"ai-localize-shared": "2.0.6"
|
|
37
37
|
},
|
|
38
38
|
"devDependencies": {
|
|
39
39
|
"tsup": "^8.0.1",
|