auto-translate-json-library 1.2.6 → 1.2.7
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/bin/cli.js +2 -128
- package/cli.d.ts +1 -1
- package/cli.js +1 -1
- package/index.js +1 -1
- package/package.json +10 -9
- /package/{README.MD → README.md} +0 -0
package/bin/cli.js
CHANGED
|
@@ -1,128 +1,2 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
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
|
-
});
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
import('../build/src/cli.js')
|
package/cli.d.ts
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
|
|
1
|
+
export {};
|
package/cli.js
CHANGED
|
@@ -8,7 +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
|
|
11
|
+
require("dotenv").config();
|
|
12
12
|
const arguments_ = process.argv.slice(2);
|
|
13
13
|
const flags = (0, minimist_1.default)(arguments_, {
|
|
14
14
|
alias: {
|
package/index.js
CHANGED
|
@@ -7,7 +7,7 @@ const config = {};
|
|
|
7
7
|
setDefaultConfiguration();
|
|
8
8
|
setConfigurationFromEnvironment();
|
|
9
9
|
setConfigurationFromCLI();
|
|
10
|
-
|
|
10
|
+
console.log(config);
|
|
11
11
|
function setConfigurationFromCLI() {
|
|
12
12
|
const argv = require("yargs").argv;
|
|
13
13
|
if (argv.mode === "file") {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "auto-translate-json-library",
|
|
3
|
-
"version": "1.2.
|
|
3
|
+
"version": "1.2.7",
|
|
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": {
|
|
@@ -15,7 +15,8 @@
|
|
|
15
15
|
"lint-fix-all": "biome check --apply-unsafe ./src",
|
|
16
16
|
"format": "biome format ./src",
|
|
17
17
|
"format-fix": "biome format ./src --write",
|
|
18
|
-
"start": "ts-node src/index.ts"
|
|
18
|
+
"start": "ts-node src/index.ts",
|
|
19
|
+
"publish": "npm run build "
|
|
19
20
|
},
|
|
20
21
|
"keywords": [
|
|
21
22
|
"translate",
|
|
@@ -47,19 +48,19 @@
|
|
|
47
48
|
"devDependencies": {
|
|
48
49
|
"@biomejs/biome": "1.2.2",
|
|
49
50
|
"@topce/typescript": "5.3.1",
|
|
50
|
-
"@types/minimist": "1.2.
|
|
51
|
-
"@types/node": "20.
|
|
52
|
-
"@types/yargs": "17.0.
|
|
51
|
+
"@types/minimist": "1.2.3",
|
|
52
|
+
"@types/node": "20.7.2",
|
|
53
|
+
"@types/yargs": "17.0.26",
|
|
53
54
|
"ts-node": "10.9.1"
|
|
54
55
|
},
|
|
55
56
|
"dependencies": {
|
|
56
|
-
"@aws-sdk/client-translate": "3.
|
|
57
|
+
"@aws-sdk/client-translate": "3.421.0",
|
|
57
58
|
"@google-cloud/translate": "8.0.2",
|
|
58
|
-
"axios": "1.5.
|
|
59
|
-
"dotenv": "
|
|
59
|
+
"axios": "1.5.1",
|
|
60
|
+
"dotenv": "16.3.1",
|
|
60
61
|
"form-data": "4.0.0",
|
|
61
62
|
"minimist": "1.2.8",
|
|
62
|
-
"openai": "4.
|
|
63
|
+
"openai": "4.11.0",
|
|
63
64
|
"picocolors": "1.0.0",
|
|
64
65
|
"uuid": "9.0.1",
|
|
65
66
|
"yargs": "17.7.2"
|
/package/{README.MD → README.md}
RENAMED
|
File without changes
|