auto-translate-json-library 1.2.4 → 1.2.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
@@ -129,5 +129,13 @@ ATJ_KEEP_EXTRA_TRANSLATIONS=keep
129
129
 
130
130
  ignore prefix translation keys to ignore
131
131
  ATJ_IGNORE_PREFIX=
132
+ ```
132
133
 
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
package/bin/cli.js ADDED
@@ -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
+ });
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "auto-translate-json-library",
3
- "version": "1.2.4",
3
+ "version": "1.2.5",
4
4
  "description": "Automatically translates JSON language files to other languages using Google Translate,AWS,Azure,DeepL or OpenAI",
5
5
  "main": "./index.js",
6
6
  "bin": {
@@ -45,18 +45,18 @@
45
45
  ],
46
46
  "license": "MIT",
47
47
  "devDependencies": {
48
+ "@biomejs/biome": "1.2.2",
48
49
  "@topce/typescript": "5.3.1",
49
50
  "@types/minimist": "1.2.2",
50
51
  "@types/node": "20.6.5",
51
52
  "@types/yargs": "17.0.25",
52
- "@biomejs/biome": "1.2.2",
53
53
  "ts-node": "10.9.1"
54
54
  },
55
55
  "dependencies": {
56
56
  "@aws-sdk/client-translate": "3.418.0",
57
57
  "@google-cloud/translate": "8.0.2",
58
58
  "axios": "1.5.0",
59
- "dotenv": "16.3.1",
59
+ "dotenv": "^16.3.1",
60
60
  "form-data": "4.0.0",
61
61
  "minimist": "1.2.8",
62
62
  "openai": "4.10.0",
package/src/cli.d.ts CHANGED
@@ -1 +1 @@
1
- export {};
1
+ import "dotenv/config";
package/src/cli.js CHANGED
@@ -8,6 +8,7 @@ const minimist_1 = __importDefault(require("minimist"));
8
8
  const picocolors_1 = __importDefault(require("picocolors"));
9
9
  const package_json_1 = require("../package.json");
10
10
  const lib_1 = require("./lib");
11
+ require("dotenv/config");
11
12
  const arguments_ = process.argv.slice(2);
12
13
  const flags = (0, minimist_1.default)(arguments_, {
13
14
  alias: {