auto-translate-json-library 1.5.5 โ 2.0.5
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 +1379 -149
- package/build/package.json +113 -25
- package/build/src/aws.d.ts +1 -1
- package/build/src/aws.js +27 -38
- package/build/src/azure.d.ts +1 -1
- package/build/src/azure.js +50 -64
- package/build/src/bin/cli.js +224 -36
- package/build/src/config.d.ts +13 -1
- package/build/src/config.js +1 -2
- package/build/src/deepl.d.ts +1 -1
- package/build/src/deepl.js +18 -64
- package/build/src/files.d.ts +11 -2
- package/build/src/files.js +356 -69
- package/build/src/folderFiles.d.ts +6 -3
- package/build/src/folderFiles.js +33 -44
- package/build/src/format/arb-handler.d.ts +33 -0
- package/build/src/format/arb-handler.js +679 -0
- package/build/src/format/base-format-handler.d.ts +75 -0
- package/build/src/format/base-format-handler.js +166 -0
- package/build/src/format/csv-handler.d.ts +38 -0
- package/build/src/format/csv-handler.js +604 -0
- package/build/src/format/index.d.ts +17 -0
- package/build/src/format/index.js +48 -0
- package/build/src/format/json-handler.d.ts +17 -0
- package/build/src/format/json-handler.js +294 -0
- package/build/src/format/po-handler.d.ts +17 -0
- package/build/src/format/po-handler.js +338 -0
- package/build/src/format/po-utils.d.ts +86 -0
- package/build/src/format/po-utils.js +385 -0
- package/build/src/format/pot-handler.d.ts +22 -0
- package/build/src/format/pot-handler.js +331 -0
- package/build/src/format/properties-handler.d.ts +26 -0
- package/build/src/format/properties-handler.js +500 -0
- package/build/src/format/tsv-handler.d.ts +13 -0
- package/build/src/format/tsv-handler.js +67 -0
- package/build/src/format/xliff-handler.d.ts +24 -0
- package/build/src/format/xliff-handler.js +433 -0
- package/build/src/format/xmb-handler.d.ts +33 -0
- package/build/src/format/xmb-handler.js +484 -0
- package/build/src/format/xmb-xtb-utils.d.ts +43 -0
- package/build/src/format/xmb-xtb-utils.js +180 -0
- package/build/src/format/xml-handler.d.ts +28 -0
- package/build/src/format/xml-handler.js +561 -0
- package/build/src/format/xtb-handler.d.ts +33 -0
- package/build/src/format/xtb-handler.js +518 -0
- package/build/src/format/yaml-handler.d.ts +26 -0
- package/build/src/format/yaml-handler.js +522 -0
- package/build/src/format-detector.d.ts +7 -0
- package/build/src/format-detector.js +58 -0
- package/build/src/format-handler-factory.d.ts +9 -0
- package/build/src/format-handler-factory.js +18 -0
- package/build/src/format.interface.d.ts +56 -0
- package/build/src/format.interface.js +1 -0
- package/build/src/google.d.ts +1 -1
- package/build/src/google.js +32 -49
- package/build/src/huggingface-local.d.ts +11 -0
- package/build/src/huggingface-local.js +71 -0
- package/build/src/huggingface.d.ts +12 -0
- package/build/src/huggingface.js +76 -0
- package/build/src/index.d.ts +4 -3
- package/build/src/index.js +32 -17
- package/build/src/lib.d.ts +1 -1
- package/build/src/lib.js +196 -133
- package/build/src/openai.d.ts +2 -2
- package/build/src/openai.js +60 -50
- package/build/src/translate.interface.d.ts +1 -1
- package/build/src/translate.interface.js +1 -2
- package/build/src/util.js +4 -9
- package/build/src/validation/enhanced-validation-result.d.ts +96 -0
- package/build/src/validation/enhanced-validation-result.js +198 -0
- package/build/src/validation/error-messages.d.ts +88 -0
- package/build/src/validation/error-messages.js +436 -0
- package/build/src/validation/error-recovery.d.ts +78 -0
- package/build/src/validation/error-recovery.js +593 -0
- package/build/src/validation/example-usage.d.ts +31 -0
- package/build/src/validation/example-usage.js +148 -0
- package/build/src/validation/format-rules.d.ts +37 -0
- package/build/src/validation/format-rules.js +550 -0
- package/build/src/validation/format-validator.d.ts +70 -0
- package/build/src/validation/format-validator.js +279 -0
- package/build/src/validation/index.d.ts +13 -0
- package/build/src/validation/index.js +30 -0
- package/build/src/validation/validation-service.d.ts +56 -0
- package/build/src/validation/validation-service.js +262 -0
- package/package.json +113 -25
package/README.MD
CHANGED
|
@@ -1,202 +1,1432 @@
|
|
|
1
|
-
#
|
|
1
|
+
# Auto Translate JSON Library
|
|
2
2
|
|
|
3
|
-
This project is used in, (and refactored from) excellent
|
|
3
|
+
This project is used in, (and refactored from) excellent VS Code extension
|
|
4
4
|
Auto Translate JSON
|
|
5
5
|
<https://marketplace.visualstudio.com/items?itemName=JeffJorczak.auto-translate-json>
|
|
6
6
|
|
|
7
7
|
It opens possibility to use Auto Translation JSON
|
|
8
|
-
not just in
|
|
8
|
+
not just in VS Code but as a library and command line interface.
|
|
9
9
|
|
|
10
|
-
You can use Azure,AWS,Google,DeepL,
|
|
11
|
-
local
|
|
12
|
-
for example [ollama](https://ollama.com/)
|
|
13
|
-
because it is compatible with
|
|
10
|
+
You can use Azure, AWS, Google, DeepL, OpenAI,
|
|
11
|
+
local OpenAI compatible REST API
|
|
12
|
+
for example [ollama](https://ollama.com/)
|
|
13
|
+
because it is compatible with OpenAI https://ollama.com/blog/openai-compatibility
|
|
14
|
+
or [Hugging Face](https://huggingface.co/) (cloud API or fully local on-device inference)
|
|
14
15
|
|
|
16
|
+
## ๐ Version 2.0.0 - Major Release
|
|
15
17
|
|
|
16
|
-
|
|
18
|
+
This major release brings comprehensive improvements including:
|
|
19
|
+
- **ES Modules support** for modern JavaScript compatibility
|
|
20
|
+
- **Enhanced validation system** with detailed error reporting and recovery
|
|
21
|
+
- **Expanded format support** with robust handling for all major translation formats
|
|
22
|
+
- **Complete demo system** with interactive examples
|
|
23
|
+
- **Comprehensive test suite** with 100% format handler coverage
|
|
24
|
+
- **Security updates** for all dependencies
|
|
25
|
+
|
|
26
|
+
## Use as Library
|
|
17
27
|
|
|
18
28
|
```shell
|
|
19
29
|
npm i auto-translate-json-library
|
|
20
30
|
```
|
|
21
31
|
|
|
22
|
-
|
|
32
|
+
### Basic Usage
|
|
33
|
+
|
|
34
|
+
```typescript
|
|
35
|
+
import { translate, Configuration } from 'auto-translate-json-library';
|
|
36
|
+
|
|
37
|
+
const config: Configuration = {
|
|
38
|
+
translationKeyInfo: {
|
|
39
|
+
kind: 'google',
|
|
40
|
+
apiKey: 'your-google-api-key'
|
|
41
|
+
},
|
|
42
|
+
sourceLocale: 'en',
|
|
43
|
+
mode: 'file' // or 'folder'
|
|
44
|
+
};
|
|
45
|
+
|
|
46
|
+
const pivotTranslation = "./translations/en.json";
|
|
47
|
+
await translate(pivotTranslation, config);
|
|
48
|
+
// Creates translated files (e.g., fr.json, es.json) in the same directory
|
|
49
|
+
```
|
|
50
|
+
|
|
51
|
+
### Advanced Configuration
|
|
52
|
+
|
|
53
|
+
```typescript
|
|
23
54
|
import { translate, Configuration } from 'auto-translate-json-library';
|
|
24
55
|
|
|
25
|
-
|
|
56
|
+
const config: Configuration = {
|
|
57
|
+
// Translation service configuration
|
|
58
|
+
translationKeyInfo: {
|
|
59
|
+
kind: 'openai', // 'google' | 'aws' | 'azure' | 'deepLPro' | 'deepLFree' | 'openai' | 'huggingface' | 'huggingface-local'
|
|
60
|
+
apiKey: 'your-api-key',
|
|
61
|
+
// OpenAI-specific options
|
|
62
|
+
baseUrl: 'https://api.openai.com/v1', // or local Ollama: 'http://localhost:11434/v1'
|
|
63
|
+
model: 'gpt-4', // or local model: 'qwen2.5:14b'
|
|
64
|
+
maxTokens: 1000,
|
|
65
|
+
temperature: 0.3
|
|
66
|
+
},
|
|
67
|
+
|
|
68
|
+
// Processing options
|
|
69
|
+
sourceLocale: 'en',
|
|
70
|
+
mode: 'folder', // Process entire folder structure
|
|
71
|
+
format: 'auto', // Auto-detect or specify: 'json', 'xml', 'yaml', etc.
|
|
72
|
+
|
|
73
|
+
// Translation behavior
|
|
74
|
+
keepTranslations: 'keep', // 'keep' | 'retranslate'
|
|
75
|
+
keepExtraTranslations: 'remove', // 'keep' | 'remove'
|
|
76
|
+
|
|
77
|
+
// Delimiters for interpolation variables
|
|
78
|
+
startDelimiter: '{{',
|
|
79
|
+
endDelimiter: '}}',
|
|
80
|
+
|
|
81
|
+
// Keys to ignore (e.g., metadata keys)
|
|
82
|
+
ignorePrefix: '@@'
|
|
83
|
+
};
|
|
84
|
+
|
|
85
|
+
await translate('./translations/en.json', config);
|
|
86
|
+
```
|
|
87
|
+
|
|
88
|
+
### Translation Service Examples
|
|
26
89
|
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
90
|
+
#### Google Translate
|
|
91
|
+
```typescript
|
|
92
|
+
const config: Configuration = {
|
|
93
|
+
translationKeyInfo: {
|
|
94
|
+
kind: 'google',
|
|
95
|
+
apiKey: process.env.GOOGLE_API_KEY
|
|
96
|
+
},
|
|
97
|
+
sourceLocale: 'en'
|
|
98
|
+
};
|
|
35
99
|
```
|
|
36
100
|
|
|
37
|
-
|
|
101
|
+
#### OpenAI (GPT-4.1 mini)
|
|
102
|
+
```typescript
|
|
103
|
+
const config: Configuration = {
|
|
104
|
+
translationKeyInfo: {
|
|
105
|
+
kind: 'openai',
|
|
106
|
+
apiKey: process.env.OPENAI_API_KEY,
|
|
107
|
+
model: 'gpt-4.1-mini', // Best balance of quality and cost for translations
|
|
108
|
+
maxTokens: 1000,
|
|
109
|
+
temperature: 0.1 // Lower for more consistent translations
|
|
110
|
+
},
|
|
111
|
+
sourceLocale: 'en'
|
|
112
|
+
};
|
|
113
|
+
```
|
|
114
|
+
|
|
115
|
+
#### Local AI (Ollama)
|
|
116
|
+
```typescript
|
|
117
|
+
const config: Configuration = {
|
|
118
|
+
translationKeyInfo: {
|
|
119
|
+
kind: 'openai',
|
|
120
|
+
apiKey: 'ollama', // Placeholder for local usage
|
|
121
|
+
baseUrl: 'http://localhost:11434/v1',
|
|
122
|
+
model: 'qwen2.5:14b', // Recommended model for high-quality translations
|
|
123
|
+
maxTokens: 512
|
|
124
|
+
},
|
|
125
|
+
sourceLocale: 'en'
|
|
126
|
+
};
|
|
127
|
+
```
|
|
128
|
+
|
|
129
|
+
#### Hugging Face Cloud (Helsinki-NLP, NLLB, etc.)
|
|
130
|
+
```typescript
|
|
131
|
+
// Requires a free HF token: https://huggingface.co/settings/tokens
|
|
132
|
+
const config: Configuration = {
|
|
133
|
+
translationKeyInfo: {
|
|
134
|
+
kind: 'huggingface',
|
|
135
|
+
apiKey: process.env.ATJ_HUGGING_FACE_API_KEY,
|
|
136
|
+
model: 'Helsinki-NLP/opus-mt-en-fr',
|
|
137
|
+
provider: 'hf-inference'
|
|
138
|
+
},
|
|
139
|
+
sourceLocale: 'en'
|
|
140
|
+
};
|
|
141
|
+
```
|
|
142
|
+
|
|
143
|
+
The cloud Hugging Face integration uses dedicated translation models such as `Helsinki-NLP/opus-mt-en-fr` and `facebook/nllb-200-distilled-600M`.
|
|
144
|
+
|
|
145
|
+
#### Hugging Face Local (No API key โ fully on-device)
|
|
146
|
+
```typescript
|
|
147
|
+
// No account, no API key, no internet after first run
|
|
148
|
+
// Model (~300 MB) is downloaded and cached automatically on first use
|
|
149
|
+
const config: Configuration = {
|
|
150
|
+
translationKeyInfo: {
|
|
151
|
+
kind: 'huggingface-local',
|
|
152
|
+
model: 'Xenova/opus-mt-en-fr' // ONNX version, runs on CPU/GPU via ONNX Runtime
|
|
153
|
+
},
|
|
154
|
+
sourceLocale: 'en'
|
|
155
|
+
};
|
|
156
|
+
```
|
|
157
|
+
|
|
158
|
+
#### AWS Translate
|
|
159
|
+
```typescript
|
|
160
|
+
const config: Configuration = {
|
|
161
|
+
translationKeyInfo: {
|
|
162
|
+
kind: 'aws',
|
|
163
|
+
accessKeyId: process.env.AWS_ACCESS_KEY_ID,
|
|
164
|
+
secretAccessKey: process.env.AWS_SECRET_ACCESS_KEY,
|
|
165
|
+
region: 'us-east-1'
|
|
166
|
+
},
|
|
167
|
+
sourceLocale: 'en'
|
|
168
|
+
};
|
|
169
|
+
```
|
|
170
|
+
|
|
171
|
+
#### Azure Translator
|
|
172
|
+
```typescript
|
|
173
|
+
const config: Configuration = {
|
|
174
|
+
translationKeyInfo: {
|
|
175
|
+
kind: 'azure',
|
|
176
|
+
apiKey: process.env.AZURE_TRANSLATOR_KEY,
|
|
177
|
+
region: 'eastus'
|
|
178
|
+
},
|
|
179
|
+
sourceLocale: 'en'
|
|
180
|
+
};
|
|
181
|
+
```
|
|
38
182
|
|
|
39
|
-
|
|
183
|
+
#### DeepL
|
|
184
|
+
```typescript
|
|
185
|
+
// DeepL Pro
|
|
186
|
+
const config: Configuration = {
|
|
187
|
+
translationKeyInfo: {
|
|
188
|
+
kind: 'deepLPro',
|
|
189
|
+
apiKey: process.env.DEEPL_PRO_API_KEY
|
|
190
|
+
},
|
|
191
|
+
sourceLocale: 'en'
|
|
192
|
+
};
|
|
193
|
+
|
|
194
|
+
// DeepL Free
|
|
195
|
+
const configFree: Configuration = {
|
|
196
|
+
translationKeyInfo: {
|
|
197
|
+
kind: 'deepLFree',
|
|
198
|
+
apiKey: process.env.DEEPL_FREE_API_KEY
|
|
199
|
+
},
|
|
200
|
+
sourceLocale: 'en'
|
|
201
|
+
};
|
|
202
|
+
```
|
|
203
|
+
|
|
204
|
+
## Use as Command Line Tool
|
|
205
|
+
|
|
206
|
+
First install it:
|
|
40
207
|
|
|
41
208
|
```shell
|
|
42
209
|
npm i auto-translate-json-library
|
|
43
210
|
```
|
|
44
211
|
|
|
45
|
-
|
|
212
|
+
### Global Installation (Recommended)
|
|
213
|
+
|
|
214
|
+
Install globally for easier access:
|
|
215
|
+
|
|
216
|
+
```shell
|
|
217
|
+
npm install -g auto-translate-json-library
|
|
218
|
+
```
|
|
219
|
+
|
|
220
|
+
Then use the convenient `atj` command:
|
|
221
|
+
|
|
222
|
+
## Publish to npm
|
|
223
|
+
|
|
224
|
+
The repo now uses npm trusted publishing from GitHub Actions instead of a long-lived `NPM_TOKEN`.
|
|
225
|
+
|
|
226
|
+
### One-time npm setup
|
|
227
|
+
|
|
228
|
+
1. Open the package settings on npm for `auto-translate-json-library`.
|
|
229
|
+
2. Enable trusted publishing for this GitHub repository.
|
|
230
|
+
3. Grant the workflow permission to publish from `topce/auto-translate-json-library`.
|
|
231
|
+
|
|
232
|
+
After that, GitHub Actions can publish with OIDC and `--provenance`, with no npm token stored in GitHub secrets.
|
|
233
|
+
|
|
234
|
+
### Release flow
|
|
235
|
+
|
|
236
|
+
1. Bump `version` in `package.json`.
|
|
237
|
+
2. Run `npm run release:check` locally.
|
|
238
|
+
3. Commit and push to `master`.
|
|
239
|
+
4. Create and push a version tag such as `v2.0.4`.
|
|
240
|
+
|
|
241
|
+
```shell
|
|
242
|
+
git tag v2.0.4
|
|
243
|
+
git push origin v2.0.4
|
|
244
|
+
```
|
|
245
|
+
|
|
246
|
+
The publish workflow will then:
|
|
247
|
+
|
|
248
|
+
- install with `npm ci`
|
|
249
|
+
- run tests
|
|
250
|
+
- build the package
|
|
251
|
+
- run `npm pack --dry-run`
|
|
252
|
+
- publish to npm with provenance
|
|
253
|
+
|
|
254
|
+
### Local dry run
|
|
255
|
+
|
|
256
|
+
If you want to inspect the package before tagging:
|
|
257
|
+
|
|
258
|
+
```shell
|
|
259
|
+
npm run release:check
|
|
260
|
+
```
|
|
261
|
+
|
|
262
|
+
This is the quickest way to catch missing files, broken builds, or packaging mistakes before a real publish.
|
|
263
|
+
|
|
264
|
+
```shell
|
|
265
|
+
atj translations/en.json -e google -s en
|
|
266
|
+
```
|
|
267
|
+
|
|
268
|
+
You can also use it with npx:
|
|
269
|
+
|
|
270
|
+
```shell
|
|
271
|
+
npx auto-translate-json-library translations/en.json -e google -s en
|
|
272
|
+
```
|
|
273
|
+
|
|
274
|
+
### CLI Examples with Modern Translation Services
|
|
275
|
+
|
|
276
|
+
#### Google Translate
|
|
277
|
+
```shell
|
|
278
|
+
# Single file translation
|
|
279
|
+
atj translations/en.json -e google -s en
|
|
280
|
+
|
|
281
|
+
# Folder translation (translates all supported files)
|
|
282
|
+
atj translations/ -e google -s en -m folder
|
|
283
|
+
|
|
284
|
+
# Specific format override
|
|
285
|
+
atj config/app.yaml -e google -s en --format yaml
|
|
286
|
+
```
|
|
287
|
+
|
|
288
|
+
#### OpenAI (GPT-4.1 mini/GPT-4o)
|
|
289
|
+
```shell
|
|
290
|
+
# Using GPT-4.1 mini for best balance of quality and cost (recommended)
|
|
291
|
+
atj translations/en.json -e openai -s en
|
|
292
|
+
|
|
293
|
+
# Using GPT-4o for higher quality translations
|
|
294
|
+
ATJ_OPEN_AI_MODEL=gpt-4o atj translations/en.json -e openai -s en
|
|
295
|
+
|
|
296
|
+
# Custom temperature for more creative translations
|
|
297
|
+
ATJ_OPEN_AI_TEMPERATURE=0.7 atj translations/en.json -e openai -s en
|
|
298
|
+
```
|
|
299
|
+
|
|
300
|
+
#### Local AI with Ollama
|
|
301
|
+
```shell
|
|
302
|
+
# Using Qwen2.5 model (recommended for high-quality translations)
|
|
303
|
+
ATJ_OPEN_AI_BASE_URL=http://localhost:11434/v1 \
|
|
304
|
+
ATJ_OPEN_AI_MODEL=qwen2.5:14b \
|
|
305
|
+
ATJ_OPEN_AI_SECRET_KEY=ollama \
|
|
306
|
+
atj translations/en.json -e openai -s en
|
|
307
|
+
|
|
308
|
+
# Alternative: Using smaller model for faster processing
|
|
309
|
+
ATJ_OPEN_AI_BASE_URL=http://localhost:11434/v1 \
|
|
310
|
+
ATJ_OPEN_AI_MODEL=qwen2.5:7b \
|
|
311
|
+
ATJ_OPEN_AI_SECRET_KEY=ollama \
|
|
312
|
+
atj translations/en.json -e openai -s en
|
|
313
|
+
```
|
|
314
|
+
|
|
315
|
+
#### AWS Translate
|
|
316
|
+
```shell
|
|
317
|
+
# Basic AWS translation
|
|
318
|
+
atj translations/en.json -e aws -s en
|
|
319
|
+
|
|
320
|
+
# Specify AWS region
|
|
321
|
+
ATJ_AWS_REGION=eu-west-1 atj translations/en.json -e aws -s en
|
|
322
|
+
```
|
|
323
|
+
|
|
324
|
+
#### Azure Translator
|
|
325
|
+
```shell
|
|
326
|
+
# Basic Azure translation
|
|
327
|
+
atj translations/en.json -e azure -s en
|
|
328
|
+
|
|
329
|
+
# Specify Azure region
|
|
330
|
+
ATJ_AZURE_REGION=westeurope atj translations/en.json -e azure -s en
|
|
331
|
+
```
|
|
332
|
+
|
|
333
|
+
#### DeepL
|
|
334
|
+
```shell
|
|
335
|
+
# DeepL Pro (higher quality, more languages)
|
|
336
|
+
atj translations/en.json -e deepLPro -s en
|
|
337
|
+
|
|
338
|
+
# DeepL Free (limited usage)
|
|
339
|
+
atj translations/en.json -e deepLFree -s en
|
|
340
|
+
```
|
|
341
|
+
|
|
342
|
+
#### Hugging Face Cloud
|
|
343
|
+
```shell
|
|
344
|
+
# Using Helsinki-NLP opus-mt model (fast, purpose-built for translation)
|
|
345
|
+
ATJ_HUGGING_FACE_API_KEY=hf_your_token \
|
|
346
|
+
atj translations/en.json -e huggingface -s en
|
|
347
|
+
|
|
348
|
+
# Different language pair model
|
|
349
|
+
ATJ_HUGGING_FACE_API_KEY=hf_your_token \
|
|
350
|
+
ATJ_HUGGING_FACE_MODEL=Helsinki-NLP/opus-mt-en-de \
|
|
351
|
+
atj translations/en.json -e huggingface -s en
|
|
352
|
+
|
|
353
|
+
# Using NLLB (supports 200+ languages)
|
|
354
|
+
ATJ_HUGGING_FACE_API_KEY=hf_your_token \
|
|
355
|
+
ATJ_HUGGING_FACE_MODEL=facebook/nllb-200-distilled-600M \
|
|
356
|
+
atj translations/en.json -e huggingface -s en
|
|
357
|
+
```
|
|
358
|
+
|
|
359
|
+
#### Hugging Face Local (No API key)
|
|
360
|
+
```shell
|
|
361
|
+
# Model downloads automatically on first run (~300 MB), then works offline
|
|
362
|
+
ATJ_HUGGING_FACE_LOCAL_MODEL=Xenova/opus-mt-en-fr \
|
|
363
|
+
atj translations/en.json -e huggingface-local -s en
|
|
364
|
+
|
|
365
|
+
# Different language pair
|
|
366
|
+
ATJ_HUGGING_FACE_LOCAL_MODEL=Xenova/opus-mt-en-de \
|
|
367
|
+
atj translations/en.json -e huggingface-local -s en
|
|
368
|
+
```
|
|
369
|
+
|
|
370
|
+
### File vs Folder Mode
|
|
371
|
+
|
|
372
|
+
#### File Mode (Default)
|
|
373
|
+
Translates a single file and creates translated versions in the same directory:
|
|
374
|
+
|
|
375
|
+
```shell
|
|
376
|
+
# Input: translations/en.json
|
|
377
|
+
# Output: translations/fr.json, translations/es.json, etc.
|
|
378
|
+
atj translations/en.json -e google -s en -m file
|
|
379
|
+
```
|
|
380
|
+
|
|
381
|
+
#### Folder Mode
|
|
382
|
+
Recursively processes all supported files in a directory structure:
|
|
46
383
|
|
|
47
384
|
```shell
|
|
48
|
-
|
|
385
|
+
# Processes all translation files in the folder tree
|
|
386
|
+
atj translations/ -e google -s en -m folder
|
|
387
|
+
|
|
388
|
+
# Example structure:
|
|
389
|
+
# translations/
|
|
390
|
+
# โโโ en/
|
|
391
|
+
# โ โโโ common.json
|
|
392
|
+
# โ โโโ errors.yaml
|
|
393
|
+
# โ โโโ mobile.properties
|
|
394
|
+
# โโโ fr/ # โ Created automatically
|
|
395
|
+
# โ โโโ common.json
|
|
396
|
+
# โ โโโ errors.yaml
|
|
397
|
+
# โ โโโ mobile.properties
|
|
398
|
+
# โโโ es/ # โ Created automatically
|
|
399
|
+
# โโโ common.json
|
|
400
|
+
# โโโ errors.yaml
|
|
401
|
+
# โโโ mobile.properties
|
|
49
402
|
```
|
|
50
403
|
|
|
404
|
+
### Format-Specific Examples
|
|
405
|
+
|
|
406
|
+
#### Android Development
|
|
407
|
+
```shell
|
|
408
|
+
# Android strings.xml files
|
|
409
|
+
atj res/values/strings.xml -e google -s en --format android-xml
|
|
410
|
+
|
|
411
|
+
# Folder mode for complete Android project
|
|
412
|
+
atj res/values/ -e google -s en -m folder --format android-xml
|
|
413
|
+
```
|
|
414
|
+
|
|
415
|
+
#### Flutter Development
|
|
416
|
+
```shell
|
|
417
|
+
# Flutter ARB files
|
|
418
|
+
atj lib/l10n/app_en.arb -e google -s en --format arb
|
|
419
|
+
|
|
420
|
+
# Process all ARB files in l10n folder
|
|
421
|
+
atj lib/l10n/ -e google -s en -m folder --format arb
|
|
422
|
+
```
|
|
423
|
+
|
|
424
|
+
#### Web Development
|
|
425
|
+
```shell
|
|
426
|
+
# JSON translation files
|
|
427
|
+
atj src/assets/i18n/en.json -e openai -s en
|
|
428
|
+
|
|
429
|
+
# YAML configuration files
|
|
430
|
+
atj config/locales/en.yaml -e google -s en --format yaml
|
|
431
|
+
|
|
432
|
+
# Properties files (Java/Spring)
|
|
433
|
+
atj src/main/resources/messages_en.properties -e aws -s en --format properties
|
|
434
|
+
```
|
|
435
|
+
|
|
436
|
+
#### Game Development
|
|
437
|
+
```shell
|
|
438
|
+
# CSV files for game localization
|
|
439
|
+
atj assets/localization/strings.csv -e deepLPro -s en --format csv
|
|
440
|
+
|
|
441
|
+
# XML-based game configs
|
|
442
|
+
atj data/strings/en.xml -e google -s en --format xml
|
|
443
|
+
```
|
|
444
|
+
|
|
445
|
+
Do not forget to set translation engine parameters in environment variables or .env file.
|
|
446
|
+
|
|
447
|
+
## Demo and Examples
|
|
448
|
+
|
|
449
|
+
The project includes a comprehensive demo system with examples for all supported formats and both translation modes:
|
|
450
|
+
|
|
451
|
+
### File Mode Demo (demo/)
|
|
452
|
+
Individual translation files - one file per language:
|
|
453
|
+
```shell
|
|
454
|
+
cd demo
|
|
455
|
+
npm install
|
|
456
|
+
node run-demo.js
|
|
457
|
+
```
|
|
458
|
+
|
|
459
|
+
### Folder Mode Demo (demo-folder/)
|
|
460
|
+
Language-organized directories - multiple files per language:
|
|
461
|
+
```shell
|
|
462
|
+
cd demo-folder
|
|
463
|
+
npm install
|
|
464
|
+
node run-demo.js
|
|
465
|
+
```
|
|
466
|
+
|
|
467
|
+
Both demos support:
|
|
468
|
+
- **Local AI translation** using Ollama (recommended for testing)
|
|
469
|
+
- **Cloud translation services** (Google, OpenAI, AWS, Azure, DeepL)
|
|
470
|
+
- **All supported formats** (JSON, XML, YAML, Properties, ARB, PO, CSV)
|
|
471
|
+
- **Interactive examples** with real translation results
|
|
472
|
+
|
|
473
|
+
Choose the demo that matches your project structure:
|
|
474
|
+
- **File mode**: Simple projects with one file per language (`en.json`, `fr.json`)
|
|
475
|
+
- **Folder mode**: Complex projects with multiple files per language (`en/common.json`, `fr/common.json`)
|
|
476
|
+
|
|
477
|
+
This will run translations on sample files in multiple formats (JSON, XML, YAML, ARB, PO, Properties, CSV) using the local Ollama setup with the `qwen2.5:14b` model and show the results.
|
|
478
|
+
|
|
51
479
|
## Contribute
|
|
52
480
|
|
|
53
|
-
Clone repo
|
|
481
|
+
Clone repo and use the following commands:
|
|
54
482
|
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
install
|
|
59
|
-
build project
|
|
60
|
-
and run it
|
|
483
|
+
1. Install ollama and run `ollama run llama2`
|
|
484
|
+
2. Rename `ollama.env` to `.env`
|
|
485
|
+
3. Install dependencies and build project:
|
|
61
486
|
|
|
62
487
|
```shell
|
|
63
488
|
npm i
|
|
64
489
|
npm run build
|
|
65
|
-
node
|
|
66
|
-
```
|
|
67
|
-
|
|
68
|
-
After some time you should see es.json file with translation
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
```
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
490
|
+
node ./build/src/index.js --pivotTranslation=./tests/translations/en.json
|
|
491
|
+
```
|
|
492
|
+
|
|
493
|
+
After some time you should see es.json file with translation.
|
|
494
|
+
|
|
495
|
+
### Development Workflow
|
|
496
|
+
|
|
497
|
+
```shell
|
|
498
|
+
# Install dependencies
|
|
499
|
+
npm install
|
|
500
|
+
|
|
501
|
+
# Run tests
|
|
502
|
+
npm test
|
|
503
|
+
|
|
504
|
+
# Run tests with coverage
|
|
505
|
+
npm run test:coverage
|
|
506
|
+
|
|
507
|
+
# Lint and format code
|
|
508
|
+
npm run lint
|
|
509
|
+
npm run format-fix
|
|
510
|
+
|
|
511
|
+
# Build project
|
|
512
|
+
npm run build
|
|
513
|
+
|
|
514
|
+
# Run demo (file mode)
|
|
515
|
+
cd demo && node run-demo.js
|
|
516
|
+
|
|
517
|
+
# Run demo (folder mode)
|
|
518
|
+
cd demo-folder && node run-demo.js
|
|
519
|
+
```
|
|
520
|
+
|
|
521
|
+
## Multi-Format Support
|
|
522
|
+
|
|
523
|
+
This tool supports a comprehensive range of translation file formats with automatic format detection and validation.
|
|
524
|
+
|
|
525
|
+
### Supported Formats Overview
|
|
526
|
+
|
|
527
|
+
| Format | Extension | Use Case | Auto-Detection |
|
|
528
|
+
|--------|-----------|----------|----------------|
|
|
529
|
+
| **JSON** | `.json` | Web apps, React, Vue, Angular | โ
|
|
|
530
|
+
| **ARB** | `.arb` | Flutter applications | โ
|
|
|
531
|
+
| **Android XML** | `.xml` | Android apps (strings.xml) | โ
|
|
|
532
|
+
| **iOS XML** | `.xml` | iOS apps (plist format) | โ
|
|
|
533
|
+
| **Generic XML** | `.xml` | Custom XML structures | โ
|
|
|
534
|
+
| **XLIFF** | `.xlf`, `.xliff` | Translation exchange | โ
|
|
|
535
|
+
| **XMB/XTB** | `.xmb`, `.xtb` | Google i18n format | โ
|
|
|
536
|
+
| **GNU gettext** | `.po`, `.pot` | Linux/Unix applications | โ
|
|
|
537
|
+
| **YAML** | `.yaml`, `.yml` | Configuration files | โ
|
|
|
538
|
+
| **Properties** | `.properties` | Java applications | โ
|
|
|
539
|
+
| **CSV** | `.csv` | Spreadsheet-based | โ
|
|
|
540
|
+
| **TSV** | `.tsv` | Tab-separated values | โ
|
|
|
541
|
+
|
|
542
|
+
### Format Detection
|
|
543
|
+
|
|
544
|
+
The tool automatically detects file formats using:
|
|
545
|
+
1. **File extension** (primary method)
|
|
546
|
+
2. **Content analysis** (fallback for ambiguous cases)
|
|
547
|
+
3. **Manual override** using `--format` parameter
|
|
548
|
+
|
|
549
|
+
```shell
|
|
550
|
+
# Auto-detection (recommended)
|
|
551
|
+
atj translations/messages.json -e google
|
|
552
|
+
|
|
553
|
+
# Manual format override
|
|
554
|
+
atj translations/data.txt --format json -e google
|
|
555
|
+
|
|
556
|
+
# List all supported formats
|
|
557
|
+
atj --list-formats
|
|
558
|
+
```
|
|
559
|
+
|
|
560
|
+
### Detailed Format Support
|
|
561
|
+
|
|
562
|
+
#### JSON-based Formats
|
|
563
|
+
|
|
564
|
+
**Standard JSON**
|
|
565
|
+
```json
|
|
566
|
+
{
|
|
567
|
+
"welcome": "Welcome to our app",
|
|
568
|
+
"user": {
|
|
569
|
+
"name": "Name",
|
|
570
|
+
"email": "Email address"
|
|
571
|
+
}
|
|
572
|
+
}
|
|
573
|
+
```
|
|
574
|
+
|
|
575
|
+
**Flutter ARB (Application Resource Bundle)**
|
|
576
|
+
```json
|
|
577
|
+
{
|
|
578
|
+
"@@locale": "en",
|
|
579
|
+
"welcome": "Welcome to our app",
|
|
580
|
+
"@welcome": {
|
|
581
|
+
"description": "Welcome message for new users"
|
|
582
|
+
},
|
|
583
|
+
"userCount": "{count, plural, =0{No users} =1{One user} other{{count} users}}",
|
|
584
|
+
"@userCount": {
|
|
585
|
+
"description": "Number of users",
|
|
586
|
+
"placeholders": {
|
|
587
|
+
"count": {
|
|
588
|
+
"type": "int"
|
|
589
|
+
}
|
|
590
|
+
}
|
|
591
|
+
}
|
|
592
|
+
}
|
|
593
|
+
```
|
|
594
|
+
|
|
595
|
+
#### XML-based Formats
|
|
596
|
+
|
|
597
|
+
**Android strings.xml**
|
|
598
|
+
```xml
|
|
599
|
+
<resources xmlns:android="http://schemas.android.com/apk/res/android">
|
|
600
|
+
<string name="app_name">My App</string>
|
|
601
|
+
<string name="welcome">Welcome</string>
|
|
602
|
+
<string name="not_translatable" translatable="false">DEBUG_MODE</string>
|
|
603
|
+
|
|
604
|
+
<!-- Resource groups -->
|
|
605
|
+
<group name="errors">
|
|
606
|
+
<string name="network_error">Network connection failed</string>
|
|
607
|
+
<string name="validation_error">Please check your input</string>
|
|
608
|
+
</group>
|
|
609
|
+
|
|
610
|
+
<!-- CDATA sections preserved -->
|
|
611
|
+
<string name="formatted_text"><![CDATA[This is <b>bold</b> text]]></string>
|
|
612
|
+
</resources>
|
|
613
|
+
```
|
|
614
|
+
|
|
615
|
+
**iOS plist XML**
|
|
616
|
+
```xml
|
|
617
|
+
<?xml version="1.0" encoding="UTF-8"?>
|
|
618
|
+
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
|
|
619
|
+
<plist version="1.0">
|
|
620
|
+
<dict>
|
|
621
|
+
<key>app_name</key>
|
|
622
|
+
<string>My iOS App</string>
|
|
623
|
+
<key>welcome_message</key>
|
|
624
|
+
<string>Welcome to iOS!</string>
|
|
625
|
+
</dict>
|
|
626
|
+
</plist>
|
|
627
|
+
```
|
|
628
|
+
|
|
629
|
+
**Generic XML (Auto-flattened)**
|
|
630
|
+
```xml
|
|
631
|
+
<?xml version="1.0" encoding="UTF-8"?>
|
|
632
|
+
<translations>
|
|
633
|
+
<messages>
|
|
634
|
+
<greeting>Hello World</greeting>
|
|
635
|
+
<farewell>Goodbye</farewell>
|
|
636
|
+
</messages>
|
|
637
|
+
<labels>
|
|
638
|
+
<submit>Submit</submit>
|
|
639
|
+
<cancel>Cancel</cancel>
|
|
640
|
+
</labels>
|
|
641
|
+
</translations>
|
|
642
|
+
```
|
|
643
|
+
*Becomes: `messages.greeting: "Hello World"`, `labels.submit: "Submit"`*
|
|
644
|
+
|
|
645
|
+
#### Text-based Formats
|
|
646
|
+
|
|
647
|
+
**GNU gettext PO files**
|
|
648
|
+
```po
|
|
649
|
+
# Comment preserved
|
|
650
|
+
msgid "hello"
|
|
651
|
+
msgstr "Hello"
|
|
652
|
+
|
|
653
|
+
msgid "goodbye"
|
|
654
|
+
msgstr "Goodbye"
|
|
655
|
+
|
|
656
|
+
# Plural forms supported
|
|
657
|
+
msgid "item"
|
|
658
|
+
msgid_plural "items"
|
|
659
|
+
msgstr[0] "item"
|
|
660
|
+
msgstr[1] "items"
|
|
661
|
+
```
|
|
662
|
+
|
|
663
|
+
**YAML translation files**
|
|
664
|
+
```yaml
|
|
665
|
+
# Comments preserved
|
|
666
|
+
greetings:
|
|
667
|
+
hello: "Hello"
|
|
668
|
+
goodbye: "Goodbye"
|
|
669
|
+
navigation:
|
|
670
|
+
home: "Home"
|
|
671
|
+
about: "About"
|
|
672
|
+
# Nested structures supported
|
|
673
|
+
menu:
|
|
674
|
+
file: "File"
|
|
675
|
+
edit: "Edit"
|
|
676
|
+
```
|
|
677
|
+
|
|
678
|
+
**Java Properties files**
|
|
679
|
+
```properties
|
|
680
|
+
# Application messages
|
|
681
|
+
app.title=My Application
|
|
682
|
+
app.welcome=Welcome to our application
|
|
683
|
+
|
|
684
|
+
# Unicode escaping supported
|
|
685
|
+
app.copyright=ยฉ 2024 My Company
|
|
686
|
+
|
|
687
|
+
# Placeholders preserved
|
|
688
|
+
user.greeting=Hello, {0}!
|
|
689
|
+
```
|
|
690
|
+
|
|
691
|
+
#### Tabular Formats
|
|
692
|
+
|
|
693
|
+
**CSV files**
|
|
694
|
+
```csv
|
|
695
|
+
key,en,fr,es
|
|
696
|
+
welcome,"Welcome","Bienvenue","Bienvenido"
|
|
697
|
+
goodbye,"Goodbye","Au revoir","Adiรณs"
|
|
698
|
+
```
|
|
699
|
+
|
|
700
|
+
**TSV files**
|
|
701
|
+
```tsv
|
|
702
|
+
key en fr es
|
|
703
|
+
welcome Welcome Bienvenue Bienvenido
|
|
704
|
+
goodbye Goodbye Au revoir Adiรณs
|
|
705
|
+
```
|
|
706
|
+
|
|
707
|
+
### Format-Specific Features
|
|
708
|
+
|
|
709
|
+
#### XML Formats
|
|
710
|
+
- **Preserve attributes**: `translatable="false"`, namespaces
|
|
711
|
+
- **Maintain structure**: Comments, CDATA sections, processing instructions
|
|
712
|
+
- **Android support**: Resource groups, plurals, string arrays
|
|
713
|
+
- **iOS support**: Plist dictionary structure with key-value pairs
|
|
714
|
+
- **Generic XML**: Automatic structure flattening for any XML format
|
|
715
|
+
- **Validation**: Robust malformed XML detection and error reporting
|
|
716
|
+
|
|
717
|
+
#### XLIFF Support
|
|
718
|
+
- **Version compatibility**: XLIFF 1.2 and 2.x support
|
|
719
|
+
- **Translation states**: Maintain workflow information (new, translated, approved)
|
|
720
|
+
- **Metadata preservation**: Notes, comments, and translation metadata
|
|
721
|
+
- **Segmentation**: Support for complex translation units
|
|
722
|
+
|
|
723
|
+
#### GNU gettext (PO/POT)
|
|
724
|
+
- **Plural forms**: Complete plural form handling for all languages
|
|
725
|
+
- **Context support**: msgctxt for disambiguation
|
|
726
|
+
- **Comments**: Preserve translator and extracted comments
|
|
727
|
+
- **Fuzzy translations**: Handle fuzzy markers appropriately
|
|
728
|
+
|
|
729
|
+
#### ARB (Flutter)
|
|
730
|
+
- **ICU message format**: Complete support for plurals, selects, and formatting
|
|
731
|
+
- **Metadata preservation**: Descriptions, placeholders, and examples
|
|
732
|
+
- **Locale inheritance**: Proper locale fallback handling
|
|
733
|
+
|
|
734
|
+
#### Properties Files
|
|
735
|
+
- **Unicode escaping**: Automatic handling of Unicode characters
|
|
736
|
+
- **Different encodings**: Support for various character encodings
|
|
737
|
+
- **Placeholder preservation**: Maintain {0}, {1} style placeholders
|
|
738
|
+
|
|
739
|
+
#### CSV/TSV Files
|
|
740
|
+
- **Configurable columns**: Flexible column mapping and headers
|
|
741
|
+
- **Multi-language support**: Handle multiple target languages in one file
|
|
742
|
+
- **Encoding detection**: Automatic character encoding detection
|
|
743
|
+
- **Quoted fields**: Proper handling of quoted and escaped content
|
|
744
|
+
|
|
745
|
+
### Usage Examples by Format
|
|
746
|
+
|
|
747
|
+
```shell
|
|
748
|
+
# JSON files (auto-detected)
|
|
749
|
+
atj translations/en.json -e google
|
|
750
|
+
|
|
751
|
+
# Android strings.xml
|
|
752
|
+
atj res/values/strings.xml -e aws --format android-xml
|
|
753
|
+
|
|
754
|
+
# Flutter ARB files
|
|
755
|
+
atj lib/l10n/app_en.arb -e azure --format arb
|
|
756
|
+
|
|
757
|
+
# XLIFF files
|
|
758
|
+
atj locales/messages.xlf -e deepLPro --format xliff
|
|
759
|
+
|
|
760
|
+
# GNU gettext PO files
|
|
761
|
+
atj locales/messages.po -e openai --format po
|
|
762
|
+
|
|
763
|
+
# YAML files
|
|
764
|
+
atj config/translations.yaml -e google --format yaml
|
|
765
|
+
|
|
766
|
+
# Properties files
|
|
767
|
+
atj messages_en.properties -e aws --format properties
|
|
768
|
+
|
|
769
|
+
# CSV files with custom structure
|
|
770
|
+
atj data/translations.csv -e google --format csv
|
|
771
|
+
|
|
772
|
+
# List all supported formats
|
|
773
|
+
atj --list-formats
|
|
774
|
+
```
|
|
775
|
+
|
|
776
|
+
## Translation Service Setup Guides
|
|
777
|
+
|
|
778
|
+
The library supports multiple translation services. Choose the one that best fits your needs and follow the setup guide below.
|
|
779
|
+
|
|
780
|
+
### ๐ Google Translate (Recommended for General Use)
|
|
781
|
+
|
|
782
|
+
**Best for**: High-quality translations, wide language support, reliable service
|
|
783
|
+
|
|
784
|
+
#### Setup Steps:
|
|
785
|
+
1. **Create Google Cloud Project**:
|
|
786
|
+
- Go to [Google Cloud Console](https://console.cloud.google.com/)
|
|
787
|
+
- Create a new project or select existing one
|
|
788
|
+
- Enable the Cloud Translation API
|
|
789
|
+
|
|
790
|
+
2. **Get API Key**:
|
|
791
|
+
- Go to APIs & Services > Credentials
|
|
792
|
+
- Click "Create Credentials" > "API Key"
|
|
793
|
+
- Copy your API key
|
|
794
|
+
|
|
795
|
+
3. **Configure Environment**:
|
|
796
|
+
```bash
|
|
797
|
+
# Copy the Google environment template
|
|
798
|
+
cp google.env .env
|
|
799
|
+
|
|
800
|
+
# Edit .env and replace your_google_api_key_here with your actual API key
|
|
801
|
+
```
|
|
802
|
+
|
|
803
|
+
4. **Usage**:
|
|
804
|
+
```bash
|
|
805
|
+
atj translations/en.json -e google -s en
|
|
806
|
+
```
|
|
807
|
+
|
|
808
|
+
#### Pricing:
|
|
809
|
+
- $20 per 1M characters
|
|
810
|
+
- Free tier: $300 credit for new users
|
|
811
|
+
|
|
812
|
+
---
|
|
813
|
+
|
|
814
|
+
### ๐ค OpenAI (Best for Context-Aware Translations)
|
|
815
|
+
|
|
816
|
+
**Best for**: Context-aware translations, technical content, creative translations
|
|
817
|
+
|
|
818
|
+
#### Setup Steps:
|
|
819
|
+
1. **Get OpenAI API Key**:
|
|
820
|
+
- Go to [OpenAI Platform](https://platform.openai.com/)
|
|
821
|
+
- Create account and add billing information
|
|
822
|
+
- Go to API Keys section and create new key
|
|
823
|
+
|
|
824
|
+
2. **Configure Environment**:
|
|
825
|
+
```bash
|
|
826
|
+
# Copy the OpenAI environment template
|
|
827
|
+
cp openai.env .env
|
|
828
|
+
|
|
829
|
+
# Edit .env and replace your_openai_api_key_here with your actual API key
|
|
830
|
+
```
|
|
831
|
+
|
|
832
|
+
3. **Usage**:
|
|
833
|
+
```bash
|
|
834
|
+
# Using GPT-4.1 mini (best balance of quality and cost - recommended)
|
|
835
|
+
atj translations/en.json -e openai -s en
|
|
836
|
+
|
|
837
|
+
# Using GPT-4o (higher quality, moderate cost)
|
|
838
|
+
ATJ_OPEN_AI_MODEL=gpt-4o atj translations/en.json -e openai -s en
|
|
839
|
+
```
|
|
840
|
+
|
|
841
|
+
#### Model Recommendations for Translation:
|
|
842
|
+
- **GPT-4.1 mini**: Best balance of quality and cost (recommended for most translations)
|
|
843
|
+
- **GPT-4o mini**: Good quality, very cost-effective (legacy but still available)
|
|
844
|
+
- **GPT-4.1**: Higher quality for complex translations, more expensive
|
|
845
|
+
- **GPT-4o**: Excellent multimodal capabilities, moderate cost
|
|
846
|
+
|
|
847
|
+
#### Pricing (Approximate):
|
|
848
|
+
- GPT-4.1 mini: ~$0.15/1M input tokens, ~$0.60/1M output tokens (most cost-effective)
|
|
849
|
+
- GPT-4o mini: ~$0.15/1M input tokens, ~$0.60/1M output tokens
|
|
850
|
+
- GPT-4.1: ~$2.00/1M input tokens, ~$8.00/1M output tokens
|
|
851
|
+
- GPT-4o: ~$2.50/1M input tokens, ~$10.00/1M output tokens
|
|
852
|
+
|
|
853
|
+
---
|
|
854
|
+
|
|
855
|
+
### ๐ Local AI with Ollama (Free & Private)
|
|
856
|
+
|
|
857
|
+
**Best for**: Privacy-sensitive projects, offline usage, no API costs
|
|
858
|
+
|
|
859
|
+
#### Setup Steps:
|
|
860
|
+
1. **Install Ollama**:
|
|
861
|
+
```bash
|
|
862
|
+
# macOS
|
|
863
|
+
brew install ollama
|
|
864
|
+
|
|
865
|
+
# Linux
|
|
866
|
+
curl -fsSL https://ollama.com/install.sh | sh
|
|
867
|
+
|
|
868
|
+
# Windows: Download from https://ollama.com/
|
|
869
|
+
```
|
|
870
|
+
|
|
871
|
+
2. **Download Model**:
|
|
872
|
+
```bash
|
|
873
|
+
# High-quality model (recommended)
|
|
874
|
+
ollama pull qwen2.5:14b
|
|
875
|
+
|
|
876
|
+
# Faster alternative
|
|
877
|
+
ollama pull qwen2.5:7b
|
|
878
|
+
```
|
|
879
|
+
|
|
880
|
+
3. **Start Ollama**:
|
|
881
|
+
```bash
|
|
882
|
+
ollama serve
|
|
883
|
+
```
|
|
884
|
+
|
|
885
|
+
4. **Configure Environment**:
|
|
886
|
+
```bash
|
|
887
|
+
# Copy the Ollama environment template
|
|
888
|
+
cp ollama.env .env
|
|
889
|
+
```
|
|
890
|
+
|
|
891
|
+
5. **Usage**:
|
|
892
|
+
```bash
|
|
893
|
+
atj translations/en.json -e openai -s en
|
|
894
|
+
```
|
|
895
|
+
|
|
896
|
+
#### Model Recommendations:
|
|
897
|
+
- **qwen2.5:14b**: Best quality (8GB RAM required)
|
|
898
|
+
- **qwen2.5:7b**: Good balance (4GB RAM required)
|
|
899
|
+
- **qwen2.5:3b**: Fastest (2GB RAM required)
|
|
900
|
+
|
|
901
|
+
---
|
|
902
|
+
|
|
903
|
+
### โ๏ธ AWS Translate (Best for AWS Ecosystem)
|
|
904
|
+
|
|
905
|
+
**Best for**: AWS-integrated projects, enterprise use, batch processing
|
|
906
|
+
|
|
907
|
+
#### Setup Steps:
|
|
908
|
+
1. **Create AWS Account**:
|
|
909
|
+
- Go to [AWS Console](https://aws.amazon.com/)
|
|
910
|
+
- Create account or sign in
|
|
911
|
+
|
|
912
|
+
2. **Create IAM User**:
|
|
913
|
+
- Go to IAM > Users > Create User
|
|
914
|
+
- Attach policy: `TranslateFullAccess`
|
|
915
|
+
- Create access key for programmatic access
|
|
916
|
+
|
|
917
|
+
3. **Configure Environment**:
|
|
918
|
+
```bash
|
|
919
|
+
# Copy the AWS environment template
|
|
920
|
+
cp aws.env .env
|
|
921
|
+
|
|
922
|
+
# Edit .env and replace with your actual AWS credentials
|
|
923
|
+
```
|
|
924
|
+
|
|
925
|
+
4. **Usage**:
|
|
926
|
+
```bash
|
|
927
|
+
atj translations/en.json -e aws -s en
|
|
928
|
+
```
|
|
929
|
+
|
|
930
|
+
#### Pricing:
|
|
931
|
+
- $15 per 1M characters
|
|
932
|
+
- Free tier: 2M characters per month for 12 months
|
|
933
|
+
|
|
934
|
+
---
|
|
935
|
+
|
|
936
|
+
### ๐ท Azure Translator (Best for Microsoft Ecosystem)
|
|
937
|
+
|
|
938
|
+
**Best for**: Microsoft-integrated projects, enterprise use, custom models
|
|
939
|
+
|
|
940
|
+
#### Setup Steps:
|
|
941
|
+
1. **Create Azure Account**:
|
|
942
|
+
- Go to [Azure Portal](https://portal.azure.com/)
|
|
943
|
+
- Create account or sign in
|
|
944
|
+
|
|
945
|
+
2. **Create Translator Resource**:
|
|
946
|
+
- Search for "Translator" in Azure Portal
|
|
947
|
+
- Create new Translator resource
|
|
948
|
+
- Choose pricing tier and region
|
|
949
|
+
- Get key and endpoint from resource
|
|
950
|
+
|
|
951
|
+
3. **Configure Environment**:
|
|
952
|
+
```bash
|
|
953
|
+
# Copy the Azure environment template
|
|
954
|
+
cp azure.env .env
|
|
955
|
+
|
|
956
|
+
# Edit .env and replace with your actual Azure credentials
|
|
957
|
+
```
|
|
958
|
+
|
|
959
|
+
4. **Usage**:
|
|
960
|
+
```bash
|
|
961
|
+
atj translations/en.json -e azure -s en
|
|
962
|
+
```
|
|
963
|
+
|
|
964
|
+
#### Pricing:
|
|
965
|
+
- Standard: $10 per 1M characters
|
|
966
|
+
- Free tier: 2M characters per month
|
|
967
|
+
|
|
968
|
+
---
|
|
969
|
+
|
|
970
|
+
### ๐ฏ DeepL (Best Translation Quality)
|
|
971
|
+
|
|
972
|
+
**Best for**: Highest quality translations, European languages, professional content
|
|
973
|
+
|
|
974
|
+
#### Setup Steps:
|
|
975
|
+
1. **Create DeepL Account**:
|
|
976
|
+
- Go to [DeepL Pro](https://www.deepl.com/pro) or [DeepL API Free](https://www.deepl.com/pro#developer)
|
|
977
|
+
- Choose Pro (paid) or Free plan
|
|
978
|
+
- Get your API key from account settings
|
|
979
|
+
|
|
980
|
+
2. **Configure Environment**:
|
|
981
|
+
```bash
|
|
982
|
+
# Copy the DeepL environment template
|
|
983
|
+
cp deepl.env .env
|
|
984
|
+
|
|
985
|
+
# Edit .env and replace with your actual DeepL API key
|
|
986
|
+
# Use either Pro or Free key (uncomment the appropriate line)
|
|
987
|
+
```
|
|
988
|
+
|
|
989
|
+
3. **Usage**:
|
|
990
|
+
```bash
|
|
991
|
+
# DeepL Pro
|
|
992
|
+
atj translations/en.json -e deepLPro -s en
|
|
993
|
+
|
|
994
|
+
# DeepL Free
|
|
995
|
+
atj translations/en.json -e deepLFree -s en
|
|
996
|
+
```
|
|
997
|
+
|
|
998
|
+
#### Pricing:
|
|
999
|
+
- **DeepL Pro**: โฌ5.99/month + โฌ20 per 1M characters
|
|
1000
|
+
- **DeepL API Free**: 500,000 characters/month free
|
|
1001
|
+
|
|
1002
|
+
---
|
|
1003
|
+
|
|
1004
|
+
### ๐ค Hugging Face Cloud (Best Free Translation Models)
|
|
1005
|
+
|
|
1006
|
+
**Best for**: High-quality translations using purpose-built models, free tier available, 200+ languages with NLLB
|
|
1007
|
+
|
|
1008
|
+
#### Setup Steps:
|
|
1009
|
+
1. **Create a Hugging Face Account**:
|
|
1010
|
+
- Go to [huggingface.co](https://huggingface.co/) and sign up (free)
|
|
1011
|
+
|
|
1012
|
+
2. **Get an Access Token**:
|
|
1013
|
+
- Go to [Settings โ Access Tokens](https://huggingface.co/settings/tokens)
|
|
1014
|
+
- Click "New token", choose "Read" role, copy the token
|
|
1015
|
+
|
|
1016
|
+
3. **Configure Environment**:
|
|
1017
|
+
```bash
|
|
1018
|
+
# Copy the HuggingFace environment template
|
|
1019
|
+
cp huggingface.env .env
|
|
1020
|
+
|
|
1021
|
+
# Edit .env and replace your_huggingface_token_here with your actual token
|
|
1022
|
+
```
|
|
1023
|
+
|
|
1024
|
+
4. **Usage**:
|
|
1025
|
+
```bash
|
|
1026
|
+
atj translations/en.json -e huggingface -s en
|
|
1027
|
+
```
|
|
1028
|
+
|
|
1029
|
+
#### Quick Run Commands:
|
|
1030
|
+
```bash
|
|
1031
|
+
# Use the default cloud example model
|
|
1032
|
+
cp huggingface.env .env
|
|
1033
|
+
atj translations/en.json -e huggingface -s en
|
|
1034
|
+
|
|
1035
|
+
# Override the model for another language pair
|
|
1036
|
+
ATJ_HUGGING_FACE_API_KEY=hf_your_token \
|
|
1037
|
+
ATJ_HUGGING_FACE_MODEL=Helsinki-NLP/opus-mt-en-de \
|
|
1038
|
+
atj translations/en.json -e huggingface -s en
|
|
1039
|
+
|
|
1040
|
+
# Use NLLB for broader language coverage
|
|
1041
|
+
ATJ_HUGGING_FACE_API_KEY=hf_your_token \
|
|
1042
|
+
ATJ_HUGGING_FACE_MODEL=facebook/nllb-200-distilled-600M \
|
|
1043
|
+
atj translations/en.json -e huggingface -s en
|
|
1044
|
+
```
|
|
1045
|
+
|
|
1046
|
+
#### Recommended Models:
|
|
1047
|
+
- **`Helsinki-NLP/opus-mt-en-fr`** โ Fast, lightweight, EnglishโFrench (swap `fr` for other languages)
|
|
1048
|
+
- **`Helsinki-NLP/opus-mt-en-de`** โ EnglishโGerman
|
|
1049
|
+
- **`facebook/nllb-200-distilled-600M`** โ 200+ languages, one model for all pairs
|
|
1050
|
+
- **`facebook/nllb-200-1.3B`** โ Higher quality, 200+ languages
|
|
1051
|
+
|
|
1052
|
+
Browse all Helsinki-NLP models: [huggingface.co/Helsinki-NLP](https://huggingface.co/Helsinki-NLP)
|
|
1053
|
+
|
|
1054
|
+
#### Pricing:
|
|
1055
|
+
- **Free tier**: Rate-limited but sufficient for development
|
|
1056
|
+
- **PRO**: $9/month for higher rate limits
|
|
1057
|
+
- **Inference Endpoints**: Pay-per-use for production workloads
|
|
1058
|
+
|
|
1059
|
+
---
|
|
1060
|
+
|
|
1061
|
+
### ๐ Hugging Face Local (Free, Private, No API Key)
|
|
1062
|
+
|
|
1063
|
+
**Best for**: Complete privacy, offline usage, zero cost, no rate limits โ using the same purpose-built translation models as the cloud mode but running entirely on your machine via ONNX Runtime.
|
|
1064
|
+
|
|
1065
|
+
> This is analogous to Ollama but uses dedicated translation models instead of general LLMs โ typically faster and more accurate for translation tasks.
|
|
1066
|
+
|
|
1067
|
+
#### Setup Steps:
|
|
1068
|
+
1. **No account or API key needed** โ just configure the model name
|
|
1069
|
+
|
|
1070
|
+
2. **Configure Environment**:
|
|
1071
|
+
```bash
|
|
1072
|
+
# Copy the local HuggingFace environment template
|
|
1073
|
+
cp huggingface-local.env .env
|
|
1074
|
+
```
|
|
1075
|
+
|
|
1076
|
+
3. **Run** โ the model downloads automatically on first use:
|
|
1077
|
+
```bash
|
|
1078
|
+
atj translations/en.json -e huggingface-local -s en
|
|
1079
|
+
```
|
|
1080
|
+
First run downloads the model (~300 MB) and caches it locally. All subsequent runs are fully offline.
|
|
1081
|
+
|
|
1082
|
+
#### Quick Run Commands:
|
|
1083
|
+
```bash
|
|
1084
|
+
# Use the default local example model
|
|
1085
|
+
cp huggingface-local.env .env
|
|
1086
|
+
atj translations/en.json -e huggingface-local -s en
|
|
1087
|
+
|
|
1088
|
+
# Use another local translation model
|
|
1089
|
+
ATJ_HUGGING_FACE_LOCAL_MODEL=Xenova/opus-mt-en-de \
|
|
1090
|
+
atj translations/en.json -e huggingface-local -s en
|
|
1091
|
+
|
|
1092
|
+
# Use a larger multilingual local model
|
|
1093
|
+
ATJ_HUGGING_FACE_LOCAL_MODEL=Xenova/nllb-200-distilled-600M \
|
|
1094
|
+
atj translations/en.json -e huggingface-local -s en
|
|
1095
|
+
```
|
|
1096
|
+
|
|
1097
|
+
#### Recommended ONNX Models (from [huggingface.co/Xenova](https://huggingface.co/Xenova)):
|
|
1098
|
+
- **`Xenova/opus-mt-en-fr`** โ EnglishโFrench (~300 MB)
|
|
1099
|
+
- **`Xenova/opus-mt-en-de`** โ EnglishโGerman (~300 MB)
|
|
1100
|
+
- **`Xenova/opus-mt-en-es`** โ EnglishโSpanish (~300 MB)
|
|
1101
|
+
- **`Xenova/nllb-200-distilled-600M`** โ 200+ languages, one model (~1.2 GB)
|
|
1102
|
+
|
|
1103
|
+
#### Pricing:
|
|
1104
|
+
- **Completely free**, forever โ no account, no limits, no internet after first run
|
|
1105
|
+
|
|
1106
|
+
---
|
|
1107
|
+
|
|
1108
|
+
## Service Comparison
|
|
1109
|
+
|
|
1110
|
+
| Service | Quality | Speed | Cost | Languages | Best For |
|
|
1111
|
+
|---------|---------|-------|------|-----------|----------|
|
|
1112
|
+
| **Google** | โญโญโญโญ | โญโญโญโญโญ | โญโญโญ | 100+ | General use, reliability |
|
|
1113
|
+
| **OpenAI** | โญโญโญโญโญ | โญโญโญโญ | โญโญโญ | 50+ | Context-aware, technical |
|
|
1114
|
+
| **Ollama** | โญโญโญโญ | โญโญ | โญโญโญโญโญ | 30+ | Privacy, offline, free |
|
|
1115
|
+
| **AWS** | โญโญโญโญ | โญโญโญโญ | โญโญโญ | 75+ | AWS ecosystem |
|
|
1116
|
+
| **Azure** | โญโญโญโญ | โญโญโญโญ | โญโญโญ | 90+ | Microsoft ecosystem |
|
|
1117
|
+
| **DeepL** | โญโญโญโญโญ | โญโญโญโญ | โญโญ | 30+ | Highest quality |
|
|
1118
|
+
| **HuggingFace** | โญโญโญโญ | โญโญโญโญ | โญโญโญโญโญ | 200+ | Free tier, many models |
|
|
1119
|
+
| **HuggingFace Local** | โญโญโญโญ | โญโญโญ | โญโญโญโญโญ | 200+ | Offline, private, free |
|
|
1120
|
+
|
|
1121
|
+
## Quick Start Examples
|
|
1122
|
+
|
|
1123
|
+
### For Web Development
|
|
1124
|
+
```bash
|
|
1125
|
+
# React/Vue/Angular projects with Google Translate
|
|
1126
|
+
cp google.env .env
|
|
1127
|
+
atj src/locales/en.json -e google -s en
|
|
1128
|
+
```
|
|
1129
|
+
|
|
1130
|
+
### For Mobile Development
|
|
1131
|
+
```bash
|
|
1132
|
+
# Flutter with DeepL for high quality
|
|
1133
|
+
cp deepl.env .env
|
|
1134
|
+
atj lib/l10n/app_en.arb -e deepLPro -s en --format arb
|
|
1135
|
+
|
|
1136
|
+
# Android with AWS
|
|
1137
|
+
cp aws.env .env
|
|
1138
|
+
atj res/values/strings.xml -e aws -s en --format android-xml
|
|
1139
|
+
```
|
|
1140
|
+
|
|
1141
|
+
### For Enterprise/Privacy
|
|
1142
|
+
```bash
|
|
1143
|
+
# Local AI for sensitive content
|
|
1144
|
+
cp ollama.env .env
|
|
1145
|
+
ollama pull qwen2.5:14b
|
|
1146
|
+
ollama serve
|
|
1147
|
+
atj translations/en.json -e openai -s en
|
|
1148
|
+
```
|
|
1149
|
+
|
|
1150
|
+
### For High-Quality Content
|
|
1151
|
+
```bash
|
|
1152
|
+
# OpenAI GPT-4 for technical documentation
|
|
1153
|
+
cp openai.env .env
|
|
1154
|
+
atj docs/en.yaml -e openai -s en --format yaml
|
|
1155
|
+
```
|
|
1156
|
+
|
|
1157
|
+
## CLI Parameters Reference
|
|
1158
|
+
|
|
1159
|
+
### Basic Parameters
|
|
1160
|
+
|
|
1161
|
+
| Parameter | Short | Description | Default | Example |
|
|
1162
|
+
|-----------|-------|-------------|---------|---------|
|
|
1163
|
+
| `--pivotTranslation` | | Source translation file/folder path | Required | `./translations/en.json` |
|
|
1164
|
+
| `--mode` | `-m` | Processing mode: `file` or `folder` | `file` | `-m folder` |
|
|
1165
|
+
| `--engine` | `-e` | Translation engine | `aws` | `-e google` |
|
|
1166
|
+
| `--sourceLocale` | `-s` | Source language code | `en` | `-s en` |
|
|
1167
|
+
| `--format` | `-f` | Force specific format | `auto-detect` | `--format yaml` |
|
|
1168
|
+
| `--help` | `-h` | Show help message | | `-h` |
|
|
1169
|
+
| `--list-formats` | | List all supported formats | | `--list-formats` |
|
|
1170
|
+
|
|
1171
|
+
### Advanced Parameters
|
|
1172
|
+
|
|
1173
|
+
| Parameter | Description | Values | Default |
|
|
1174
|
+
|-----------|-------------|--------|---------|
|
|
1175
|
+
| `--keepTranslations` | Handle existing translations | `keep`, `retranslate` | `keep` |
|
|
1176
|
+
| `--keepExtraTranslations` | Handle extra keys not in source | `keep`, `remove` | `remove` |
|
|
1177
|
+
| `--startDelimiter` | Variable start delimiter | Any string | `{` |
|
|
1178
|
+
| `--endDelimiter` | Variable end delimiter | Any string | `}` |
|
|
1179
|
+
| `--ignorePrefix` | Skip keys starting with prefix | Any string | (none) |
|
|
1180
|
+
|
|
1181
|
+
### Translation Engines
|
|
1182
|
+
|
|
1183
|
+
| Engine | Parameter Value | Description | API Required |
|
|
1184
|
+
|--------|----------------|-------------|--------------|
|
|
1185
|
+
| **Google Translate** | `google` | Google Cloud Translation API | Google API Key |
|
|
1186
|
+
| **AWS Translate** | `aws` | Amazon Translate service | AWS credentials |
|
|
1187
|
+
| **Azure Translator** | `azure` | Microsoft Translator service | Azure key + region |
|
|
1188
|
+
| **DeepL Pro** | `deepLPro` | DeepL Pro API (higher limits) | DeepL Pro API key |
|
|
1189
|
+
| **DeepL Free** | `deepLFree` | DeepL Free API (limited) | DeepL Free API key |
|
|
1190
|
+
| **OpenAI** | `openai` | GPT models for translation | OpenAI API key |
|
|
1191
|
+
| **Hugging Face Cloud** | `huggingface` | HF Inference API (Helsinki-NLP, NLLBโฆ) | HF Access Token |
|
|
1192
|
+
| **Hugging Face Local** | `huggingface-local` | On-device ONNX inference, no internet | None |
|
|
1193
|
+
|
|
1194
|
+
### Environment Variables
|
|
1195
|
+
|
|
1196
|
+
#### Google Translate
|
|
1197
|
+
```bash
|
|
1198
|
+
ATJ_GOOGLE_API_KEY=your_google_api_key_here
|
|
1199
|
+
```
|
|
1200
|
+
|
|
1201
|
+
#### AWS Translate
|
|
1202
|
+
```bash
|
|
1203
|
+
ATJ_AWS_ACCESS_KEY_ID=your_aws_access_key
|
|
1204
|
+
ATJ_AWS_SECRET_ACCESS_KEY=your_aws_secret_key
|
|
1205
|
+
ATJ_AWS_REGION=us-east-1
|
|
1206
|
+
```
|
|
1207
|
+
|
|
1208
|
+
#### Azure Translator
|
|
1209
|
+
```bash
|
|
1210
|
+
ATJ_AZURE_SECRET_KEY=your_azure_translator_key
|
|
1211
|
+
ATJ_AZURE_REGION=eastus
|
|
1212
|
+
```
|
|
1213
|
+
|
|
1214
|
+
#### DeepL
|
|
1215
|
+
```bash
|
|
1216
|
+
# DeepL Pro
|
|
1217
|
+
ATJ_DEEPL_PRO_SECRET_KEY=your_deepl_pro_key
|
|
1218
|
+
|
|
1219
|
+
# DeepL Free
|
|
1220
|
+
ATJ_DEEPL_FREE_SECRET_KEY=your_deepl_free_key
|
|
1221
|
+
```
|
|
1222
|
+
|
|
1223
|
+
#### OpenAI / Local AI
|
|
1224
|
+
```bash
|
|
1225
|
+
# OpenAI (GPT-4.1 mini, GPT-4o, GPT-4.1)
|
|
1226
|
+
ATJ_OPEN_AI_SECRET_KEY=your_openai_api_key
|
|
1227
|
+
ATJ_OPEN_AI_BASE_URL=https://api.openai.com/v1
|
|
1228
|
+
ATJ_OPEN_AI_MODEL=gpt-4.1-mini
|
|
1229
|
+
ATJ_OPEN_AI_MAX_TOKENS=1000
|
|
1230
|
+
ATJ_OPEN_AI_TEMPERATURE=0.1
|
|
1231
|
+
ATJ_OPEN_AI_TOP_P=1.0
|
|
1232
|
+
ATJ_OPEN_AI_N=1
|
|
1233
|
+
ATJ_OPEN_AI_FREQUENCY_PENALTY=0
|
|
1234
|
+
ATJ_OPEN_AI_PRESENCE_PENALTY=0
|
|
1235
|
+
|
|
1236
|
+
# Local AI (Ollama, Jan.ai, etc.)
|
|
1237
|
+
ATJ_OPEN_AI_SECRET_KEY=ollama
|
|
1238
|
+
ATJ_OPEN_AI_BASE_URL=http://localhost:11434/v1
|
|
1239
|
+
ATJ_OPEN_AI_MODEL=qwen2.5:14b
|
|
1240
|
+
ATJ_OPEN_AI_MAX_TOKENS=512
|
|
1241
|
+
ATJ_OPEN_AI_TEMPERATURE=0.3
|
|
1242
|
+
```
|
|
1243
|
+
|
|
1244
|
+
#### Hugging Face Cloud
|
|
1245
|
+
```bash
|
|
1246
|
+
# Requires a free HF token: https://huggingface.co/settings/tokens
|
|
1247
|
+
ATJ_HUGGING_FACE_API_KEY=your_huggingface_token_here
|
|
1248
|
+
# Optional explicit provider when model auto-selection does not work
|
|
1249
|
+
ATJ_HUGGING_FACE_PROVIDER=hf-inference
|
|
1250
|
+
# Model to use
|
|
1251
|
+
ATJ_HUGGING_FACE_MODEL=Helsinki-NLP/opus-mt-en-fr
|
|
1252
|
+
```
|
|
1253
|
+
|
|
1254
|
+
Run it with:
|
|
1255
|
+
|
|
1256
|
+
```bash
|
|
1257
|
+
atj translations/en.json -e huggingface -s en
|
|
1258
|
+
```
|
|
1259
|
+
|
|
1260
|
+
#### Hugging Face Local (no API key needed)
|
|
1261
|
+
```bash
|
|
1262
|
+
# ONNX model ID โ downloaded and cached on first run (~300 MB)
|
|
1263
|
+
# Find models at: https://huggingface.co/Xenova
|
|
1264
|
+
ATJ_HUGGING_FACE_LOCAL_MODEL=Xenova/opus-mt-en-fr
|
|
1265
|
+
```
|
|
1266
|
+
|
|
1267
|
+
Run it with:
|
|
1268
|
+
|
|
1269
|
+
```bash
|
|
1270
|
+
atj translations/en.json -e huggingface-local -s en
|
|
1271
|
+
```
|
|
1272
|
+
|
|
1273
|
+
#### Other Configuration
|
|
1274
|
+
```bash
|
|
1275
|
+
# Processing options
|
|
164
1276
|
ATJ_START_DELIMITER={{
|
|
165
|
-
end delimiter
|
|
166
1277
|
ATJ_END_DELIMITER=}}
|
|
167
|
-
|
|
168
|
-
file or folder
|
|
169
1278
|
ATJ_MODE=file
|
|
170
|
-
|
|
171
|
-
source locale
|
|
172
1279
|
ATJ_SOURCE_LOCALE=en
|
|
173
|
-
|
|
174
|
-
keep or retranslate existing translations
|
|
175
1280
|
ATJ_KEEP_TRANSLATIONS=keep
|
|
1281
|
+
ATJ_KEEP_EXTRA_TRANSLATIONS=remove
|
|
1282
|
+
ATJ_IGNORE_PREFIX=@@
|
|
1283
|
+
```
|
|
1284
|
+
|
|
1285
|
+
### Complete CLI Examples
|
|
1286
|
+
|
|
1287
|
+
#### Basic Usage
|
|
1288
|
+
```shell
|
|
1289
|
+
# Translate single JSON file with Google
|
|
1290
|
+
atj translations/en.json -e google -s en
|
|
176
1291
|
|
|
177
|
-
|
|
178
|
-
|
|
1292
|
+
# Translate folder structure with AWS
|
|
1293
|
+
atj translations/ -e aws -s en -m folder
|
|
179
1294
|
|
|
180
|
-
|
|
181
|
-
|
|
1295
|
+
# Force YAML format detection
|
|
1296
|
+
atj config/app.txt --format yaml -e azure -s en
|
|
182
1297
|
```
|
|
183
1298
|
|
|
184
|
-
|
|
1299
|
+
#### Advanced Usage
|
|
1300
|
+
```shell
|
|
1301
|
+
# Retranslate existing files, keep extra keys
|
|
1302
|
+
atj translations/en.json -e openai -s en \
|
|
1303
|
+
--keepTranslations retranslate \
|
|
1304
|
+
--keepExtraTranslations keep
|
|
185
1305
|
|
|
186
|
-
|
|
1306
|
+
# Custom delimiters for Vue.js i18n
|
|
1307
|
+
atj src/locales/en.json -e google -s en \
|
|
1308
|
+
--startDelimiter "{{" \
|
|
1309
|
+
--endDelimiter "}}"
|
|
187
1310
|
|
|
1311
|
+
# Ignore metadata keys starting with @@
|
|
1312
|
+
atj lib/l10n/app_en.arb -e deepLPro -s en \
|
|
1313
|
+
--ignorePrefix "@@"
|
|
1314
|
+
```
|
|
1315
|
+
|
|
1316
|
+
#### Production Workflows
|
|
188
1317
|
```shell
|
|
189
|
-
|
|
190
|
-
atj
|
|
1318
|
+
# Android app localization
|
|
1319
|
+
atj res/values/strings.xml -e google -s en \
|
|
1320
|
+
--format android-xml \
|
|
1321
|
+
--keepTranslations keep
|
|
1322
|
+
|
|
1323
|
+
# Flutter app with ARB files
|
|
1324
|
+
atj lib/l10n/ -e azure -s en -m folder \
|
|
1325
|
+
--format arb \
|
|
1326
|
+
--keepExtraTranslations remove
|
|
1327
|
+
|
|
1328
|
+
# Web app with nested JSON structure
|
|
1329
|
+
atj src/assets/i18n/en.json -e openai -s en \
|
|
1330
|
+
--keepTranslations retranslate \
|
|
1331
|
+
--startDelimiter "{" \
|
|
1332
|
+
--endDelimiter "}"
|
|
1333
|
+
|
|
1334
|
+
# Game localization with CSV
|
|
1335
|
+
atj assets/localization/strings.csv -e deepLPro -s en \
|
|
1336
|
+
--format csv \
|
|
1337
|
+
--keepTranslations keep
|
|
191
1338
|
```
|
|
192
1339
|
|
|
193
|
-
You can also use
|
|
1340
|
+
You can also use .env file to store environment variables for easier configuration management.
|
|
1341
|
+
|
|
1342
|
+
## Recent Improvements
|
|
1343
|
+
|
|
1344
|
+
### Version 2.0.0 - Major Release (2025-01-04)
|
|
1345
|
+
|
|
1346
|
+
This major release represents a complete rewrite and enhancement of the library:
|
|
1347
|
+
|
|
1348
|
+
#### ๐ **ES Modules Migration**
|
|
1349
|
+
- Complete migration from CommonJS to ES modules
|
|
1350
|
+
- Modern JavaScript compatibility with `"type": "module"`
|
|
1351
|
+
- Updated import/export syntax throughout codebase
|
|
1352
|
+
|
|
1353
|
+
#### ๐ก๏ธ **Enhanced Validation System**
|
|
1354
|
+
- New comprehensive validation framework with detailed error reporting
|
|
1355
|
+
- Automatic error recovery and correction capabilities
|
|
1356
|
+
- Format-specific validation rules and error messages
|
|
1357
|
+
- Enhanced debugging and troubleshooting information
|
|
1358
|
+
|
|
1359
|
+
#### ๐ฏ **Demo System**
|
|
1360
|
+
- **Dual demo modes**: File mode (`demo/`) and Folder mode (`demo-folder/`)
|
|
1361
|
+
- Interactive examples with examples for all supported formats
|
|
1362
|
+
- **Local AI integration** with Ollama for offline testing
|
|
1363
|
+
- Automated reset and run scripts for easy testing
|
|
1364
|
+
- Sample files demonstrating real-world usage patterns
|
|
1365
|
+
- Quick start examples for new users
|
|
1366
|
+
- **Comprehensive format coverage**: JSON, XML, YAML, Properties, ARB, PO, CSV
|
|
1367
|
+
|
|
1368
|
+
#### ๐งช **Comprehensive Testing**
|
|
1369
|
+
- 100% test coverage for all format handlers
|
|
1370
|
+
- Integration tests for CLI functionality
|
|
1371
|
+
- Error handling and edge case testing
|
|
1372
|
+
- Cross-format compatibility validation
|
|
1373
|
+
|
|
1374
|
+
#### ๐ง **Code Quality Improvements**
|
|
1375
|
+
- Complete codebase formatting with Biome linter
|
|
1376
|
+
- Enhanced TypeScript configurations and type safety
|
|
1377
|
+
- Improved error handling and user feedback
|
|
1378
|
+
- Optimized performance for large files
|
|
1379
|
+
|
|
1380
|
+
#### ๐ **Security Updates**
|
|
1381
|
+
- Updated all dependencies to latest secure versions
|
|
1382
|
+
- Fixed security vulnerabilities in axios and jws
|
|
1383
|
+
- Enhanced input validation and sanitization
|
|
1384
|
+
|
|
1385
|
+
### XML Handler Enhancements (v1.5.5)
|
|
1386
|
+
|
|
1387
|
+
The XML handler has been significantly improved with the following features:
|
|
1388
|
+
|
|
1389
|
+
- **Enhanced Format Detection**: Automatically detects Android, iOS, and generic XML formats even with attributes and namespaces
|
|
1390
|
+
- **Improved Validation**: Robust validation that properly identifies invalid XML structures and provides specific error messages
|
|
1391
|
+
- **Better Error Handling**: Detects malformed XML with unclosed tags and provides clear error messages
|
|
1392
|
+
- **Generic XML Flattening**: Automatically flattens nested XML structures for easier translation (e.g., `<messages><greeting>Hello</greeting></messages>` becomes `messages.greeting: "Hello"`)
|
|
1393
|
+
- **Attribute Preservation**: Maintains XML attributes like `translatable="false"` and namespace declarations
|
|
1394
|
+
- **Round-trip Translation**: Ensures translated content can be serialized back to valid XML while preserving structure
|
|
1395
|
+
|
|
1396
|
+
### Supported XML Structures
|
|
1397
|
+
|
|
1398
|
+
1. **Android strings.xml**: Full support for resource groups, CDATA sections, and Android-specific attributes
|
|
1399
|
+
2. **iOS plist XML**: Complete support for Apple's property list format with key-value pairs
|
|
1400
|
+
3. **Generic XML**: Automatic structure detection and flattening for any XML translation format
|
|
1401
|
+
|
|
1402
|
+
### Debug and Development
|
|
1403
|
+
|
|
1404
|
+
1. Create .env file in main folder with the desired key/keys from **ENVIRONMENT VARIABLES** section
|
|
1405
|
+
2. Add also in .env source locale `ATJ_SOURCE_LOCALE=en` to test from en
|
|
1406
|
+
3. Run: `npm run debug`
|
|
1407
|
+
|
|
1408
|
+
### Testing
|
|
1409
|
+
|
|
1410
|
+
Run the comprehensive test suite:
|
|
194
1411
|
|
|
195
1412
|
```shell
|
|
196
|
-
|
|
1413
|
+
# Run all tests
|
|
1414
|
+
npm test
|
|
1415
|
+
|
|
1416
|
+
# Run tests with coverage report
|
|
1417
|
+
npm run test:coverage
|
|
1418
|
+
|
|
1419
|
+
# Run tests in watch mode (for development)
|
|
1420
|
+
npm run test:watch
|
|
197
1421
|
```
|
|
198
1422
|
|
|
199
|
-
###
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
1423
|
+
### Migration from v1.x to v2.0
|
|
1424
|
+
|
|
1425
|
+
If upgrading from version 1.x, please note:
|
|
1426
|
+
|
|
1427
|
+
1. **Node.js Requirements**: Ensure you're using a Node.js version that supports ES modules
|
|
1428
|
+
2. **Import Syntax**: Update any custom integrations to use ES module import syntax
|
|
1429
|
+
3. **API Changes**: Review the updated TypeScript definitions for any breaking changes
|
|
1430
|
+
4. **Testing**: Thoroughly test your specific file formats and workflows with the new version
|
|
1431
|
+
|
|
1432
|
+
For detailed migration assistance, see the [CHANGELOG.md](CHANGELOG.md) file.
|