@umituz/react-native-google-translate 1.0.6 → 1.0.8

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.
Files changed (68) hide show
  1. package/dist/domain/entities/Language.entity.d.ts +14 -0
  2. package/dist/domain/entities/Language.entity.d.ts.map +1 -0
  3. package/dist/domain/entities/Translation.entity.d.ts +31 -0
  4. package/dist/domain/entities/Translation.entity.d.ts.map +1 -0
  5. package/dist/domain/entities/index.d.ts +7 -0
  6. package/dist/domain/entities/index.d.ts.map +1 -0
  7. package/dist/domain/index.d.ts +9 -0
  8. package/dist/domain/index.d.ts.map +1 -0
  9. package/dist/domain/interfaces/ITranslationService.interface.d.ts +19 -0
  10. package/dist/domain/interfaces/ITranslationService.interface.d.ts.map +1 -0
  11. package/dist/domain/interfaces/index.d.ts +6 -0
  12. package/dist/domain/interfaces/index.d.ts.map +1 -0
  13. package/dist/index.d.ts +25 -0
  14. package/dist/index.d.ts.map +1 -0
  15. package/dist/index.js +40 -0
  16. package/dist/infrastructure/constants/api.constants.d.ts +9 -0
  17. package/dist/infrastructure/constants/api.constants.d.ts.map +1 -0
  18. package/dist/infrastructure/constants/index.d.ts +7 -0
  19. package/dist/infrastructure/constants/index.d.ts.map +1 -0
  20. package/dist/infrastructure/constants/languages.constants.d.ts +9 -0
  21. package/dist/infrastructure/constants/languages.constants.d.ts.map +1 -0
  22. package/dist/infrastructure/index.d.ts +10 -0
  23. package/dist/infrastructure/index.d.ts.map +1 -0
  24. package/dist/infrastructure/services/GoogleTranslate.service.d.ts +20 -0
  25. package/dist/infrastructure/services/GoogleTranslate.service.d.ts.map +1 -0
  26. package/dist/infrastructure/services/GoogleTranslate.service.js +114 -27
  27. package/dist/infrastructure/services/index.d.ts +8 -0
  28. package/dist/infrastructure/services/index.d.ts.map +1 -0
  29. package/dist/infrastructure/utils/index.d.ts +7 -0
  30. package/dist/infrastructure/utils/index.d.ts.map +1 -0
  31. package/dist/infrastructure/utils/rateLimit.util.d.ts +12 -0
  32. package/dist/infrastructure/utils/rateLimit.util.d.ts.map +1 -0
  33. package/dist/infrastructure/utils/textValidator.util.d.ts +11 -0
  34. package/dist/infrastructure/utils/textValidator.util.d.ts.map +1 -0
  35. package/dist/presentation/hooks/index.d.ts +9 -0
  36. package/dist/presentation/hooks/index.d.ts.map +1 -0
  37. package/dist/presentation/hooks/index.js +11 -0
  38. package/dist/presentation/hooks/useBatchTranslation.hook.d.ts +20 -0
  39. package/dist/presentation/hooks/useBatchTranslation.hook.d.ts.map +1 -0
  40. package/dist/presentation/hooks/useBatchTranslation.hook.js +105 -0
  41. package/dist/presentation/hooks/useTranslation.hook.d.ts +16 -0
  42. package/dist/presentation/hooks/useTranslation.hook.d.ts.map +1 -0
  43. package/dist/presentation/hooks/useTranslation.hook.js +67 -0
  44. package/dist/presentation/index.d.ts +8 -0
  45. package/dist/presentation/index.d.ts.map +1 -0
  46. package/dist/presentation/index.js +23 -0
  47. package/dist/scripts/index.d.ts +9 -0
  48. package/dist/scripts/index.d.ts.map +1 -0
  49. package/dist/scripts/setup.d.ts +13 -0
  50. package/dist/scripts/setup.d.ts.map +1 -0
  51. package/dist/scripts/sync.d.ts +21 -0
  52. package/dist/scripts/sync.d.ts.map +1 -0
  53. package/dist/scripts/translate.d.ts +13 -0
  54. package/dist/scripts/translate.d.ts.map +1 -0
  55. package/dist/scripts/utils/file-parser.d.ts +8 -0
  56. package/dist/scripts/utils/file-parser.d.ts.map +1 -0
  57. package/dist/scripts/utils/index.d.ts +10 -0
  58. package/dist/scripts/utils/index.d.ts.map +1 -0
  59. package/dist/scripts/utils/key-detector.d.ts +11 -0
  60. package/dist/scripts/utils/key-detector.d.ts.map +1 -0
  61. package/dist/scripts/utils/key-extractor.d.ts +2 -0
  62. package/dist/scripts/utils/key-extractor.d.ts.map +1 -0
  63. package/dist/scripts/utils/object-helper.d.ts +14 -0
  64. package/dist/scripts/utils/object-helper.d.ts.map +1 -0
  65. package/dist/scripts/utils/sync-helper.d.ts +13 -0
  66. package/dist/scripts/utils/sync-helper.d.ts.map +1 -0
  67. package/package.json +13 -12
  68. package/src/infrastructure/services/GoogleTranslate.service.ts +130 -24
@@ -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,9 @@
1
+ /**
2
+ * Domain Layer
3
+ * @description Subpath: @umituz/react-native-google-translate/core
4
+ *
5
+ * Exports all domain entities and interfaces
6
+ */
7
+ export * from "./entities";
8
+ export * from "./interfaces";
9
+ //# sourceMappingURL=index.d.ts.map
@@ -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,6 @@
1
+ /**
2
+ * Domain Interfaces
3
+ * @description Exports all interface definitions
4
+ */
5
+ export type { TranslationServiceConfig, ITranslationService, } from "./ITranslationService.interface";
6
+ //# sourceMappingURL=index.d.ts.map
@@ -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"}
@@ -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"}
@@ -84,6 +84,8 @@ class GoogleTranslateService {
84
84
  translatedKeys: [],
85
85
  };
86
86
  }
87
+ // Use batch API call for better performance
88
+ const batchSize = 50;
87
89
  const stats = {
88
90
  totalCount: requests.length,
89
91
  successCount: 0,
@@ -91,23 +93,52 @@ class GoogleTranslateService {
91
93
  skippedCount: 0,
92
94
  translatedKeys: [],
93
95
  };
94
- for (const request of requests) {
95
- const result = await this.translate(request);
96
- if (result.success) {
97
- if (result.translatedText === result.originalText) {
98
- stats.skippedCount++;
99
- }
100
- else {
101
- stats.successCount++;
102
- stats.translatedKeys.push({
103
- key: request.text,
104
- from: result.originalText,
105
- to: result.translatedText,
106
- });
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
+ }
107
119
  }
108
120
  }
109
- else {
110
- stats.failureCount++;
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
+ }
111
142
  }
112
143
  }
113
144
  return stats;
@@ -129,6 +160,8 @@ class GoogleTranslateService {
129
160
  return;
130
161
  }
131
162
  const keys = Object.keys(sourceObject);
163
+ // Collect all texts to translate first
164
+ const textsToTranslate = [];
132
165
  for (const key of keys) {
133
166
  const enValue = sourceObject[key];
134
167
  const targetValue = targetObject[key];
@@ -143,30 +176,42 @@ class GoogleTranslateService {
143
176
  else if (typeof enValue === "string") {
144
177
  stats.totalCount++;
145
178
  if ((0, textValidator_util_1.needsTranslation)(targetValue, enValue)) {
146
- const request = {
147
- text: enValue,
148
- targetLanguage,
149
- };
150
- const result = await this.translate(request);
151
- if (result.success && result.translatedText !== enValue) {
152
- targetObject[key] = result.translatedText;
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;
153
201
  stats.successCount++;
154
202
  stats.translatedKeys.push({
155
203
  key: currentPath,
156
204
  from: enValue,
157
- to: result.translatedText,
205
+ to: translatedKey.to,
158
206
  });
159
207
  }
160
- else if (!result.success) {
208
+ else if (!translatedKey) {
161
209
  stats.failureCount++;
162
210
  }
163
211
  else {
164
212
  stats.skippedCount++;
165
213
  }
166
214
  }
167
- else {
168
- stats.skippedCount++;
169
- }
170
215
  }
171
216
  }
172
217
  }
@@ -199,5 +244,47 @@ class GoogleTranslateService {
199
244
  clearTimeout(timeoutId);
200
245
  }
201
246
  }
247
+ async callTranslateAPIBatch(requests, targetLanguage, sourceLanguage = "en") {
248
+ const timeout = this.config?.timeout || constants_1.DEFAULT_TIMEOUT;
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
+ 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
+ // Google Translate batch response format:
263
+ // [[["translated1", ...]], [["translated2", ...]], ...]
264
+ const translations = [];
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]);
273
+ }
274
+ else {
275
+ translations.push(requests[i].text); // Fallback to original
276
+ }
277
+ }
278
+ }
279
+ // Fill missing translations with original text
280
+ while (translations.length < requests.length) {
281
+ translations.push(requests[translations.length].text);
282
+ }
283
+ return translations;
284
+ }
285
+ finally {
286
+ clearTimeout(timeoutId);
287
+ }
288
+ }
202
289
  }
203
290
  exports.googleTranslateService = new GoogleTranslateService();
@@ -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"}