auto-translate-json-library 1.5.4 โ†’ 2.0.2

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