auto-translate-json-library 2.1.0 → 2.3.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.
package/README.MD CHANGED
@@ -1,5 +1,7 @@
1
1
  # Auto Translate JSON Library
2
2
 
3
+ [![GitHub Sponsors](https://img.shields.io/github/sponsors/topce?color=ea4aaa&label=Sponsor&logo=github)](https://github.com/sponsors/topce)
4
+
3
5
  This project is used in, (and refactored from) excellent VS Code extension
4
6
  Auto Translate JSON
5
7
  <https://marketplace.visualstudio.com/items?itemName=JeffJorczak.auto-translate-json>
@@ -13,15 +15,19 @@ for example [ollama](https://ollama.com/)
13
15
  because it is compatible with OpenAI https://ollama.com/blog/openai-compatibility
14
16
  or [Hugging Face](https://huggingface.co/) (cloud API or fully local on-device inference)
15
17
 
16
- ## 🚀 Version 2.0.0 - Major Release
18
+ ## 💖 Sponsor this Project
17
19
 
18
- This major release brings comprehensive improvements including:
19
- - **ES Modules support** for modern JavaScript compatibility
20
- - **Enhanced validation system** with detailed error reporting and recovery
21
- - **Expanded format support** with robust handling for all major translation formats
22
- - **Complete demo system** with interactive examples
23
- - **Comprehensive test suite** with 100% format handler coverage
24
- - **Security updates** for all dependencies
20
+ If you find this library valuable and would like to support its ongoing development, please consider sponsoring the project on GitHub.
21
+
22
+ **Sponsor via GitHub Sponsors:** [https://github.com/sponsors/topce](https://github.com/sponsors/topce)
23
+
24
+ Your sponsorship helps with:
25
+ - Ongoing maintenance and bug fixes
26
+ - Adding new features and translation services
27
+ - Supporting open-source development
28
+ - Keeping the library up-to-date with the latest translation APIs
29
+
30
+ Even a small monthly contribution makes a big difference in ensuring this project remains actively maintained and continues to improve.
25
31
 
26
32
  ## ⚡ Version 2.1.0 - Performance & CLI Improvements
27
33
 
@@ -50,6 +56,16 @@ This release focuses on performance optimization and enhanced developer experien
50
56
  - **After**: Only needed SDK loads on demand
51
57
  - **Result**: 70% faster startup, 80% lower memory for most use cases
52
58
 
59
+ ## 🚀 Version 2.0.0 - Major Release
60
+
61
+ This major release brings comprehensive improvements including:
62
+ - **ES Modules support** for modern JavaScript compatibility
63
+ - **Enhanced validation system** with detailed error reporting and recovery
64
+ - **Expanded format support** with robust handling for all major translation formats
65
+ - **Complete demo system** with interactive examples
66
+ - **Comprehensive test suite** with 100% format handler coverage
67
+ - **Security updates** for all dependencies
68
+
53
69
  ## Use as Library
54
70
 
55
71
  ```shell
@@ -543,6 +559,12 @@ This will run translations on sample files in multiple formats (JSON, XML, YAML,
543
559
 
544
560
  ## Contribute
545
561
 
562
+ There are several ways to contribute to this project:
563
+
564
+ ### 💖 Financial Support
565
+ If you find this library valuable in your projects, consider supporting its development through [GitHub Sponsors](https://github.com/sponsors/topce). Your sponsorship helps ensure ongoing maintenance, bug fixes, and new features.
566
+
567
+ ### 🛠️ Code Contributions
546
568
  Clone repo and use the following commands:
547
569
 
548
570
  1. Install ollama and run `ollama run llama2`
@@ -1,12 +1,12 @@
1
1
  {
2
2
  "name": "auto-translate-json-library",
3
- "version": "2.1.0",
3
+ "version": "2.3.0",
4
4
  "type": "module",
5
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
- "auto-translate-json-library": "build/src/bin/cli.js",
9
- "atj": "build/src/bin/cli.js"
8
+ "auto-translate-json-library": "./build/src/bin/cli.js",
9
+ "atj": "./build/src/bin/cli.js"
10
10
  },
11
11
  "types": "./build/src/index.d.ts",
12
12
  "files": [
@@ -128,40 +128,40 @@
128
128
  ],
129
129
  "license": "MIT",
130
130
  "devDependencies": {
131
- "@biomejs/biome": "2.4.8",
132
- "@topce/native-preview": "7.0.0-dev.20260215",
131
+ "@biomejs/biome": "2.5.6",
132
+ "@topce/native-preview": "7.0.3",
133
133
  "@types/gettext-parser": "9.0.0",
134
134
  "@types/jest": "30.0.0",
135
135
  "@types/minimist": "1.2.5",
136
- "@types/node": "25.5.0",
136
+ "@types/node": "26.1.2",
137
137
  "@types/properties-parser": "0.3.3",
138
138
  "@types/yargs": "17.0.35",
139
- "jest": "30.3.0",
140
- "ts-jest": "29.4.6",
139
+ "jest": "30.4.2",
140
+ "ts-jest": "29.4.12",
141
141
  "ts-node": "10.9.2",
142
- "typescript": "5.9.3"
142
+ "typescript": "6.0.3"
143
143
  },
144
144
  "dependencies": {
145
- "@aws-sdk/client-translate": "3.1014.0",
146
- "@google-cloud/translate": "9.3.0",
147
- "@huggingface/inference": "^4.13.15",
148
- "@huggingface/transformers": "^3.8.1",
145
+ "@aws-sdk/client-translate": "3.1100.0",
146
+ "@google-cloud/translate": "9.4.2",
147
+ "@huggingface/inference": "^4.13.24",
148
+ "@huggingface/transformers": "^4.2.0",
149
149
  "@types/js-yaml": "4.0.9",
150
- "axios": "1.13.6",
151
- "csv-parser": "3.2.0",
150
+ "axios": "1.19.0",
151
+ "csv-parser": "3.2.1",
152
152
  "csv-writer": "1.6.0",
153
- "deepl-node": "1.24.0",
154
- "dotenv": "17.3.1",
155
- "fast-xml-parser": "5.5.8",
156
- "form-data": "4.0.5",
157
- "gettext-parser": "9.0.2",
158
- "js-yaml": "4.1.1",
153
+ "deepl-node": "1.27.0",
154
+ "dotenv": "17.4.2",
155
+ "fast-xml-parser": "5.10.1",
156
+ "form-data": "4.0.6",
157
+ "gettext-parser": "9.1.1",
158
+ "js-yaml": "4.3.1",
159
159
  "minimist": "1.2.8",
160
- "openai": "6.32.0",
160
+ "openai": "7.3.0",
161
161
  "picocolors": "1.1.1",
162
162
  "properties-parser": "0.6.0",
163
- "sharp": "^0.34.5",
164
- "uuid": "13.0.0",
165
- "yargs": "18.0.0"
163
+ "sharp": "^0.35.3",
164
+ "uuid": "14.0.1",
165
+ "yargs": "18.1.0"
166
166
  }
167
167
  }
File without changes
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,170 @@
1
+ import { config as dotenvConfig } from "dotenv";
2
+ import minimist from "minimist";
3
+ import { translate } from "./lib.js";
4
+ const config = {};
5
+ setDefaultConfiguration();
6
+ console.log(config);
7
+ try {
8
+ setConfigurationFromEnvironment();
9
+ }
10
+ catch (error) {
11
+ console.log(config);
12
+ console.log(error);
13
+ }
14
+ try {
15
+ setConfigurationFromCLI();
16
+ }
17
+ catch (error) {
18
+ console.log(config);
19
+ console.log(error);
20
+ }
21
+ function setConfigurationFromCLI() {
22
+ const argv = minimist(process.argv.slice(2));
23
+ if (argv === undefined) {
24
+ console.log("No arguments provided in CLI");
25
+ return;
26
+ }
27
+ if (argv.mode === "file") {
28
+ config.mode = "file";
29
+ }
30
+ else if (argv.mode === "folder") {
31
+ config.mode = "folder";
32
+ }
33
+ if (argv.startDelimiter !== undefined) {
34
+ config.startDelimiter = argv.startDelimiter;
35
+ }
36
+ if (argv.endDelimiter !== undefined) {
37
+ config.endDelimiter = argv.endDelimiter;
38
+ }
39
+ if (argv.keepExtraTranslations === "keep") {
40
+ config.keepExtraTranslations = "keep";
41
+ }
42
+ else if (argv.keepExtraTranslations === "remove") {
43
+ config.keepExtraTranslations = "remove";
44
+ }
45
+ if (argv.keepTranslations === "keep") {
46
+ config.keepTranslations = "keep";
47
+ }
48
+ else if (argv.keepTranslations === "retranslate") {
49
+ config.keepTranslations = "retranslate";
50
+ }
51
+ if (argv.sourceLocale !== undefined) {
52
+ config.sourceLocale = argv.sourceLocale;
53
+ }
54
+ if (argv.ignorePrefix !== undefined) {
55
+ config.ignorePrefix = argv.ignorePrefix;
56
+ }
57
+ if (argv.pivotTranslation !== undefined) {
58
+ translate(argv.pivotTranslation, config);
59
+ }
60
+ else {
61
+ console.log(argv);
62
+ console.log("Please provide a pivot translation");
63
+ }
64
+ }
65
+ function setDefaultConfiguration() {
66
+ config.mode = "file";
67
+ config.startDelimiter = "{";
68
+ config.endDelimiter = "}";
69
+ config.keepExtraTranslations = "keep";
70
+ config.keepTranslations = "keep";
71
+ config.sourceLocale = "en";
72
+ config.ignorePrefix = "";
73
+ }
74
+ function setConfigurationFromEnvironment() {
75
+ dotenvConfig();
76
+ if (process.env.ATJ_GOOGLE_API_KEY) {
77
+ config.translationKeyInfo = {
78
+ kind: "google",
79
+ apiKey: process.env.ATJ_GOOGLE_API_KEY,
80
+ };
81
+ }
82
+ if (process.env.ATJ_AWS_ACCESS_KEY_ID &&
83
+ process.env.ATJ_AWS_SECRET_ACCESS_KEY &&
84
+ process.env.ATJ_AWS_REGION) {
85
+ config.translationKeyInfo = {
86
+ kind: "aws",
87
+ accessKeyId: process.env.ATJ_AWS_ACCESS_KEY_ID,
88
+ secretAccessKey: process.env.ATJ_AWS_SECRET_ACCESS_KEY,
89
+ region: process.env.ATJ_AWS_REGION,
90
+ };
91
+ }
92
+ if (process.env.ATJ_AZURE_SECRET_KEY && process.env.ATJ_AZURE_REGION) {
93
+ config.translationKeyInfo = {
94
+ kind: "azure",
95
+ secretKey: process.env.ATJ_AZURE_SECRET_KEY,
96
+ region: process.env.ATJ_AZURE_REGION,
97
+ };
98
+ }
99
+ if (process.env.ATJ_DEEPL_PRO_SECRET_KEY) {
100
+ config.translationKeyInfo = {
101
+ kind: "deepLPro",
102
+ secretKey: process.env.ATJ_DEEPL_PRO_SECRET_KEY,
103
+ };
104
+ }
105
+ if (process.env.ATJ_DEEPL_FREE_SECRET_KEY) {
106
+ config.translationKeyInfo = {
107
+ kind: "deepLFree",
108
+ secretKey: process.env.ATJ_DEEPL_FREE_SECRET_KEY,
109
+ };
110
+ }
111
+ if (process.env.ATJ_OPEN_AI_SECRET_KEY) {
112
+ config.translationKeyInfo = {
113
+ kind: "openai",
114
+ apiKey: process.env.ATJ_OPEN_AI_SECRET_KEY,
115
+ baseUrl: process.env.ATJ_OPEN_AI_BASE_URL ?? "https://api.openai.com/v1",
116
+ model: process.env.ATJ_OPEN_AI_MODEL ?? "gpt-3.5-turbo",
117
+ maxTokens: Number(process.env.ATJ_OPEN_AI_MAX_TOKENS ?? "256"),
118
+ temperature: Number(process.env.ATJ_OPEN_AI_TEMPERATURE ?? "0.7"),
119
+ topP: Number(process.env.ATJ_OPEN_AI_TOP_P ?? "0.9"),
120
+ n: Number(process.env.ATJ_OPEN_AI_N ?? "1"),
121
+ frequencyPenalty: Number(process.env.ATJ_OPEN_AI_FREQUENCY_PENALTY ?? "0"),
122
+ presencePenalty: Number(process.env.ATJ_OPEN_AI_PRESENCE_PENALTY ?? "0"),
123
+ };
124
+ }
125
+ // Hugging Face cloud mode (requires API key)
126
+ if (process.env.ATJ_HUGGING_FACE_API_KEY) {
127
+ config.translationKeyInfo = {
128
+ kind: "huggingface",
129
+ apiKey: process.env.ATJ_HUGGING_FACE_API_KEY,
130
+ model: process.env.ATJ_HUGGING_FACE_MODEL ?? "Helsinki-NLP/opus-mt-en-fr",
131
+ provider: process.env.ATJ_HUGGING_FACE_PROVIDER,
132
+ };
133
+ }
134
+ // Hugging Face local mode (no API key, ONNX on-device — takes priority)
135
+ if (process.env.ATJ_HUGGING_FACE_LOCAL_MODEL) {
136
+ config.translationKeyInfo = {
137
+ kind: "huggingface-local",
138
+ model: process.env.ATJ_HUGGING_FACE_LOCAL_MODEL,
139
+ };
140
+ }
141
+ if (process.env.ATJ_START_DELIMITER) {
142
+ config.startDelimiter = process.env.ATJ_START_DELIMITER;
143
+ }
144
+ if (process.env.ATJ_END_DELIMITER) {
145
+ config.endDelimiter = process.env.ATJ_END_DELIMITER;
146
+ }
147
+ if (process.env.ATJ_END_DELIMITER) {
148
+ config.endDelimiter = process.env.ATJ_END_DELIMITER;
149
+ }
150
+ if (process.env.ATJ_MODE &&
151
+ (process.env.ATJ_MODE === "file" || process.env.ATJ_MODE === "folder")) {
152
+ config.mode = process.env.ATJ_MODE;
153
+ }
154
+ if (process.env.ATJ_SOURCE_LOCALE) {
155
+ config.sourceLocale = process.env.ATJ_SOURCE_LOCALE;
156
+ }
157
+ if (process.env.ATJ_KEEP_TRANSLATIONS &&
158
+ (process.env.ATJ_KEEP_TRANSLATIONS === "keep" ||
159
+ process.env.ATJ_KEEP_TRANSLATIONS === "retranslate")) {
160
+ config.keepTranslations = process.env.ATJ_KEEP_TRANSLATIONS;
161
+ }
162
+ if (process.env.ATJ_KEEP_EXTRA_TRANSLATIONS &&
163
+ (process.env.ATJ_KEEP_EXTRA_TRANSLATIONS === "keep" ||
164
+ process.env.ATJ_KEEP_EXTRA_TRANSLATIONS === "remove")) {
165
+ config.keepExtraTranslations = process.env.ATJ_KEEP_EXTRA_TRANSLATIONS;
166
+ }
167
+ if (process.env.ATJ_IGNORE_PREFIX && process.env.ATJ_IGNORE_PREFIX !== "") {
168
+ config.ignorePrefix = process.env.ATJ_IGNORE_PREFIX;
169
+ }
170
+ }
@@ -141,25 +141,14 @@ export class OpenAITranslate {
141
141
  if (sourceLocale !== "en") {
142
142
  throw Error(`${sourceLocale} is not supported.Currently we support just English `);
143
143
  }
144
- // DEBUG: Log what text is being sent for translation
145
- console.log(`🔍 DEBUG - Translating text: "${text}" (length: ${text.length})`);
146
- console.log(`🔍 DEBUG - Source locale: ${sourceLocale}, Target locale: ${targetLocale}`);
147
- if (context) {
148
- console.log(`🔍 DEBUG - Context: ${context}`);
149
- }
150
144
  let result = "";
151
145
  let args;
152
146
  ({ args, text } = Util.replaceContextVariables(text));
153
- // DEBUG: Log text after context variable replacement
154
- console.log(`🔍 DEBUG - Text after context replacement: "${text}" (length: ${text.length})`);
155
147
  let systemPrompt = `You will be provided with a sentence or words in English, and your task is to translate it into ${supportedLanguages[targetLocale]}. Return ONLY the translation, without any additional text or explanations.`;
156
148
  if (context) {
157
149
  systemPrompt += `\nContext for the translation: ${context}`;
158
150
  }
159
151
  const userPrompt = text;
160
- // DEBUG: Log the prompts being sent
161
- console.log(`🔍 DEBUG - System prompt: "${systemPrompt}"`);
162
- console.log(`🔍 DEBUG - User prompt: "${userPrompt}"`);
163
152
  const response = await this.openai.chat.completions.create({
164
153
  model: this.model,
165
154
  messages: [
@@ -176,8 +165,6 @@ export class OpenAITranslate {
176
165
  if (response.choices[0].message.content !== null) {
177
166
  result = Util.replaceArgumentsWithNumbers(args, response.choices[0].message.content);
178
167
  result = result.replace(/^\n+|\n+$/g, "");
179
- // DEBUG: Log the translation result
180
- console.log(`🔍 DEBUG - Translation result: "${result}"`);
181
168
  }
182
169
  else {
183
170
  console.error(`can not translate text with
package/package.json CHANGED
@@ -1,12 +1,12 @@
1
1
  {
2
2
  "name": "auto-translate-json-library",
3
- "version": "2.1.0",
3
+ "version": "2.3.0",
4
4
  "type": "module",
5
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
- "auto-translate-json-library": "build/src/bin/cli.js",
9
- "atj": "build/src/bin/cli.js"
8
+ "auto-translate-json-library": "./build/src/bin/cli.js",
9
+ "atj": "./build/src/bin/cli.js"
10
10
  },
11
11
  "types": "./build/src/index.d.ts",
12
12
  "files": [
@@ -128,40 +128,40 @@
128
128
  ],
129
129
  "license": "MIT",
130
130
  "devDependencies": {
131
- "@biomejs/biome": "2.4.8",
132
- "@topce/native-preview": "7.0.0-dev.20260215",
131
+ "@biomejs/biome": "2.5.6",
132
+ "@topce/native-preview": "7.0.3",
133
133
  "@types/gettext-parser": "9.0.0",
134
134
  "@types/jest": "30.0.0",
135
135
  "@types/minimist": "1.2.5",
136
- "@types/node": "25.5.0",
136
+ "@types/node": "26.1.2",
137
137
  "@types/properties-parser": "0.3.3",
138
138
  "@types/yargs": "17.0.35",
139
- "jest": "30.3.0",
140
- "ts-jest": "29.4.6",
139
+ "jest": "30.4.2",
140
+ "ts-jest": "29.4.12",
141
141
  "ts-node": "10.9.2",
142
- "typescript": "5.9.3"
142
+ "typescript": "6.0.3"
143
143
  },
144
144
  "dependencies": {
145
- "@aws-sdk/client-translate": "3.1014.0",
146
- "@google-cloud/translate": "9.3.0",
147
- "@huggingface/inference": "^4.13.15",
148
- "@huggingface/transformers": "^3.8.1",
145
+ "@aws-sdk/client-translate": "3.1100.0",
146
+ "@google-cloud/translate": "9.4.2",
147
+ "@huggingface/inference": "^4.13.24",
148
+ "@huggingface/transformers": "^4.2.0",
149
149
  "@types/js-yaml": "4.0.9",
150
- "axios": "1.13.6",
151
- "csv-parser": "3.2.0",
150
+ "axios": "1.19.0",
151
+ "csv-parser": "3.2.1",
152
152
  "csv-writer": "1.6.0",
153
- "deepl-node": "1.24.0",
154
- "dotenv": "17.3.1",
155
- "fast-xml-parser": "5.5.8",
156
- "form-data": "4.0.5",
157
- "gettext-parser": "9.0.2",
158
- "js-yaml": "4.1.1",
153
+ "deepl-node": "1.27.0",
154
+ "dotenv": "17.4.2",
155
+ "fast-xml-parser": "5.10.1",
156
+ "form-data": "4.0.6",
157
+ "gettext-parser": "9.1.1",
158
+ "js-yaml": "4.3.1",
159
159
  "minimist": "1.2.8",
160
- "openai": "6.32.0",
160
+ "openai": "7.3.0",
161
161
  "picocolors": "1.1.1",
162
162
  "properties-parser": "0.6.0",
163
- "sharp": "^0.34.5",
164
- "uuid": "13.0.0",
165
- "yargs": "18.0.0"
163
+ "sharp": "^0.35.3",
164
+ "uuid": "14.0.1",
165
+ "yargs": "18.1.0"
166
166
  }
167
167
  }