auto-translate-json-library 1.3.4 → 1.3.6
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 +11 -6
- package/build/package.json +12 -9
- package/build/src/deepl.js +1 -1
- package/build/src/files.js +2 -2
- package/build/src/lib.js +3 -3
- package/build/src/openai.js +11 -4
- package/package.json +12 -9
package/README.MD
CHANGED
|
@@ -1,10 +1,10 @@
|
|
|
1
|
-
# About
|
|
1
|
+
# About project
|
|
2
2
|
|
|
3
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
|
-
It opens posibility to use Auto
|
|
7
|
+
It opens posibility to use Auto Translation JSON
|
|
8
8
|
not just in vs code but as a library and command line interface
|
|
9
9
|
|
|
10
10
|
## Use as library
|
|
@@ -42,17 +42,17 @@ do not forget to set translation engine parameters in environment variables or .
|
|
|
42
42
|
node node_modules\auto-translate-json-library\index.js --pivotTranslation=./translations/en.json
|
|
43
43
|
```
|
|
44
44
|
|
|
45
|
-
if you clone repo
|
|
45
|
+
if you clone repo you can use the following commands
|
|
46
46
|
|
|
47
47
|
```shell
|
|
48
48
|
npm i
|
|
49
49
|
npm run build
|
|
50
|
-
node .\build\src\index.js --pivotTranslation=./tests/translations/en.json
|
|
50
|
+
node .\build\src\index.js --pivotTranslation=./tests/translations/en.json
|
|
51
51
|
```
|
|
52
52
|
|
|
53
53
|
## CLI PARAMETERS
|
|
54
54
|
|
|
55
|
-
```
|
|
55
|
+
```config
|
|
56
56
|
mode,
|
|
57
57
|
file or folder,
|
|
58
58
|
default is file
|
|
@@ -131,7 +131,7 @@ ATJ_IGNORE_PREFIX=
|
|
|
131
131
|
|
|
132
132
|
You can also use .env file to store environment variables
|
|
133
133
|
|
|
134
|
-
There is also improved version of CLI
|
|
134
|
+
There is also improved version of CLI (since version 1.3.2) for example:
|
|
135
135
|
|
|
136
136
|
```shell
|
|
137
137
|
npm install -g auto-translate-library
|
|
@@ -143,3 +143,8 @@ You can also use it with npx
|
|
|
143
143
|
```shell
|
|
144
144
|
npx auto-translate-library tests/translations/en.json -e google -m file
|
|
145
145
|
```
|
|
146
|
+
|
|
147
|
+
### Debug
|
|
148
|
+
1. Create .env file in main folder with the desired key/keys from # ENVIRONMENT VARIABLES
|
|
149
|
+
2. Add also in .env source locale "ATJ_SOURCE_LOCALE=en" to test from en
|
|
150
|
+
3. npm run debug
|
package/build/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "auto-translate-json-library",
|
|
3
|
-
"version": "1.3.
|
|
3
|
+
"version": "1.3.6",
|
|
4
4
|
"description": "Automatically translates JSON language files to other languages using Google Translate,AWS,Azure,DeepL or OpenAI",
|
|
5
5
|
"main": "./build/src/index.js",
|
|
6
6
|
"bin": {
|
|
@@ -11,6 +11,8 @@
|
|
|
11
11
|
"scripts": {
|
|
12
12
|
"prepare": "tsc",
|
|
13
13
|
"build": "tsc",
|
|
14
|
+
"build:run": "ts-node ./build/src/index.js --pivotTranslation=./tests/translations/en.json",
|
|
15
|
+
"debug": "ts-node src/index.ts --pivotTranslation=./tests/translations/en.json",
|
|
14
16
|
"lint": "biome check ./src",
|
|
15
17
|
"lint-fix": "biome check ./src --apply",
|
|
16
18
|
"lint-fix-all": "biome check --apply-unsafe ./src",
|
|
@@ -42,25 +44,26 @@
|
|
|
42
44
|
"gajo357",
|
|
43
45
|
"topce",
|
|
44
46
|
"BenGMiles",
|
|
45
|
-
"stonega"
|
|
47
|
+
"stonega",
|
|
48
|
+
"alexei-petru"
|
|
46
49
|
],
|
|
47
50
|
"license": "MIT",
|
|
48
51
|
"devDependencies": {
|
|
49
|
-
"@biomejs/biome": "1.
|
|
52
|
+
"@biomejs/biome": "1.3.1",
|
|
50
53
|
"@topce/typescript": "5.3.1",
|
|
51
|
-
"@types/minimist": "1.2.
|
|
52
|
-
"@types/node": "20.8.
|
|
53
|
-
"@types/yargs": "17.0.
|
|
54
|
+
"@types/minimist": "1.2.4",
|
|
55
|
+
"@types/node": "20.8.9",
|
|
56
|
+
"@types/yargs": "17.0.29",
|
|
54
57
|
"ts-node": "10.9.1"
|
|
55
58
|
},
|
|
56
59
|
"dependencies": {
|
|
57
|
-
"@aws-sdk/client-translate": "3.
|
|
60
|
+
"@aws-sdk/client-translate": "3.438.0",
|
|
58
61
|
"@google-cloud/translate": "8.0.2",
|
|
59
|
-
"axios": "1.
|
|
62
|
+
"axios": "1.6.0",
|
|
60
63
|
"dotenv": "16.3.1",
|
|
61
64
|
"form-data": "4.0.0",
|
|
62
65
|
"minimist": "1.2.8",
|
|
63
|
-
"openai": "4.
|
|
66
|
+
"openai": "4.14.1",
|
|
64
67
|
"picocolors": "1.0.0",
|
|
65
68
|
"uuid": "9.0.1",
|
|
66
69
|
"yargs": "17.7.2"
|
package/build/src/deepl.js
CHANGED
package/build/src/files.js
CHANGED
|
@@ -71,12 +71,12 @@ class Files {
|
|
|
71
71
|
getTargetLocales() {
|
|
72
72
|
const locales = new Array();
|
|
73
73
|
const files = fs.readdirSync(this.folderPath);
|
|
74
|
-
|
|
74
|
+
for (const file of files) {
|
|
75
75
|
const locale = this.getLocaleFromFilename(file);
|
|
76
76
|
if (locale !== this.sourceLocale) {
|
|
77
77
|
locales.push(locale);
|
|
78
78
|
}
|
|
79
|
-
}
|
|
79
|
+
}
|
|
80
80
|
return locales;
|
|
81
81
|
}
|
|
82
82
|
loadJsonFromLocale(locale) {
|
package/build/src/lib.js
CHANGED
|
@@ -78,7 +78,7 @@ function translate(sourceFile, config) {
|
|
|
78
78
|
return;
|
|
79
79
|
}
|
|
80
80
|
// Iterate target Locales
|
|
81
|
-
|
|
81
|
+
for (const targetLocale of files.targetLocales) {
|
|
82
82
|
try {
|
|
83
83
|
const isValid = yield translateEngine.isValidLocale(targetLocale);
|
|
84
84
|
if (!isValid) {
|
|
@@ -98,7 +98,7 @@ function translate(sourceFile, config) {
|
|
|
98
98
|
}
|
|
99
99
|
return;
|
|
100
100
|
}
|
|
101
|
-
}
|
|
101
|
+
}
|
|
102
102
|
});
|
|
103
103
|
}
|
|
104
104
|
exports.translate = translate;
|
|
@@ -132,7 +132,7 @@ function recurseNode(source, original, keepTranslations, keepExtras, sourceLocal
|
|
|
132
132
|
for (const term in source) {
|
|
133
133
|
const node = source[term];
|
|
134
134
|
if (node instanceof Object && node !== null) {
|
|
135
|
-
destination[term] = yield recurseNode(node, (_a = original[term]) !== null && _a !== void 0 ? _a : {}, keepTranslations, keepExtras, sourceLocale, locale, translateEngine, ignorePrefix, node
|
|
135
|
+
destination[term] = yield recurseNode(node, (_a = original[term]) !== null && _a !== void 0 ? _a : {}, keepTranslations, keepExtras, sourceLocale, locale, translateEngine, ignorePrefix, Array.isArray(node));
|
|
136
136
|
}
|
|
137
137
|
else {
|
|
138
138
|
// if we already have a translation, keep it
|
package/build/src/openai.js
CHANGED
|
@@ -140,11 +140,15 @@ class OpenAITranslate {
|
|
|
140
140
|
let result = "";
|
|
141
141
|
let args;
|
|
142
142
|
({ args, text } = util_1.Util.replaceContextVariables(text));
|
|
143
|
-
const
|
|
143
|
+
const systemPrompt = `You will be provided with a sentence in English, and your task is to translate it into ${supportedLanguages[targetLocale]}`;
|
|
144
|
+
const userPrompt = text;
|
|
144
145
|
const response = yield this.openai.chat.completions.create({
|
|
145
146
|
model: "text-davinci-003",
|
|
146
|
-
messages: [
|
|
147
|
-
|
|
147
|
+
messages: [
|
|
148
|
+
{ role: "system", content: systemPrompt },
|
|
149
|
+
{ role: "user", content: userPrompt },
|
|
150
|
+
],
|
|
151
|
+
temperature: 0,
|
|
148
152
|
max_tokens: 250,
|
|
149
153
|
top_p: 1.0,
|
|
150
154
|
n: 1,
|
|
@@ -156,7 +160,10 @@ class OpenAITranslate {
|
|
|
156
160
|
result = result.replace(/^\n+|\n+$/g, "");
|
|
157
161
|
}
|
|
158
162
|
else {
|
|
159
|
-
console.error(`can not translate text with
|
|
163
|
+
console.error(`can not translate text with
|
|
164
|
+
system prompt : ${systemPrompt}
|
|
165
|
+
and
|
|
166
|
+
user prompt : ${userPrompt} `);
|
|
160
167
|
result = util_1.Util.replaceArgumentsWithNumbers(args, result);
|
|
161
168
|
}
|
|
162
169
|
return result;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "auto-translate-json-library",
|
|
3
|
-
"version": "1.3.
|
|
3
|
+
"version": "1.3.6",
|
|
4
4
|
"description": "Automatically translates JSON language files to other languages using Google Translate,AWS,Azure,DeepL or OpenAI",
|
|
5
5
|
"main": "./build/src/index.js",
|
|
6
6
|
"bin": {
|
|
@@ -11,6 +11,8 @@
|
|
|
11
11
|
"scripts": {
|
|
12
12
|
"prepare": "tsc",
|
|
13
13
|
"build": "tsc",
|
|
14
|
+
"build:run": "ts-node ./build/src/index.js --pivotTranslation=./tests/translations/en.json",
|
|
15
|
+
"debug": "ts-node src/index.ts --pivotTranslation=./tests/translations/en.json",
|
|
14
16
|
"lint": "biome check ./src",
|
|
15
17
|
"lint-fix": "biome check ./src --apply",
|
|
16
18
|
"lint-fix-all": "biome check --apply-unsafe ./src",
|
|
@@ -42,25 +44,26 @@
|
|
|
42
44
|
"gajo357",
|
|
43
45
|
"topce",
|
|
44
46
|
"BenGMiles",
|
|
45
|
-
"stonega"
|
|
47
|
+
"stonega",
|
|
48
|
+
"alexei-petru"
|
|
46
49
|
],
|
|
47
50
|
"license": "MIT",
|
|
48
51
|
"devDependencies": {
|
|
49
|
-
"@biomejs/biome": "1.
|
|
52
|
+
"@biomejs/biome": "1.3.1",
|
|
50
53
|
"@topce/typescript": "5.3.1",
|
|
51
|
-
"@types/minimist": "1.2.
|
|
52
|
-
"@types/node": "20.8.
|
|
53
|
-
"@types/yargs": "17.0.
|
|
54
|
+
"@types/minimist": "1.2.4",
|
|
55
|
+
"@types/node": "20.8.9",
|
|
56
|
+
"@types/yargs": "17.0.29",
|
|
54
57
|
"ts-node": "10.9.1"
|
|
55
58
|
},
|
|
56
59
|
"dependencies": {
|
|
57
|
-
"@aws-sdk/client-translate": "3.
|
|
60
|
+
"@aws-sdk/client-translate": "3.438.0",
|
|
58
61
|
"@google-cloud/translate": "8.0.2",
|
|
59
|
-
"axios": "1.
|
|
62
|
+
"axios": "1.6.0",
|
|
60
63
|
"dotenv": "16.3.1",
|
|
61
64
|
"form-data": "4.0.0",
|
|
62
65
|
"minimist": "1.2.8",
|
|
63
|
-
"openai": "4.
|
|
66
|
+
"openai": "4.14.1",
|
|
64
67
|
"picocolors": "1.0.0",
|
|
65
68
|
"uuid": "9.0.1",
|
|
66
69
|
"yargs": "17.7.2"
|