auto-translate-json-library 2.0.2 → 2.1.0

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 (43) hide show
  1. package/README.MD +305 -3
  2. package/build/package.json +31 -16
  3. package/build/src/bin/cli.d.ts +1 -1
  4. package/build/src/bin/cli.js +253 -58
  5. package/build/src/config.d.ts +12 -1
  6. package/build/src/files.js +2 -2
  7. package/build/src/format-detector.js +1 -1
  8. package/build/src/huggingface-local.d.ts +11 -0
  9. package/build/src/huggingface-local.js +71 -0
  10. package/build/src/huggingface.d.ts +12 -0
  11. package/build/src/huggingface.js +76 -0
  12. package/build/src/index.js +16 -0
  13. package/build/src/lib.js +10 -26
  14. package/build/src/openai.js +1 -0
  15. package/build/src/provider-factory.d.ts +3 -0
  16. package/build/src/provider-factory.js +38 -0
  17. package/package.json +31 -16
  18. package/build/tests/arb-handler.test.d.ts +0 -1
  19. package/build/tests/arb-handler.test.js +0 -694
  20. package/build/tests/cli-integration.test.d.ts +0 -1
  21. package/build/tests/cli-integration.test.js +0 -352
  22. package/build/tests/csv-handler.test.d.ts +0 -1
  23. package/build/tests/csv-handler.test.js +0 -507
  24. package/build/tests/error-handling.test.d.ts +0 -1
  25. package/build/tests/error-handling.test.js +0 -456
  26. package/build/tests/files-integration.test.d.ts +0 -1
  27. package/build/tests/files-integration.test.js +0 -421
  28. package/build/tests/json-handler.test.d.ts +0 -1
  29. package/build/tests/json-handler.test.js +0 -526
  30. package/build/tests/po-handler.test.d.ts +0 -1
  31. package/build/tests/po-handler.test.js +0 -768
  32. package/build/tests/properties-handler.test.d.ts +0 -1
  33. package/build/tests/properties-handler.test.js +0 -316
  34. package/build/tests/setup.d.ts +0 -1
  35. package/build/tests/setup.js +0 -5
  36. package/build/tests/xliff-handler.test.d.ts +0 -1
  37. package/build/tests/xliff-handler.test.js +0 -459
  38. package/build/tests/xmb-xtb-handler.test.d.ts +0 -1
  39. package/build/tests/xmb-xtb-handler.test.js +0 -758
  40. package/build/tests/xml-handler.test.d.ts +0 -1
  41. package/build/tests/xml-handler.test.js +0 -570
  42. package/build/tests/yaml-handler.test.d.ts +0 -1
  43. package/build/tests/yaml-handler.test.js +0 -156
@@ -123,6 +123,22 @@ function setConfigurationFromEnvironment() {
123
123
  presencePenalty: Number(process.env.ATJ_OPEN_AI_PRESENCE_PENALTY ?? "0"),
124
124
  };
125
125
  }
126
+ // Hugging Face cloud mode (requires API key)
127
+ if (process.env.ATJ_HUGGING_FACE_API_KEY) {
128
+ config.translationKeyInfo = {
129
+ kind: "huggingface",
130
+ apiKey: process.env.ATJ_HUGGING_FACE_API_KEY,
131
+ model: process.env.ATJ_HUGGING_FACE_MODEL ?? "Helsinki-NLP/opus-mt-en-fr",
132
+ provider: process.env.ATJ_HUGGING_FACE_PROVIDER,
133
+ };
134
+ }
135
+ // Hugging Face local mode (no API key, ONNX on-device — takes priority)
136
+ if (process.env.ATJ_HUGGING_FACE_LOCAL_MODEL) {
137
+ config.translationKeyInfo = {
138
+ kind: "huggingface-local",
139
+ model: process.env.ATJ_HUGGING_FACE_LOCAL_MODEL,
140
+ };
141
+ }
126
142
  if (process.env.ATJ_START_DELIMITER) {
127
143
  config.startDelimiter = process.env.ATJ_START_DELIMITER;
128
144
  }
package/build/src/lib.js CHANGED
@@ -1,12 +1,6 @@
1
- // The module 'vscode' contains the VS Code extensibility API
2
- // Import the module and reference it with the alias vscode in your code below
3
- import { AWSTranslate } from "./aws.js";
4
- import { AzureTranslate } from "./azure.js";
5
- import { DeepLTranslate } from "./deepl.js";
6
1
  import { Files } from "./files.js";
7
2
  import { FolderFiles } from "./folderFiles.js";
8
- import { GoogleTranslate } from "./google.js";
9
- import { OpenAITranslate } from "./openai.js";
3
+ import { createTranslateEngine } from "./provider-factory.js";
10
4
  import { Util } from "./util.js";
11
5
  export async function translate(sourceFile, config) {
12
6
  // set the delimiters for named arguments
@@ -19,26 +13,16 @@ export async function translate(sourceFile, config) {
19
13
  Util.endDelimiter = endDelimiter;
20
14
  }
21
15
  let translateEngine;
22
- if (config.translationKeyInfo.kind === "google") {
23
- translateEngine = await GoogleTranslate.initialize(config.translationKeyInfo.apiKey);
24
- }
25
- else if (config.translationKeyInfo.kind === "aws") {
26
- translateEngine = new AWSTranslate(config.translationKeyInfo.accessKeyId, config.translationKeyInfo.secretAccessKey, config.translationKeyInfo.region);
27
- }
28
- else if (config.translationKeyInfo.kind === "azure") {
29
- translateEngine = new AzureTranslate(config.translationKeyInfo.secretKey, config.translationKeyInfo.region);
30
- }
31
- else if (config.translationKeyInfo.kind === "deepLFree") {
32
- translateEngine = new DeepLTranslate(config.translationKeyInfo.secretKey, "free");
33
- }
34
- else if (config.translationKeyInfo.kind === "deepLPro") {
35
- translateEngine = new DeepLTranslate(config.translationKeyInfo.secretKey, "pro");
36
- }
37
- else if (config.translationKeyInfo.kind === "openai") {
38
- translateEngine = new OpenAITranslate(config.translationKeyInfo.apiKey, config.translationKeyInfo.baseUrl, config.translationKeyInfo.model, config.translationKeyInfo.maxTokens, config.translationKeyInfo.temperature, config.translationKeyInfo.topP, config.translationKeyInfo.n, config.translationKeyInfo.presencePenalty, config.translationKeyInfo.frequencyPenalty);
16
+ try {
17
+ translateEngine = await createTranslateEngine(config);
39
18
  }
40
- else {
41
- console.warn("You must provide a Google, AWS, Azure, deepL, openai parameters first in the extension settings.");
19
+ catch (error) {
20
+ if (error instanceof Error) {
21
+ console.warn(error.message);
22
+ }
23
+ else {
24
+ console.warn("You must provide a Google, AWS, Azure, deepL, openai, huggingface, or huggingface-local parameters first in the extension settings.");
25
+ }
42
26
  return;
43
27
  }
44
28
  const fileMode = config.mode ?? "file";
@@ -130,6 +130,7 @@ export class OpenAITranslate {
130
130
  const configuration = {
131
131
  apiKey: apiKey,
132
132
  baseURL: baseUrl,
133
+ timeout: 120000, // 2 minutes timeout for local models like Ollama
133
134
  };
134
135
  this.openai = new OpenAI(configuration);
135
136
  }
@@ -0,0 +1,3 @@
1
+ import type { Configuration } from "./config.js";
2
+ import type { ITranslate } from "./translate.interface.js";
3
+ export declare function createTranslateEngine(config: Configuration): Promise<ITranslate>;
@@ -0,0 +1,38 @@
1
+ export async function createTranslateEngine(config) {
2
+ const { translationKeyInfo } = config;
3
+ if (translationKeyInfo.kind === "google") {
4
+ const { GoogleTranslate } = await import("./google.js");
5
+ return GoogleTranslate.initialize(translationKeyInfo.apiKey);
6
+ }
7
+ else if (translationKeyInfo.kind === "aws") {
8
+ const { AWSTranslate } = await import("./aws.js");
9
+ return new AWSTranslate(translationKeyInfo.accessKeyId, translationKeyInfo.secretAccessKey, translationKeyInfo.region);
10
+ }
11
+ else if (translationKeyInfo.kind === "azure") {
12
+ const { AzureTranslate } = await import("./azure.js");
13
+ return new AzureTranslate(translationKeyInfo.secretKey, translationKeyInfo.region);
14
+ }
15
+ else if (translationKeyInfo.kind === "deepLFree") {
16
+ const { DeepLTranslate } = await import("./deepl.js");
17
+ return new DeepLTranslate(translationKeyInfo.secretKey, "free");
18
+ }
19
+ else if (translationKeyInfo.kind === "deepLPro") {
20
+ const { DeepLTranslate } = await import("./deepl.js");
21
+ return new DeepLTranslate(translationKeyInfo.secretKey, "pro");
22
+ }
23
+ else if (translationKeyInfo.kind === "openai") {
24
+ const { OpenAITranslate } = await import("./openai.js");
25
+ return new OpenAITranslate(translationKeyInfo.apiKey, translationKeyInfo.baseUrl, translationKeyInfo.model, translationKeyInfo.maxTokens, translationKeyInfo.temperature, translationKeyInfo.topP, translationKeyInfo.n, translationKeyInfo.presencePenalty, translationKeyInfo.frequencyPenalty);
26
+ }
27
+ else if (translationKeyInfo.kind === "huggingface") {
28
+ const { HuggingFaceTranslate } = await import("./huggingface.js");
29
+ return new HuggingFaceTranslate(translationKeyInfo.apiKey, translationKeyInfo.model, translationKeyInfo.provider);
30
+ }
31
+ else if (translationKeyInfo.kind === "huggingface-local") {
32
+ const { HuggingFaceLocalTranslate } = await import("./huggingface-local.js");
33
+ return new HuggingFaceLocalTranslate(translationKeyInfo.model);
34
+ }
35
+ else {
36
+ throw new Error("You must provide a Google, AWS, Azure, deepL, openai, huggingface, or huggingface-local parameters first in the extension settings.");
37
+ }
38
+ }
package/package.json CHANGED
@@ -1,8 +1,8 @@
1
1
  {
2
2
  "name": "auto-translate-json-library",
3
- "version": "2.0.2",
3
+ "version": "2.1.0",
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
- "README.md"
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,36 +128,39 @@
116
128
  ],
117
129
  "license": "MIT",
118
130
  "devDependencies": {
119
- "@biomejs/biome": "2.3.11",
120
- "@topce/native-preview": "7.0.0-dev.20250824",
121
- "@types/gettext-parser": "8.0.0",
131
+ "@biomejs/biome": "2.4.8",
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.3",
136
+ "@types/node": "25.5.0",
125
137
  "@types/properties-parser": "0.3.3",
126
138
  "@types/yargs": "17.0.35",
127
- "jest": "30.2.0",
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.962.0",
145
+ "@aws-sdk/client-translate": "3.1014.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.2",
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.2.3",
141
- "fast-xml-parser": "5.3.3",
154
+ "dotenv": "17.3.1",
155
+ "fast-xml-parser": "5.5.8",
142
156
  "form-data": "4.0.5",
143
- "gettext-parser": "9.0.0",
157
+ "gettext-parser": "9.0.2",
144
158
  "js-yaml": "4.1.1",
145
159
  "minimist": "1.2.8",
146
- "openai": "6.15.0",
160
+ "openai": "6.32.0",
147
161
  "picocolors": "1.1.1",
148
162
  "properties-parser": "0.6.0",
163
+ "sharp": "^0.34.5",
149
164
  "uuid": "13.0.0",
150
165
  "yargs": "18.0.0"
151
166
  }
@@ -1 +0,0 @@
1
- export {};