auto-translate-json-library 1.2.0 → 1.2.2
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 +124 -0
- package/aws.d.ts +1 -1
- package/aws.js +81 -81
- package/azure.d.ts +1 -1
- package/azure.js +118 -118
- package/config.d.ts +10 -9
- package/deepl.d.ts +2 -2
- package/deepl.js +40 -40
- package/files.d.ts +7 -6
- package/files.js +10 -10
- package/folderFiles.d.ts +4 -3
- package/folderFiles.js +2 -2
- package/google.d.ts +1 -1
- package/google.js +115 -115
- package/index.d.ts +2 -2
- package/index.js +41 -35
- package/lib.d.ts +1 -1
- package/lib.js +35 -31
- package/openai.d.ts +0 -1
- package/openai.js +112 -113
- package/package.json +18 -6
- package/translate.interface.d.ts +3 -0
- package/util.js +7 -7
package/deepl.js
CHANGED
|
@@ -11,45 +11,45 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
|
|
|
11
11
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
12
|
exports.DeepLTranslate = void 0;
|
|
13
13
|
const FormData = require("form-data");
|
|
14
|
-
const axios = require(
|
|
14
|
+
const axios = require("axios").default;
|
|
15
15
|
const util_1 = require("./util");
|
|
16
16
|
const supportedLanguages = [
|
|
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
|
-
|
|
17
|
+
"BG",
|
|
18
|
+
"CS",
|
|
19
|
+
"DA",
|
|
20
|
+
"DE",
|
|
21
|
+
"EL",
|
|
22
|
+
"EN-GB",
|
|
23
|
+
"EN-US",
|
|
24
|
+
"EN",
|
|
25
|
+
"ES",
|
|
26
|
+
"ET",
|
|
27
|
+
"FI",
|
|
28
|
+
"FR",
|
|
29
|
+
"HU",
|
|
30
|
+
"IT",
|
|
31
|
+
"JA",
|
|
32
|
+
"LT",
|
|
33
|
+
"LV",
|
|
34
|
+
"NL",
|
|
35
|
+
"PL",
|
|
36
|
+
"PT-PT",
|
|
37
|
+
"PT-BR",
|
|
38
|
+
"PT",
|
|
39
|
+
"RO",
|
|
40
|
+
"RU",
|
|
41
|
+
"SK",
|
|
42
|
+
"SL",
|
|
43
|
+
"SV",
|
|
44
|
+
"ZH",
|
|
45
45
|
];
|
|
46
46
|
class DeepLTranslate {
|
|
47
47
|
constructor(subscriptionKey, type) {
|
|
48
48
|
this.subscriptionKey = subscriptionKey;
|
|
49
49
|
this.type = type;
|
|
50
|
-
this.endpoint =
|
|
51
|
-
if (this.type ===
|
|
52
|
-
this.endpoint =
|
|
50
|
+
this.endpoint = "https://api.deepl.com";
|
|
51
|
+
if (this.type === "free") {
|
|
52
|
+
this.endpoint = "https://api.free.deepl.com";
|
|
53
53
|
}
|
|
54
54
|
}
|
|
55
55
|
isValidLocale(targetLocale) {
|
|
@@ -59,18 +59,18 @@ class DeepLTranslate {
|
|
|
59
59
|
return __awaiter(this, void 0, void 0, function* () {
|
|
60
60
|
let args;
|
|
61
61
|
({ args, text } = util_1.Util.replaceContextVariables(text));
|
|
62
|
-
let result =
|
|
62
|
+
let result = "";
|
|
63
63
|
const formData = new FormData();
|
|
64
|
-
formData.append(
|
|
65
|
-
formData.append(
|
|
66
|
-
formData.append(
|
|
67
|
-
formData.append(
|
|
64
|
+
formData.append("auth_key", this.subscriptionKey);
|
|
65
|
+
formData.append("text", text);
|
|
66
|
+
formData.append("source_lang", sourceLocale.toUpperCase());
|
|
67
|
+
formData.append("target_lang", targetLocale.toUpperCase());
|
|
68
68
|
const response = yield axios({
|
|
69
69
|
baseURL: this.endpoint,
|
|
70
|
-
url:
|
|
71
|
-
method:
|
|
70
|
+
url: "v2/translate",
|
|
71
|
+
method: "post",
|
|
72
72
|
data: formData,
|
|
73
|
-
responseType:
|
|
73
|
+
responseType: "json",
|
|
74
74
|
});
|
|
75
75
|
result = response.translations[1].text;
|
|
76
76
|
result = util_1.Util.replaceArgumentsWithNumbers(args, result);
|
package/files.d.ts
CHANGED
|
@@ -1,12 +1,13 @@
|
|
|
1
|
+
import { TranslationFile } from "./translate.interface";
|
|
1
2
|
export interface IFiles {
|
|
2
3
|
sourceLocale: string;
|
|
3
4
|
targetLocales: Array<string>;
|
|
4
|
-
loadJsonFromLocale(locale: string): Promise<
|
|
5
|
-
saveJsonToLocale(locale: string, file:
|
|
5
|
+
loadJsonFromLocale(locale: string): Promise<TranslationFile>;
|
|
6
|
+
saveJsonToLocale(locale: string, file: TranslationFile): void;
|
|
6
7
|
}
|
|
7
8
|
export declare const readFileAsync: (filename: string) => Promise<string>;
|
|
8
|
-
export declare const loadJsonFromLocale: (fileName: string) => Promise<
|
|
9
|
-
export declare const saveJsonToLocale: (filename: string, file:
|
|
9
|
+
export declare const loadJsonFromLocale: (fileName: string) => Promise<TranslationFile>;
|
|
10
|
+
export declare const saveJsonToLocale: (filename: string, file: TranslationFile) => void;
|
|
10
11
|
export declare class Files implements IFiles {
|
|
11
12
|
folderPath: string;
|
|
12
13
|
sourceLocale: string;
|
|
@@ -14,6 +15,6 @@ export declare class Files implements IFiles {
|
|
|
14
15
|
constructor(filePath: string);
|
|
15
16
|
private getLocaleFromFilename;
|
|
16
17
|
private getTargetLocales;
|
|
17
|
-
loadJsonFromLocale(locale: string): Promise<
|
|
18
|
-
saveJsonToLocale(locale: string, file:
|
|
18
|
+
loadJsonFromLocale(locale: string): Promise<TranslationFile>;
|
|
19
|
+
saveJsonToLocale(locale: string, file: TranslationFile): void;
|
|
19
20
|
}
|
package/files.js
CHANGED
|
@@ -45,31 +45,31 @@ const loadJsonFromLocale = (fileName) => __awaiter(void 0, void 0, void 0, funct
|
|
|
45
45
|
let data = yield (0, exports.readFileAsync)(fileName);
|
|
46
46
|
// handle empty files
|
|
47
47
|
if (!data) {
|
|
48
|
-
data =
|
|
48
|
+
data = "{}";
|
|
49
49
|
}
|
|
50
50
|
return JSON.parse(data);
|
|
51
51
|
});
|
|
52
52
|
exports.loadJsonFromLocale = loadJsonFromLocale;
|
|
53
53
|
const saveJsonToLocale = (filename, file) => {
|
|
54
|
-
|
|
55
|
-
fs.writeFileSync(filename, data,
|
|
54
|
+
const data = JSON.stringify(file, null, " ");
|
|
55
|
+
fs.writeFileSync(filename, data, "utf8");
|
|
56
56
|
};
|
|
57
57
|
exports.saveJsonToLocale = saveJsonToLocale;
|
|
58
58
|
class Files {
|
|
59
59
|
constructor(filePath) {
|
|
60
60
|
this.folderPath = path.dirname(filePath);
|
|
61
|
-
|
|
61
|
+
const fileName = path.basename(filePath);
|
|
62
62
|
this.sourceLocale = this.getLocaleFromFilename(fileName);
|
|
63
63
|
this.targetLocales = this.getTargetLocales();
|
|
64
64
|
}
|
|
65
65
|
getLocaleFromFilename(fileName) {
|
|
66
|
-
return fileName.replace(
|
|
66
|
+
return fileName.replace(".json", "");
|
|
67
67
|
}
|
|
68
68
|
getTargetLocales() {
|
|
69
|
-
|
|
70
|
-
|
|
69
|
+
const locales = new Array();
|
|
70
|
+
const files = fs.readdirSync(this.folderPath);
|
|
71
71
|
files.forEach((file) => {
|
|
72
|
-
|
|
72
|
+
const locale = this.getLocaleFromFilename(file);
|
|
73
73
|
if (locale !== this.sourceLocale) {
|
|
74
74
|
locales.push(locale);
|
|
75
75
|
}
|
|
@@ -77,11 +77,11 @@ class Files {
|
|
|
77
77
|
return locales;
|
|
78
78
|
}
|
|
79
79
|
loadJsonFromLocale(locale) {
|
|
80
|
-
|
|
80
|
+
const filename = `${this.folderPath}/${locale}.json`;
|
|
81
81
|
return (0, exports.loadJsonFromLocale)(filename);
|
|
82
82
|
}
|
|
83
83
|
saveJsonToLocale(locale, file) {
|
|
84
|
-
|
|
84
|
+
const filename = `${this.folderPath}/${locale}.json`;
|
|
85
85
|
(0, exports.saveJsonToLocale)(filename, file);
|
|
86
86
|
}
|
|
87
87
|
}
|
package/folderFiles.d.ts
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
|
-
import { IFiles } from
|
|
1
|
+
import { IFiles } from "./files";
|
|
2
|
+
import { TranslationFile } from "./translate.interface";
|
|
2
3
|
export declare class FolderFiles implements IFiles {
|
|
3
4
|
folderPath: string;
|
|
4
5
|
sourceLocale: string;
|
|
@@ -7,6 +8,6 @@ export declare class FolderFiles implements IFiles {
|
|
|
7
8
|
constructor(filePath: string);
|
|
8
9
|
private getTargetLocales;
|
|
9
10
|
private createFileName;
|
|
10
|
-
loadJsonFromLocale(locale: string): Promise<
|
|
11
|
-
saveJsonToLocale(locale: string, file:
|
|
11
|
+
loadJsonFromLocale(locale: string): Promise<TranslationFile>;
|
|
12
|
+
saveJsonToLocale(locale: string, file: TranslationFile): void;
|
|
12
13
|
}
|
package/folderFiles.js
CHANGED
|
@@ -37,10 +37,10 @@ class FolderFiles {
|
|
|
37
37
|
console.log(this.folderPath, this.fileName, this.sourceLocale, this.targetLocales);
|
|
38
38
|
}
|
|
39
39
|
getTargetLocales() {
|
|
40
|
-
|
|
40
|
+
const files = fs
|
|
41
41
|
.readdirSync(this.folderPath)
|
|
42
42
|
.map((folder) => path.basename(folder))
|
|
43
|
-
.map((locale) => (locale !== this.sourceLocale ? locale :
|
|
43
|
+
.map((locale) => (locale !== this.sourceLocale ? locale : ""))
|
|
44
44
|
.filter((x) => x); // do not want empty strings
|
|
45
45
|
return files;
|
|
46
46
|
}
|
package/google.d.ts
CHANGED
package/google.js
CHANGED
|
@@ -14,116 +14,116 @@ exports.GoogleTranslate = void 0;
|
|
|
14
14
|
const v2_1 = require("@google-cloud/translate/build/src/v2");
|
|
15
15
|
const util_1 = require("./util");
|
|
16
16
|
const supportedLanguages = [
|
|
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
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
17
|
+
"af",
|
|
18
|
+
"sq",
|
|
19
|
+
"am",
|
|
20
|
+
"ar",
|
|
21
|
+
"hy",
|
|
22
|
+
"az",
|
|
23
|
+
"eu",
|
|
24
|
+
"be",
|
|
25
|
+
"bn",
|
|
26
|
+
"bs",
|
|
27
|
+
"bg",
|
|
28
|
+
"ca",
|
|
29
|
+
"ceb",
|
|
30
|
+
"zh-CN",
|
|
31
|
+
"zh",
|
|
32
|
+
"zh-TW",
|
|
33
|
+
"co",
|
|
34
|
+
"hr",
|
|
35
|
+
"cs",
|
|
36
|
+
"da",
|
|
37
|
+
"nl",
|
|
38
|
+
"en",
|
|
39
|
+
"eo",
|
|
40
|
+
"et",
|
|
41
|
+
"fi",
|
|
42
|
+
"fr",
|
|
43
|
+
"fy",
|
|
44
|
+
"gl",
|
|
45
|
+
"ka",
|
|
46
|
+
"de",
|
|
47
|
+
"el",
|
|
48
|
+
"gu",
|
|
49
|
+
"ht",
|
|
50
|
+
"ha",
|
|
51
|
+
"haw",
|
|
52
|
+
"he",
|
|
53
|
+
"iw",
|
|
54
|
+
"hi",
|
|
55
|
+
"hmn",
|
|
56
|
+
"hu",
|
|
57
|
+
"is",
|
|
58
|
+
"ig",
|
|
59
|
+
"id",
|
|
60
|
+
"ga",
|
|
61
|
+
"it",
|
|
62
|
+
"ja",
|
|
63
|
+
"jv",
|
|
64
|
+
"kn",
|
|
65
|
+
"kk",
|
|
66
|
+
"km",
|
|
67
|
+
"rw",
|
|
68
|
+
"ko",
|
|
69
|
+
"ku",
|
|
70
|
+
"ky",
|
|
71
|
+
"lo",
|
|
72
|
+
"lv",
|
|
73
|
+
"lt",
|
|
74
|
+
"lb",
|
|
75
|
+
"mk",
|
|
76
|
+
"mg",
|
|
77
|
+
"ms",
|
|
78
|
+
"ml",
|
|
79
|
+
"mt",
|
|
80
|
+
"mi",
|
|
81
|
+
"mr",
|
|
82
|
+
"mn",
|
|
83
|
+
"my",
|
|
84
|
+
"ne",
|
|
85
|
+
"no",
|
|
86
|
+
"ny",
|
|
87
|
+
"or",
|
|
88
|
+
"ps",
|
|
89
|
+
"fa",
|
|
90
|
+
"pl",
|
|
91
|
+
"pt",
|
|
92
|
+
"pa",
|
|
93
|
+
"ro",
|
|
94
|
+
"ru",
|
|
95
|
+
"sm",
|
|
96
|
+
"gd",
|
|
97
|
+
"sr",
|
|
98
|
+
"st",
|
|
99
|
+
"sn",
|
|
100
|
+
"sd",
|
|
101
|
+
"si",
|
|
102
|
+
"sk",
|
|
103
|
+
"sl",
|
|
104
|
+
"so",
|
|
105
|
+
"es",
|
|
106
|
+
"su",
|
|
107
|
+
"sw",
|
|
108
|
+
"sv",
|
|
109
|
+
"tl",
|
|
110
|
+
"tg",
|
|
111
|
+
"ta",
|
|
112
|
+
"tt",
|
|
113
|
+
"te",
|
|
114
|
+
"th",
|
|
115
|
+
"tr",
|
|
116
|
+
"tk",
|
|
117
|
+
"uk",
|
|
118
|
+
"ur",
|
|
119
|
+
"ug",
|
|
120
|
+
"uz",
|
|
121
|
+
"vi",
|
|
122
|
+
"cy",
|
|
123
|
+
"xh",
|
|
124
|
+
"yi",
|
|
125
|
+
"yo",
|
|
126
|
+
"zu",
|
|
127
127
|
];
|
|
128
128
|
class GoogleTranslate {
|
|
129
129
|
constructor(apikey) {
|
|
@@ -138,7 +138,7 @@ class GoogleTranslate {
|
|
|
138
138
|
return __awaiter(this, void 0, void 0, function* () {
|
|
139
139
|
let args;
|
|
140
140
|
({ args, text } = util_1.Util.replaceContextVariables(text));
|
|
141
|
-
let result =
|
|
141
|
+
let result = "";
|
|
142
142
|
try {
|
|
143
143
|
const response = yield this.googleTranslate.translate(text, targetLocale);
|
|
144
144
|
result = response[0];
|
|
@@ -146,13 +146,13 @@ class GoogleTranslate {
|
|
|
146
146
|
catch (error) {
|
|
147
147
|
if (error instanceof Error) {
|
|
148
148
|
let message = error.message;
|
|
149
|
-
if (error.message ===
|
|
150
|
-
message =
|
|
149
|
+
if (error.message === "Invalid Value") {
|
|
150
|
+
message = `Invalid Locale ${targetLocale}`;
|
|
151
151
|
}
|
|
152
|
-
console.
|
|
152
|
+
console.error(message);
|
|
153
153
|
return message;
|
|
154
154
|
}
|
|
155
|
-
return
|
|
155
|
+
return "error";
|
|
156
156
|
}
|
|
157
157
|
// replace arguments with numbers
|
|
158
158
|
result = util_1.Util.replaceArgumentsWithNumbers(args, result);
|
package/index.d.ts
CHANGED
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
import { Configuration } from
|
|
2
|
-
import { translate } from
|
|
1
|
+
import { Configuration } from "./config";
|
|
2
|
+
import { translate } from "./lib";
|
|
3
3
|
export { Configuration, translate };
|
package/index.js
CHANGED
|
@@ -1,21 +1,20 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.translate = void 0;
|
|
4
|
-
const process_1 = require("process");
|
|
5
4
|
const lib_1 = require("./lib");
|
|
6
5
|
Object.defineProperty(exports, "translate", { enumerable: true, get: function () { return lib_1.translate; } });
|
|
7
|
-
|
|
6
|
+
const config = {};
|
|
8
7
|
setDefaultConfiguration();
|
|
9
8
|
setConfigurationFromEnvironment();
|
|
10
9
|
setConfigurationFromCLI();
|
|
11
10
|
// console.log(config);
|
|
12
11
|
function setConfigurationFromCLI() {
|
|
13
|
-
const argv = require(
|
|
14
|
-
if (argv.mode ===
|
|
15
|
-
config.mode =
|
|
12
|
+
const argv = require("yargs").argv;
|
|
13
|
+
if (argv.mode === "file") {
|
|
14
|
+
config.mode = "file";
|
|
16
15
|
}
|
|
17
|
-
else if (argv.mode ===
|
|
18
|
-
config.mode =
|
|
16
|
+
else if (argv.mode === "folder") {
|
|
17
|
+
config.mode = "folder";
|
|
19
18
|
}
|
|
20
19
|
if (argv.startDelimiter !== undefined) {
|
|
21
20
|
config.startDelimiter = argv.startDelimiter;
|
|
@@ -23,42 +22,46 @@ function setConfigurationFromCLI() {
|
|
|
23
22
|
if (argv.endDelimiter !== undefined) {
|
|
24
23
|
config.endDelimiter = argv.endDelimiter;
|
|
25
24
|
}
|
|
26
|
-
if (argv.keepExtraTranslations ===
|
|
27
|
-
config.keepExtraTranslations =
|
|
25
|
+
if (argv.keepExtraTranslations === "keep") {
|
|
26
|
+
config.keepExtraTranslations = "keep";
|
|
28
27
|
}
|
|
29
|
-
else if (argv.keepExtraTranslations ===
|
|
30
|
-
config.keepExtraTranslations =
|
|
28
|
+
else if (argv.keepExtraTranslations === "remove") {
|
|
29
|
+
config.keepExtraTranslations = "remove";
|
|
31
30
|
}
|
|
32
|
-
if (argv.keepTranslations ===
|
|
33
|
-
config.keepTranslations =
|
|
31
|
+
if (argv.keepTranslations === "keep") {
|
|
32
|
+
config.keepTranslations = "keep";
|
|
34
33
|
}
|
|
35
|
-
else if (argv.keepTranslations ===
|
|
36
|
-
config.keepTranslations =
|
|
34
|
+
else if (argv.keepTranslations === "retranslate") {
|
|
35
|
+
config.keepTranslations = "retranslate";
|
|
37
36
|
}
|
|
38
37
|
if (argv.sourceLocale !== undefined) {
|
|
39
38
|
config.sourceLocale = argv.sourceLocale;
|
|
40
39
|
}
|
|
40
|
+
if (argv.ignorePrefix !== undefined) {
|
|
41
|
+
config.ignorePrefix = argv.ignorePrefix;
|
|
42
|
+
}
|
|
41
43
|
if (argv.pivotTranslation !== undefined) {
|
|
42
44
|
(0, lib_1.translate)(argv.pivotTranslation, config);
|
|
43
45
|
}
|
|
44
46
|
else {
|
|
45
|
-
console.log(
|
|
46
|
-
(
|
|
47
|
+
console.log(argv);
|
|
48
|
+
console.log("Please provide a pivot translation");
|
|
47
49
|
}
|
|
48
50
|
}
|
|
49
51
|
function setDefaultConfiguration() {
|
|
50
|
-
config.mode =
|
|
51
|
-
config.startDelimiter =
|
|
52
|
-
config.endDelimiter =
|
|
53
|
-
config.keepExtraTranslations =
|
|
54
|
-
config.keepTranslations =
|
|
55
|
-
config.sourceLocale =
|
|
52
|
+
config.mode = "file";
|
|
53
|
+
config.startDelimiter = "{";
|
|
54
|
+
config.endDelimiter = "}";
|
|
55
|
+
config.keepExtraTranslations = "keep";
|
|
56
|
+
config.keepTranslations = "keep";
|
|
57
|
+
config.sourceLocale = "en";
|
|
58
|
+
config.ignorePrefix = "";
|
|
56
59
|
}
|
|
57
60
|
function setConfigurationFromEnvironment() {
|
|
58
|
-
require(
|
|
61
|
+
require("dotenv").config();
|
|
59
62
|
if (process.env.ATJ_GOOGLE_API_KEY) {
|
|
60
63
|
config.translationKeyInfo = {
|
|
61
|
-
kind:
|
|
64
|
+
kind: "google",
|
|
62
65
|
apiKey: process.env.ATJ_GOOGLE_API_KEY,
|
|
63
66
|
};
|
|
64
67
|
}
|
|
@@ -66,7 +69,7 @@ function setConfigurationFromEnvironment() {
|
|
|
66
69
|
process.env.ATJ_AWS_SECRET_ACCESS_KEY &&
|
|
67
70
|
process.env.ATJ_AWS_REGION) {
|
|
68
71
|
config.translationKeyInfo = {
|
|
69
|
-
kind:
|
|
72
|
+
kind: "aws",
|
|
70
73
|
accessKeyId: process.env.ATJ_AWS_ACCESS_KEY_ID,
|
|
71
74
|
secretAccessKey: process.env.ATJ_AWS_SECRET_ACCESS_KEY,
|
|
72
75
|
region: process.env.ATJ_AWS_REGION,
|
|
@@ -74,26 +77,26 @@ function setConfigurationFromEnvironment() {
|
|
|
74
77
|
}
|
|
75
78
|
if (process.env.ATJ_AZURE_SECRET_KEY && process.env.ATJ_AZURE_REGION) {
|
|
76
79
|
config.translationKeyInfo = {
|
|
77
|
-
kind:
|
|
80
|
+
kind: "azure",
|
|
78
81
|
secretKey: process.env.ATJ_AZURE_SECRET_KEY,
|
|
79
82
|
region: process.env.ATJ_AZURE_REGION,
|
|
80
83
|
};
|
|
81
84
|
}
|
|
82
85
|
if (process.env.ATJ_DEEPL_PRO_SECRET_KEY) {
|
|
83
86
|
config.translationKeyInfo = {
|
|
84
|
-
kind:
|
|
87
|
+
kind: "deepLPro",
|
|
85
88
|
secretKey: process.env.ATJ_DEEPL_PRO_SECRET_KEY,
|
|
86
89
|
};
|
|
87
90
|
}
|
|
88
91
|
if (process.env.ATJ_DEEPL_FREE_SECRET_KEY) {
|
|
89
92
|
config.translationKeyInfo = {
|
|
90
|
-
kind:
|
|
93
|
+
kind: "deepLFree",
|
|
91
94
|
secretKey: process.env.ATJ_DEEPL_FREE_SECRET_KEY,
|
|
92
95
|
};
|
|
93
96
|
}
|
|
94
97
|
if (process.env.ATJ_OPEN_AI_SECRET_KEY) {
|
|
95
98
|
config.translationKeyInfo = {
|
|
96
|
-
kind:
|
|
99
|
+
kind: "openai",
|
|
97
100
|
apiKey: process.env.ATJ_OPEN_AI_SECRET_KEY,
|
|
98
101
|
};
|
|
99
102
|
}
|
|
@@ -107,20 +110,23 @@ function setConfigurationFromEnvironment() {
|
|
|
107
110
|
config.endDelimiter = process.env.ATJ_END_DELIMITER;
|
|
108
111
|
}
|
|
109
112
|
if (process.env.ATJ_MODE &&
|
|
110
|
-
(process.env.ATJ_MODE ===
|
|
113
|
+
(process.env.ATJ_MODE === "file" || process.env.ATJ_MODE === "folder")) {
|
|
111
114
|
config.mode = process.env.ATJ_MODE;
|
|
112
115
|
}
|
|
113
116
|
if (process.env.ATJ_SOURCE_LOCALE) {
|
|
114
117
|
config.sourceLocale = process.env.ATJ_SOURCE_LOCALE;
|
|
115
118
|
}
|
|
116
119
|
if (process.env.ATJ_KEEP_TRANSLATIONS &&
|
|
117
|
-
(process.env.ATJ_KEEP_TRANSLATIONS ===
|
|
118
|
-
process.env.ATJ_KEEP_TRANSLATIONS ===
|
|
120
|
+
(process.env.ATJ_KEEP_TRANSLATIONS === "keep" ||
|
|
121
|
+
process.env.ATJ_KEEP_TRANSLATIONS === "retranslate")) {
|
|
119
122
|
config.keepTranslations = process.env.ATJ_KEEP_TRANSLATIONS;
|
|
120
123
|
}
|
|
121
124
|
if (process.env.ATJ_KEEP_EXTRA_TRANSLATIONS &&
|
|
122
|
-
(process.env.ATJ_KEEP_EXTRA_TRANSLATIONS ===
|
|
123
|
-
process.env.ATJ_KEEP_EXTRA_TRANSLATIONS ===
|
|
125
|
+
(process.env.ATJ_KEEP_EXTRA_TRANSLATIONS === "keep" ||
|
|
126
|
+
process.env.ATJ_KEEP_EXTRA_TRANSLATIONS === "remove")) {
|
|
124
127
|
config.keepExtraTranslations = process.env.ATJ_KEEP_EXTRA_TRANSLATIONS;
|
|
125
128
|
}
|
|
129
|
+
if (process.env.ATJ_IGNORE_PREFIX && process.env.ATJ_IGNORE_PREFIX !== "") {
|
|
130
|
+
config.ignorePrefix = process.env.ATJ_IGNORE_PREFIX;
|
|
131
|
+
}
|
|
126
132
|
}
|
package/lib.d.ts
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import { Configuration } from
|
|
1
|
+
import { Configuration } from "./config";
|
|
2
2
|
export declare function translate(sourceFile: string, config: Configuration): Promise<void>;
|