auto-translate-json-library 1.3.4 → 1.3.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 CHANGED
@@ -1,10 +1,10 @@
1
- # About project
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 Taransation JSON
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 you can use the following commands
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
- ``` config
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 (since version 1.3.2) for example:
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
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "auto-translate-json-library",
3
- "version": "1.3.4",
3
+ "version": "1.3.5",
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
52
  "@biomejs/biome": "1.2.2",
50
53
  "@topce/typescript": "5.3.1",
51
54
  "@types/minimist": "1.2.3",
52
- "@types/node": "20.8.0",
53
- "@types/yargs": "17.0.26",
55
+ "@types/node": "20.8.6",
56
+ "@types/yargs": "17.0.28",
54
57
  "ts-node": "10.9.1"
55
58
  },
56
59
  "dependencies": {
57
- "@aws-sdk/client-translate": "3.421.0",
60
+ "@aws-sdk/client-translate": "3.428.0",
58
61
  "@google-cloud/translate": "8.0.2",
59
62
  "axios": "1.5.1",
60
63
  "dotenv": "16.3.1",
61
64
  "form-data": "4.0.0",
62
65
  "minimist": "1.2.8",
63
- "openai": "4.11.0",
66
+ "openai": "4.12.1",
64
67
  "picocolors": "1.0.0",
65
68
  "uuid": "9.0.1",
66
69
  "yargs": "17.7.2"
@@ -0,0 +1,141 @@
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 open posibility to use Auto Taransation JSON
8
+ not just in vs code but as a library and command line interface
9
+
10
+ # Use as library
11
+
12
+ ```shell
13
+ npm i auto-translate-json-library
14
+ ```
15
+
16
+ ```Typescript
17
+ import { translate, Configuration } from 'auto-translate-json-library';
18
+
19
+ let config: Configuration = {} as Configuration;
20
+
21
+ // set google api key
22
+ config.translationKeyInfo = {
23
+ kind: 'google',
24
+ apiKey: googleApiKey
25
+ };
26
+ const pivotTranslation="./en.json";
27
+ await translate(pivotTranslation, config) ;
28
+ // translation for example fr.json in same folder as pivotTranslation should contain the translations
29
+ ```
30
+
31
+ # Use as command line tool
32
+
33
+ first install it
34
+
35
+ ```shell
36
+ npm i auto-translate-json-library
37
+ ```
38
+
39
+ do not forget to set translation engine parameters in environment variables or .env file
40
+
41
+ ```shell
42
+
43
+ ```shell
44
+ node node_modules\auto-translate-json-library\index.js --pivotTranslation=./translations/en.json
45
+ ```
46
+
47
+ if you clone repo you can use the following commands
48
+
49
+ ```shell
50
+ npm i
51
+ npm run build
52
+ node .\build\src\index.js --pivotTranslation=./tests/translations/en.json
53
+ ```
54
+
55
+ ```
56
+ # CLI PARAMETERS
57
+
58
+ mode,
59
+ file or folder,
60
+ default is file
61
+
62
+ startDelimiter,
63
+ start delimiter,
64
+ default is {
65
+
66
+ endDelimiter,
67
+ end delimiter,
68
+ default is }
69
+
70
+ keepExtraTranslations,
71
+ keep extra translations (not present in pivot translation),
72
+ default is keep,
73
+ it could be keep or remove
74
+
75
+ keepTranslations,
76
+ keep existing translations,
77
+ default is keep
78
+ it could be keep or retranslate
79
+
80
+ sourceLocale
81
+ source locale
82
+ it could be en or fr ...
83
+ if specified it must match with pivot translation
84
+
85
+ pivotTranslation
86
+ pivot translation file that will be used as source for translations
87
+
88
+ ignorePrefix
89
+ ignore translation that key starts with ignore prefix
90
+
91
+ # ENVIRONMENT VARIABLES
92
+
93
+ google parameters
94
+ ATJ_GOOGLE_API_KEY=
95
+
96
+ aws parameters
97
+ ATJ_AWS_ACCESS_KEY_ID=
98
+ ATJ_AWS_SECRET_ACCESS_KEY=
99
+ ATJ_AWS_REGION=
100
+
101
+ azure parameters
102
+ ATJ_AZURE_SECRET_KEY=
103
+ ATJ_AZURE_REGION=
104
+
105
+ deepl pro parameters
106
+ ATJ_DEEPL_PRO_SECRET_KEY=
107
+ deepl free parameters
108
+ ATJ_DEEPL_FREE_SECRET_KEY=
109
+
110
+ OpenAI parameters
111
+ ATJ_OPEN_AI_SECRET_KEY=
112
+
113
+ start delimiter
114
+ ATJ_START_DELIMITER={{
115
+ end delimiter
116
+ ATJ_END_DELIMITER=}}
117
+
118
+ file or folder
119
+ ATJ_MODE=file
120
+
121
+ source locale
122
+ ATJ_SOURCE_LOCALE=en
123
+
124
+ keep or retranslate existing translations
125
+ ATJ_KEEP_TRANSLATIONS=keep
126
+
127
+ keep or remove extra translations
128
+ ATJ_KEEP_EXTRA_TRANSLATIONS=keep
129
+
130
+ ignore prefix translation keys to ignore
131
+ ATJ_IGNORE_PREFIX=
132
+ ```
133
+
134
+ You can also use .env file to store environment variables
135
+
136
+ There is also improved version of CLI for example:
137
+
138
+ ```shell
139
+ atj tests/translations/en.json -e google -m file
140
+ ```
141
+ since version 1.2.5
@@ -0,0 +1 @@
1
+ import "dotenv/config";
@@ -0,0 +1,128 @@
1
+ "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ const path_1 = __importDefault(require("path"));
7
+ const minimist_1 = __importDefault(require("minimist"));
8
+ const picocolors_1 = __importDefault(require("picocolors"));
9
+ const package_json_1 = require("../package.json");
10
+ const lib_1 = require("./lib");
11
+ require("dotenv/config");
12
+ const arguments_ = process.argv.slice(2);
13
+ const flags = (0, minimist_1.default)(arguments_, {
14
+ alias: {
15
+ mode: ["m"],
16
+ engine: ["e"],
17
+ keepTranslations: ["kt"],
18
+ keepExtraTranslations: ["ket"],
19
+ sourceLocale: ["s"],
20
+ },
21
+ string: ["mode", "engine", "sourceLocale"],
22
+ boolean: ["keepTranslations", "keepExtraTranslations"],
23
+ default: {
24
+ engine: "google",
25
+ sourceLocale: "en",
26
+ keepTranslations: true,
27
+ keepExtraTranslations: true,
28
+ mode: "file",
29
+ },
30
+ });
31
+ console.log(picocolors_1.default.green(`🔨 Auto translate json cli v${package_json_1.version}`));
32
+ const inputPath = flags._[0];
33
+ const { mode, engine, sourceLocale, keepTranslations, keepExtraTranslations } = flags;
34
+ const config = {};
35
+ // set translate engine config
36
+ switch (engine) {
37
+ case "google": {
38
+ const googleApiKey = process.env.ATJ_GOOGLE_API_KEY;
39
+ if (!googleApiKey) {
40
+ console.error(picocolors_1.default.red("❌ Google api key not found in environment variable ATJ_GOOGLE_API_KEY"));
41
+ process.exit(1);
42
+ }
43
+ config.translationKeyInfo = {
44
+ kind: "google",
45
+ apiKey: googleApiKey,
46
+ };
47
+ break;
48
+ }
49
+ case "aws": {
50
+ const awsAccessKeyId = process.env.ATJ_AWS_ACCESS_KEY_ID;
51
+ const awsSecretAccessKey = process.env.ATJ_AWS_SECRET_ACCESS_KEY;
52
+ const awsRegion = process.env.ATJ_AWS_REGION;
53
+ if (!awsAccessKeyId || !awsSecretAccessKey || !awsRegion) {
54
+ console.error(picocolors_1.default.red("❌ AWS credentials not found in environment variables ATJ_AWS_ACCESS_KEY_ID, ATJ_AWS_SECRET_ACCESS_KEY, ATJ_AWS_REGION"));
55
+ process.exit(1);
56
+ }
57
+ config.translationKeyInfo = {
58
+ kind: "aws",
59
+ accessKeyId: awsAccessKeyId,
60
+ secretAccessKey: awsSecretAccessKey,
61
+ region: awsRegion,
62
+ };
63
+ break;
64
+ }
65
+ case "azure": {
66
+ const azureSecretKey = process.env.ATJ_AZURE_SECRET_KEY;
67
+ const azureRegion = process.env.ATJ_AZURE_REGION;
68
+ if (!azureSecretKey || !azureRegion) {
69
+ console.error(picocolors_1.default.red("❌ Azure credentials not found in environment variables ATJ_AZURE_SECRET_KEY, ATJ_AZURE_REGION"));
70
+ process.exit(1);
71
+ }
72
+ config.translationKeyInfo = {
73
+ kind: "azure",
74
+ secretKey: azureSecretKey,
75
+ region: azureRegion,
76
+ };
77
+ break;
78
+ }
79
+ case "openai": {
80
+ const openaiApiKey = process.env.ATJ_OPENAI_API_KEY;
81
+ if (!openaiApiKey) {
82
+ console.error(picocolors_1.default.red("❌ Openai api key not found in environment variable ATJ_OPENAI_API_KEY"));
83
+ process.exit(1);
84
+ }
85
+ config.translationKeyInfo = {
86
+ kind: "openai",
87
+ apiKey: openaiApiKey,
88
+ };
89
+ break;
90
+ }
91
+ case "deepLPro": {
92
+ const deepLProSecretKey = process.env.ATJ_DEEPL_PRO_SECRET_KEY;
93
+ if (!deepLProSecretKey) {
94
+ console.log(picocolors_1.default.red("❌ DeepL pro api key not found in environment variable ATJ_DEEPL_PRO_SECRET_KEY"));
95
+ process.exit(1);
96
+ }
97
+ config.translationKeyInfo = {
98
+ kind: "deepLPro",
99
+ secretKey: deepLProSecretKey,
100
+ };
101
+ break;
102
+ }
103
+ case "deepLFree": {
104
+ const deepLFreeSecretKey = process.env.ATJ_DEEPL_FREE_SECRET_KEY;
105
+ if (!deepLFreeSecretKey) {
106
+ console.error(picocolors_1.default.red("❌ DeepL free api key not found in environment variable ATJ_DEEPL_FREE_SECRET_KEY"));
107
+ process.exit(1);
108
+ }
109
+ config.translationKeyInfo = {
110
+ kind: "deepLFree",
111
+ secretKey: deepLFreeSecretKey,
112
+ };
113
+ break;
114
+ }
115
+ default:
116
+ console.error(picocolors_1.default.red(`❌ Engine ${engine} not supported`));
117
+ process.exit(1);
118
+ }
119
+ config.sourceLocale = sourceLocale;
120
+ config.keepTranslations = keepTranslations ? "keep" : "retranslate";
121
+ config.keepExtraTranslations = keepExtraTranslations ? "keep" : "remove";
122
+ config.mode = mode;
123
+ const sourcePath = path_1.default.join(process.cwd(), inputPath);
124
+ console.log(picocolors_1.default.green(`🌐 Translating ${sourcePath}`));
125
+ (0, lib_1.translate)(sourcePath, config).catch((error) => {
126
+ console.error(picocolors_1.default.red("❌ Translate error:\n"), error);
127
+ process.exit(1);
128
+ });
@@ -72,7 +72,7 @@ class DeepLTranslate {
72
72
  data: formData,
73
73
  responseType: "json",
74
74
  });
75
- result = response.translations[1].text;
75
+ result = response.data.translations[0].text;
76
76
  result = util_1.Util.replaceArgumentsWithNumbers(args, result);
77
77
  return result;
78
78
  });
@@ -0,0 +1,67 @@
1
+ {
2
+ "name": "auto-translate-json-library",
3
+ "version": "1.2.6",
4
+ "description": "Automatically translates JSON language files to other languages using Google Translate,AWS,Azure,DeepL or OpenAI",
5
+ "main": "./index.js",
6
+ "bin": {
7
+ "atj": "./bin/cli.js"
8
+ },
9
+ "types": "./index.d.ts",
10
+ "scripts": {
11
+ "prepare": "tsc",
12
+ "build": "tsc",
13
+ "lint": "biome check ./src",
14
+ "lint-fix": "biome check ./src --apply",
15
+ "lint-fix-all": "biome check --apply-unsafe ./src",
16
+ "format": "biome format ./src",
17
+ "format-fix": "biome format ./src --write",
18
+ "start": "ts-node src/index.ts"
19
+ },
20
+ "keywords": [
21
+ "translate",
22
+ "language",
23
+ "json",
24
+ "flutter",
25
+ "angular",
26
+ "ngx-translate",
27
+ "transloco",
28
+ "auto-translate-json",
29
+ "google",
30
+ "Azure",
31
+ "DeepL",
32
+ "OpenAI"
33
+ ],
34
+ "author": "codegrue",
35
+ "repository": {
36
+ "type": "git",
37
+ "url": "https://github.com/topce/auto-translate-json-library"
38
+ },
39
+ "contributors": [
40
+ "codegrue",
41
+ "gajo357",
42
+ "topce",
43
+ "BenGMiles",
44
+ "stonega"
45
+ ],
46
+ "license": "MIT",
47
+ "devDependencies": {
48
+ "@biomejs/biome": "1.2.2",
49
+ "@topce/typescript": "5.3.1",
50
+ "@types/minimist": "1.2.2",
51
+ "@types/node": "20.6.5",
52
+ "@types/yargs": "17.0.25",
53
+ "ts-node": "10.9.1"
54
+ },
55
+ "dependencies": {
56
+ "@aws-sdk/client-translate": "3.418.0",
57
+ "@google-cloud/translate": "8.0.2",
58
+ "axios": "1.5.0",
59
+ "dotenv": "^16.3.1",
60
+ "form-data": "4.0.0",
61
+ "minimist": "1.2.8",
62
+ "openai": "4.10.0",
63
+ "picocolors": "1.0.0",
64
+ "uuid": "9.0.1",
65
+ "yargs": "17.7.2"
66
+ }
67
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "auto-translate-json-library",
3
- "version": "1.3.4",
3
+ "version": "1.3.5",
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
52
  "@biomejs/biome": "1.2.2",
50
53
  "@topce/typescript": "5.3.1",
51
54
  "@types/minimist": "1.2.3",
52
- "@types/node": "20.8.0",
53
- "@types/yargs": "17.0.26",
55
+ "@types/node": "20.8.6",
56
+ "@types/yargs": "17.0.28",
54
57
  "ts-node": "10.9.1"
55
58
  },
56
59
  "dependencies": {
57
- "@aws-sdk/client-translate": "3.421.0",
60
+ "@aws-sdk/client-translate": "3.428.0",
58
61
  "@google-cloud/translate": "8.0.2",
59
62
  "axios": "1.5.1",
60
63
  "dotenv": "16.3.1",
61
64
  "form-data": "4.0.0",
62
65
  "minimist": "1.2.8",
63
- "openai": "4.11.0",
66
+ "openai": "4.12.1",
64
67
  "picocolors": "1.0.0",
65
68
  "uuid": "9.0.1",
66
69
  "yargs": "17.7.2"