@umituz/react-native-google-translate 1.0.5 → 1.0.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/dist/domain/entities/Language.entity.js +2 -1
- package/dist/domain/entities/Translation.entity.js +2 -1
- package/dist/domain/entities/index.js +2 -1
- package/dist/domain/index.js +18 -2
- package/dist/domain/interfaces/ITranslationService.interface.js +2 -1
- package/dist/domain/interfaces/index.js +2 -1
- package/dist/infrastructure/constants/api.constants.js +7 -4
- package/dist/infrastructure/constants/index.js +12 -2
- package/dist/infrastructure/constants/languages.constants.js +6 -3
- package/dist/infrastructure/index.js +25 -0
- package/dist/infrastructure/services/GoogleTranslate.service.js +123 -39
- package/dist/infrastructure/services/index.js +16 -3
- package/dist/infrastructure/utils/index.js +16 -0
- package/dist/infrastructure/utils/rateLimit.util.js +5 -1
- package/dist/infrastructure/utils/textValidator.util.js +18 -10
- package/dist/scripts/index.js +20 -4
- package/dist/scripts/setup.js +23 -15
- package/dist/scripts/sync.js +39 -30
- package/dist/scripts/translate.js +28 -20
- package/dist/scripts/utils/file-parser.js +19 -11
- package/dist/scripts/utils/index.js +21 -5
- package/dist/scripts/utils/key-detector.js +6 -2
- package/dist/scripts/utils/key-extractor.js +17 -11
- package/dist/scripts/utils/object-helper.js +6 -2
- package/dist/scripts/utils/sync-helper.js +6 -2
- package/package.json +1 -1
- package/src/infrastructure/services/GoogleTranslate.service.ts +123 -24
- package/src/scripts/setup.ts +2 -1
- package/src/scripts/sync.ts +2 -1
- package/src/scripts/translate.ts +2 -1
package/dist/domain/index.js
CHANGED
|
@@ -1,8 +1,24 @@
|
|
|
1
|
+
"use strict";
|
|
1
2
|
/**
|
|
2
3
|
* Domain Layer
|
|
3
4
|
* @description Subpath: @umituz/react-native-google-translate/core
|
|
4
5
|
*
|
|
5
6
|
* Exports all domain entities and interfaces
|
|
6
7
|
*/
|
|
7
|
-
|
|
8
|
-
|
|
8
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
9
|
+
if (k2 === undefined) k2 = k;
|
|
10
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
11
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
12
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
13
|
+
}
|
|
14
|
+
Object.defineProperty(o, k2, desc);
|
|
15
|
+
}) : (function(o, m, k, k2) {
|
|
16
|
+
if (k2 === undefined) k2 = k;
|
|
17
|
+
o[k2] = m[k];
|
|
18
|
+
}));
|
|
19
|
+
var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
20
|
+
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
21
|
+
};
|
|
22
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
23
|
+
__exportStar(require("./entities"), exports);
|
|
24
|
+
__exportStar(require("./interfaces"), exports);
|
|
@@ -1,8 +1,11 @@
|
|
|
1
|
+
"use strict";
|
|
1
2
|
/**
|
|
2
3
|
* API Constants
|
|
3
4
|
* @description Google Translate API configuration
|
|
4
5
|
*/
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
6
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
7
|
+
exports.DEFAULT_MAX_RETRIES = exports.DEFAULT_MIN_DELAY = exports.DEFAULT_TIMEOUT = exports.GOOGLE_TRANSLATE_API_URL = void 0;
|
|
8
|
+
exports.GOOGLE_TRANSLATE_API_URL = "https://translate.googleapis.com/translate_a/single";
|
|
9
|
+
exports.DEFAULT_TIMEOUT = 10000;
|
|
10
|
+
exports.DEFAULT_MIN_DELAY = 100;
|
|
11
|
+
exports.DEFAULT_MAX_RETRIES = 3;
|
|
@@ -1,6 +1,16 @@
|
|
|
1
|
+
"use strict";
|
|
1
2
|
/**
|
|
2
3
|
* Infrastructure Constants
|
|
3
4
|
* @description Exports all constant definitions
|
|
4
5
|
*/
|
|
5
|
-
|
|
6
|
-
|
|
6
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
7
|
+
exports.DEFAULT_MAX_RETRIES = exports.DEFAULT_MIN_DELAY = exports.DEFAULT_TIMEOUT = exports.GOOGLE_TRANSLATE_API_URL = exports.LANGUAGE_NAMES = exports.SKIP_WORDS = exports.LANGUAGE_MAP = void 0;
|
|
8
|
+
var languages_constants_1 = require("./languages.constants");
|
|
9
|
+
Object.defineProperty(exports, "LANGUAGE_MAP", { enumerable: true, get: function () { return languages_constants_1.LANGUAGE_MAP; } });
|
|
10
|
+
Object.defineProperty(exports, "SKIP_WORDS", { enumerable: true, get: function () { return languages_constants_1.SKIP_WORDS; } });
|
|
11
|
+
Object.defineProperty(exports, "LANGUAGE_NAMES", { enumerable: true, get: function () { return languages_constants_1.LANGUAGE_NAMES; } });
|
|
12
|
+
var api_constants_1 = require("./api.constants");
|
|
13
|
+
Object.defineProperty(exports, "GOOGLE_TRANSLATE_API_URL", { enumerable: true, get: function () { return api_constants_1.GOOGLE_TRANSLATE_API_URL; } });
|
|
14
|
+
Object.defineProperty(exports, "DEFAULT_TIMEOUT", { enumerable: true, get: function () { return api_constants_1.DEFAULT_TIMEOUT; } });
|
|
15
|
+
Object.defineProperty(exports, "DEFAULT_MIN_DELAY", { enumerable: true, get: function () { return api_constants_1.DEFAULT_MIN_DELAY; } });
|
|
16
|
+
Object.defineProperty(exports, "DEFAULT_MAX_RETRIES", { enumerable: true, get: function () { return api_constants_1.DEFAULT_MAX_RETRIES; } });
|
|
@@ -1,8 +1,11 @@
|
|
|
1
|
+
"use strict";
|
|
1
2
|
/**
|
|
2
3
|
* Language Constants
|
|
3
4
|
* @description Language mappings and metadata
|
|
4
5
|
*/
|
|
5
|
-
|
|
6
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
7
|
+
exports.LANGUAGE_NAMES = exports.SKIP_WORDS = exports.LANGUAGE_MAP = void 0;
|
|
8
|
+
exports.LANGUAGE_MAP = {
|
|
6
9
|
"ar-SA": "ar",
|
|
7
10
|
"bg-BG": "bg",
|
|
8
11
|
"cs-CZ": "cs",
|
|
@@ -43,7 +46,7 @@ export const LANGUAGE_MAP = {
|
|
|
43
46
|
"zh-CN": "zh-CN",
|
|
44
47
|
"zh-TW": "zh-TW",
|
|
45
48
|
};
|
|
46
|
-
|
|
49
|
+
exports.SKIP_WORDS = new Set([
|
|
47
50
|
"Google",
|
|
48
51
|
"Apple",
|
|
49
52
|
"Facebook",
|
|
@@ -52,7 +55,7 @@ export const SKIP_WORDS = new Set([
|
|
|
52
55
|
"YouTube",
|
|
53
56
|
"WhatsApp",
|
|
54
57
|
]);
|
|
55
|
-
|
|
58
|
+
exports.LANGUAGE_NAMES = {
|
|
56
59
|
"ar-SA": "Arabic (Saudi Arabia)",
|
|
57
60
|
"bg-BG": "Bulgarian",
|
|
58
61
|
"cs-CZ": "Czech",
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* Infrastructure Layer
|
|
4
|
+
* @description Subpath: @umituz/react-native-google-translate/infrastructure
|
|
5
|
+
*
|
|
6
|
+
* Exports all infrastructure services, utils, and constants
|
|
7
|
+
*/
|
|
8
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
9
|
+
if (k2 === undefined) k2 = k;
|
|
10
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
11
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
12
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
13
|
+
}
|
|
14
|
+
Object.defineProperty(o, k2, desc);
|
|
15
|
+
}) : (function(o, m, k, k2) {
|
|
16
|
+
if (k2 === undefined) k2 = k;
|
|
17
|
+
o[k2] = m[k];
|
|
18
|
+
}));
|
|
19
|
+
var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
20
|
+
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
21
|
+
};
|
|
22
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
23
|
+
__exportStar(require("./services"), exports);
|
|
24
|
+
__exportStar(require("./utils"), exports);
|
|
25
|
+
__exportStar(require("./constants"), exports);
|
|
@@ -1,21 +1,24 @@
|
|
|
1
|
+
"use strict";
|
|
1
2
|
/**
|
|
2
3
|
* Google Translate Service
|
|
3
4
|
* @description Main translation service using Google Translate API
|
|
4
5
|
*/
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
6
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
7
|
+
exports.googleTranslateService = void 0;
|
|
8
|
+
const rateLimit_util_1 = require("../utils/rateLimit.util");
|
|
9
|
+
const textValidator_util_1 = require("../utils/textValidator.util");
|
|
10
|
+
const constants_1 = require("../constants");
|
|
8
11
|
class GoogleTranslateService {
|
|
9
12
|
config = null;
|
|
10
13
|
rateLimiter = null;
|
|
11
14
|
initialize(config) {
|
|
12
15
|
this.config = {
|
|
13
|
-
minDelay: DEFAULT_MIN_DELAY,
|
|
14
|
-
maxRetries: DEFAULT_MAX_RETRIES,
|
|
15
|
-
timeout: DEFAULT_TIMEOUT,
|
|
16
|
+
minDelay: constants_1.DEFAULT_MIN_DELAY,
|
|
17
|
+
maxRetries: constants_1.DEFAULT_MAX_RETRIES,
|
|
18
|
+
timeout: constants_1.DEFAULT_TIMEOUT,
|
|
16
19
|
...config,
|
|
17
20
|
};
|
|
18
|
-
this.rateLimiter = new RateLimiter(this.config.minDelay);
|
|
21
|
+
this.rateLimiter = new rateLimit_util_1.RateLimiter(this.config.minDelay);
|
|
19
22
|
}
|
|
20
23
|
isInitialized() {
|
|
21
24
|
return this.config !== null && this.rateLimiter !== null;
|
|
@@ -28,7 +31,7 @@ class GoogleTranslateService {
|
|
|
28
31
|
async translate(request) {
|
|
29
32
|
this.ensureInitialized();
|
|
30
33
|
const { text, targetLanguage, sourceLanguage = "en" } = request;
|
|
31
|
-
if (!isValidText(text) || shouldSkipWord(text)) {
|
|
34
|
+
if (!(0, textValidator_util_1.isValidText)(text) || (0, textValidator_util_1.shouldSkipWord)(text)) {
|
|
32
35
|
return {
|
|
33
36
|
originalText: text,
|
|
34
37
|
translatedText: text,
|
|
@@ -81,6 +84,8 @@ class GoogleTranslateService {
|
|
|
81
84
|
translatedKeys: [],
|
|
82
85
|
};
|
|
83
86
|
}
|
|
87
|
+
// Use batch API call for better performance
|
|
88
|
+
const batchSize = 50;
|
|
84
89
|
const stats = {
|
|
85
90
|
totalCount: requests.length,
|
|
86
91
|
successCount: 0,
|
|
@@ -88,23 +93,52 @@ class GoogleTranslateService {
|
|
|
88
93
|
skippedCount: 0,
|
|
89
94
|
translatedKeys: [],
|
|
90
95
|
};
|
|
91
|
-
for (
|
|
92
|
-
const
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
96
|
+
for (let i = 0; i < requests.length; i += batchSize) {
|
|
97
|
+
const batch = requests.slice(i, i + batchSize);
|
|
98
|
+
// Wait for rate limiter once per batch instead of once per request
|
|
99
|
+
await this.rateLimiter.waitForSlot();
|
|
100
|
+
try {
|
|
101
|
+
const translations = await this.callTranslateAPIBatch(batch, requests[0].targetLanguage);
|
|
102
|
+
for (let j = 0; j < batch.length; j++) {
|
|
103
|
+
const request = batch[j];
|
|
104
|
+
const translatedText = translations[j];
|
|
105
|
+
if (translatedText && translatedText !== request.text) {
|
|
106
|
+
stats.successCount++;
|
|
107
|
+
stats.translatedKeys.push({
|
|
108
|
+
key: request.text,
|
|
109
|
+
from: request.text,
|
|
110
|
+
to: translatedText,
|
|
111
|
+
});
|
|
112
|
+
}
|
|
113
|
+
else if (!translatedText) {
|
|
114
|
+
stats.failureCount++;
|
|
115
|
+
}
|
|
116
|
+
else {
|
|
117
|
+
stats.skippedCount++;
|
|
118
|
+
}
|
|
104
119
|
}
|
|
105
120
|
}
|
|
106
|
-
|
|
107
|
-
|
|
121
|
+
catch (error) {
|
|
122
|
+
// Fallback to individual requests on batch failure
|
|
123
|
+
for (const request of batch) {
|
|
124
|
+
const result = await this.translate(request);
|
|
125
|
+
if (result.success) {
|
|
126
|
+
if (result.translatedText === result.originalText) {
|
|
127
|
+
stats.skippedCount++;
|
|
128
|
+
}
|
|
129
|
+
else {
|
|
130
|
+
stats.successCount++;
|
|
131
|
+
stats.translatedKeys.push({
|
|
132
|
+
key: request.text,
|
|
133
|
+
from: result.originalText,
|
|
134
|
+
to: result.translatedText,
|
|
135
|
+
});
|
|
136
|
+
}
|
|
137
|
+
}
|
|
138
|
+
else {
|
|
139
|
+
stats.failureCount++;
|
|
140
|
+
}
|
|
141
|
+
}
|
|
108
142
|
}
|
|
109
143
|
}
|
|
110
144
|
return stats;
|
|
@@ -126,6 +160,8 @@ class GoogleTranslateService {
|
|
|
126
160
|
return;
|
|
127
161
|
}
|
|
128
162
|
const keys = Object.keys(sourceObject);
|
|
163
|
+
// Collect all texts to translate first
|
|
164
|
+
const textsToTranslate = [];
|
|
129
165
|
for (const key of keys) {
|
|
130
166
|
const enValue = sourceObject[key];
|
|
131
167
|
const targetValue = targetObject[key];
|
|
@@ -139,38 +175,50 @@ class GoogleTranslateService {
|
|
|
139
175
|
}
|
|
140
176
|
else if (typeof enValue === "string") {
|
|
141
177
|
stats.totalCount++;
|
|
142
|
-
if (needsTranslation(targetValue, enValue)) {
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
178
|
+
if ((0, textValidator_util_1.needsTranslation)(targetValue, enValue)) {
|
|
179
|
+
textsToTranslate.push({ key, enValue, currentPath });
|
|
180
|
+
}
|
|
181
|
+
else {
|
|
182
|
+
stats.skippedCount++;
|
|
183
|
+
}
|
|
184
|
+
}
|
|
185
|
+
}
|
|
186
|
+
// Batch translate all texts at once
|
|
187
|
+
if (textsToTranslate.length > 0) {
|
|
188
|
+
const batchSize = 50; // Google Translate API can handle ~50 texts at once
|
|
189
|
+
for (let i = 0; i < textsToTranslate.length; i += batchSize) {
|
|
190
|
+
const batch = textsToTranslate.slice(i, i + batchSize);
|
|
191
|
+
const results = await this.translateBatch(batch.map(item => ({
|
|
192
|
+
text: item.enValue,
|
|
193
|
+
targetLanguage,
|
|
194
|
+
})));
|
|
195
|
+
// Apply translations
|
|
196
|
+
for (let j = 0; j < batch.length; j++) {
|
|
197
|
+
const { key, enValue, currentPath } = batch[j];
|
|
198
|
+
const translatedKey = results.translatedKeys[j];
|
|
199
|
+
if (translatedKey && translatedKey.from !== enValue) {
|
|
200
|
+
targetObject[key] = translatedKey.to;
|
|
150
201
|
stats.successCount++;
|
|
151
202
|
stats.translatedKeys.push({
|
|
152
203
|
key: currentPath,
|
|
153
204
|
from: enValue,
|
|
154
|
-
to:
|
|
205
|
+
to: translatedKey.to,
|
|
155
206
|
});
|
|
156
207
|
}
|
|
157
|
-
else if (!
|
|
208
|
+
else if (!translatedKey) {
|
|
158
209
|
stats.failureCount++;
|
|
159
210
|
}
|
|
160
211
|
else {
|
|
161
212
|
stats.skippedCount++;
|
|
162
213
|
}
|
|
163
214
|
}
|
|
164
|
-
else {
|
|
165
|
-
stats.skippedCount++;
|
|
166
|
-
}
|
|
167
215
|
}
|
|
168
216
|
}
|
|
169
217
|
}
|
|
170
218
|
async callTranslateAPI(text, targetLanguage, sourceLanguage) {
|
|
171
|
-
const timeout = this.config?.timeout || DEFAULT_TIMEOUT;
|
|
219
|
+
const timeout = this.config?.timeout || constants_1.DEFAULT_TIMEOUT;
|
|
172
220
|
const encodedText = encodeURIComponent(text);
|
|
173
|
-
const url = `${GOOGLE_TRANSLATE_API_URL}?client=gtx&sl=${sourceLanguage}&tl=${targetLanguage}&dt=t&q=${encodedText}`;
|
|
221
|
+
const url = `${constants_1.GOOGLE_TRANSLATE_API_URL}?client=gtx&sl=${sourceLanguage}&tl=${targetLanguage}&dt=t&q=${encodedText}`;
|
|
174
222
|
const controller = new AbortController();
|
|
175
223
|
const timeoutId = setTimeout(() => controller.abort(), timeout);
|
|
176
224
|
try {
|
|
@@ -196,5 +244,41 @@ class GoogleTranslateService {
|
|
|
196
244
|
clearTimeout(timeoutId);
|
|
197
245
|
}
|
|
198
246
|
}
|
|
247
|
+
async callTranslateAPIBatch(requests, targetLanguage, sourceLanguage = "en") {
|
|
248
|
+
const timeout = this.config?.timeout || constants_1.DEFAULT_TIMEOUT;
|
|
249
|
+
// Build batch request URL
|
|
250
|
+
const queryParts = requests.map(req => encodeURIComponent(req.text)).join('&q=');
|
|
251
|
+
const url = `${constants_1.GOOGLE_TRANSLATE_API_URL}?client=gtx&sl=${sourceLanguage}&tl=${targetLanguage}&dt=t&q=${queryParts}`;
|
|
252
|
+
const controller = new AbortController();
|
|
253
|
+
const timeoutId = setTimeout(() => controller.abort(), timeout);
|
|
254
|
+
try {
|
|
255
|
+
const response = await fetch(url, {
|
|
256
|
+
signal: controller.signal,
|
|
257
|
+
});
|
|
258
|
+
if (!response.ok) {
|
|
259
|
+
throw new Error(`Batch API request failed: ${response.status}`);
|
|
260
|
+
}
|
|
261
|
+
const data = await response.json();
|
|
262
|
+
// Extract translations from batch response
|
|
263
|
+
const translations = [];
|
|
264
|
+
if (Array.isArray(data) && data.length > 0) {
|
|
265
|
+
for (let i = 0; i < requests.length; i++) {
|
|
266
|
+
if (Array.isArray(data[i]) &&
|
|
267
|
+
data[i].length > 0 &&
|
|
268
|
+
Array.isArray(data[i][0]) &&
|
|
269
|
+
typeof data[i][0][0] === "string") {
|
|
270
|
+
translations.push(data[i][0][0]);
|
|
271
|
+
}
|
|
272
|
+
else {
|
|
273
|
+
translations.push(requests[i].text); // Fallback to original
|
|
274
|
+
}
|
|
275
|
+
}
|
|
276
|
+
}
|
|
277
|
+
return translations;
|
|
278
|
+
}
|
|
279
|
+
finally {
|
|
280
|
+
clearTimeout(timeoutId);
|
|
281
|
+
}
|
|
282
|
+
}
|
|
199
283
|
}
|
|
200
|
-
|
|
284
|
+
exports.googleTranslateService = new GoogleTranslateService();
|
|
@@ -1,7 +1,20 @@
|
|
|
1
|
+
"use strict";
|
|
1
2
|
/**
|
|
2
3
|
* Infrastructure Services
|
|
3
4
|
* @description Exports all services and utilities
|
|
4
5
|
*/
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
6
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
7
|
+
exports.LANGUAGE_NAMES = exports.SKIP_WORDS = exports.LANGUAGE_MAP = exports.getLanguageDisplayName = exports.isEnglishVariant = exports.getTargetLanguage = exports.isValidText = exports.needsTranslation = exports.shouldSkipWord = exports.googleTranslateService = void 0;
|
|
8
|
+
var GoogleTranslate_service_1 = require("./GoogleTranslate.service");
|
|
9
|
+
Object.defineProperty(exports, "googleTranslateService", { enumerable: true, get: function () { return GoogleTranslate_service_1.googleTranslateService; } });
|
|
10
|
+
var textValidator_util_1 = require("../utils/textValidator.util");
|
|
11
|
+
Object.defineProperty(exports, "shouldSkipWord", { enumerable: true, get: function () { return textValidator_util_1.shouldSkipWord; } });
|
|
12
|
+
Object.defineProperty(exports, "needsTranslation", { enumerable: true, get: function () { return textValidator_util_1.needsTranslation; } });
|
|
13
|
+
Object.defineProperty(exports, "isValidText", { enumerable: true, get: function () { return textValidator_util_1.isValidText; } });
|
|
14
|
+
Object.defineProperty(exports, "getTargetLanguage", { enumerable: true, get: function () { return textValidator_util_1.getTargetLanguage; } });
|
|
15
|
+
Object.defineProperty(exports, "isEnglishVariant", { enumerable: true, get: function () { return textValidator_util_1.isEnglishVariant; } });
|
|
16
|
+
Object.defineProperty(exports, "getLanguageDisplayName", { enumerable: true, get: function () { return textValidator_util_1.getLanguageDisplayName; } });
|
|
17
|
+
var languages_constants_1 = require("../constants/languages.constants");
|
|
18
|
+
Object.defineProperty(exports, "LANGUAGE_MAP", { enumerable: true, get: function () { return languages_constants_1.LANGUAGE_MAP; } });
|
|
19
|
+
Object.defineProperty(exports, "SKIP_WORDS", { enumerable: true, get: function () { return languages_constants_1.SKIP_WORDS; } });
|
|
20
|
+
Object.defineProperty(exports, "LANGUAGE_NAMES", { enumerable: true, get: function () { return languages_constants_1.LANGUAGE_NAMES; } });
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* Infrastructure Utils
|
|
4
|
+
* @description Exports all utility functions
|
|
5
|
+
*/
|
|
6
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
7
|
+
exports.getLanguageDisplayName = exports.isEnglishVariant = exports.getTargetLanguage = exports.isValidText = exports.needsTranslation = exports.shouldSkipWord = exports.RateLimiter = void 0;
|
|
8
|
+
var rateLimit_util_1 = require("./rateLimit.util");
|
|
9
|
+
Object.defineProperty(exports, "RateLimiter", { enumerable: true, get: function () { return rateLimit_util_1.RateLimiter; } });
|
|
10
|
+
var textValidator_util_1 = require("./textValidator.util");
|
|
11
|
+
Object.defineProperty(exports, "shouldSkipWord", { enumerable: true, get: function () { return textValidator_util_1.shouldSkipWord; } });
|
|
12
|
+
Object.defineProperty(exports, "needsTranslation", { enumerable: true, get: function () { return textValidator_util_1.needsTranslation; } });
|
|
13
|
+
Object.defineProperty(exports, "isValidText", { enumerable: true, get: function () { return textValidator_util_1.isValidText; } });
|
|
14
|
+
Object.defineProperty(exports, "getTargetLanguage", { enumerable: true, get: function () { return textValidator_util_1.getTargetLanguage; } });
|
|
15
|
+
Object.defineProperty(exports, "isEnglishVariant", { enumerable: true, get: function () { return textValidator_util_1.isEnglishVariant; } });
|
|
16
|
+
Object.defineProperty(exports, "getLanguageDisplayName", { enumerable: true, get: function () { return textValidator_util_1.getLanguageDisplayName; } });
|
|
@@ -1,8 +1,11 @@
|
|
|
1
|
+
"use strict";
|
|
1
2
|
/**
|
|
2
3
|
* Rate Limit Utility
|
|
3
4
|
* @description Handles rate limiting for API requests
|
|
4
5
|
*/
|
|
5
|
-
|
|
6
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
7
|
+
exports.RateLimiter = void 0;
|
|
8
|
+
class RateLimiter {
|
|
6
9
|
lastCallTime = 0;
|
|
7
10
|
minDelay;
|
|
8
11
|
constructor(minDelay = 100) {
|
|
@@ -21,3 +24,4 @@ export class RateLimiter {
|
|
|
21
24
|
this.lastCallTime = 0;
|
|
22
25
|
}
|
|
23
26
|
}
|
|
27
|
+
exports.RateLimiter = RateLimiter;
|
|
@@ -1,12 +1,20 @@
|
|
|
1
|
+
"use strict";
|
|
1
2
|
/**
|
|
2
3
|
* Text Validator Utility
|
|
3
4
|
* @description Validates text for translation eligibility
|
|
4
5
|
*/
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
6
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
7
|
+
exports.shouldSkipWord = shouldSkipWord;
|
|
8
|
+
exports.needsTranslation = needsTranslation;
|
|
9
|
+
exports.isValidText = isValidText;
|
|
10
|
+
exports.getTargetLanguage = getTargetLanguage;
|
|
11
|
+
exports.isEnglishVariant = isEnglishVariant;
|
|
12
|
+
exports.getLanguageDisplayName = getLanguageDisplayName;
|
|
13
|
+
const constants_1 = require("../constants");
|
|
14
|
+
function shouldSkipWord(word) {
|
|
15
|
+
return constants_1.SKIP_WORDS.has(word);
|
|
8
16
|
}
|
|
9
|
-
|
|
17
|
+
function needsTranslation(value, enValue) {
|
|
10
18
|
if (typeof enValue !== "string" || !enValue.trim()) {
|
|
11
19
|
return false;
|
|
12
20
|
}
|
|
@@ -35,16 +43,16 @@ export function needsTranslation(value, enValue) {
|
|
|
35
43
|
}
|
|
36
44
|
return false;
|
|
37
45
|
}
|
|
38
|
-
|
|
46
|
+
function isValidText(text) {
|
|
39
47
|
return typeof text === "string" && text.length > 0;
|
|
40
48
|
}
|
|
41
|
-
|
|
42
|
-
return LANGUAGE_MAP[langCode];
|
|
49
|
+
function getTargetLanguage(langCode) {
|
|
50
|
+
return constants_1.LANGUAGE_MAP[langCode];
|
|
43
51
|
}
|
|
44
|
-
|
|
52
|
+
function isEnglishVariant(langCode) {
|
|
45
53
|
const targetLang = getTargetLanguage(langCode);
|
|
46
54
|
return targetLang === "en";
|
|
47
55
|
}
|
|
48
|
-
|
|
49
|
-
return LANGUAGE_NAMES[code] || code;
|
|
56
|
+
function getLanguageDisplayName(code) {
|
|
57
|
+
return constants_1.LANGUAGE_NAMES[code] || code;
|
|
50
58
|
}
|
package/dist/scripts/index.js
CHANGED
|
@@ -1,8 +1,24 @@
|
|
|
1
|
+
"use strict";
|
|
1
2
|
/**
|
|
2
3
|
* Translation Scripts
|
|
3
4
|
* Scripts for translating and synchronizing localization files
|
|
4
5
|
*/
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
6
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
7
|
+
if (k2 === undefined) k2 = k;
|
|
8
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
9
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
10
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
11
|
+
}
|
|
12
|
+
Object.defineProperty(o, k2, desc);
|
|
13
|
+
}) : (function(o, m, k, k2) {
|
|
14
|
+
if (k2 === undefined) k2 = k;
|
|
15
|
+
o[k2] = m[k];
|
|
16
|
+
}));
|
|
17
|
+
var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
18
|
+
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
19
|
+
};
|
|
20
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
21
|
+
__exportStar(require("./translate"), exports);
|
|
22
|
+
__exportStar(require("./sync"), exports);
|
|
23
|
+
__exportStar(require("./setup"), exports);
|
|
24
|
+
__exportStar(require("./utils"), exports);
|
package/dist/scripts/setup.js
CHANGED
|
@@ -1,30 +1,37 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
|
+
"use strict";
|
|
2
3
|
/**
|
|
3
4
|
* Setup Languages Script
|
|
4
5
|
* Creates stub files for all supported languages (if not exist),
|
|
5
6
|
* then generates index.ts from all available translation files.
|
|
6
7
|
* Usage: node setup.ts [locales-dir]
|
|
7
8
|
*/
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
9
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
10
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
11
|
+
};
|
|
12
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
13
|
+
exports.setupLanguages = setupLanguages;
|
|
14
|
+
exports.runSetupLanguages = runSetupLanguages;
|
|
15
|
+
const fs_1 = __importDefault(require("fs"));
|
|
16
|
+
const path_1 = __importDefault(require("path"));
|
|
17
|
+
const services_1 = require("../infrastructure/services");
|
|
18
|
+
function setupLanguages(options) {
|
|
12
19
|
const { targetDir } = options;
|
|
13
|
-
const localesDir =
|
|
14
|
-
if (!
|
|
20
|
+
const localesDir = path_1.default.resolve(process.cwd(), targetDir);
|
|
21
|
+
if (!fs_1.default.existsSync(localesDir)) {
|
|
15
22
|
console.error(`❌ Locales directory not found: ${localesDir}`);
|
|
16
23
|
return false;
|
|
17
24
|
}
|
|
18
25
|
// Create stub files for all supported languages that don't exist yet
|
|
19
26
|
let created = 0;
|
|
20
|
-
for (const langCode of Object.keys(LANGUAGE_MAP)) {
|
|
27
|
+
for (const langCode of Object.keys(services_1.LANGUAGE_MAP)) {
|
|
21
28
|
// Skip English variants — en-US is the base, others (en-AU, en-GB) are redundant
|
|
22
29
|
if (langCode.startsWith('en-') && langCode !== 'en-US')
|
|
23
30
|
continue;
|
|
24
|
-
const filePath =
|
|
25
|
-
if (!
|
|
26
|
-
const langName = getLanguageDisplayName(langCode);
|
|
27
|
-
|
|
31
|
+
const filePath = path_1.default.join(localesDir, `${langCode}.ts`);
|
|
32
|
+
if (!fs_1.default.existsSync(filePath)) {
|
|
33
|
+
const langName = (0, services_1.getLanguageDisplayName)(langCode);
|
|
34
|
+
fs_1.default.writeFileSync(filePath, `/**\n * ${langName} Translations\n * Auto-synced from en-US.ts\n */\n\nexport default {};\n`);
|
|
28
35
|
console.log(` ✅ Created ${langCode}.ts (${langName})`);
|
|
29
36
|
created++;
|
|
30
37
|
}
|
|
@@ -33,7 +40,7 @@ export function setupLanguages(options) {
|
|
|
33
40
|
console.log(`\n📦 Created ${created} new language stubs.\n`);
|
|
34
41
|
}
|
|
35
42
|
// Generate index.ts from all language files
|
|
36
|
-
const files =
|
|
43
|
+
const files = fs_1.default.readdirSync(localesDir)
|
|
37
44
|
.filter(f => f.match(/^[a-z]{2}-[A-Z]{2}\.ts$/))
|
|
38
45
|
.sort();
|
|
39
46
|
const imports = [];
|
|
@@ -60,16 +67,17 @@ export type TranslationKey = keyof typeof translations;
|
|
|
60
67
|
|
|
61
68
|
export default translations;
|
|
62
69
|
`;
|
|
63
|
-
|
|
70
|
+
fs_1.default.writeFileSync(path_1.default.join(localesDir, 'index.ts'), content);
|
|
64
71
|
console.log(`✅ Generated index.ts with ${files.length} languages`);
|
|
65
72
|
return true;
|
|
66
73
|
}
|
|
67
74
|
// CLI interface
|
|
68
|
-
|
|
75
|
+
function runSetupLanguages() {
|
|
69
76
|
const targetDir = process.argv[2] || 'src/infrastructure/locales';
|
|
70
77
|
console.log('🚀 Setting up language files...\n');
|
|
71
78
|
setupLanguages({ targetDir });
|
|
72
79
|
}
|
|
73
|
-
if
|
|
80
|
+
// Check if this file is being run directly
|
|
81
|
+
if (require.main === module || process.argv[1].endsWith('/setup.js') || process.argv[1].endsWith('\\setup.js')) {
|
|
74
82
|
runSetupLanguages();
|
|
75
83
|
}
|