ai-localize-validators 2.0.4 → 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 CHANGED
@@ -1,5 +1,31 @@
1
1
  # ai-localize-validators
2
2
 
3
+ ## 2.0.6
4
+
5
+ ### Patch Changes
6
+
7
+ - Add per-package README.md files so each package displays documentation on npmjs.com
8
+ - Update README version badge to 2.0.6
9
+
10
+ ## 2.0.5
11
+
12
+ ### Patch Changes
13
+
14
+ - **Bug fix — `validate` always reported "valid"**: `MissingKeyValidator` now correctly
15
+ detects un-translated keys when the extractor has seeded target language files with the
16
+ English source value (the `localeStructure` default behaviour introduced in 2.0.3).
17
+ Previously the check `targetValue === ""` never fired because values were non-empty strings;
18
+ the validator now adds a third condition — `targetValue === sourceValue` — so a key that
19
+ still holds its English placeholder is flagged as "Missing translation (value equals source)".
20
+ (`packages/validators/src/missing-key-validator.ts`)
21
+
22
+ ## 2.0.4
23
+
24
+ ### Patch Changes
25
+
26
+ - Updated dependencies
27
+ - ai-localize-shared@2.0.4
28
+
3
29
  ## 2.0.3
4
30
 
5
31
  ### Patch Changes
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
+ [![npm version](https://img.shields.io/npm/v/ai-localize-validators.svg)](https://www.npmjs.com/package/ai-localize-validators)
6
+ [![License: MIT](https://img.shields.io/badge/License-MIT-yellow.svg)](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/dist/index.js CHANGED
@@ -66,9 +66,18 @@ var MissingKeyValidator = class {
66
66
  const targetPath = path.join(this.localesDir, lang, nsFile);
67
67
  const targetEntries = (0, import_ai_localize_shared.readJsonSafe)(targetPath) || {};
68
68
  for (const key of Object.keys(defaultEntries)) {
69
- if (!(key in targetEntries) || targetEntries[key] === "") {
69
+ const sourceValue = defaultEntries[key];
70
+ const targetValue = targetEntries[key];
71
+ const isMissing = !(key in targetEntries) || targetValue === "" || targetValue !== void 0 && targetValue === sourceValue;
72
+ if (isMissing) {
70
73
  const fullKey = `${namespace}.${key}`;
71
- errors.push({ type: "missing-key", key: fullKey, language: lang, message: `Missing key "${fullKey}" in "${lang}"`, filePath: targetPath });
74
+ errors.push({
75
+ type: "missing-key",
76
+ key: fullKey,
77
+ language: lang,
78
+ message: `Missing translation for "${fullKey}" in "${lang}" (value equals source)`,
79
+ filePath: targetPath
80
+ });
72
81
  if (!missingByLanguage[lang]) missingByLanguage[lang] = [];
73
82
  missingByLanguage[lang].push(fullKey);
74
83
  }
package/dist/index.mjs CHANGED
@@ -26,9 +26,18 @@ var MissingKeyValidator = class {
26
26
  const targetPath = path.join(this.localesDir, lang, nsFile);
27
27
  const targetEntries = readJsonSafe(targetPath) || {};
28
28
  for (const key of Object.keys(defaultEntries)) {
29
- if (!(key in targetEntries) || targetEntries[key] === "") {
29
+ const sourceValue = defaultEntries[key];
30
+ const targetValue = targetEntries[key];
31
+ const isMissing = !(key in targetEntries) || targetValue === "" || targetValue !== void 0 && targetValue === sourceValue;
32
+ if (isMissing) {
30
33
  const fullKey = `${namespace}.${key}`;
31
- errors.push({ type: "missing-key", key: fullKey, language: lang, message: `Missing key "${fullKey}" in "${lang}"`, filePath: targetPath });
34
+ errors.push({
35
+ type: "missing-key",
36
+ key: fullKey,
37
+ language: lang,
38
+ message: `Missing translation for "${fullKey}" in "${lang}" (value equals source)`,
39
+ filePath: targetPath
40
+ });
32
41
  if (!missingByLanguage[lang]) missingByLanguage[lang] = [];
33
42
  missingByLanguage[lang].push(fullKey);
34
43
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "ai-localize-validators",
3
- "version": "2.0.4",
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.4"
36
+ "ai-localize-shared": "2.0.6"
37
37
  },
38
38
  "devDependencies": {
39
39
  "tsup": "^8.0.1",