auto-translate-json-library 2.0.2 → 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 +240 -3
- package/build/package.json +30 -16
- package/build/src/bin/cli.d.ts +1 -1
- package/build/src/bin/cli.js +82 -53
- package/build/src/config.d.ts +12 -1
- package/build/src/files.js +2 -2
- 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.js +17 -0
- package/build/src/lib.js +9 -1
- package/build/src/openai.js +1 -0
- package/package.json +30 -16
- package/build/tests/arb-handler.test.d.ts +0 -1
- package/build/tests/arb-handler.test.js +0 -694
- package/build/tests/cli-integration.test.d.ts +0 -1
- package/build/tests/cli-integration.test.js +0 -352
- package/build/tests/csv-handler.test.d.ts +0 -1
- package/build/tests/csv-handler.test.js +0 -507
- package/build/tests/error-handling.test.d.ts +0 -1
- package/build/tests/error-handling.test.js +0 -456
- package/build/tests/files-integration.test.d.ts +0 -1
- package/build/tests/files-integration.test.js +0 -421
- package/build/tests/json-handler.test.d.ts +0 -1
- package/build/tests/json-handler.test.js +0 -526
- package/build/tests/po-handler.test.d.ts +0 -1
- package/build/tests/po-handler.test.js +0 -768
- package/build/tests/properties-handler.test.d.ts +0 -1
- package/build/tests/properties-handler.test.js +0 -316
- package/build/tests/setup.d.ts +0 -1
- package/build/tests/setup.js +0 -5
- package/build/tests/xliff-handler.test.d.ts +0 -1
- package/build/tests/xliff-handler.test.js +0 -459
- package/build/tests/xmb-xtb-handler.test.d.ts +0 -1
- package/build/tests/xmb-xtb-handler.test.js +0 -758
- package/build/tests/xml-handler.test.d.ts +0 -1
- package/build/tests/xml-handler.test.js +0 -570
- package/build/tests/yaml-handler.test.d.ts +0 -1
- package/build/tests/yaml-handler.test.js +0 -156
package/README.MD
CHANGED
|
@@ -7,10 +7,11 @@ Auto Translate JSON
|
|
|
7
7
|
It opens possibility to use Auto Translation JSON
|
|
8
8
|
not just in VS Code but as a library and command line interface.
|
|
9
9
|
|
|
10
|
-
You can use Azure, AWS, Google, DeepL, OpenAI
|
|
10
|
+
You can use Azure, AWS, Google, DeepL, OpenAI,
|
|
11
11
|
local OpenAI compatible REST API
|
|
12
|
-
for example [ollama](https://ollama.com/)
|
|
12
|
+
for example [ollama](https://ollama.com/)
|
|
13
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
|
|
|
15
16
|
## 🚀 Version 2.0.0 - Major Release
|
|
16
17
|
|
|
@@ -55,7 +56,7 @@ import { translate, Configuration } from 'auto-translate-json-library';
|
|
|
55
56
|
const config: Configuration = {
|
|
56
57
|
// Translation service configuration
|
|
57
58
|
translationKeyInfo: {
|
|
58
|
-
kind: 'openai', // 'google' | 'aws' | 'azure' | 'deepLPro' | 'deepLFree' | 'openai'
|
|
59
|
+
kind: 'openai', // 'google' | 'aws' | 'azure' | 'deepLPro' | 'deepLFree' | 'openai' | 'huggingface' | 'huggingface-local'
|
|
59
60
|
apiKey: 'your-api-key',
|
|
60
61
|
// OpenAI-specific options
|
|
61
62
|
baseUrl: 'https://api.openai.com/v1', // or local Ollama: 'http://localhost:11434/v1'
|
|
@@ -125,6 +126,35 @@ const config: Configuration = {
|
|
|
125
126
|
};
|
|
126
127
|
```
|
|
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
|
+
|
|
128
158
|
#### AWS Translate
|
|
129
159
|
```typescript
|
|
130
160
|
const config: Configuration = {
|
|
@@ -189,6 +219,48 @@ npm install -g auto-translate-json-library
|
|
|
189
219
|
|
|
190
220
|
Then use the convenient `atj` command:
|
|
191
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
|
+
|
|
192
264
|
```shell
|
|
193
265
|
atj translations/en.json -e google -s en
|
|
194
266
|
```
|
|
@@ -267,6 +339,34 @@ atj translations/en.json -e deepLPro -s en
|
|
|
267
339
|
atj translations/en.json -e deepLFree -s en
|
|
268
340
|
```
|
|
269
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
|
+
|
|
270
370
|
### File vs Folder Mode
|
|
271
371
|
|
|
272
372
|
#### File Mode (Default)
|
|
@@ -901,6 +1001,110 @@ The library supports multiple translation services. Choose the one that best fit
|
|
|
901
1001
|
|
|
902
1002
|
---
|
|
903
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
|
+
|
|
904
1108
|
## Service Comparison
|
|
905
1109
|
|
|
906
1110
|
| Service | Quality | Speed | Cost | Languages | Best For |
|
|
@@ -911,6 +1115,8 @@ The library supports multiple translation services. Choose the one that best fit
|
|
|
911
1115
|
| **AWS** | ⭐⭐⭐⭐ | ⭐⭐⭐⭐ | ⭐⭐⭐ | 75+ | AWS ecosystem |
|
|
912
1116
|
| **Azure** | ⭐⭐⭐⭐ | ⭐⭐⭐⭐ | ⭐⭐⭐ | 90+ | Microsoft ecosystem |
|
|
913
1117
|
| **DeepL** | ⭐⭐⭐⭐⭐ | ⭐⭐⭐⭐ | ⭐⭐ | 30+ | Highest quality |
|
|
1118
|
+
| **HuggingFace** | ⭐⭐⭐⭐ | ⭐⭐⭐⭐ | ⭐⭐⭐⭐⭐ | 200+ | Free tier, many models |
|
|
1119
|
+
| **HuggingFace Local** | ⭐⭐⭐⭐ | ⭐⭐⭐ | ⭐⭐⭐⭐⭐ | 200+ | Offline, private, free |
|
|
914
1120
|
|
|
915
1121
|
## Quick Start Examples
|
|
916
1122
|
|
|
@@ -982,6 +1188,8 @@ atj docs/en.yaml -e openai -s en --format yaml
|
|
|
982
1188
|
| **DeepL Pro** | `deepLPro` | DeepL Pro API (higher limits) | DeepL Pro API key |
|
|
983
1189
|
| **DeepL Free** | `deepLFree` | DeepL Free API (limited) | DeepL Free API key |
|
|
984
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 |
|
|
985
1193
|
|
|
986
1194
|
### Environment Variables
|
|
987
1195
|
|
|
@@ -1033,6 +1241,35 @@ ATJ_OPEN_AI_MAX_TOKENS=512
|
|
|
1033
1241
|
ATJ_OPEN_AI_TEMPERATURE=0.3
|
|
1034
1242
|
```
|
|
1035
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
|
+
|
|
1036
1273
|
#### Other Configuration
|
|
1037
1274
|
```bash
|
|
1038
1275
|
# Processing options
|
package/build/package.json
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "auto-translate-json-library",
|
|
3
|
-
"version": "2.0.
|
|
3
|
+
"version": "2.0.5",
|
|
4
4
|
"type": "module",
|
|
5
|
-
"description": "Automatically translates JSON language files to other languages using Google Translate,AWS,Azure,DeepL,OpenAI or local OpenAI compatible server",
|
|
5
|
+
"description": "Automatically translates JSON language files to other languages using Google Translate, AWS, Azure, DeepL, OpenAI, Hugging Face (cloud & local) or local OpenAI compatible server",
|
|
6
6
|
"main": "./build/src/index.js",
|
|
7
7
|
"bin": {
|
|
8
8
|
"auto-translate-json-library": "build/src/bin/cli.js",
|
|
@@ -10,15 +10,21 @@
|
|
|
10
10
|
},
|
|
11
11
|
"types": "./build/src/index.d.ts",
|
|
12
12
|
"files": [
|
|
13
|
-
"build",
|
|
14
|
-
"
|
|
13
|
+
"build/src",
|
|
14
|
+
"build/package.json",
|
|
15
|
+
"README.MD"
|
|
15
16
|
],
|
|
17
|
+
"publishConfig": {
|
|
18
|
+
"access": "public"
|
|
19
|
+
},
|
|
16
20
|
"scripts": {
|
|
17
21
|
"prepare": "tsc",
|
|
22
|
+
"prepack": "npm run build",
|
|
18
23
|
"build": "tsc",
|
|
19
24
|
"build:go": "tsgo --skipLibCheck",
|
|
20
25
|
"build:run": "ts-node ./build/src/index.js --pivotTranslation=./tests/translations/en.json",
|
|
21
26
|
"debug": "ts-node src/index.ts --pivotTranslation=./tests/translations/en.json",
|
|
27
|
+
"release:check": "npm test && npm pack --dry-run",
|
|
22
28
|
"test": "node --experimental-vm-modules node_modules/jest/bin/jest.js",
|
|
23
29
|
"test:watch": "jest --watch",
|
|
24
30
|
"test:coverage": "jest --coverage",
|
|
@@ -99,7 +105,13 @@
|
|
|
99
105
|
"automation",
|
|
100
106
|
"batch-translation",
|
|
101
107
|
"multi-format",
|
|
102
|
-
"gettext"
|
|
108
|
+
"gettext",
|
|
109
|
+
"huggingface",
|
|
110
|
+
"hugging-face",
|
|
111
|
+
"helsinki-nlp",
|
|
112
|
+
"nllb",
|
|
113
|
+
"transformers-js",
|
|
114
|
+
"local-translation"
|
|
103
115
|
],
|
|
104
116
|
"author": "codegrue",
|
|
105
117
|
"repository": {
|
|
@@ -116,34 +128,36 @@
|
|
|
116
128
|
],
|
|
117
129
|
"license": "MIT",
|
|
118
130
|
"devDependencies": {
|
|
119
|
-
"@biomejs/biome": "2.
|
|
120
|
-
"@topce/native-preview": "7.0.0-dev.
|
|
121
|
-
"@types/gettext-parser": "
|
|
131
|
+
"@biomejs/biome": "2.4.7",
|
|
132
|
+
"@topce/native-preview": "7.0.0-dev.20260215",
|
|
133
|
+
"@types/gettext-parser": "9.0.0",
|
|
122
134
|
"@types/jest": "30.0.0",
|
|
123
135
|
"@types/minimist": "1.2.5",
|
|
124
|
-
"@types/node": "25.0
|
|
136
|
+
"@types/node": "25.5.0",
|
|
125
137
|
"@types/properties-parser": "0.3.3",
|
|
126
138
|
"@types/yargs": "17.0.35",
|
|
127
|
-
"jest": "30.
|
|
139
|
+
"jest": "30.3.0",
|
|
128
140
|
"ts-jest": "29.4.6",
|
|
129
141
|
"ts-node": "10.9.2",
|
|
130
142
|
"typescript": "5.9.3"
|
|
131
143
|
},
|
|
132
144
|
"dependencies": {
|
|
133
|
-
"@aws-sdk/client-translate": "3.
|
|
145
|
+
"@aws-sdk/client-translate": "3.1011.0",
|
|
134
146
|
"@google-cloud/translate": "9.3.0",
|
|
147
|
+
"@huggingface/inference": "^4.13.15",
|
|
148
|
+
"@huggingface/transformers": "^3.8.1",
|
|
135
149
|
"@types/js-yaml": "4.0.9",
|
|
136
|
-
"axios": "1.13.
|
|
150
|
+
"axios": "1.13.6",
|
|
137
151
|
"csv-parser": "3.2.0",
|
|
138
152
|
"csv-writer": "1.6.0",
|
|
139
153
|
"deepl-node": "1.24.0",
|
|
140
|
-
"dotenv": "17.
|
|
141
|
-
"fast-xml-parser": "5.
|
|
154
|
+
"dotenv": "17.3.1",
|
|
155
|
+
"fast-xml-parser": "5.5.6",
|
|
142
156
|
"form-data": "4.0.5",
|
|
143
|
-
"gettext-parser": "9.0.
|
|
157
|
+
"gettext-parser": "9.0.2",
|
|
144
158
|
"js-yaml": "4.1.1",
|
|
145
159
|
"minimist": "1.2.8",
|
|
146
|
-
"openai": "6.
|
|
160
|
+
"openai": "6.32.0",
|
|
147
161
|
"picocolors": "1.1.1",
|
|
148
162
|
"properties-parser": "0.6.0",
|
|
149
163
|
"uuid": "13.0.0",
|
package/build/src/bin/cli.d.ts
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
|
-
|
|
2
|
+
export {};
|
package/build/src/bin/cli.js
CHANGED
|
@@ -5,12 +5,50 @@ import minimist from "minimist";
|
|
|
5
5
|
import c from "picocolors";
|
|
6
6
|
import packageJson from "../../package.json" with { type: "json" };
|
|
7
7
|
const { version } = packageJson;
|
|
8
|
-
import { FormatHandlerFactory } from "../format-handler-factory.js";
|
|
9
|
-
import { translate } from "../lib.js";
|
|
10
|
-
// Import format handlers to ensure they are registered
|
|
11
|
-
import "../format/index.js";
|
|
12
8
|
import { config as dotenvConfig } from "dotenv";
|
|
13
9
|
dotenvConfig();
|
|
10
|
+
const formatDetails = {
|
|
11
|
+
json: { extensions: [".json"], description: "JSON translation files" },
|
|
12
|
+
arb: {
|
|
13
|
+
extensions: [".arb"],
|
|
14
|
+
description: "Flutter Application Resource Bundle",
|
|
15
|
+
},
|
|
16
|
+
xml: { extensions: [".xml"], description: "Generic XML translation files" },
|
|
17
|
+
"android-xml": {
|
|
18
|
+
extensions: [".xml"],
|
|
19
|
+
description: "Android strings.xml format",
|
|
20
|
+
},
|
|
21
|
+
"ios-xml": {
|
|
22
|
+
extensions: [".xml"],
|
|
23
|
+
description: "iOS localization XML format",
|
|
24
|
+
},
|
|
25
|
+
"generic-xml": { extensions: [".xml"], description: "Generic XML format" },
|
|
26
|
+
xliff: {
|
|
27
|
+
extensions: [".xlf", ".xliff"],
|
|
28
|
+
description: "XLIFF 1.2 and 2.x translation files",
|
|
29
|
+
},
|
|
30
|
+
xmb: {
|
|
31
|
+
extensions: [".xmb"],
|
|
32
|
+
description: "XML Message Bundle source files",
|
|
33
|
+
},
|
|
34
|
+
xtb: { extensions: [".xtb"], description: "XML Translation Bundle files" },
|
|
35
|
+
po: { extensions: [".po"], description: "GNU gettext PO files" },
|
|
36
|
+
pot: {
|
|
37
|
+
extensions: [".pot"],
|
|
38
|
+
description: "GNU gettext POT template files",
|
|
39
|
+
},
|
|
40
|
+
yaml: {
|
|
41
|
+
extensions: [".yaml", ".yml"],
|
|
42
|
+
description: "YAML translation files",
|
|
43
|
+
},
|
|
44
|
+
properties: {
|
|
45
|
+
extensions: [".properties"],
|
|
46
|
+
description: "Java Properties files",
|
|
47
|
+
},
|
|
48
|
+
csv: { extensions: [".csv"], description: "Comma-separated values files" },
|
|
49
|
+
tsv: { extensions: [".tsv"], description: "Tab-separated values files" },
|
|
50
|
+
};
|
|
51
|
+
const supportedFormats = Object.keys(formatDetails);
|
|
14
52
|
// Define a function to display the help message
|
|
15
53
|
function displayHelp() {
|
|
16
54
|
console.log(`🔨 Auto translate json/xml cli v${version}`);
|
|
@@ -28,7 +66,6 @@ function displayHelp() {
|
|
|
28
66
|
console.log(" --keepExtraTranslations, --no-keepExtraTranslations Keep or remove extra translations");
|
|
29
67
|
console.log("");
|
|
30
68
|
console.log("Supported formats:");
|
|
31
|
-
const formats = FormatHandlerFactory.getSupportedFormats();
|
|
32
69
|
const formatGroups = {
|
|
33
70
|
"JSON-based": ["json", "arb"],
|
|
34
71
|
"XML-based": [
|
|
@@ -44,7 +81,7 @@ function displayHelp() {
|
|
|
44
81
|
Tabular: ["csv", "tsv"],
|
|
45
82
|
};
|
|
46
83
|
for (const [group, groupFormats] of Object.entries(formatGroups)) {
|
|
47
|
-
const availableFormats = groupFormats.filter((f) =>
|
|
84
|
+
const availableFormats = groupFormats.filter((f) => supportedFormats.includes(f));
|
|
48
85
|
if (availableFormats.length > 0) {
|
|
49
86
|
console.log(` ${group}: ${availableFormats.join(", ")}`);
|
|
50
87
|
}
|
|
@@ -76,49 +113,7 @@ function listFormats() {
|
|
|
76
113
|
console.log("");
|
|
77
114
|
console.log("Supported file formats:");
|
|
78
115
|
console.log("");
|
|
79
|
-
const
|
|
80
|
-
const formatDetails = {
|
|
81
|
-
json: { extensions: [".json"], description: "JSON translation files" },
|
|
82
|
-
arb: {
|
|
83
|
-
extensions: [".arb"],
|
|
84
|
-
description: "Flutter Application Resource Bundle",
|
|
85
|
-
},
|
|
86
|
-
xml: { extensions: [".xml"], description: "Generic XML translation files" },
|
|
87
|
-
"android-xml": {
|
|
88
|
-
extensions: [".xml"],
|
|
89
|
-
description: "Android strings.xml format",
|
|
90
|
-
},
|
|
91
|
-
"ios-xml": {
|
|
92
|
-
extensions: [".xml"],
|
|
93
|
-
description: "iOS localization XML format",
|
|
94
|
-
},
|
|
95
|
-
"generic-xml": { extensions: [".xml"], description: "Generic XML format" },
|
|
96
|
-
xliff: {
|
|
97
|
-
extensions: [".xlf", ".xliff"],
|
|
98
|
-
description: "XLIFF 1.2 and 2.x translation files",
|
|
99
|
-
},
|
|
100
|
-
xmb: {
|
|
101
|
-
extensions: [".xmb"],
|
|
102
|
-
description: "XML Message Bundle source files",
|
|
103
|
-
},
|
|
104
|
-
xtb: { extensions: [".xtb"], description: "XML Translation Bundle files" },
|
|
105
|
-
po: { extensions: [".po"], description: "GNU gettext PO files" },
|
|
106
|
-
pot: {
|
|
107
|
-
extensions: [".pot"],
|
|
108
|
-
description: "GNU gettext POT template files",
|
|
109
|
-
},
|
|
110
|
-
yaml: {
|
|
111
|
-
extensions: [".yaml", ".yml"],
|
|
112
|
-
description: "YAML translation files",
|
|
113
|
-
},
|
|
114
|
-
properties: {
|
|
115
|
-
extensions: [".properties"],
|
|
116
|
-
description: "Java Properties files",
|
|
117
|
-
},
|
|
118
|
-
csv: { extensions: [".csv"], description: "Comma-separated values files" },
|
|
119
|
-
tsv: { extensions: [".tsv"], description: "Tab-separated values files" },
|
|
120
|
-
};
|
|
121
|
-
for (const format of formats.sort()) {
|
|
116
|
+
for (const format of [...supportedFormats].sort()) {
|
|
122
117
|
const details = formatDetails[format];
|
|
123
118
|
if (details) {
|
|
124
119
|
console.log(` ${format.padEnd(15)} ${details.extensions.join(", ").padEnd(20)} ${details.description}`);
|
|
@@ -188,7 +183,7 @@ if (!inputPath) {
|
|
|
188
183
|
process.exit(1);
|
|
189
184
|
}
|
|
190
185
|
// Validate format if specified
|
|
191
|
-
if (format && !
|
|
186
|
+
if (format && !supportedFormats.includes(format)) {
|
|
192
187
|
console.error(c.red(`❌ Unsupported format: ${format}`));
|
|
193
188
|
console.error(c.yellow("💡 Use --list-formats to see all supported formats"));
|
|
194
189
|
process.exit(1);
|
|
@@ -207,6 +202,8 @@ const validEngines = [
|
|
|
207
202
|
"deepLPro",
|
|
208
203
|
"deepLFree",
|
|
209
204
|
"openai",
|
|
205
|
+
"huggingface",
|
|
206
|
+
"huggingface-local",
|
|
210
207
|
];
|
|
211
208
|
if (engine && !validEngines.includes(engine)) {
|
|
212
209
|
console.error(c.red(`❌ Invalid engine: ${engine}`));
|
|
@@ -307,6 +304,32 @@ switch (engine) {
|
|
|
307
304
|
};
|
|
308
305
|
break;
|
|
309
306
|
}
|
|
307
|
+
case "huggingface": {
|
|
308
|
+
const huggingFaceApiKey = process.env.ATJ_HUGGING_FACE_API_KEY;
|
|
309
|
+
if (!huggingFaceApiKey) {
|
|
310
|
+
console.error(c.red("❌ Hugging Face API key not found in environment variable ATJ_HUGGING_FACE_API_KEY"));
|
|
311
|
+
process.exit(1);
|
|
312
|
+
}
|
|
313
|
+
config.translationKeyInfo = {
|
|
314
|
+
kind: "huggingface",
|
|
315
|
+
apiKey: huggingFaceApiKey,
|
|
316
|
+
model: process.env.ATJ_HUGGING_FACE_MODEL ?? "Helsinki-NLP/opus-mt-en-fr",
|
|
317
|
+
provider: process.env.ATJ_HUGGING_FACE_PROVIDER,
|
|
318
|
+
};
|
|
319
|
+
break;
|
|
320
|
+
}
|
|
321
|
+
case "huggingface-local": {
|
|
322
|
+
const huggingFaceLocalModel = process.env.ATJ_HUGGING_FACE_LOCAL_MODEL;
|
|
323
|
+
if (!huggingFaceLocalModel) {
|
|
324
|
+
console.error(c.red("❌ Hugging Face local model not found in environment variable ATJ_HUGGING_FACE_LOCAL_MODEL"));
|
|
325
|
+
process.exit(1);
|
|
326
|
+
}
|
|
327
|
+
config.translationKeyInfo = {
|
|
328
|
+
kind: "huggingface-local",
|
|
329
|
+
model: huggingFaceLocalModel,
|
|
330
|
+
};
|
|
331
|
+
break;
|
|
332
|
+
}
|
|
310
333
|
default:
|
|
311
334
|
console.error(c.red(`❌ Engine ${engine} not supported`));
|
|
312
335
|
process.exit(1);
|
|
@@ -324,9 +347,15 @@ config.mode = mode;
|
|
|
324
347
|
if (format) {
|
|
325
348
|
config.format = format;
|
|
326
349
|
}
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
|
|
350
|
+
async function main() {
|
|
351
|
+
// Load the translation runtime only when an actual translation command is executed.
|
|
352
|
+
await import("../format/index.js");
|
|
353
|
+
const { translate } = await import("../lib.js");
|
|
354
|
+
const sourcePath = path.join(process.cwd(), inputPath);
|
|
355
|
+
console.log(c.green(`🌐 Translating ${sourcePath}`));
|
|
356
|
+
await translate(sourcePath, config);
|
|
357
|
+
}
|
|
358
|
+
main().catch((error) => {
|
|
330
359
|
console.error(c.red("❌ Translate error:\n"), error);
|
|
331
360
|
process.exit(1);
|
|
332
361
|
});
|
package/build/src/config.d.ts
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
|
+
import type { InferenceProviderOrPolicy } from "@huggingface/inference";
|
|
1
2
|
export type Configuration = {
|
|
2
|
-
translationKeyInfo: GoogleTranslationKey | AwsTranslationKey | AzureTranslationKey | DeepLProTranslationKey | DeepLFreeTranslationKey | OpenAITranslationKey;
|
|
3
|
+
translationKeyInfo: GoogleTranslationKey | AwsTranslationKey | AzureTranslationKey | DeepLProTranslationKey | DeepLFreeTranslationKey | OpenAITranslationKey | HuggingFaceTranslationKey | HuggingFaceLocalTranslationKey;
|
|
3
4
|
startDelimiter: string;
|
|
4
5
|
endDelimiter: string;
|
|
5
6
|
mode: "file" | "folder";
|
|
@@ -44,4 +45,14 @@ type OpenAITranslationKey = {
|
|
|
44
45
|
frequencyPenalty: number;
|
|
45
46
|
presencePenalty: number;
|
|
46
47
|
};
|
|
48
|
+
type HuggingFaceTranslationKey = {
|
|
49
|
+
kind: "huggingface";
|
|
50
|
+
apiKey: string;
|
|
51
|
+
model: string;
|
|
52
|
+
provider?: InferenceProviderOrPolicy;
|
|
53
|
+
};
|
|
54
|
+
type HuggingFaceLocalTranslationKey = {
|
|
55
|
+
kind: "huggingface-local";
|
|
56
|
+
model: string;
|
|
57
|
+
};
|
|
47
58
|
export {};
|
package/build/src/files.js
CHANGED
|
@@ -110,8 +110,8 @@ export const loadJsonFromLocale = async (fileName) => {
|
|
|
110
110
|
.join(", ");
|
|
111
111
|
console.warn(`${format.toUpperCase()} validation warnings for ${fileName}: ${warningMessages}`);
|
|
112
112
|
}
|
|
113
|
-
//
|
|
114
|
-
if (format ===
|
|
113
|
+
// Preserve handler metadata for formats that cannot be reconstructed from plain key/value content.
|
|
114
|
+
if (format === "yaml" || format === "yml" || format === "arb") {
|
|
115
115
|
return tempResult;
|
|
116
116
|
}
|
|
117
117
|
// Remove metadata for backward compatibility
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import type { ITranslate } from "./translate.interface.js";
|
|
2
|
+
export declare class HuggingFaceLocalTranslate implements ITranslate {
|
|
3
|
+
private model;
|
|
4
|
+
private pipelinePromise;
|
|
5
|
+
constructor(model: string);
|
|
6
|
+
isValidLocale(_targetLocale: string): boolean;
|
|
7
|
+
private getPipeline;
|
|
8
|
+
private sanitizeResult;
|
|
9
|
+
private translateWithTranslationPipeline;
|
|
10
|
+
translateText(text: string, sourceLocale: string, targetLocale: string, _context?: string): Promise<string>;
|
|
11
|
+
}
|