@umituz/react-native-google-translate 1.0.7 → 1.0.9
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.d.ts +14 -0
- package/dist/domain/entities/Language.entity.d.ts.map +1 -0
- package/dist/domain/entities/Translation.entity.d.ts +31 -0
- package/dist/domain/entities/Translation.entity.d.ts.map +1 -0
- package/dist/domain/entities/index.d.ts +7 -0
- package/dist/domain/entities/index.d.ts.map +1 -0
- package/dist/domain/index.d.ts +9 -0
- package/dist/domain/index.d.ts.map +1 -0
- package/dist/domain/interfaces/ITranslationService.interface.d.ts +19 -0
- package/dist/domain/interfaces/ITranslationService.interface.d.ts.map +1 -0
- package/dist/domain/interfaces/index.d.ts +6 -0
- package/dist/domain/interfaces/index.d.ts.map +1 -0
- package/dist/index.d.ts +25 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +40 -0
- package/dist/infrastructure/constants/api.constants.d.ts +9 -0
- package/dist/infrastructure/constants/api.constants.d.ts.map +1 -0
- package/dist/infrastructure/constants/index.d.ts +7 -0
- package/dist/infrastructure/constants/index.d.ts.map +1 -0
- package/dist/infrastructure/constants/languages.constants.d.ts +9 -0
- package/dist/infrastructure/constants/languages.constants.d.ts.map +1 -0
- package/dist/infrastructure/index.d.ts +10 -0
- package/dist/infrastructure/index.d.ts.map +1 -0
- package/dist/infrastructure/services/GoogleTranslate.service.d.ts +20 -0
- package/dist/infrastructure/services/GoogleTranslate.service.d.ts.map +1 -0
- package/dist/infrastructure/services/GoogleTranslate.service.js +17 -11
- package/dist/infrastructure/services/index.d.ts +8 -0
- package/dist/infrastructure/services/index.d.ts.map +1 -0
- package/dist/infrastructure/utils/index.d.ts +7 -0
- package/dist/infrastructure/utils/index.d.ts.map +1 -0
- package/dist/infrastructure/utils/rateLimit.util.d.ts +12 -0
- package/dist/infrastructure/utils/rateLimit.util.d.ts.map +1 -0
- package/dist/infrastructure/utils/textValidator.util.d.ts +11 -0
- package/dist/infrastructure/utils/textValidator.util.d.ts.map +1 -0
- package/dist/presentation/hooks/index.d.ts +9 -0
- package/dist/presentation/hooks/index.d.ts.map +1 -0
- package/dist/presentation/hooks/index.js +11 -0
- package/dist/presentation/hooks/useBatchTranslation.hook.d.ts +20 -0
- package/dist/presentation/hooks/useBatchTranslation.hook.d.ts.map +1 -0
- package/dist/presentation/hooks/useBatchTranslation.hook.js +105 -0
- package/dist/presentation/hooks/useTranslation.hook.d.ts +16 -0
- package/dist/presentation/hooks/useTranslation.hook.d.ts.map +1 -0
- package/dist/presentation/hooks/useTranslation.hook.js +67 -0
- package/dist/presentation/index.d.ts +8 -0
- package/dist/presentation/index.d.ts.map +1 -0
- package/dist/presentation/index.js +23 -0
- package/dist/scripts/index.d.ts +9 -0
- package/dist/scripts/index.d.ts.map +1 -0
- package/dist/scripts/setup.d.ts +13 -0
- package/dist/scripts/setup.d.ts.map +1 -0
- package/dist/scripts/sync.d.ts +21 -0
- package/dist/scripts/sync.d.ts.map +1 -0
- package/dist/scripts/translate.d.ts +13 -0
- package/dist/scripts/translate.d.ts.map +1 -0
- package/dist/scripts/utils/file-parser.d.ts +8 -0
- package/dist/scripts/utils/file-parser.d.ts.map +1 -0
- package/dist/scripts/utils/index.d.ts +10 -0
- package/dist/scripts/utils/index.d.ts.map +1 -0
- package/dist/scripts/utils/key-detector.d.ts +11 -0
- package/dist/scripts/utils/key-detector.d.ts.map +1 -0
- package/dist/scripts/utils/key-extractor.d.ts +2 -0
- package/dist/scripts/utils/key-extractor.d.ts.map +1 -0
- package/dist/scripts/utils/object-helper.d.ts +14 -0
- package/dist/scripts/utils/object-helper.d.ts.map +1 -0
- package/dist/scripts/utils/sync-helper.d.ts +13 -0
- package/dist/scripts/utils/sync-helper.d.ts.map +1 -0
- package/package.json +13 -12
- package/src/infrastructure/services/GoogleTranslate.service.ts +18 -11
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Language Entity
|
|
3
|
+
* @description Language code mappings and metadata
|
|
4
|
+
*/
|
|
5
|
+
export type LanguageCode = `${string}-${string}`;
|
|
6
|
+
export interface LanguageInfo {
|
|
7
|
+
readonly code: LanguageCode;
|
|
8
|
+
readonly name: string;
|
|
9
|
+
readonly targetLanguage: string;
|
|
10
|
+
}
|
|
11
|
+
export interface LanguageMap {
|
|
12
|
+
readonly [key: string]: string;
|
|
13
|
+
}
|
|
14
|
+
//# sourceMappingURL=Language.entity.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"Language.entity.d.ts","sourceRoot":"","sources":["../../../src/domain/entities/Language.entity.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,MAAM,MAAM,YAAY,GAAG,GAAG,MAAM,IAAI,MAAM,EAAE,CAAC;AAEjD,MAAM,WAAW,YAAY;IAC3B,QAAQ,CAAC,IAAI,EAAE,YAAY,CAAC;IAC5B,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAC;IACtB,QAAQ,CAAC,cAAc,EAAE,MAAM,CAAC;CACjC;AAED,MAAM,WAAW,WAAW;IAC1B,QAAQ,EAAE,GAAG,EAAE,MAAM,GAAG,MAAM,CAAC;CAChC"}
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Translation Entity
|
|
3
|
+
* @description Represents a translation request and response
|
|
4
|
+
*/
|
|
5
|
+
export interface TranslationRequest {
|
|
6
|
+
readonly text: string;
|
|
7
|
+
readonly targetLanguage: string;
|
|
8
|
+
readonly sourceLanguage?: string;
|
|
9
|
+
}
|
|
10
|
+
export interface TranslationResponse {
|
|
11
|
+
readonly originalText: string;
|
|
12
|
+
readonly translatedText: string;
|
|
13
|
+
readonly sourceLanguage: string;
|
|
14
|
+
readonly targetLanguage: string;
|
|
15
|
+
readonly success: boolean;
|
|
16
|
+
readonly error?: string;
|
|
17
|
+
}
|
|
18
|
+
export interface TranslationStats {
|
|
19
|
+
totalCount: number;
|
|
20
|
+
successCount: number;
|
|
21
|
+
failureCount: number;
|
|
22
|
+
skippedCount: number;
|
|
23
|
+
translatedKeys: TranslationKeyInfo[];
|
|
24
|
+
}
|
|
25
|
+
export interface TranslationKeyInfo {
|
|
26
|
+
readonly key: string;
|
|
27
|
+
readonly from: string;
|
|
28
|
+
readonly to: string;
|
|
29
|
+
}
|
|
30
|
+
export type BatchTranslationResult = Record<string, TranslationResponse>;
|
|
31
|
+
//# sourceMappingURL=Translation.entity.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"Translation.entity.d.ts","sourceRoot":"","sources":["../../../src/domain/entities/Translation.entity.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,MAAM,WAAW,kBAAkB;IACjC,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAC;IACtB,QAAQ,CAAC,cAAc,EAAE,MAAM,CAAC;IAChC,QAAQ,CAAC,cAAc,CAAC,EAAE,MAAM,CAAC;CAClC;AAED,MAAM,WAAW,mBAAmB;IAClC,QAAQ,CAAC,YAAY,EAAE,MAAM,CAAC;IAC9B,QAAQ,CAAC,cAAc,EAAE,MAAM,CAAC;IAChC,QAAQ,CAAC,cAAc,EAAE,MAAM,CAAC;IAChC,QAAQ,CAAC,cAAc,EAAE,MAAM,CAAC;IAChC,QAAQ,CAAC,OAAO,EAAE,OAAO,CAAC;IAC1B,QAAQ,CAAC,KAAK,CAAC,EAAE,MAAM,CAAC;CACzB;AAED,MAAM,WAAW,gBAAgB;IAC/B,UAAU,EAAE,MAAM,CAAC;IACnB,YAAY,EAAE,MAAM,CAAC;IACrB,YAAY,EAAE,MAAM,CAAC;IACrB,YAAY,EAAE,MAAM,CAAC;IACrB,cAAc,EAAE,kBAAkB,EAAE,CAAC;CACtC;AAED,MAAM,WAAW,kBAAkB;IACjC,QAAQ,CAAC,GAAG,EAAE,MAAM,CAAC;IACrB,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAC;IACtB,QAAQ,CAAC,EAAE,EAAE,MAAM,CAAC;CACrB;AAED,MAAM,MAAM,sBAAsB,GAAG,MAAM,CAAC,MAAM,EAAE,mBAAmB,CAAC,CAAC"}
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Domain Entities
|
|
3
|
+
* @description Exports all entity types
|
|
4
|
+
*/
|
|
5
|
+
export type { TranslationRequest, TranslationResponse, TranslationStats, TranslationKeyInfo, BatchTranslationResult, } from "./Translation.entity";
|
|
6
|
+
export type { LanguageCode, LanguageInfo, LanguageMap } from "./Language.entity";
|
|
7
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/domain/entities/index.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,YAAY,EACV,kBAAkB,EAClB,mBAAmB,EACnB,gBAAgB,EAChB,kBAAkB,EAClB,sBAAsB,GACvB,MAAM,sBAAsB,CAAC;AAE9B,YAAY,EAAE,YAAY,EAAE,YAAY,EAAE,WAAW,EAAE,MAAM,mBAAmB,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/domain/index.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,cAAc,YAAY,CAAC;AAC3B,cAAc,cAAc,CAAC"}
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Translation Service Interface
|
|
3
|
+
* @description Defines the contract for translation services
|
|
4
|
+
*/
|
|
5
|
+
import type { TranslationRequest, TranslationResponse, TranslationStats } from "../entities";
|
|
6
|
+
export interface TranslationServiceConfig {
|
|
7
|
+
readonly apiKey?: string;
|
|
8
|
+
readonly minDelay?: number;
|
|
9
|
+
readonly maxRetries?: number;
|
|
10
|
+
readonly timeout?: number;
|
|
11
|
+
}
|
|
12
|
+
export interface ITranslationService {
|
|
13
|
+
initialize(config: TranslationServiceConfig): void;
|
|
14
|
+
isInitialized(): boolean;
|
|
15
|
+
translate(request: TranslationRequest): Promise<TranslationResponse>;
|
|
16
|
+
translateBatch(requests: TranslationRequest[]): Promise<TranslationStats>;
|
|
17
|
+
translateObject(sourceObject: Record<string, unknown>, targetObject: Record<string, unknown>, targetLanguage: string, path?: string, stats?: TranslationStats): Promise<void>;
|
|
18
|
+
}
|
|
19
|
+
//# sourceMappingURL=ITranslationService.interface.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"ITranslationService.interface.d.ts","sourceRoot":"","sources":["../../../src/domain/interfaces/ITranslationService.interface.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,OAAO,KAAK,EAAE,kBAAkB,EAAE,mBAAmB,EAAE,gBAAgB,EAAE,MAAM,aAAa,CAAC;AAE7F,MAAM,WAAW,wBAAwB;IACvC,QAAQ,CAAC,MAAM,CAAC,EAAE,MAAM,CAAC;IACzB,QAAQ,CAAC,QAAQ,CAAC,EAAE,MAAM,CAAC;IAC3B,QAAQ,CAAC,UAAU,CAAC,EAAE,MAAM,CAAC;IAC7B,QAAQ,CAAC,OAAO,CAAC,EAAE,MAAM,CAAC;CAC3B;AAED,MAAM,WAAW,mBAAmB;IAClC,UAAU,CAAC,MAAM,EAAE,wBAAwB,GAAG,IAAI,CAAC;IACnD,aAAa,IAAI,OAAO,CAAC;IACzB,SAAS,CAAC,OAAO,EAAE,kBAAkB,GAAG,OAAO,CAAC,mBAAmB,CAAC,CAAC;IACrE,cAAc,CAAC,QAAQ,EAAE,kBAAkB,EAAE,GAAG,OAAO,CAAC,gBAAgB,CAAC,CAAC;IAC1E,eAAe,CACb,YAAY,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,EACrC,YAAY,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,EACrC,cAAc,EAAE,MAAM,EACtB,IAAI,CAAC,EAAE,MAAM,EACb,KAAK,CAAC,EAAE,gBAAgB,GACvB,OAAO,CAAC,IAAI,CAAC,CAAC;CAClB"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/domain/interfaces/index.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,YAAY,EACV,wBAAwB,EACxB,mBAAmB,GACpB,MAAM,iCAAiC,CAAC"}
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @umituz/react-native-google-translate
|
|
3
|
+
* Google Translate integration for React Native applications
|
|
4
|
+
*
|
|
5
|
+
* For better tree-shaking and explicit dependencies, use subpath imports:
|
|
6
|
+
* - @umituz/react-native-google-translate/core - Domain entities and interfaces
|
|
7
|
+
* - @umituz/react-native-google-translate/services - Translation services
|
|
8
|
+
* - @umituz/react-native-google-translate/hooks - React hooks
|
|
9
|
+
*
|
|
10
|
+
* @example
|
|
11
|
+
* ```ts
|
|
12
|
+
* // ✅ RECOMMENDED: Subpath import (better tree-shaking)
|
|
13
|
+
* import { googleTranslateService } from "@umituz/react-native-google-translate/services";
|
|
14
|
+
* import { useTranslation } from "@umituz/react-native-google-translate/hooks";
|
|
15
|
+
*
|
|
16
|
+
* // ✅ ALSO SUPPORTED: Root import (convenience)
|
|
17
|
+
* import { googleTranslateService, useTranslation } from "@umituz/react-native-google-translate";
|
|
18
|
+
* ```
|
|
19
|
+
*/
|
|
20
|
+
export * from "./domain";
|
|
21
|
+
export * from "./infrastructure/services";
|
|
22
|
+
export * from "./infrastructure/utils";
|
|
23
|
+
export * from "./infrastructure/constants";
|
|
24
|
+
export * from "./presentation";
|
|
25
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;GAkBG;AAEH,cAAc,UAAU,CAAC;AACzB,cAAc,2BAA2B,CAAC;AAC1C,cAAc,wBAAwB,CAAC;AACvC,cAAc,4BAA4B,CAAC;AAC3C,cAAc,gBAAgB,CAAC"}
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* @umituz/react-native-google-translate
|
|
4
|
+
* Google Translate integration for React Native applications
|
|
5
|
+
*
|
|
6
|
+
* For better tree-shaking and explicit dependencies, use subpath imports:
|
|
7
|
+
* - @umituz/react-native-google-translate/core - Domain entities and interfaces
|
|
8
|
+
* - @umituz/react-native-google-translate/services - Translation services
|
|
9
|
+
* - @umituz/react-native-google-translate/hooks - React hooks
|
|
10
|
+
*
|
|
11
|
+
* @example
|
|
12
|
+
* ```ts
|
|
13
|
+
* // ✅ RECOMMENDED: Subpath import (better tree-shaking)
|
|
14
|
+
* import { googleTranslateService } from "@umituz/react-native-google-translate/services";
|
|
15
|
+
* import { useTranslation } from "@umituz/react-native-google-translate/hooks";
|
|
16
|
+
*
|
|
17
|
+
* // ✅ ALSO SUPPORTED: Root import (convenience)
|
|
18
|
+
* import { googleTranslateService, useTranslation } from "@umituz/react-native-google-translate";
|
|
19
|
+
* ```
|
|
20
|
+
*/
|
|
21
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
22
|
+
if (k2 === undefined) k2 = k;
|
|
23
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
24
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
25
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
26
|
+
}
|
|
27
|
+
Object.defineProperty(o, k2, desc);
|
|
28
|
+
}) : (function(o, m, k, k2) {
|
|
29
|
+
if (k2 === undefined) k2 = k;
|
|
30
|
+
o[k2] = m[k];
|
|
31
|
+
}));
|
|
32
|
+
var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
33
|
+
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
34
|
+
};
|
|
35
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
36
|
+
__exportStar(require("./domain"), exports);
|
|
37
|
+
__exportStar(require("./infrastructure/services"), exports);
|
|
38
|
+
__exportStar(require("./infrastructure/utils"), exports);
|
|
39
|
+
__exportStar(require("./infrastructure/constants"), exports);
|
|
40
|
+
__exportStar(require("./presentation"), exports);
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* API Constants
|
|
3
|
+
* @description Google Translate API configuration
|
|
4
|
+
*/
|
|
5
|
+
export declare const GOOGLE_TRANSLATE_API_URL = "https://translate.googleapis.com/translate_a/single";
|
|
6
|
+
export declare const DEFAULT_TIMEOUT = 10000;
|
|
7
|
+
export declare const DEFAULT_MIN_DELAY = 100;
|
|
8
|
+
export declare const DEFAULT_MAX_RETRIES = 3;
|
|
9
|
+
//# sourceMappingURL=api.constants.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"api.constants.d.ts","sourceRoot":"","sources":["../../../src/infrastructure/constants/api.constants.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,eAAO,MAAM,wBAAwB,wDAAwD,CAAC;AAE9F,eAAO,MAAM,eAAe,QAAQ,CAAC;AACrC,eAAO,MAAM,iBAAiB,MAAM,CAAC;AACrC,eAAO,MAAM,mBAAmB,IAAI,CAAC"}
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Infrastructure Constants
|
|
3
|
+
* @description Exports all constant definitions
|
|
4
|
+
*/
|
|
5
|
+
export { LANGUAGE_MAP, SKIP_WORDS, LANGUAGE_NAMES, } from "./languages.constants";
|
|
6
|
+
export { GOOGLE_TRANSLATE_API_URL, DEFAULT_TIMEOUT, DEFAULT_MIN_DELAY, DEFAULT_MAX_RETRIES, } from "./api.constants";
|
|
7
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/infrastructure/constants/index.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,OAAO,EACL,YAAY,EACZ,UAAU,EACV,cAAc,GACf,MAAM,uBAAuB,CAAC;AAE/B,OAAO,EACL,wBAAwB,EACxB,eAAe,EACf,iBAAiB,EACjB,mBAAmB,GACpB,MAAM,iBAAiB,CAAC"}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Language Constants
|
|
3
|
+
* @description Language mappings and metadata
|
|
4
|
+
*/
|
|
5
|
+
import type { LanguageMap } from "../../domain";
|
|
6
|
+
export declare const LANGUAGE_MAP: LanguageMap;
|
|
7
|
+
export declare const SKIP_WORDS: Set<string>;
|
|
8
|
+
export declare const LANGUAGE_NAMES: Record<string, string>;
|
|
9
|
+
//# sourceMappingURL=languages.constants.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"languages.constants.d.ts","sourceRoot":"","sources":["../../../src/infrastructure/constants/languages.constants.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,cAAc,CAAC;AAEhD,eAAO,MAAM,YAAY,EAAE,WAwC1B,CAAC;AAEF,eAAO,MAAM,UAAU,aAQrB,CAAC;AAEH,eAAO,MAAM,cAAc,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAyCjD,CAAC"}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Infrastructure Layer
|
|
3
|
+
* @description Subpath: @umituz/react-native-google-translate/infrastructure
|
|
4
|
+
*
|
|
5
|
+
* Exports all infrastructure services, utils, and constants
|
|
6
|
+
*/
|
|
7
|
+
export * from "./services";
|
|
8
|
+
export * from "./utils";
|
|
9
|
+
export * from "./constants";
|
|
10
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/infrastructure/index.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,cAAc,YAAY,CAAC;AAC3B,cAAc,SAAS,CAAC;AACxB,cAAc,aAAa,CAAC"}
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Google Translate Service
|
|
3
|
+
* @description Main translation service using Google Translate API
|
|
4
|
+
*/
|
|
5
|
+
import type { TranslationRequest, TranslationResponse, TranslationStats, ITranslationService, TranslationServiceConfig } from "../../domain";
|
|
6
|
+
declare class GoogleTranslateService implements ITranslationService {
|
|
7
|
+
private config;
|
|
8
|
+
private rateLimiter;
|
|
9
|
+
initialize(config: TranslationServiceConfig): void;
|
|
10
|
+
isInitialized(): boolean;
|
|
11
|
+
private ensureInitialized;
|
|
12
|
+
translate(request: TranslationRequest): Promise<TranslationResponse>;
|
|
13
|
+
translateBatch(requests: TranslationRequest[]): Promise<TranslationStats>;
|
|
14
|
+
translateObject(sourceObject: Record<string, unknown>, targetObject: Record<string, unknown>, targetLanguage: string, path?: string, stats?: TranslationStats): Promise<void>;
|
|
15
|
+
private callTranslateAPI;
|
|
16
|
+
private callTranslateAPIBatch;
|
|
17
|
+
}
|
|
18
|
+
export declare const googleTranslateService: GoogleTranslateService;
|
|
19
|
+
export {};
|
|
20
|
+
//# sourceMappingURL=GoogleTranslate.service.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"GoogleTranslate.service.d.ts","sourceRoot":"","sources":["../../../src/infrastructure/services/GoogleTranslate.service.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,OAAO,KAAK,EACV,kBAAkB,EAClB,mBAAmB,EACnB,gBAAgB,EAChB,mBAAmB,EACnB,wBAAwB,EACzB,MAAM,cAAc,CAAC;AActB,cAAM,sBAAuB,YAAW,mBAAmB;IACzD,OAAO,CAAC,MAAM,CAAyC;IACvD,OAAO,CAAC,WAAW,CAA4B;IAE/C,UAAU,CAAC,MAAM,EAAE,wBAAwB,GAAG,IAAI;IAUlD,aAAa,IAAI,OAAO;IAIxB,OAAO,CAAC,iBAAiB;IAQnB,SAAS,CAAC,OAAO,EAAE,kBAAkB,GAAG,OAAO,CAAC,mBAAmB,CAAC;IAuDpE,cAAc,CAAC,QAAQ,EAAE,kBAAkB,EAAE,GAAG,OAAO,CAAC,gBAAgB,CAAC;IA2EzE,eAAe,CACnB,YAAY,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,EACrC,YAAY,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,EACrC,cAAc,EAAE,MAAM,EACtB,IAAI,SAAK,EACT,KAAK,GAAE,gBAMN,GACA,OAAO,CAAC,IAAI,CAAC;YAmFF,gBAAgB;YAyChB,qBAAqB;CAuDpC;AAED,eAAO,MAAM,sBAAsB,wBAA+B,CAAC"}
|
|
@@ -246,9 +246,9 @@ class GoogleTranslateService {
|
|
|
246
246
|
}
|
|
247
247
|
async callTranslateAPIBatch(requests, targetLanguage, sourceLanguage = "en") {
|
|
248
248
|
const timeout = this.config?.timeout || constants_1.DEFAULT_TIMEOUT;
|
|
249
|
-
// Build batch request URL
|
|
250
|
-
const
|
|
251
|
-
const url = `${constants_1.GOOGLE_TRANSLATE_API_URL}?client=gtx&sl=${sourceLanguage}&tl=${targetLanguage}&dt=t
|
|
249
|
+
// Build batch request URL - Google Translate accepts multiple q parameters
|
|
250
|
+
const queryParams = requests.map(req => `q=${encodeURIComponent(req.text)}`).join('&');
|
|
251
|
+
const url = `${constants_1.GOOGLE_TRANSLATE_API_URL}?client=gtx&sl=${sourceLanguage}&tl=${targetLanguage}&dt=t&${queryParams}`;
|
|
252
252
|
const controller = new AbortController();
|
|
253
253
|
const timeoutId = setTimeout(() => controller.abort(), timeout);
|
|
254
254
|
try {
|
|
@@ -259,21 +259,27 @@ class GoogleTranslateService {
|
|
|
259
259
|
throw new Error(`Batch API request failed: ${response.status}`);
|
|
260
260
|
}
|
|
261
261
|
const data = await response.json();
|
|
262
|
-
//
|
|
262
|
+
// Google Translate batch response format:
|
|
263
|
+
// [[["translated1", ...]], [["translated2", ...]], ...]
|
|
263
264
|
const translations = [];
|
|
264
|
-
if (Array.isArray(data)
|
|
265
|
-
for (let i = 0; i < requests.length; i++) {
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
265
|
+
if (Array.isArray(data)) {
|
|
266
|
+
for (let i = 0; i < Math.min(requests.length, data.length); i++) {
|
|
267
|
+
const item = data[i];
|
|
268
|
+
if (Array.isArray(item) &&
|
|
269
|
+
item.length > 0 &&
|
|
270
|
+
Array.isArray(item[0]) &&
|
|
271
|
+
typeof item[0][0] === "string") {
|
|
272
|
+
translations.push(item[0][0]);
|
|
271
273
|
}
|
|
272
274
|
else {
|
|
273
275
|
translations.push(requests[i].text); // Fallback to original
|
|
274
276
|
}
|
|
275
277
|
}
|
|
276
278
|
}
|
|
279
|
+
// Fill missing translations with original text
|
|
280
|
+
while (translations.length < requests.length) {
|
|
281
|
+
translations.push(requests[translations.length].text);
|
|
282
|
+
}
|
|
277
283
|
return translations;
|
|
278
284
|
}
|
|
279
285
|
finally {
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Infrastructure Services
|
|
3
|
+
* @description Exports all services and utilities
|
|
4
|
+
*/
|
|
5
|
+
export { googleTranslateService } from "./GoogleTranslate.service";
|
|
6
|
+
export { shouldSkipWord, needsTranslation, isValidText, getTargetLanguage, isEnglishVariant, getLanguageDisplayName, } from "../utils/textValidator.util";
|
|
7
|
+
export { LANGUAGE_MAP, SKIP_WORDS, LANGUAGE_NAMES, } from "../constants/languages.constants";
|
|
8
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/infrastructure/services/index.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,OAAO,EAAE,sBAAsB,EAAE,MAAM,2BAA2B,CAAC;AAEnE,OAAO,EACL,cAAc,EACd,gBAAgB,EAChB,WAAW,EACX,iBAAiB,EACjB,gBAAgB,EAChB,sBAAsB,GACvB,MAAM,6BAA6B,CAAC;AAErC,OAAO,EACL,YAAY,EACZ,UAAU,EACV,cAAc,GACf,MAAM,kCAAkC,CAAC"}
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Infrastructure Utils
|
|
3
|
+
* @description Exports all utility functions
|
|
4
|
+
*/
|
|
5
|
+
export { RateLimiter } from "./rateLimit.util";
|
|
6
|
+
export { shouldSkipWord, needsTranslation, isValidText, getTargetLanguage, isEnglishVariant, getLanguageDisplayName, } from "./textValidator.util";
|
|
7
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/infrastructure/utils/index.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,OAAO,EAAE,WAAW,EAAE,MAAM,kBAAkB,CAAC;AAC/C,OAAO,EACL,cAAc,EACd,gBAAgB,EAChB,WAAW,EACX,iBAAiB,EACjB,gBAAgB,EAChB,sBAAsB,GACvB,MAAM,sBAAsB,CAAC"}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Rate Limit Utility
|
|
3
|
+
* @description Handles rate limiting for API requests
|
|
4
|
+
*/
|
|
5
|
+
export declare class RateLimiter {
|
|
6
|
+
private lastCallTime;
|
|
7
|
+
private readonly minDelay;
|
|
8
|
+
constructor(minDelay?: number);
|
|
9
|
+
waitForSlot(): Promise<void>;
|
|
10
|
+
reset(): void;
|
|
11
|
+
}
|
|
12
|
+
//# sourceMappingURL=rateLimit.util.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"rateLimit.util.d.ts","sourceRoot":"","sources":["../../../src/infrastructure/utils/rateLimit.util.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,qBAAa,WAAW;IACtB,OAAO,CAAC,YAAY,CAAa;IACjC,OAAO,CAAC,QAAQ,CAAC,QAAQ,CAAS;gBAEtB,QAAQ,GAAE,MAAY;IAI5B,WAAW,IAAI,OAAO,CAAC,IAAI,CAAC;IAYlC,KAAK,IAAI,IAAI;CAGd"}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Text Validator Utility
|
|
3
|
+
* @description Validates text for translation eligibility
|
|
4
|
+
*/
|
|
5
|
+
export declare function shouldSkipWord(word: string): boolean;
|
|
6
|
+
export declare function needsTranslation(value: unknown, enValue: unknown): boolean;
|
|
7
|
+
export declare function isValidText(text: unknown): text is string;
|
|
8
|
+
export declare function getTargetLanguage(langCode: string): string | undefined;
|
|
9
|
+
export declare function isEnglishVariant(langCode: string): boolean;
|
|
10
|
+
export declare function getLanguageDisplayName(code: string): string;
|
|
11
|
+
//# sourceMappingURL=textValidator.util.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"textValidator.util.d.ts","sourceRoot":"","sources":["../../../src/infrastructure/utils/textValidator.util.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAIH,wBAAgB,cAAc,CAAC,IAAI,EAAE,MAAM,GAAG,OAAO,CAEpD;AAED,wBAAgB,gBAAgB,CAC9B,KAAK,EAAE,OAAO,EACd,OAAO,EAAE,OAAO,GACf,OAAO,CAkCT;AAED,wBAAgB,WAAW,CAAC,IAAI,EAAE,OAAO,GAAG,IAAI,IAAI,MAAM,CAEzD;AAED,wBAAgB,iBAAiB,CAAC,QAAQ,EAAE,MAAM,GAAG,MAAM,GAAG,SAAS,CAEtE;AAED,wBAAgB,gBAAgB,CAAC,QAAQ,EAAE,MAAM,GAAG,OAAO,CAG1D;AAED,wBAAgB,sBAAsB,CAAC,IAAI,EAAE,MAAM,GAAG,MAAM,CAE3D"}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Presentation Hooks
|
|
3
|
+
* @description Exports all React hooks
|
|
4
|
+
*/
|
|
5
|
+
export { useTranslation } from "./useTranslation.hook";
|
|
6
|
+
export { useBatchTranslation } from "./useBatchTranslation.hook";
|
|
7
|
+
export type { UseTranslationOptions, UseTranslationReturn, } from "./useTranslation.hook";
|
|
8
|
+
export type { UseBatchTranslationOptions, UseBatchTranslationReturn, } from "./useBatchTranslation.hook";
|
|
9
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/presentation/hooks/index.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,OAAO,EAAE,cAAc,EAAE,MAAM,uBAAuB,CAAC;AACvD,OAAO,EAAE,mBAAmB,EAAE,MAAM,4BAA4B,CAAC;AAEjE,YAAY,EACV,qBAAqB,EACrB,oBAAoB,GACrB,MAAM,uBAAuB,CAAC;AAE/B,YAAY,EACV,0BAA0B,EAC1B,yBAAyB,GAC1B,MAAM,4BAA4B,CAAC"}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* Presentation Hooks
|
|
4
|
+
* @description Exports all React hooks
|
|
5
|
+
*/
|
|
6
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
7
|
+
exports.useBatchTranslation = exports.useTranslation = void 0;
|
|
8
|
+
var useTranslation_hook_1 = require("./useTranslation.hook");
|
|
9
|
+
Object.defineProperty(exports, "useTranslation", { enumerable: true, get: function () { return useTranslation_hook_1.useTranslation; } });
|
|
10
|
+
var useBatchTranslation_hook_1 = require("./useBatchTranslation.hook");
|
|
11
|
+
Object.defineProperty(exports, "useBatchTranslation", { enumerable: true, get: function () { return useBatchTranslation_hook_1.useBatchTranslation; } });
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* useBatchTranslation Hook
|
|
3
|
+
* @description React hook for batch translation of multiple texts
|
|
4
|
+
*/
|
|
5
|
+
import type { TranslationRequest, TranslationStats } from "../../domain";
|
|
6
|
+
export interface UseBatchTranslationOptions {
|
|
7
|
+
readonly onSuccess?: (stats: TranslationStats) => void;
|
|
8
|
+
readonly onError?: (error: Error) => void;
|
|
9
|
+
readonly onProgress?: (current: number, total: number) => void;
|
|
10
|
+
}
|
|
11
|
+
export interface UseBatchTranslationReturn {
|
|
12
|
+
readonly translateBatch: (requests: TranslationRequest[]) => Promise<TranslationStats>;
|
|
13
|
+
readonly translateObject: (sourceObject: Record<string, unknown>, targetObject: Record<string, unknown>, targetLanguage: string) => Promise<TranslationStats>;
|
|
14
|
+
readonly isLoading: boolean;
|
|
15
|
+
readonly progress: number;
|
|
16
|
+
readonly total: number;
|
|
17
|
+
readonly error: Error | null;
|
|
18
|
+
}
|
|
19
|
+
export declare function useBatchTranslation(options?: UseBatchTranslationOptions): UseBatchTranslationReturn;
|
|
20
|
+
//# sourceMappingURL=useBatchTranslation.hook.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"useBatchTranslation.hook.d.ts","sourceRoot":"","sources":["../../../src/presentation/hooks/useBatchTranslation.hook.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAGH,OAAO,KAAK,EACV,kBAAkB,EAClB,gBAAgB,EACjB,MAAM,cAAc,CAAC;AAGtB,MAAM,WAAW,0BAA0B;IACzC,QAAQ,CAAC,SAAS,CAAC,EAAE,CAAC,KAAK,EAAE,gBAAgB,KAAK,IAAI,CAAC;IACvD,QAAQ,CAAC,OAAO,CAAC,EAAE,CAAC,KAAK,EAAE,KAAK,KAAK,IAAI,CAAC;IAC1C,QAAQ,CAAC,UAAU,CAAC,EAAE,CAAC,OAAO,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM,KAAK,IAAI,CAAC;CAChE;AAED,MAAM,WAAW,yBAAyB;IACxC,QAAQ,CAAC,cAAc,EAAE,CACvB,QAAQ,EAAE,kBAAkB,EAAE,KAC3B,OAAO,CAAC,gBAAgB,CAAC,CAAC;IAC/B,QAAQ,CAAC,eAAe,EAAE,CACxB,YAAY,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,EACrC,YAAY,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,EACrC,cAAc,EAAE,MAAM,KACnB,OAAO,CAAC,gBAAgB,CAAC,CAAC;IAC/B,QAAQ,CAAC,SAAS,EAAE,OAAO,CAAC;IAC5B,QAAQ,CAAC,QAAQ,EAAE,MAAM,CAAC;IAC1B,QAAQ,CAAC,KAAK,EAAE,MAAM,CAAC;IACvB,QAAQ,CAAC,KAAK,EAAE,KAAK,GAAG,IAAI,CAAC;CAC9B;AAED,wBAAgB,mBAAmB,CACjC,OAAO,CAAC,EAAE,0BAA0B,GACnC,yBAAyB,CA+H3B"}
|
|
@@ -0,0 +1,105 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* useBatchTranslation Hook
|
|
4
|
+
* @description React hook for batch translation of multiple texts
|
|
5
|
+
*/
|
|
6
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
7
|
+
exports.useBatchTranslation = useBatchTranslation;
|
|
8
|
+
const react_1 = require("react");
|
|
9
|
+
const services_1 = require("../../infrastructure/services");
|
|
10
|
+
function useBatchTranslation(options) {
|
|
11
|
+
const [isLoading, setIsLoading] = (0, react_1.useState)(false);
|
|
12
|
+
const [error, setError] = (0, react_1.useState)(null);
|
|
13
|
+
const [progress, setProgress] = (0, react_1.useState)(0);
|
|
14
|
+
const [total, setTotal] = (0, react_1.useState)(0);
|
|
15
|
+
const translateBatch = (0, react_1.useCallback)(async (requests) => {
|
|
16
|
+
if (!Array.isArray(requests) || requests.length === 0) {
|
|
17
|
+
return {
|
|
18
|
+
totalCount: 0,
|
|
19
|
+
successCount: 0,
|
|
20
|
+
failureCount: 0,
|
|
21
|
+
skippedCount: 0,
|
|
22
|
+
translatedKeys: [],
|
|
23
|
+
};
|
|
24
|
+
}
|
|
25
|
+
setIsLoading(true);
|
|
26
|
+
setError(null);
|
|
27
|
+
setTotal(requests.length);
|
|
28
|
+
setProgress(0);
|
|
29
|
+
try {
|
|
30
|
+
const stats = await services_1.googleTranslateService.translateBatch(requests);
|
|
31
|
+
// Progress is completed
|
|
32
|
+
setProgress(stats.totalCount);
|
|
33
|
+
options?.onProgress?.(stats.totalCount, stats.totalCount);
|
|
34
|
+
if (stats.failureCount > 0) {
|
|
35
|
+
const error = new Error(`${stats.failureCount} of ${stats.totalCount} translations failed`);
|
|
36
|
+
setError(error);
|
|
37
|
+
options?.onError?.(error);
|
|
38
|
+
}
|
|
39
|
+
else {
|
|
40
|
+
options?.onSuccess?.(stats);
|
|
41
|
+
}
|
|
42
|
+
return stats;
|
|
43
|
+
}
|
|
44
|
+
catch (err) {
|
|
45
|
+
const error = err instanceof Error ? err : new Error("Unknown error occurred");
|
|
46
|
+
setError(error);
|
|
47
|
+
options?.onError?.(error);
|
|
48
|
+
throw error;
|
|
49
|
+
}
|
|
50
|
+
finally {
|
|
51
|
+
setIsLoading(false);
|
|
52
|
+
}
|
|
53
|
+
}, [options]);
|
|
54
|
+
const translateObject = (0, react_1.useCallback)(async (sourceObject, targetObject, targetLanguage) => {
|
|
55
|
+
if (!sourceObject || typeof sourceObject !== "object") {
|
|
56
|
+
throw new Error("Source object is invalid");
|
|
57
|
+
}
|
|
58
|
+
if (!targetObject || typeof targetObject !== "object") {
|
|
59
|
+
throw new Error("Target object is invalid");
|
|
60
|
+
}
|
|
61
|
+
if (!targetLanguage || targetLanguage.trim().length === 0) {
|
|
62
|
+
throw new Error("Target language is required");
|
|
63
|
+
}
|
|
64
|
+
setIsLoading(true);
|
|
65
|
+
setError(null);
|
|
66
|
+
try {
|
|
67
|
+
const stats = {
|
|
68
|
+
totalCount: 0,
|
|
69
|
+
successCount: 0,
|
|
70
|
+
failureCount: 0,
|
|
71
|
+
skippedCount: 0,
|
|
72
|
+
translatedKeys: [],
|
|
73
|
+
};
|
|
74
|
+
await services_1.googleTranslateService.translateObject(sourceObject, targetObject, targetLanguage, "", stats);
|
|
75
|
+
setTotal(stats.totalCount);
|
|
76
|
+
setProgress(stats.totalCount);
|
|
77
|
+
if (stats.failureCount > 0) {
|
|
78
|
+
const error = new Error(`${stats.failureCount} of ${stats.totalCount} translations failed`);
|
|
79
|
+
setError(error);
|
|
80
|
+
options?.onError?.(error);
|
|
81
|
+
}
|
|
82
|
+
else {
|
|
83
|
+
options?.onSuccess?.(stats);
|
|
84
|
+
}
|
|
85
|
+
return stats;
|
|
86
|
+
}
|
|
87
|
+
catch (err) {
|
|
88
|
+
const error = err instanceof Error ? err : new Error("Unknown error occurred");
|
|
89
|
+
setError(error);
|
|
90
|
+
options?.onError?.(error);
|
|
91
|
+
throw error;
|
|
92
|
+
}
|
|
93
|
+
finally {
|
|
94
|
+
setIsLoading(false);
|
|
95
|
+
}
|
|
96
|
+
}, [options]);
|
|
97
|
+
return {
|
|
98
|
+
translateBatch,
|
|
99
|
+
translateObject,
|
|
100
|
+
isLoading,
|
|
101
|
+
progress,
|
|
102
|
+
total,
|
|
103
|
+
error,
|
|
104
|
+
};
|
|
105
|
+
}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* useTranslation Hook
|
|
3
|
+
* @description React hook for single text translation
|
|
4
|
+
*/
|
|
5
|
+
import type { TranslationResponse } from "../../domain";
|
|
6
|
+
export interface UseTranslationOptions {
|
|
7
|
+
readonly onSuccess?: (result: TranslationResponse) => void;
|
|
8
|
+
readonly onError?: (error: Error) => void;
|
|
9
|
+
}
|
|
10
|
+
export interface UseTranslationReturn {
|
|
11
|
+
readonly translate: (text: string, targetLanguage: string) => Promise<TranslationResponse>;
|
|
12
|
+
readonly isLoading: boolean;
|
|
13
|
+
readonly error: Error | null;
|
|
14
|
+
}
|
|
15
|
+
export declare function useTranslation(options?: UseTranslationOptions): UseTranslationReturn;
|
|
16
|
+
//# sourceMappingURL=useTranslation.hook.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"useTranslation.hook.d.ts","sourceRoot":"","sources":["../../../src/presentation/hooks/useTranslation.hook.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAGH,OAAO,KAAK,EAAsB,mBAAmB,EAAE,MAAM,cAAc,CAAC;AAG5E,MAAM,WAAW,qBAAqB;IACpC,QAAQ,CAAC,SAAS,CAAC,EAAE,CAAC,MAAM,EAAE,mBAAmB,KAAK,IAAI,CAAC;IAC3D,QAAQ,CAAC,OAAO,CAAC,EAAE,CAAC,KAAK,EAAE,KAAK,KAAK,IAAI,CAAC;CAC3C;AAED,MAAM,WAAW,oBAAoB;IACnC,QAAQ,CAAC,SAAS,EAAE,CAAC,IAAI,EAAE,MAAM,EAAE,cAAc,EAAE,MAAM,KAAK,OAAO,CAAC,mBAAmB,CAAC,CAAC;IAC3F,QAAQ,CAAC,SAAS,EAAE,OAAO,CAAC;IAC5B,QAAQ,CAAC,KAAK,EAAE,KAAK,GAAG,IAAI,CAAC;CAC9B;AAED,wBAAgB,cAAc,CAC5B,OAAO,CAAC,EAAE,qBAAqB,GAC9B,oBAAoB,CAkEtB"}
|
|
@@ -0,0 +1,67 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* useTranslation Hook
|
|
4
|
+
* @description React hook for single text translation
|
|
5
|
+
*/
|
|
6
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
7
|
+
exports.useTranslation = useTranslation;
|
|
8
|
+
const react_1 = require("react");
|
|
9
|
+
const services_1 = require("../../infrastructure/services");
|
|
10
|
+
function useTranslation(options) {
|
|
11
|
+
const [isLoading, setIsLoading] = (0, react_1.useState)(false);
|
|
12
|
+
const [error, setError] = (0, react_1.useState)(null);
|
|
13
|
+
const translate = (0, react_1.useCallback)(async (text, targetLanguage) => {
|
|
14
|
+
if (!text || text.trim().length === 0) {
|
|
15
|
+
return {
|
|
16
|
+
originalText: text,
|
|
17
|
+
translatedText: text,
|
|
18
|
+
sourceLanguage: "en",
|
|
19
|
+
targetLanguage,
|
|
20
|
+
success: false,
|
|
21
|
+
error: "Text is empty",
|
|
22
|
+
};
|
|
23
|
+
}
|
|
24
|
+
if (!targetLanguage || targetLanguage.trim().length === 0) {
|
|
25
|
+
return {
|
|
26
|
+
originalText: text,
|
|
27
|
+
translatedText: text,
|
|
28
|
+
sourceLanguage: "en",
|
|
29
|
+
targetLanguage,
|
|
30
|
+
success: false,
|
|
31
|
+
error: "Target language is empty",
|
|
32
|
+
};
|
|
33
|
+
}
|
|
34
|
+
setIsLoading(true);
|
|
35
|
+
setError(null);
|
|
36
|
+
try {
|
|
37
|
+
const request = {
|
|
38
|
+
text,
|
|
39
|
+
targetLanguage,
|
|
40
|
+
};
|
|
41
|
+
const result = await services_1.googleTranslateService.translate(request);
|
|
42
|
+
if (result.success) {
|
|
43
|
+
options?.onSuccess?.(result);
|
|
44
|
+
}
|
|
45
|
+
else {
|
|
46
|
+
const error = new Error(result.error || "Translation failed");
|
|
47
|
+
setError(error);
|
|
48
|
+
options?.onError?.(error);
|
|
49
|
+
}
|
|
50
|
+
return result;
|
|
51
|
+
}
|
|
52
|
+
catch (err) {
|
|
53
|
+
const error = err instanceof Error ? err : new Error("Unknown error occurred");
|
|
54
|
+
setError(error);
|
|
55
|
+
options?.onError?.(error);
|
|
56
|
+
throw error;
|
|
57
|
+
}
|
|
58
|
+
finally {
|
|
59
|
+
setIsLoading(false);
|
|
60
|
+
}
|
|
61
|
+
}, [options]);
|
|
62
|
+
return {
|
|
63
|
+
translate,
|
|
64
|
+
isLoading,
|
|
65
|
+
error,
|
|
66
|
+
};
|
|
67
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/presentation/index.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,cAAc,SAAS,CAAC"}
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* Presentation Layer
|
|
4
|
+
* @description Subpath: @umituz/react-native-google-translate/hooks
|
|
5
|
+
*
|
|
6
|
+
* Exports all React hooks and presentation layer components
|
|
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("./hooks"), exports);
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/scripts/index.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,cAAc,aAAa,CAAC;AAC5B,cAAc,QAAQ,CAAC;AACvB,cAAc,SAAS,CAAC;AACxB,cAAc,SAAS,CAAC"}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
/**
|
|
3
|
+
* Setup Languages Script
|
|
4
|
+
* Creates stub files for all supported languages (if not exist),
|
|
5
|
+
* then generates index.ts from all available translation files.
|
|
6
|
+
* Usage: node setup.ts [locales-dir]
|
|
7
|
+
*/
|
|
8
|
+
export interface SetupLanguagesOptions {
|
|
9
|
+
targetDir: string;
|
|
10
|
+
}
|
|
11
|
+
export declare function setupLanguages(options: SetupLanguagesOptions): boolean;
|
|
12
|
+
export declare function runSetupLanguages(): void;
|
|
13
|
+
//# sourceMappingURL=setup.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"setup.d.ts","sourceRoot":"","sources":["../../src/scripts/setup.ts"],"names":[],"mappings":";AAEA;;;;;GAKG;AAMH,MAAM,WAAW,qBAAqB;IACpC,SAAS,EAAE,MAAM,CAAC;CACnB;AAED,wBAAgB,cAAc,CAAC,OAAO,EAAE,qBAAqB,GAAG,OAAO,CAkEtE;AAGD,wBAAgB,iBAAiB,IAAI,IAAI,CAIxC"}
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
/**
|
|
3
|
+
* Sync Translations Script
|
|
4
|
+
* Synchronizes translation keys from en-US.ts to all other language files
|
|
5
|
+
*/
|
|
6
|
+
export interface SyncTranslationsOptions {
|
|
7
|
+
targetDir: string;
|
|
8
|
+
srcDir?: string;
|
|
9
|
+
}
|
|
10
|
+
export interface SyncLanguageFileResult {
|
|
11
|
+
added?: number;
|
|
12
|
+
newKeys?: string[];
|
|
13
|
+
removed?: number;
|
|
14
|
+
removedKeys?: string[];
|
|
15
|
+
changed: boolean;
|
|
16
|
+
detectedNewKeys: unknown[];
|
|
17
|
+
}
|
|
18
|
+
export declare function syncLanguageFile(enUSPath: string, targetPath: string, langCode: string): SyncLanguageFileResult;
|
|
19
|
+
export declare function syncTranslations(options: SyncTranslationsOptions): boolean;
|
|
20
|
+
export declare function runSyncTranslations(): void;
|
|
21
|
+
//# sourceMappingURL=sync.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"sync.d.ts","sourceRoot":"","sources":["../../src/scripts/sync.ts"],"names":[],"mappings":";AAEA;;;GAGG;AAiBH,MAAM,WAAW,uBAAuB;IACtC,SAAS,EAAE,MAAM,CAAC;IAClB,MAAM,CAAC,EAAE,MAAM,CAAC;CACjB;AAED,MAAM,WAAW,sBAAsB;IACrC,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,OAAO,CAAC,EAAE,MAAM,EAAE,CAAC;IACnB,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,WAAW,CAAC,EAAE,MAAM,EAAE,CAAC;IACvB,OAAO,EAAE,OAAO,CAAC;IACjB,eAAe,EAAE,OAAO,EAAE,CAAC;CAC5B;AAED,wBAAgB,gBAAgB,CAC9B,QAAQ,EAAE,MAAM,EAChB,UAAU,EAAE,MAAM,EAClB,QAAQ,EAAE,MAAM,GACf,sBAAsB,CAgCxB;AAwCD,wBAAgB,gBAAgB,CAAC,OAAO,EAAE,uBAAuB,GAAG,OAAO,CA4B1E;AAGD,wBAAgB,mBAAmB,IAAI,IAAI,CAK1C"}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
/**
|
|
3
|
+
* Translate Missing Script
|
|
4
|
+
* Automatically translates missing strings using Google Translate
|
|
5
|
+
*/
|
|
6
|
+
export interface TranslateMissingOptions {
|
|
7
|
+
targetDir: string;
|
|
8
|
+
srcDir?: string;
|
|
9
|
+
skipSync?: boolean;
|
|
10
|
+
}
|
|
11
|
+
export declare function translateMissing(options: TranslateMissingOptions): Promise<void>;
|
|
12
|
+
export declare function runTranslateMissing(): void;
|
|
13
|
+
//# sourceMappingURL=translate.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"translate.d.ts","sourceRoot":"","sources":["../../src/scripts/translate.ts"],"names":[],"mappings":";AAEA;;;GAGG;AAcH,MAAM,WAAW,uBAAuB;IACtC,SAAS,EAAE,MAAM,CAAC;IAClB,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,QAAQ,CAAC,EAAE,OAAO,CAAC;CACpB;AAED,wBAAsB,gBAAgB,CAAC,OAAO,EAAE,uBAAuB,GAAG,OAAO,CAAC,IAAI,CAAC,CAkFtF;AAGD,wBAAgB,mBAAmB,IAAI,IAAI,CAW1C"}
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* File Parser
|
|
3
|
+
* Parse and generate TypeScript translation files
|
|
4
|
+
*/
|
|
5
|
+
export declare function parseTypeScriptFile(filePath: string): Record<string, unknown>;
|
|
6
|
+
export declare function stringifyValue(value: unknown, indent?: number): string;
|
|
7
|
+
export declare function generateTypeScriptContent(obj: Record<string, unknown>, langCode: string): string;
|
|
8
|
+
//# sourceMappingURL=file-parser.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"file-parser.d.ts","sourceRoot":"","sources":["../../../src/scripts/utils/file-parser.ts"],"names":[],"mappings":"AAIA;;;GAGG;AAEH,wBAAgB,mBAAmB,CAAC,QAAQ,EAAE,MAAM,GAAG,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CA0C7E;AAED,wBAAgB,cAAc,CAAC,KAAK,EAAE,OAAO,EAAE,MAAM,SAAI,GAAG,MAAM,CAmCjE;AAED,wBAAgB,yBAAyB,CAAC,GAAG,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,EAAE,QAAQ,EAAE,MAAM,GAAG,MAAM,CAYhG"}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Scripts Utils
|
|
3
|
+
* Utility functions for translation scripts
|
|
4
|
+
*/
|
|
5
|
+
export * from './file-parser';
|
|
6
|
+
export * from './key-detector';
|
|
7
|
+
export * from './key-extractor';
|
|
8
|
+
export * from './object-helper';
|
|
9
|
+
export * from './sync-helper';
|
|
10
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/scripts/utils/index.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,cAAc,eAAe,CAAC;AAC9B,cAAc,gBAAgB,CAAC;AAC/B,cAAc,iBAAiB,CAAC;AAChC,cAAc,iBAAiB,CAAC;AAChC,cAAc,eAAe,CAAC"}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Key Detector
|
|
3
|
+
* Detects new, missing, and removed keys between source and target objects
|
|
4
|
+
*/
|
|
5
|
+
export interface NewKey {
|
|
6
|
+
path: string;
|
|
7
|
+
value: unknown;
|
|
8
|
+
}
|
|
9
|
+
export declare function detectNewKeys(sourceObj: Record<string, unknown>, targetObj: Record<string, unknown>, path?: string, newKeys?: NewKey[]): NewKey[];
|
|
10
|
+
export declare function detectMissingKeys(sourceObj: Record<string, unknown>, targetObj: Record<string, unknown>, path?: string, missingKeys?: string[]): string[];
|
|
11
|
+
//# sourceMappingURL=key-detector.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"key-detector.d.ts","sourceRoot":"","sources":["../../../src/scripts/utils/key-detector.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,MAAM,WAAW,MAAM;IACrB,IAAI,EAAE,MAAM,CAAC;IACb,KAAK,EAAE,OAAO,CAAC;CAChB;AAED,wBAAgB,aAAa,CAC3B,SAAS,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,EAClC,SAAS,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,EAClC,IAAI,SAAK,EACT,OAAO,GAAE,MAAM,EAAO,GACrB,MAAM,EAAE,CAwBV;AAED,wBAAgB,iBAAiB,CAC/B,SAAS,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,EAClC,SAAS,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,EAClC,IAAI,SAAK,EACT,WAAW,GAAE,MAAM,EAAO,GACzB,MAAM,EAAE,CAuBV"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"key-extractor.d.ts","sourceRoot":"","sources":["../../../src/scripts/utils/key-extractor.ts"],"names":[],"mappings":"AA0FA,wBAAgB,eAAe,CAAC,MAAM,EAAE,MAAM,GAAG,GAAG,CAAC,MAAM,EAAE,MAAM,CAAC,CAiBnE"}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Object Helper
|
|
3
|
+
* Utilities for deep object manipulation
|
|
4
|
+
*/
|
|
5
|
+
/**
|
|
6
|
+
* Set a value in a nested object, creating intermediate objects if necessary
|
|
7
|
+
* Returns true if the key was newly added, false if it already existed
|
|
8
|
+
*/
|
|
9
|
+
export declare function setDeep(obj: Record<string, unknown>, path: string, value: unknown): boolean;
|
|
10
|
+
/**
|
|
11
|
+
* Count all leaf keys in a nested object
|
|
12
|
+
*/
|
|
13
|
+
export declare function countKeys(obj: Record<string, unknown>): number;
|
|
14
|
+
//# sourceMappingURL=object-helper.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"object-helper.d.ts","sourceRoot":"","sources":["../../../src/scripts/utils/object-helper.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH;;;GAGG;AACH,wBAAgB,OAAO,CAAC,GAAG,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,EAAE,IAAI,EAAE,MAAM,EAAE,KAAK,EAAE,OAAO,GAAG,OAAO,CAmB3F;AAED;;GAEG;AACH,wBAAgB,SAAS,CAAC,GAAG,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,GAAG,MAAM,CAe9D"}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Sync Helper
|
|
3
|
+
* Helper functions for synchronizing translation keys
|
|
4
|
+
*/
|
|
5
|
+
export interface SyncStats {
|
|
6
|
+
added?: number;
|
|
7
|
+
newKeys?: string[];
|
|
8
|
+
removed?: number;
|
|
9
|
+
removedKeys?: string[];
|
|
10
|
+
}
|
|
11
|
+
export declare function addMissingKeys(sourceObj: Record<string, unknown>, targetObj: Record<string, unknown>, stats?: SyncStats): SyncStats;
|
|
12
|
+
export declare function removeExtraKeys(sourceObj: Record<string, unknown>, targetObj: Record<string, unknown>, stats?: SyncStats): SyncStats;
|
|
13
|
+
//# sourceMappingURL=sync-helper.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"sync-helper.d.ts","sourceRoot":"","sources":["../../../src/scripts/utils/sync-helper.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,MAAM,WAAW,SAAS;IACxB,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,OAAO,CAAC,EAAE,MAAM,EAAE,CAAC;IACnB,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,WAAW,CAAC,EAAE,MAAM,EAAE,CAAC;CACxB;AAED,wBAAgB,cAAc,CAC5B,SAAS,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,EAClC,SAAS,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,EAClC,KAAK,GAAE,SAAc,GACpB,SAAS,CA4BX;AAED,wBAAgB,eAAe,CAC7B,SAAS,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,EAClC,SAAS,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,EAClC,KAAK,GAAE,SAAc,GACpB,SAAS,CA2BX"}
|
package/package.json
CHANGED
|
@@ -1,27 +1,28 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@umituz/react-native-google-translate",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.9",
|
|
4
4
|
"description": "Google Translate integration for React Native apps with rate limiting, batch translation, and TypeScript support",
|
|
5
|
-
"main": "./
|
|
6
|
-
"types": "./
|
|
5
|
+
"main": "./dist/index.js",
|
|
6
|
+
"types": "./dist/index.d.ts",
|
|
7
7
|
"sideEffects": false,
|
|
8
8
|
"exports": {
|
|
9
|
-
".": "./
|
|
10
|
-
"./core": "./
|
|
11
|
-
"./services": "./
|
|
12
|
-
"./constants": "./
|
|
13
|
-
"./hooks": "./
|
|
14
|
-
"./scripts": "./
|
|
15
|
-
"./package.json": "./package.json"
|
|
16
|
-
"./*": "./src/*/index.ts"
|
|
9
|
+
".": "./dist/index.js",
|
|
10
|
+
"./core": "./dist/domain/index.js",
|
|
11
|
+
"./services": "./dist/infrastructure/services/index.js",
|
|
12
|
+
"./constants": "./dist/infrastructure/constants/index.js",
|
|
13
|
+
"./hooks": "./dist/presentation/hooks/index.js",
|
|
14
|
+
"./scripts": "./dist/scripts/index.js",
|
|
15
|
+
"./package.json": "./package.json"
|
|
17
16
|
},
|
|
18
17
|
"scripts": {
|
|
18
|
+
"build": "tsc -p tsconfig.build.json",
|
|
19
19
|
"build:scripts": "tsc -p tsconfig.scripts.json",
|
|
20
|
+
"build:all": "npm run build && npm run build:scripts",
|
|
20
21
|
"setup": "node dist/scripts/setup.js",
|
|
21
22
|
"translate": "node dist/scripts/translate.js",
|
|
22
23
|
"sync": "node dist/scripts/sync.js",
|
|
23
24
|
"i18n:setup": "node dist/scripts/setup.js",
|
|
24
|
-
"prepublishOnly": "npm run build:
|
|
25
|
+
"prepublishOnly": "npm run build:all",
|
|
25
26
|
"typecheck": "tsc --noEmit",
|
|
26
27
|
"lint": "echo 'Lint passed'",
|
|
27
28
|
"version:patch": "npm version patch -m 'chore: release v%s'",
|
|
@@ -322,9 +322,9 @@ class GoogleTranslateService implements ITranslationService {
|
|
|
322
322
|
): Promise<string[]> {
|
|
323
323
|
const timeout = this.config?.timeout || DEFAULT_TIMEOUT;
|
|
324
324
|
|
|
325
|
-
// Build batch request URL
|
|
326
|
-
const
|
|
327
|
-
const url = `${GOOGLE_TRANSLATE_API_URL}?client=gtx&sl=${sourceLanguage}&tl=${targetLanguage}&dt=t
|
|
325
|
+
// Build batch request URL - Google Translate accepts multiple q parameters
|
|
326
|
+
const queryParams = requests.map(req => `q=${encodeURIComponent(req.text)}`).join('&');
|
|
327
|
+
const url = `${GOOGLE_TRANSLATE_API_URL}?client=gtx&sl=${sourceLanguage}&tl=${targetLanguage}&dt=t&${queryParams}`;
|
|
328
328
|
|
|
329
329
|
const controller = new AbortController();
|
|
330
330
|
const timeoutId = setTimeout(() => controller.abort(), timeout);
|
|
@@ -340,24 +340,31 @@ class GoogleTranslateService implements ITranslationService {
|
|
|
340
340
|
|
|
341
341
|
const data = await response.json();
|
|
342
342
|
|
|
343
|
-
//
|
|
343
|
+
// Google Translate batch response format:
|
|
344
|
+
// [[["translated1", ...]], [["translated2", ...]], ...]
|
|
344
345
|
const translations: string[] = [];
|
|
345
346
|
|
|
346
|
-
if (Array.isArray(data)
|
|
347
|
-
for (let i = 0; i < requests.length; i++) {
|
|
347
|
+
if (Array.isArray(data)) {
|
|
348
|
+
for (let i = 0; i < Math.min(requests.length, data.length); i++) {
|
|
349
|
+
const item = data[i];
|
|
348
350
|
if (
|
|
349
|
-
Array.isArray(
|
|
350
|
-
|
|
351
|
-
Array.isArray(
|
|
352
|
-
typeof
|
|
351
|
+
Array.isArray(item) &&
|
|
352
|
+
item.length > 0 &&
|
|
353
|
+
Array.isArray(item[0]) &&
|
|
354
|
+
typeof item[0][0] === "string"
|
|
353
355
|
) {
|
|
354
|
-
translations.push(
|
|
356
|
+
translations.push(item[0][0]);
|
|
355
357
|
} else {
|
|
356
358
|
translations.push(requests[i].text); // Fallback to original
|
|
357
359
|
}
|
|
358
360
|
}
|
|
359
361
|
}
|
|
360
362
|
|
|
363
|
+
// Fill missing translations with original text
|
|
364
|
+
while (translations.length < requests.length) {
|
|
365
|
+
translations.push(requests[translations.length].text);
|
|
366
|
+
}
|
|
367
|
+
|
|
361
368
|
return translations;
|
|
362
369
|
} finally {
|
|
363
370
|
clearTimeout(timeoutId);
|