ai-localize-locale-engine 2.0.5 → 2.0.7

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,20 @@
1
1
  # ai-localize-locale-engine
2
2
 
3
+ ## 2.0.7
4
+
5
+ ### Patch Changes
6
+
7
+ - Added `repository`, `homepage`, `bugs`, `author` fields to `package.json` for npm registry display.
8
+ - Added `sideEffects: false` to enable tree-shaking in bundlers.
9
+ - Added `prepublishOnly` script to ensure the package is built before publishing.
10
+
11
+ ## 2.0.6
12
+
13
+ ### Patch Changes
14
+
15
+ - Add per-package README.md files so each package displays documentation on npmjs.com
16
+ - Update README version badge to 2.0.6
17
+
3
18
  ## 2.0.3
4
19
 
5
20
  ### Minor Changes
package/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2024-2026 ai-localize-core contributors
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md ADDED
@@ -0,0 +1,97 @@
1
+ # ai-localize-locale-engine
2
+
3
+ > Locale file extraction, writing, merging, deduplication, and synchronization 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-locale-engine.svg)](https://www.npmjs.com/package/ai-localize-locale-engine)
6
+ [![License: MIT](https://img.shields.io/badge/License-MIT-yellow.svg)](LICENSE)
7
+
8
+ ---
9
+
10
+ ## What it does
11
+
12
+ - **`LocaleExtractor`** — converts `DetectedText[]` into `LocaleFile[]` with namespace splitting, key deduplication, and `staticKeys` injection
13
+ - **`LocaleWriter`** — writes locale JSON files with merge support (preserves existing translations)
14
+ - **`deduplicateTexts()`** — deduplicates scanned texts by key so the same string isn't extracted twice
15
+ - **Flat and nested layouts** — one file per language, or one per language+namespace
16
+
17
+ ## Installation
18
+
19
+ ```bash
20
+ npm install ai-localize-locale-engine
21
+ ```
22
+
23
+ ## Usage
24
+
25
+ ```ts
26
+ import { LocaleExtractor, LocaleWriter, deduplicateTexts } from 'ai-localize-locale-engine';
27
+
28
+ // Extract
29
+ const extractor = new LocaleExtractor({
30
+ defaultLanguage: 'en',
31
+ targetLanguages: ['fr', 'de'],
32
+ namespaceSplitting: true, // split by first path segment
33
+ staticKeys: { // injected into every locale file
34
+ MAX_COUNT: 'Max Count',
35
+ ALLOWED: 'Allowed',
36
+ },
37
+ });
38
+ const uniqueTexts = deduplicateTexts(scanResult.detectedTexts);
39
+ const { localeFiles, keyCount, namespaces } = extractor.extract(uniqueTexts);
40
+
41
+ // Write
42
+ const writer = new LocaleWriter({
43
+ localesDir: './locales',
44
+ merge: true, // preserve existing translations
45
+ localeStructure: 'nested', // or 'flat'
46
+ });
47
+ const { written, created, merged } = writer.write(localeFiles);
48
+ ```
49
+
50
+ ## Locale layouts
51
+
52
+ ### `nested` (default)
53
+
54
+ ```
55
+ locales/
56
+ en/
57
+ translation.json ← default namespace
58
+ dashboard.json
59
+ fr/
60
+ translation.json ← seeded with English values for translators
61
+ dashboard.json
62
+ ```
63
+
64
+ ### `flat`
65
+
66
+ ```
67
+ locales/
68
+ en.json ← all namespaces merged
69
+ fr.json
70
+ ```
71
+
72
+ ## Static keys
73
+
74
+ Inject constant strings into every locale file using `staticKeys`. These are identical across all languages and are **not** flagged as untranslated by the validator:
75
+
76
+ ```ts
77
+ const extractor = new LocaleExtractor({
78
+ staticKeys: {
79
+ MAX_COUNT: 'Max Count',
80
+ ALLOWED: 'Allowed',
81
+ DISABLED: 'Disabled',
82
+ UNLIMITED: 'Unlimited',
83
+ },
84
+ });
85
+ ```
86
+
87
+ ## Merge behaviour
88
+
89
+ When `merge: true` (default), existing translations are preserved. Only **new** keys (or keys with empty values) are updated. This prevents overwriting human-provided translations on re-extraction.
90
+
91
+ ---
92
+
93
+ ## Part of ai-localize-core
94
+
95
+ Install the CLI for the complete toolset: `npm install -g ai-localize-cli`
96
+
97
+ MIT © ai-localize-core contributors
package/package.json CHANGED
@@ -1,10 +1,22 @@
1
1
  {
2
2
  "name": "ai-localize-locale-engine",
3
- "version": "2.0.5",
3
+ "version": "2.0.7",
4
4
  "description": "Locale file generation, merging, deduplication and synchronization",
5
+ "author": "ai-localize-core contributors",
6
+ "license": "MIT",
7
+ "repository": {
8
+ "type": "git",
9
+ "url": "https://github.com/ai-localize/ai-localize-core.git",
10
+ "directory": "packages/locale-engine"
11
+ },
12
+ "homepage": "https://github.com/ai-localize/ai-localize-core/tree/main/packages/locale-engine#readme",
13
+ "bugs": {
14
+ "url": "https://github.com/ai-localize/ai-localize-core/issues"
15
+ },
5
16
  "main": "./dist/index.js",
6
17
  "module": "./dist/index.mjs",
7
18
  "types": "./dist/index.d.ts",
19
+ "sideEffects": false,
8
20
  "files": [
9
21
  "dist",
10
22
  "README.md",
@@ -33,14 +45,13 @@
33
45
  "node": ">=18.0.0"
34
46
  },
35
47
  "dependencies": {
36
- "ai-localize-shared": "2.0.5"
48
+ "ai-localize-shared": "2.0.7"
37
49
  },
38
50
  "devDependencies": {
39
51
  "tsup": "^8.0.1",
40
52
  "typescript": "^5.3.3",
41
53
  "vitest": "^1.2.1"
42
54
  },
43
- "license": "MIT",
44
55
  "publishConfig": {
45
56
  "access": "public"
46
57
  },