auto-translate-json-library 1.3.7 → 1.3.9
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 +181 -0
- package/build/package.json +71 -0
- package/{src → build/src}/bin/cli.js +2 -2
- package/{src → build/src}/openai.js +12 -4
- package/package.json +69 -69
- /package/{src → build/src}/aws.d.ts +0 -0
- /package/{src → build/src}/aws.js +0 -0
- /package/{src → build/src}/azure.d.ts +0 -0
- /package/{src → build/src}/azure.js +0 -0
- /package/{src → build/src}/bin/cli.d.ts +0 -0
- /package/{src → build/src}/config.d.ts +0 -0
- /package/{src → build/src}/config.js +0 -0
- /package/{src → build/src}/deepl.d.ts +0 -0
- /package/{src → build/src}/deepl.js +0 -0
- /package/{src → build/src}/files.d.ts +0 -0
- /package/{src → build/src}/files.js +0 -0
- /package/{src → build/src}/folderFiles.d.ts +0 -0
- /package/{src → build/src}/folderFiles.js +0 -0
- /package/{src → build/src}/google.d.ts +0 -0
- /package/{src → build/src}/google.js +0 -0
- /package/{src → build/src}/index.d.ts +0 -0
- /package/{src → build/src}/index.js +0 -0
- /package/{src → build/src}/lib.d.ts +0 -0
- /package/{src → build/src}/lib.js +0 -0
- /package/{src → build/src}/openai.d.ts +0 -0
- /package/{src → build/src}/translate.interface.d.ts +0 -0
- /package/{src → build/src}/translate.interface.js +0 -0
- /package/{src → build/src}/util.d.ts +0 -0
- /package/{src → build/src}/util.js +0 -0
package/README.MD
ADDED
|
@@ -0,0 +1,181 @@
|
|
|
1
|
+
# About project
|
|
2
|
+
|
|
3
|
+
This project is used in, (and refactored from) excellent vs code extension
|
|
4
|
+
Auto Translate JSON
|
|
5
|
+
<https://marketplace.visualstudio.com/items?itemName=JeffJorczak.auto-translate-json>
|
|
6
|
+
|
|
7
|
+
It opens possibility to use Auto Translation JSON
|
|
8
|
+
not just in vs code but as a library and command line interface
|
|
9
|
+
|
|
10
|
+
You can use Azure,AWS,Google,DeepL,Open AI or
|
|
11
|
+
local OPEN AI compatible REST API
|
|
12
|
+
for example [jan](https://jan.ai/) local server
|
|
13
|
+
http://localhost:1337/v1
|
|
14
|
+
and model mistral-ins-7b-q4
|
|
15
|
+
|
|
16
|
+
## Use as library
|
|
17
|
+
|
|
18
|
+
```shell
|
|
19
|
+
npm i auto-translate-json-library
|
|
20
|
+
```
|
|
21
|
+
|
|
22
|
+
```Typescript
|
|
23
|
+
import { translate, Configuration } from 'auto-translate-json-library';
|
|
24
|
+
|
|
25
|
+
let config: Configuration = {} as Configuration;
|
|
26
|
+
|
|
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
|
|
35
|
+
```
|
|
36
|
+
|
|
37
|
+
## Use as command line tool
|
|
38
|
+
|
|
39
|
+
first install it
|
|
40
|
+
|
|
41
|
+
```shell
|
|
42
|
+
npm i auto-translate-json-library
|
|
43
|
+
```
|
|
44
|
+
|
|
45
|
+
do not forget to set translation engine parameters in environment variables or .env file
|
|
46
|
+
|
|
47
|
+
```shell
|
|
48
|
+
node node_modules\auto-translate-json-library\index.js --pivotTranslation=./translations/en.json
|
|
49
|
+
```
|
|
50
|
+
|
|
51
|
+
if you clone repo you can use the following commands
|
|
52
|
+
|
|
53
|
+
```shell
|
|
54
|
+
npm i
|
|
55
|
+
npm run build
|
|
56
|
+
node .\build\src\index.js --pivotTranslation=./tests/translations/en.json
|
|
57
|
+
```
|
|
58
|
+
|
|
59
|
+
## CLI PARAMETERS
|
|
60
|
+
|
|
61
|
+
```config
|
|
62
|
+
mode,
|
|
63
|
+
file or folder,
|
|
64
|
+
default is file
|
|
65
|
+
|
|
66
|
+
startDelimiter,
|
|
67
|
+
start delimiter,
|
|
68
|
+
default is {
|
|
69
|
+
|
|
70
|
+
endDelimiter,
|
|
71
|
+
end delimiter,
|
|
72
|
+
default is }
|
|
73
|
+
|
|
74
|
+
keepExtraTranslations,
|
|
75
|
+
keep extra translations (not present in pivot translation),
|
|
76
|
+
default is keep,
|
|
77
|
+
it could be keep or remove
|
|
78
|
+
|
|
79
|
+
keepTranslations,
|
|
80
|
+
keep existing translations,
|
|
81
|
+
default is keep
|
|
82
|
+
it could be keep or retranslate
|
|
83
|
+
|
|
84
|
+
sourceLocale
|
|
85
|
+
source locale
|
|
86
|
+
it could be en or fr ...
|
|
87
|
+
if specified it must match with pivot translation
|
|
88
|
+
|
|
89
|
+
pivotTranslation
|
|
90
|
+
pivot translation file that will be used as source for translations
|
|
91
|
+
|
|
92
|
+
ignorePrefix
|
|
93
|
+
ignore translation that key starts with ignore prefix
|
|
94
|
+
|
|
95
|
+
# ENVIRONMENT VARIABLES
|
|
96
|
+
|
|
97
|
+
google parameters
|
|
98
|
+
ATJ_GOOGLE_API_KEY=
|
|
99
|
+
|
|
100
|
+
aws parameters
|
|
101
|
+
ATJ_AWS_ACCESS_KEY_ID=
|
|
102
|
+
ATJ_AWS_SECRET_ACCESS_KEY=
|
|
103
|
+
ATJ_AWS_REGION=
|
|
104
|
+
|
|
105
|
+
azure parameters
|
|
106
|
+
ATJ_AZURE_SECRET_KEY=
|
|
107
|
+
ATJ_AZURE_REGION=
|
|
108
|
+
|
|
109
|
+
deepl pro parameters
|
|
110
|
+
ATJ_DEEPL_PRO_SECRET_KEY=
|
|
111
|
+
deepl free parameters
|
|
112
|
+
ATJ_DEEPL_FREE_SECRET_KEY=
|
|
113
|
+
|
|
114
|
+
OpenAI parameters
|
|
115
|
+
ATJ_OPEN_AI_SECRET_KEY=
|
|
116
|
+
ATJ_OPEN_AI_BASE_URL=
|
|
117
|
+
default value "https://api.openai.com/v1",
|
|
118
|
+
ATJ_OPEN_AI_MODEL
|
|
119
|
+
default value gpt-3.5-turbo
|
|
120
|
+
ATJ_OPEN_AI_MAX_TOKENS
|
|
121
|
+
default value 256
|
|
122
|
+
ATJ_OPEN_AI_TEMPERATURE
|
|
123
|
+
default value 0
|
|
124
|
+
ATJ_OPEN_AI_TOP_P
|
|
125
|
+
default value 1.0
|
|
126
|
+
ATJ_OPEN_AI_N
|
|
127
|
+
default value 1
|
|
128
|
+
ATJ_OPEN_AI_FREQUENCY_PENALTY
|
|
129
|
+
default value 0
|
|
130
|
+
ATJ_OPEN_AI_PRESENCE_PENALTY
|
|
131
|
+
default value 0
|
|
132
|
+
|
|
133
|
+
If you want to run it locally without using Open AI but compatible API
|
|
134
|
+
you need to modify base URL and model for example
|
|
135
|
+
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
|
|
136
|
+
ATJ_OPEN_AI_SECRET_KEY=whatever
|
|
137
|
+
ATJ_OPEN_AI_BASE_URL=http://localhost:1337/v1
|
|
138
|
+
ATJ_OPEN_AI_MODEL=mistral-ins-7b-q4
|
|
139
|
+
ATJ_OPEN_AI_MAX_TOKENS=4096
|
|
140
|
+
|
|
141
|
+
|
|
142
|
+
start delimiter
|
|
143
|
+
ATJ_START_DELIMITER={{
|
|
144
|
+
end delimiter
|
|
145
|
+
ATJ_END_DELIMITER=}}
|
|
146
|
+
|
|
147
|
+
file or folder
|
|
148
|
+
ATJ_MODE=file
|
|
149
|
+
|
|
150
|
+
source locale
|
|
151
|
+
ATJ_SOURCE_LOCALE=en
|
|
152
|
+
|
|
153
|
+
keep or retranslate existing translations
|
|
154
|
+
ATJ_KEEP_TRANSLATIONS=keep
|
|
155
|
+
|
|
156
|
+
keep or remove extra translations
|
|
157
|
+
ATJ_KEEP_EXTRA_TRANSLATIONS=keep
|
|
158
|
+
|
|
159
|
+
ignore prefix translation keys to ignore
|
|
160
|
+
ATJ_IGNORE_PREFIX=
|
|
161
|
+
```
|
|
162
|
+
|
|
163
|
+
You can also use .env file to store environment variables
|
|
164
|
+
|
|
165
|
+
There is also improved version of CLI (since version 1.3.2) for example:
|
|
166
|
+
|
|
167
|
+
```shell
|
|
168
|
+
npm install -g auto-translate-library
|
|
169
|
+
atj tests/translations/en.json -e google -m file
|
|
170
|
+
```
|
|
171
|
+
|
|
172
|
+
You can also use it with npx
|
|
173
|
+
|
|
174
|
+
```shell
|
|
175
|
+
npx auto-translate-library tests/translations/en.json -e google -m file
|
|
176
|
+
```
|
|
177
|
+
|
|
178
|
+
### Debug
|
|
179
|
+
1. Create .env file in main folder with the desired key/keys from # ENVIRONMENT VARIABLES
|
|
180
|
+
2. Add also in .env source locale "ATJ_SOURCE_LOCALE=en" to test from en
|
|
181
|
+
3. npm run debug
|
|
@@ -0,0 +1,71 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "auto-translate-json-library",
|
|
3
|
+
"version": "1.3.9",
|
|
4
|
+
"description": "Automatically translates JSON language files to other languages using Google Translate,AWS,Azure,DeepL,OpenAI or local OpenAI compatible server",
|
|
5
|
+
"main": "./build/src/index.js",
|
|
6
|
+
"bin": {
|
|
7
|
+
"auto-translate-json-library": "./build/src/bin/cli.js",
|
|
8
|
+
"atj": "./build/src/bin/cli.js"
|
|
9
|
+
},
|
|
10
|
+
"types": "./build/src/index.d.ts",
|
|
11
|
+
"scripts": {
|
|
12
|
+
"prepare": "tsc",
|
|
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",
|
|
16
|
+
"lint": "biome check ./src",
|
|
17
|
+
"lint-fix": "biome check ./src --apply",
|
|
18
|
+
"lint-fix-all": "biome check --apply-unsafe ./src",
|
|
19
|
+
"format": "biome format ./src",
|
|
20
|
+
"format-fix": "biome format ./src --write",
|
|
21
|
+
"start": "ts-node src/index.ts"
|
|
22
|
+
},
|
|
23
|
+
"keywords": [
|
|
24
|
+
"translate",
|
|
25
|
+
"language",
|
|
26
|
+
"json",
|
|
27
|
+
"flutter",
|
|
28
|
+
"angular",
|
|
29
|
+
"ngx-translate",
|
|
30
|
+
"transloco",
|
|
31
|
+
"auto-translate-json",
|
|
32
|
+
"google",
|
|
33
|
+
"Azure",
|
|
34
|
+
"DeepL",
|
|
35
|
+
"OpenAI"
|
|
36
|
+
],
|
|
37
|
+
"author": "codegrue",
|
|
38
|
+
"repository": {
|
|
39
|
+
"type": "git",
|
|
40
|
+
"url": "https://github.com/topce/auto-translate-json-library"
|
|
41
|
+
},
|
|
42
|
+
"contributors": [
|
|
43
|
+
"codegrue",
|
|
44
|
+
"gajo357",
|
|
45
|
+
"topce",
|
|
46
|
+
"BenGMiles",
|
|
47
|
+
"stonega",
|
|
48
|
+
"alexei-petru"
|
|
49
|
+
],
|
|
50
|
+
"license": "MIT",
|
|
51
|
+
"devDependencies": {
|
|
52
|
+
"@biomejs/biome": "1.5.3",
|
|
53
|
+
"@topce/typescript": "5.3.1",
|
|
54
|
+
"@types/minimist": "1.2.5",
|
|
55
|
+
"@types/node": "20.11.24",
|
|
56
|
+
"@types/yargs": "17.0.32",
|
|
57
|
+
"ts-node": "10.9.2"
|
|
58
|
+
},
|
|
59
|
+
"dependencies": {
|
|
60
|
+
"@aws-sdk/client-translate": "3.525.0",
|
|
61
|
+
"@google-cloud/translate": "8.1.0",
|
|
62
|
+
"axios": "1.6.7",
|
|
63
|
+
"dotenv": "16.4.5",
|
|
64
|
+
"form-data": "4.0.0",
|
|
65
|
+
"minimist": "1.2.8",
|
|
66
|
+
"openai": "4.28.4",
|
|
67
|
+
"picocolors": "1.0.0",
|
|
68
|
+
"uuid": "9.0.1",
|
|
69
|
+
"yargs": "17.7.2"
|
|
70
|
+
}
|
|
71
|
+
}
|
|
@@ -108,9 +108,9 @@ switch (engine) {
|
|
|
108
108
|
break;
|
|
109
109
|
}
|
|
110
110
|
case "openai": {
|
|
111
|
-
const openaiApiKey = process.env.
|
|
111
|
+
const openaiApiKey = process.env.ATJ_OPEN_AI_SECRET_KEY;
|
|
112
112
|
if (!openaiApiKey) {
|
|
113
|
-
console.error(picocolors_1.default.red("❌ Openai api key not found in environment variable
|
|
113
|
+
console.error(picocolors_1.default.red("❌ Openai api key not found in environment variable ATJ_OPEN_AI_SECRET_KEY"));
|
|
114
114
|
process.exit(1);
|
|
115
115
|
}
|
|
116
116
|
config.translationKeyInfo = {
|
|
@@ -167,10 +167,18 @@ class OpenAITranslate {
|
|
|
167
167
|
console.log(response.choices[0].message.content);
|
|
168
168
|
}
|
|
169
169
|
catch (_a) {
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
170
|
+
try {
|
|
171
|
+
// for local server sometimes does not return response in json format
|
|
172
|
+
// disable type script compiler for next line
|
|
173
|
+
// @ts-ignore
|
|
174
|
+
response = JSON.parse(response);
|
|
175
|
+
console.log(response.choices[0].message.content);
|
|
176
|
+
}
|
|
177
|
+
catch (error) {
|
|
178
|
+
console.error(error);
|
|
179
|
+
console.log("can not parse response");
|
|
180
|
+
console.log(response);
|
|
181
|
+
}
|
|
174
182
|
}
|
|
175
183
|
if (response.choices[0].message.content !== null) {
|
|
176
184
|
result = util_1.Util.replaceArgumentsWithNumbers(args, response.choices[0].message.content);
|
package/package.json
CHANGED
|
@@ -1,71 +1,71 @@
|
|
|
1
1
|
{
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
2
|
+
"name": "auto-translate-json-library",
|
|
3
|
+
"version": "1.3.9",
|
|
4
|
+
"description": "Automatically translates JSON language files to other languages using Google Translate,AWS,Azure,DeepL,OpenAI or local OpenAI compatible server",
|
|
5
|
+
"main": "./build/src/index.js",
|
|
6
|
+
"bin": {
|
|
7
|
+
"auto-translate-json-library": "./build/src/bin/cli.js",
|
|
8
|
+
"atj": "./build/src/bin/cli.js"
|
|
9
|
+
},
|
|
10
|
+
"types": "./build/src/index.d.ts",
|
|
11
|
+
"scripts": {
|
|
12
|
+
"prepare": "tsc",
|
|
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",
|
|
16
|
+
"lint": "biome check ./src",
|
|
17
|
+
"lint-fix": "biome check ./src --apply",
|
|
18
|
+
"lint-fix-all": "biome check --apply-unsafe ./src",
|
|
19
|
+
"format": "biome format ./src",
|
|
20
|
+
"format-fix": "biome format ./src --write",
|
|
21
|
+
"start": "ts-node src/index.ts"
|
|
22
|
+
},
|
|
23
|
+
"keywords": [
|
|
24
|
+
"translate",
|
|
25
|
+
"language",
|
|
26
|
+
"json",
|
|
27
|
+
"flutter",
|
|
28
|
+
"angular",
|
|
29
|
+
"ngx-translate",
|
|
30
|
+
"transloco",
|
|
31
|
+
"auto-translate-json",
|
|
32
|
+
"google",
|
|
33
|
+
"Azure",
|
|
34
|
+
"DeepL",
|
|
35
|
+
"OpenAI"
|
|
36
|
+
],
|
|
37
|
+
"author": "codegrue",
|
|
38
|
+
"repository": {
|
|
39
|
+
"type": "git",
|
|
40
|
+
"url": "https://github.com/topce/auto-translate-json-library"
|
|
41
|
+
},
|
|
42
|
+
"contributors": [
|
|
43
|
+
"codegrue",
|
|
44
|
+
"gajo357",
|
|
45
|
+
"topce",
|
|
46
|
+
"BenGMiles",
|
|
47
|
+
"stonega",
|
|
48
|
+
"alexei-petru"
|
|
49
|
+
],
|
|
50
|
+
"license": "MIT",
|
|
51
|
+
"devDependencies": {
|
|
52
|
+
"@biomejs/biome": "1.5.3",
|
|
53
|
+
"@topce/typescript": "5.3.1",
|
|
54
|
+
"@types/minimist": "1.2.5",
|
|
55
|
+
"@types/node": "20.11.24",
|
|
56
|
+
"@types/yargs": "17.0.32",
|
|
57
|
+
"ts-node": "10.9.2"
|
|
58
|
+
},
|
|
59
|
+
"dependencies": {
|
|
60
|
+
"@aws-sdk/client-translate": "3.525.0",
|
|
61
|
+
"@google-cloud/translate": "8.1.0",
|
|
62
|
+
"axios": "1.6.7",
|
|
63
|
+
"dotenv": "16.4.5",
|
|
64
|
+
"form-data": "4.0.0",
|
|
65
|
+
"minimist": "1.2.8",
|
|
66
|
+
"openai": "4.28.4",
|
|
67
|
+
"picocolors": "1.0.0",
|
|
68
|
+
"uuid": "9.0.1",
|
|
69
|
+
"yargs": "17.7.2"
|
|
70
|
+
}
|
|
71
71
|
}
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|