auto-translate-json-library 1.1.4 → 1.2.0

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/google.js CHANGED
@@ -1,163 +1,163 @@
1
- "use strict";
2
- var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
3
- function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
4
- return new (P || (P = Promise))(function (resolve, reject) {
5
- function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
6
- function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
7
- function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
8
- step((generator = generator.apply(thisArg, _arguments || [])).next());
9
- });
10
- };
11
- Object.defineProperty(exports, "__esModule", { value: true });
12
- exports.GoogleTranslate = void 0;
13
- //const {Translate} = require('@google-cloud/translate').v2;
14
- const v2_1 = require("@google-cloud/translate/build/src/v2");
15
- const util_1 = require("./util");
16
- const supportedLanguages = [
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
- ];
128
- class GoogleTranslate {
129
- constructor(apikey) {
130
- this.apikey = apikey;
131
- this.googleTranslate = new v2_1.Translate({ key: this.apikey });
132
- // this.googleTranslate.getSupportedLanguages();
133
- }
134
- isValidLocale(targetLocale) {
135
- return supportedLanguages.includes(targetLocale);
136
- }
137
- translateText(text, _sourceLocale, targetLocale) {
138
- return __awaiter(this, void 0, void 0, function* () {
139
- let args;
140
- ({ args, text } = util_1.Util.replaceContextVariables(text));
141
- let result = '';
142
- try {
143
- const response = yield this.googleTranslate.translate(text, targetLocale);
144
- result = response[0];
145
- }
146
- catch (error) {
147
- if (error instanceof Error) {
148
- let message = error.message;
149
- if (error.message === 'Invalid Value') {
150
- message = 'Invalid Locale ' + targetLocale;
151
- }
152
- console.log(message);
153
- return message;
154
- }
155
- return 'error';
156
- }
157
- // replace arguments with numbers
158
- result = util_1.Util.replaceArgumentsWithNumbers(args, result);
159
- return result;
160
- });
161
- }
162
- }
163
- exports.GoogleTranslate = GoogleTranslate;
1
+ "use strict";
2
+ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
3
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
4
+ return new (P || (P = Promise))(function (resolve, reject) {
5
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
6
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
7
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
8
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
9
+ });
10
+ };
11
+ Object.defineProperty(exports, "__esModule", { value: true });
12
+ exports.GoogleTranslate = void 0;
13
+ //const {Translate} = require('@google-cloud/translate').v2;
14
+ const v2_1 = require("@google-cloud/translate/build/src/v2");
15
+ const util_1 = require("./util");
16
+ const supportedLanguages = [
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
+ ];
128
+ class GoogleTranslate {
129
+ constructor(apikey) {
130
+ this.apikey = apikey;
131
+ this.googleTranslate = new v2_1.Translate({ key: this.apikey });
132
+ // this.googleTranslate.getSupportedLanguages();
133
+ }
134
+ isValidLocale(targetLocale) {
135
+ return supportedLanguages.includes(targetLocale);
136
+ }
137
+ translateText(text, _sourceLocale, targetLocale) {
138
+ return __awaiter(this, void 0, void 0, function* () {
139
+ let args;
140
+ ({ args, text } = util_1.Util.replaceContextVariables(text));
141
+ let result = '';
142
+ try {
143
+ const response = yield this.googleTranslate.translate(text, targetLocale);
144
+ result = response[0];
145
+ }
146
+ catch (error) {
147
+ if (error instanceof Error) {
148
+ let message = error.message;
149
+ if (error.message === 'Invalid Value') {
150
+ message = 'Invalid Locale ' + targetLocale;
151
+ }
152
+ console.log(message);
153
+ return message;
154
+ }
155
+ return 'error';
156
+ }
157
+ // replace arguments with numbers
158
+ result = util_1.Util.replaceArgumentsWithNumbers(args, result);
159
+ return result;
160
+ });
161
+ }
162
+ }
163
+ exports.GoogleTranslate = GoogleTranslate;
package/index.d.ts CHANGED
@@ -1,3 +1,3 @@
1
- import { Configuration } from './config';
2
- import { translate } from './lib';
3
- export { Configuration, translate };
1
+ import { Configuration } from './config';
2
+ import { translate } from './lib';
3
+ export { Configuration, translate };
package/index.js CHANGED
@@ -1,120 +1,126 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.translate = void 0;
4
- const process_1 = require("process");
5
- const lib_1 = require("./lib");
6
- Object.defineProperty(exports, "translate", { enumerable: true, get: function () { return lib_1.translate; } });
7
- let config = {};
8
- setDefaultConfiguration();
9
- setConfigurationFromEnvironment();
10
- setConfigurationFromCLI();
11
- // console.log(config);
12
- function setConfigurationFromCLI() {
13
- const argv = require('yargs').argv;
14
- if (argv.mode === 'file') {
15
- config.mode = 'file';
16
- }
17
- else if (argv.mode === 'folder') {
18
- config.mode = 'folder';
19
- }
20
- if (argv.startDelimiter !== undefined) {
21
- config.startDelimiter = argv.startDelimiter;
22
- }
23
- if (argv.endDelimiter !== undefined) {
24
- config.endDelimiter = argv.endDelimiter;
25
- }
26
- if (argv.keepExtraTranslations === 'keep') {
27
- config.keepExtraTranslations = 'keep';
28
- }
29
- else if (argv.keepExtraTranslations === 'remove') {
30
- config.keepExtraTranslations = 'remove';
31
- }
32
- if (argv.keepTranslations === 'keep') {
33
- config.keepTranslations = 'keep';
34
- }
35
- else if (argv.keepTranslations === 'retranslate') {
36
- config.keepTranslations = 'retranslate';
37
- }
38
- if (argv.sourceLocale !== undefined) {
39
- config.sourceLocale = argv.sourceLocale;
40
- }
41
- if (argv.pivotTranslation !== undefined) {
42
- (0, lib_1.translate)(argv.pivotTranslation, config);
43
- }
44
- else {
45
- console.log('Please provide a pivot translation');
46
- (0, process_1.exit)(1);
47
- }
48
- }
49
- function setDefaultConfiguration() {
50
- config.mode = 'file';
51
- config.startDelimiter = '{';
52
- config.endDelimiter = '}';
53
- config.keepExtraTranslations = 'keep';
54
- config.keepTranslations = 'keep';
55
- config.sourceLocale = 'en';
56
- }
57
- function setConfigurationFromEnvironment() {
58
- require('dotenv').config();
59
- if (process.env.ATJ_GOOGLE_API_KEY) {
60
- config.translationKeyInfo = {
61
- kind: 'google',
62
- apiKey: process.env.ATJ_GOOGLE_API_KEY,
63
- };
64
- }
65
- if (process.env.ATJ_AWS_ACCESS_KEY_ID &&
66
- process.env.ATJ_AWS_SECRET_ACCESS_KEY &&
67
- process.env.ATJ_AWS_REGION) {
68
- config.translationKeyInfo = {
69
- kind: 'aws',
70
- accessKeyId: process.env.ATJ_AWS_ACCESS_KEY_ID,
71
- secretAccessKey: process.env.ATJ_AWS_SECRET_ACCESS_KEY,
72
- region: process.env.ATJ_AWS_REGION,
73
- };
74
- }
75
- if (process.env.ATJ_AZURE_SECRET_KEY && process.env.ATJ_AZURE_REGION) {
76
- config.translationKeyInfo = {
77
- kind: 'azure',
78
- secretKey: process.env.ATJ_AZURE_SECRET_KEY,
79
- region: process.env.ATJ_AZURE_REGION,
80
- };
81
- }
82
- if (process.env.ATJ_DEEPL_PRO_SECRET_KEY) {
83
- config.translationKeyInfo = {
84
- kind: 'deepLPro',
85
- secretKey: process.env.ATJ_DEEPL_PRO_SECRET_KEY,
86
- };
87
- }
88
- if (process.env.ATJ_DEEPL_FREE_SECRET_KEY) {
89
- config.translationKeyInfo = {
90
- kind: 'deepLFree',
91
- secretKey: process.env.ATJ_DEEPL_FREE_SECRET_KEY,
92
- };
93
- }
94
- if (process.env.ATJ_START_DELIMITER) {
95
- config.startDelimiter = process.env.ATJ_START_DELIMITER;
96
- }
97
- if (process.env.ATJ_END_DELIMITER) {
98
- config.endDelimiter = process.env.ATJ_END_DELIMITER;
99
- }
100
- if (process.env.ATJ_END_DELIMITER) {
101
- config.endDelimiter = process.env.ATJ_END_DELIMITER;
102
- }
103
- if (process.env.ATJ_MODE &&
104
- (process.env.ATJ_MODE === 'file' || process.env.ATJ_MODE === 'folder')) {
105
- config.mode = process.env.ATJ_MODE;
106
- }
107
- if (process.env.ATJ_SOURCE_LOCALE) {
108
- config.sourceLocale = process.env.ATJ_SOURCE_LOCALE;
109
- }
110
- if (process.env.ATJ_KEEP_TRANSLATIONS &&
111
- (process.env.ATJ_KEEP_TRANSLATIONS === 'keep' ||
112
- process.env.ATJ_KEEP_TRANSLATIONS === 'retranslate')) {
113
- config.keepTranslations = process.env.ATJ_KEEP_TRANSLATIONS;
114
- }
115
- if (process.env.ATJ_KEEP_EXTRA_TRANSLATIONS &&
116
- (process.env.ATJ_KEEP_EXTRA_TRANSLATIONS === 'keep' ||
117
- process.env.ATJ_KEEP_EXTRA_TRANSLATIONS === 'remove')) {
118
- config.keepExtraTranslations = process.env.ATJ_KEEP_EXTRA_TRANSLATIONS;
119
- }
120
- }
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.translate = void 0;
4
+ const process_1 = require("process");
5
+ const lib_1 = require("./lib");
6
+ Object.defineProperty(exports, "translate", { enumerable: true, get: function () { return lib_1.translate; } });
7
+ let config = {};
8
+ setDefaultConfiguration();
9
+ setConfigurationFromEnvironment();
10
+ setConfigurationFromCLI();
11
+ // console.log(config);
12
+ function setConfigurationFromCLI() {
13
+ const argv = require('yargs').argv;
14
+ if (argv.mode === 'file') {
15
+ config.mode = 'file';
16
+ }
17
+ else if (argv.mode === 'folder') {
18
+ config.mode = 'folder';
19
+ }
20
+ if (argv.startDelimiter !== undefined) {
21
+ config.startDelimiter = argv.startDelimiter;
22
+ }
23
+ if (argv.endDelimiter !== undefined) {
24
+ config.endDelimiter = argv.endDelimiter;
25
+ }
26
+ if (argv.keepExtraTranslations === 'keep') {
27
+ config.keepExtraTranslations = 'keep';
28
+ }
29
+ else if (argv.keepExtraTranslations === 'remove') {
30
+ config.keepExtraTranslations = 'remove';
31
+ }
32
+ if (argv.keepTranslations === 'keep') {
33
+ config.keepTranslations = 'keep';
34
+ }
35
+ else if (argv.keepTranslations === 'retranslate') {
36
+ config.keepTranslations = 'retranslate';
37
+ }
38
+ if (argv.sourceLocale !== undefined) {
39
+ config.sourceLocale = argv.sourceLocale;
40
+ }
41
+ if (argv.pivotTranslation !== undefined) {
42
+ (0, lib_1.translate)(argv.pivotTranslation, config);
43
+ }
44
+ else {
45
+ console.log('Please provide a pivot translation');
46
+ (0, process_1.exit)(1);
47
+ }
48
+ }
49
+ function setDefaultConfiguration() {
50
+ config.mode = 'file';
51
+ config.startDelimiter = '{';
52
+ config.endDelimiter = '}';
53
+ config.keepExtraTranslations = 'keep';
54
+ config.keepTranslations = 'keep';
55
+ config.sourceLocale = 'en';
56
+ }
57
+ function setConfigurationFromEnvironment() {
58
+ require('dotenv').config();
59
+ if (process.env.ATJ_GOOGLE_API_KEY) {
60
+ config.translationKeyInfo = {
61
+ kind: 'google',
62
+ apiKey: process.env.ATJ_GOOGLE_API_KEY,
63
+ };
64
+ }
65
+ if (process.env.ATJ_AWS_ACCESS_KEY_ID &&
66
+ process.env.ATJ_AWS_SECRET_ACCESS_KEY &&
67
+ process.env.ATJ_AWS_REGION) {
68
+ config.translationKeyInfo = {
69
+ kind: 'aws',
70
+ accessKeyId: process.env.ATJ_AWS_ACCESS_KEY_ID,
71
+ secretAccessKey: process.env.ATJ_AWS_SECRET_ACCESS_KEY,
72
+ region: process.env.ATJ_AWS_REGION,
73
+ };
74
+ }
75
+ if (process.env.ATJ_AZURE_SECRET_KEY && process.env.ATJ_AZURE_REGION) {
76
+ config.translationKeyInfo = {
77
+ kind: 'azure',
78
+ secretKey: process.env.ATJ_AZURE_SECRET_KEY,
79
+ region: process.env.ATJ_AZURE_REGION,
80
+ };
81
+ }
82
+ if (process.env.ATJ_DEEPL_PRO_SECRET_KEY) {
83
+ config.translationKeyInfo = {
84
+ kind: 'deepLPro',
85
+ secretKey: process.env.ATJ_DEEPL_PRO_SECRET_KEY,
86
+ };
87
+ }
88
+ if (process.env.ATJ_DEEPL_FREE_SECRET_KEY) {
89
+ config.translationKeyInfo = {
90
+ kind: 'deepLFree',
91
+ secretKey: process.env.ATJ_DEEPL_FREE_SECRET_KEY,
92
+ };
93
+ }
94
+ if (process.env.ATJ_OPEN_AI_SECRET_KEY) {
95
+ config.translationKeyInfo = {
96
+ kind: 'openai',
97
+ apiKey: process.env.ATJ_OPEN_AI_SECRET_KEY,
98
+ };
99
+ }
100
+ if (process.env.ATJ_START_DELIMITER) {
101
+ config.startDelimiter = process.env.ATJ_START_DELIMITER;
102
+ }
103
+ if (process.env.ATJ_END_DELIMITER) {
104
+ config.endDelimiter = process.env.ATJ_END_DELIMITER;
105
+ }
106
+ if (process.env.ATJ_END_DELIMITER) {
107
+ config.endDelimiter = process.env.ATJ_END_DELIMITER;
108
+ }
109
+ if (process.env.ATJ_MODE &&
110
+ (process.env.ATJ_MODE === 'file' || process.env.ATJ_MODE === 'folder')) {
111
+ config.mode = process.env.ATJ_MODE;
112
+ }
113
+ if (process.env.ATJ_SOURCE_LOCALE) {
114
+ config.sourceLocale = process.env.ATJ_SOURCE_LOCALE;
115
+ }
116
+ if (process.env.ATJ_KEEP_TRANSLATIONS &&
117
+ (process.env.ATJ_KEEP_TRANSLATIONS === 'keep' ||
118
+ process.env.ATJ_KEEP_TRANSLATIONS === 'retranslate')) {
119
+ config.keepTranslations = process.env.ATJ_KEEP_TRANSLATIONS;
120
+ }
121
+ if (process.env.ATJ_KEEP_EXTRA_TRANSLATIONS &&
122
+ (process.env.ATJ_KEEP_EXTRA_TRANSLATIONS === 'keep' ||
123
+ process.env.ATJ_KEEP_EXTRA_TRANSLATIONS === 'remove')) {
124
+ config.keepExtraTranslations = process.env.ATJ_KEEP_EXTRA_TRANSLATIONS;
125
+ }
126
+ }
package/lib.d.ts CHANGED
@@ -1,2 +1,2 @@
1
- import { Configuration } from './config';
2
- export declare function translate(sourceFile: string, config: Configuration): Promise<void>;
1
+ import { Configuration } from './config';
2
+ export declare function translate(sourceFile: string, config: Configuration): Promise<void>;