generaltranslation 8.2.12 → 8.2.14

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 (222) hide show
  1. package/CHANGELOG.md +19 -0
  2. package/dist/{ApiError-IYfaOR30.mjs → ApiError-0DxxIHLp.mjs} +1 -1
  3. package/dist/{ApiError-CZ45tkW6.cjs.map → ApiError-0DxxIHLp.mjs.map} +1 -1
  4. package/dist/{ApiError-CZ45tkW6.cjs → ApiError-D-IBuHj6.cjs} +1 -1
  5. package/dist/{ApiError-IYfaOR30.mjs.map → ApiError-D-IBuHj6.cjs.map} +1 -1
  6. package/dist/LocaleConfig.d.ts +1 -0
  7. package/dist/LocaleConfig.js +1 -0
  8. package/dist/backwards-compatability/dataConversion.d.ts +23 -0
  9. package/dist/backwards-compatability/dataConversion.js +207 -0
  10. package/dist/backwards-compatability/oldHashJsxChildren.d.ts +23 -0
  11. package/dist/backwards-compatability/oldHashJsxChildren.js +79 -0
  12. package/dist/backwards-compatability/oldTypes.d.ts +21 -0
  13. package/dist/backwards-compatability/oldTypes.js +1 -0
  14. package/dist/backwards-compatability/typeChecking.d.ts +21 -0
  15. package/dist/backwards-compatability/typeChecking.js +61 -0
  16. package/dist/{base64-2fu94Klt.cjs → base64-C6BHySOc.cjs} +17 -1
  17. package/dist/base64-C6BHySOc.cjs.map +1 -0
  18. package/dist/{base64-DH0STixb.mjs → base64-CWITCfhU.mjs} +6 -2
  19. package/dist/base64-CWITCfhU.mjs.map +1 -0
  20. package/dist/core.cjs +9 -8
  21. package/dist/core.d.cts +1 -2
  22. package/dist/core.d.mts +1 -2
  23. package/dist/core.d.ts +1 -0
  24. package/dist/core.js +1 -0
  25. package/dist/core.mjs +2 -2
  26. package/dist/derive/condenseVars.d.ts +7 -0
  27. package/dist/derive/condenseVars.js +30 -0
  28. package/dist/derive/declareVar.d.ts +26 -0
  29. package/dist/derive/declareVar.js +38 -0
  30. package/dist/derive/decodeVars.d.ts +9 -0
  31. package/dist/derive/decodeVars.js +52 -0
  32. package/dist/derive/derive.d.ts +53 -0
  33. package/dist/derive/derive.js +55 -0
  34. package/dist/derive/extractVars.d.ts +9 -0
  35. package/dist/derive/extractVars.js +34 -0
  36. package/dist/derive/index.d.ts +7 -0
  37. package/dist/derive/index.js +7 -0
  38. package/dist/derive/indexVars.d.ts +6 -0
  39. package/dist/derive/indexVars.js +52 -0
  40. package/dist/derive/utils/constants.d.ts +2 -0
  41. package/dist/derive/utils/constants.js +2 -0
  42. package/dist/derive/utils/regex.d.ts +2 -0
  43. package/dist/derive/utils/regex.js +4 -0
  44. package/dist/derive/utils/sanitizeVar.d.ts +12 -0
  45. package/dist/derive/utils/sanitizeVar.js +38 -0
  46. package/dist/derive/utils/traverseHelpers.d.ts +4 -0
  47. package/dist/derive/utils/traverseHelpers.js +22 -0
  48. package/dist/derive/utils/traverseIcu.d.ts +20 -0
  49. package/dist/derive/utils/traverseIcu.js +49 -0
  50. package/dist/derive/utils/types.d.ts +23 -0
  51. package/dist/derive/utils/types.js +1 -0
  52. package/dist/errors/ApiError.d.ts +7 -0
  53. package/dist/errors/ApiError.js +33 -0
  54. package/dist/errors.cjs +1 -1
  55. package/dist/errors.d.ts +1 -0
  56. package/dist/errors.js +1 -0
  57. package/dist/errors.mjs +1 -1
  58. package/dist/id/hashSource.d.ts +25 -0
  59. package/dist/id/hashSource.js +98 -0
  60. package/dist/id/hashTemplate.d.ts +4 -0
  61. package/dist/id/hashTemplate.js +6 -0
  62. package/dist/id/types.d.ts +7 -0
  63. package/dist/id/types.js +1 -0
  64. package/dist/{id-CyiXsQrY.cjs → id-C2orn1MA.cjs} +2 -2
  65. package/dist/{id-CyiXsQrY.cjs.map → id-C2orn1MA.cjs.map} +1 -1
  66. package/dist/{id-DbD7K-HL.mjs → id-DEaFhGqX.mjs} +2 -2
  67. package/dist/{id-DbD7K-HL.mjs.map → id-DEaFhGqX.mjs.map} +1 -1
  68. package/dist/id.cjs +1 -1
  69. package/dist/id.d.cts +1 -1
  70. package/dist/id.d.mts +1 -1
  71. package/dist/id.d.ts +3 -0
  72. package/dist/id.js +3 -0
  73. package/dist/id.mjs +1 -1
  74. package/dist/index.cjs +368 -385
  75. package/dist/index.cjs.map +1 -1
  76. package/dist/index.d.cts +4 -242
  77. package/dist/index.d.mts +4 -242
  78. package/dist/index.d.ts +786 -0
  79. package/dist/index.js +1345 -0
  80. package/dist/index.mjs +215 -352
  81. package/dist/index.mjs.map +1 -1
  82. package/dist/internal.cjs +7 -7
  83. package/dist/internal.cjs.map +1 -1
  84. package/dist/internal.d.cts +7 -6
  85. package/dist/internal.d.mts +7 -6
  86. package/dist/internal.d.ts +19 -0
  87. package/dist/internal.js +17 -0
  88. package/dist/internal.mjs +5 -5
  89. package/dist/internal.mjs.map +1 -1
  90. package/dist/{isVariable-B08mggBy.cjs → isVariable-Ba1gLXdB.cjs} +1 -1
  91. package/dist/{isVariable-B08mggBy.cjs.map → isVariable-Ba1gLXdB.cjs.map} +1 -1
  92. package/dist/{isVariable-CYsKFHvR.mjs → isVariable-fAKEB7gF.mjs} +1 -1
  93. package/dist/{isVariable-CYsKFHvR.mjs.map → isVariable-fAKEB7gF.mjs.map} +1 -1
  94. package/dist/locales/getPluralForm.d.ts +9 -0
  95. package/dist/locales/getPluralForm.js +63 -0
  96. package/dist/logging/errors.d.ts +10 -0
  97. package/dist/logging/errors.js +29 -0
  98. package/dist/logging/logger.d.ts +118 -0
  99. package/dist/logging/logger.js +256 -0
  100. package/dist/projects/getProjectData.d.ts +1 -0
  101. package/dist/projects/getProjectData.js +87 -0
  102. package/dist/settings/plurals.d.ts +3 -0
  103. package/dist/settings/plurals.js +14 -0
  104. package/dist/settings/settings.d.ts +2 -0
  105. package/dist/settings/settings.js +2 -0
  106. package/dist/settings/settingsUrls.d.ts +3 -0
  107. package/dist/settings/settingsUrls.js +3 -0
  108. package/dist/translate/api.d.ts +1 -0
  109. package/dist/translate/api.js +1 -0
  110. package/dist/translate/awaitJobs.d.ts +19 -0
  111. package/dist/translate/awaitJobs.js +112 -0
  112. package/dist/translate/checkJobStatus.d.ts +8 -0
  113. package/dist/translate/checkJobStatus.js +55 -0
  114. package/dist/translate/createBranch.d.ts +10 -0
  115. package/dist/translate/createBranch.js +53 -0
  116. package/dist/translate/createTag.d.ts +19 -0
  117. package/dist/translate/createTag.js +67 -0
  118. package/dist/translate/downloadFileBatch.d.ts +1 -0
  119. package/dist/translate/downloadFileBatch.js +77 -0
  120. package/dist/translate/enqueueFiles.d.ts +8 -0
  121. package/dist/translate/enqueueFiles.js +96 -0
  122. package/dist/translate/getOrphanedFiles.d.ts +8 -0
  123. package/dist/translate/getOrphanedFiles.js +97 -0
  124. package/dist/translate/processFileMoves.d.ts +25 -0
  125. package/dist/translate/processFileMoves.js +90 -0
  126. package/dist/translate/publishFiles.d.ts +17 -0
  127. package/dist/translate/publishFiles.js +56 -0
  128. package/dist/translate/queryBranchData.d.ts +3 -0
  129. package/dist/translate/queryBranchData.js +53 -0
  130. package/dist/translate/queryFileData.d.ts +42 -0
  131. package/dist/translate/queryFileData.js +71 -0
  132. package/dist/translate/querySourceFile.d.ts +1 -0
  133. package/dist/translate/querySourceFile.js +67 -0
  134. package/dist/translate/setupProject.d.ts +11 -0
  135. package/dist/translate/setupProject.js +63 -0
  136. package/dist/translate/submitUserEditDiffs.d.ts +12 -0
  137. package/dist/translate/submitUserEditDiffs.js +68 -0
  138. package/dist/translate/translateMany.d.ts +1 -0
  139. package/dist/translate/translateMany.js +103 -0
  140. package/dist/translate/uploadSourceFiles.d.ts +1 -0
  141. package/dist/translate/uploadSourceFiles.js +87 -0
  142. package/dist/translate/uploadTranslations.d.ts +1 -0
  143. package/dist/translate/uploadTranslations.js +101 -0
  144. package/dist/translate/utils/apiRequest.d.ts +1 -0
  145. package/dist/translate/utils/apiRequest.js +130 -0
  146. package/dist/translate/utils/batch.d.ts +52 -0
  147. package/dist/translate/utils/batch.js +126 -0
  148. package/dist/translate/utils/fetchWithTimeout.d.ts +1 -0
  149. package/dist/translate/utils/fetchWithTimeout.js +93 -0
  150. package/dist/translate/utils/generateRequestHeaders.d.ts +2 -0
  151. package/dist/translate/utils/generateRequestHeaders.js +26 -0
  152. package/dist/translate/utils/handleFetchError.d.ts +1 -0
  153. package/dist/translate/utils/handleFetchError.js +12 -0
  154. package/dist/translate/utils/validateFileFormatTransform.d.ts +16 -0
  155. package/dist/translate/utils/validateFileFormatTransform.js +29 -0
  156. package/dist/translate/utils/validateResponse.d.ts +1 -0
  157. package/dist/translate/utils/validateResponse.js +72 -0
  158. package/dist/{types-V5rqd1WR.d.cts → types-73XFwmhH.d.mts} +39 -115
  159. package/dist/{types-BsGsgJWF.d.mts → types-YrrGRHBP.d.cts} +39 -115
  160. package/dist/types-dir/api/branch.d.ts +10 -0
  161. package/dist/types-dir/api/branch.js +1 -0
  162. package/dist/types-dir/api/checkFileTranslations.d.ts +37 -0
  163. package/dist/types-dir/api/checkFileTranslations.js +1 -0
  164. package/dist/types-dir/api/downloadFile.d.ts +3 -0
  165. package/dist/types-dir/api/downloadFile.js +1 -0
  166. package/dist/types-dir/api/downloadFileBatch.d.ts +35 -0
  167. package/dist/types-dir/api/downloadFileBatch.js +1 -0
  168. package/dist/types-dir/api/enqueueEntries.d.ts +21 -0
  169. package/dist/types-dir/api/enqueueEntries.js +1 -0
  170. package/dist/types-dir/api/enqueueFiles.d.ts +70 -0
  171. package/dist/types-dir/api/enqueueFiles.js +1 -0
  172. package/dist/types-dir/api/entry.d.ts +39 -0
  173. package/dist/types-dir/api/entry.js +1 -0
  174. package/dist/types-dir/api/fetchTranslations.d.ts +12 -0
  175. package/dist/types-dir/api/fetchTranslations.js +1 -0
  176. package/dist/types-dir/api/file.d.ts +57 -0
  177. package/dist/types-dir/api/file.js +1 -0
  178. package/dist/types-dir/api/json.d.ts +5 -0
  179. package/dist/types-dir/api/json.js +1 -0
  180. package/dist/types-dir/api/project.d.ts +7 -0
  181. package/dist/types-dir/api/project.js +1 -0
  182. package/dist/types-dir/api/translate.d.ts +34 -0
  183. package/dist/types-dir/api/translate.js +1 -0
  184. package/dist/types-dir/api/translateMany.d.ts +5 -0
  185. package/dist/types-dir/api/translateMany.js +1 -0
  186. package/dist/types-dir/api/translationStatus.d.ts +9 -0
  187. package/dist/types-dir/api/translationStatus.js +1 -0
  188. package/dist/types-dir/api/uploadFiles.d.ts +44 -0
  189. package/dist/types-dir/api/uploadFiles.js +1 -0
  190. package/dist/types-dir/transformations.d.ts +8 -0
  191. package/dist/types-dir/transformations.js +1 -0
  192. package/dist/types.cjs +7 -16
  193. package/dist/types.d.cts +2 -2
  194. package/dist/types.d.mts +2 -2
  195. package/dist/types.d.ts +127 -0
  196. package/dist/types.js +1 -0
  197. package/dist/types.mjs +1 -15
  198. package/dist/utils/base64.d.ts +2 -0
  199. package/dist/utils/base64.js +28 -0
  200. package/dist/utils/isSupportedFileFormatTransform.d.ts +8 -0
  201. package/dist/utils/isSupportedFileFormatTransform.js +26 -0
  202. package/dist/utils/isVariable.d.ts +2 -0
  203. package/dist/utils/isVariable.js +22 -0
  204. package/dist/utils/minify.d.ts +2 -0
  205. package/dist/utils/minify.js +10 -0
  206. package/dist/utils/stableStringify.d.ts +1 -0
  207. package/dist/utils/stableStringify.js +40 -0
  208. package/package.json +5 -4
  209. package/dist/IntlCache-CAW8tKhd.cjs +0 -212
  210. package/dist/IntlCache-CAW8tKhd.cjs.map +0 -1
  211. package/dist/IntlCache-WZk0rKvj.mjs +0 -195
  212. package/dist/IntlCache-WZk0rKvj.mjs.map +0 -1
  213. package/dist/base64-2fu94Klt.cjs.map +0 -1
  214. package/dist/base64-DH0STixb.mjs.map +0 -1
  215. package/dist/core-7RJsqw6c.mjs +0 -1498
  216. package/dist/core-7RJsqw6c.mjs.map +0 -1
  217. package/dist/core-CGhlXrrK.d.mts +0 -209
  218. package/dist/core-CST4J4WU.cjs +0 -1677
  219. package/dist/core-CST4J4WU.cjs.map +0 -1
  220. package/dist/core-D-E8qhLn.d.cts +0 -209
  221. package/dist/types.cjs.map +0 -1
  222. package/dist/types.mjs.map +0 -1
package/dist/index.js ADDED
@@ -0,0 +1,1345 @@
1
+ // `generaltranslation` language toolkit
2
+ // © 2026, General Translation, Inc.
3
+ var __assign = (this && this.__assign) || function () {
4
+ __assign = Object.assign || function(t) {
5
+ for (var s, i = 1, n = arguments.length; i < n; i++) {
6
+ s = arguments[i];
7
+ for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
8
+ t[p] = s[p];
9
+ }
10
+ return t;
11
+ };
12
+ return __assign.apply(this, arguments);
13
+ };
14
+ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
15
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
16
+ return new (P || (P = Promise))(function (resolve, reject) {
17
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
18
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
19
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
20
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
21
+ });
22
+ };
23
+ var __generator = (this && this.__generator) || function (thisArg, body) {
24
+ var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g = Object.create((typeof Iterator === "function" ? Iterator : Object).prototype);
25
+ return g.next = verb(0), g["throw"] = verb(1), g["return"] = verb(2), typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
26
+ function verb(n) { return function (v) { return step([n, v]); }; }
27
+ function step(op) {
28
+ if (f) throw new TypeError("Generator is already executing.");
29
+ while (g && (g = 0, op[0] && (_ = 0)), _) try {
30
+ if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
31
+ if (y = 0, t) op = [op[0] & 2, t.value];
32
+ switch (op[0]) {
33
+ case 0: case 1: t = op; break;
34
+ case 4: _.label++; return { value: op[1], done: false };
35
+ case 5: _.label++; y = op[1]; op = [0]; continue;
36
+ case 7: op = _.ops.pop(); _.trys.pop(); continue;
37
+ default:
38
+ if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
39
+ if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
40
+ if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
41
+ if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
42
+ if (t[2]) _.ops.pop();
43
+ _.trys.pop(); continue;
44
+ }
45
+ op = body.call(thisArg, _);
46
+ } catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
47
+ if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
48
+ }
49
+ };
50
+ // ----- IMPORTS ----- //
51
+ import { LocaleConfig, determineLocale as _determineLocale, getRegionProperties as _getRegionProperties, isValidLocale as _isValidLocale, requiresTranslation as _requiresTranslation, resolveAliasLocale as _resolveAliasLocale, resolveCanonicalLocale as _resolveCanonicalLocale, standardizeLocale as _standardizeLocale, } from '@generaltranslation/format';
52
+ import { libraryDefaultLocale } from './settings/settings';
53
+ import { noSourceLocaleProvidedError, noTargetLocaleProvidedError, invalidLocaleError, invalidLocalesError, noProjectIdProvidedError, noApiKeyProvidedError, } from './logging/errors';
54
+ import { gtInstanceLogger } from './logging/logger';
55
+ import _translateMany from './translate/translateMany';
56
+ import _setupProject from './translate/setupProject';
57
+ import _enqueueFiles from './translate/enqueueFiles';
58
+ import _createTag from './translate/createTag';
59
+ import _downloadFileBatch from './translate/downloadFileBatch';
60
+ import _submitUserEditDiffs from './translate/submitUserEditDiffs';
61
+ import _uploadSourceFiles from './translate/uploadSourceFiles';
62
+ import _uploadTranslations from './translate/uploadTranslations';
63
+ import _querySourceFile from './translate/querySourceFile';
64
+ import _getProjectData from './projects/getProjectData';
65
+ import { _checkJobStatus, } from './translate/checkJobStatus';
66
+ import _awaitJobs from './translate/awaitJobs';
67
+ import _queryFileData from './translate/queryFileData';
68
+ import _queryBranchData from './translate/queryBranchData';
69
+ import _createBranch from './translate/createBranch';
70
+ import _processFileMoves from './translate/processFileMoves';
71
+ import _getOrphanedFiles from './translate/getOrphanedFiles';
72
+ import _publishFiles from './translate/publishFiles';
73
+ import { API_VERSION as _API_VERSION } from './translate/api';
74
+ export { LocaleConfig, } from '@generaltranslation/format';
75
+ export { determineLocale, formatCurrency, formatCutoff, formatDateTime, formatList, formatListToParts, formatMessage, formatNum, formatRelativeTime, formatRelativeTimeFromDate, getLocaleDirection, getLocaleEmoji, getLocaleName, getLocaleProperties, getRegionProperties, isSameDialect, isSameLanguage, isSupersetLocale, isValidLocale, requiresTranslation, resolveAliasLocale, resolveCanonicalLocale, standardizeLocale, } from '@generaltranslation/format';
76
+ /**
77
+ * GT is the core driver for the General Translation library.
78
+ * This class provides functionality for locale management, formatting, and translation operations.
79
+ *
80
+ * @class GT
81
+ * @description A comprehensive toolkit for handling internationalization and localization.
82
+ *
83
+ * @example
84
+ * const gt = new GT({
85
+ * sourceLocale: 'en-US',
86
+ * targetLocale: 'es-ES',
87
+ * locales: ['en-US', 'es-ES', 'fr-FR']
88
+ * });
89
+ */
90
+ var GT = /** @class */ (function () {
91
+ /**
92
+ * Constructs an instance of the GT class.
93
+ *
94
+ * @param {GTConstructorParams} [params] - The parameters for initializing the GT instance
95
+ * @throws {Error} If an invalid locale is provided
96
+ * @throws {Error} If any of the provided locales are invalid
97
+ *
98
+ * @example
99
+ * const gt = new GT({
100
+ * apiKey: 'your-api-key',
101
+ * sourceLocale: 'en-US',
102
+ * targetLocale: 'es-ES',
103
+ * locales: ['en-US', 'es-ES', 'fr-FR']
104
+ * });
105
+ */
106
+ function GT(params) {
107
+ if (params === void 0) { params = {}; }
108
+ var _a, _b, _c;
109
+ // Read environment
110
+ if (typeof process !== 'undefined') {
111
+ this.apiKey || (this.apiKey = (_a = process.env) === null || _a === void 0 ? void 0 : _a.GT_API_KEY);
112
+ this.devApiKey || (this.devApiKey = (_b = process.env) === null || _b === void 0 ? void 0 : _b.GT_DEV_API_KEY);
113
+ this.projectId || (this.projectId = (_c = process.env) === null || _c === void 0 ? void 0 : _c.GT_PROJECT_ID);
114
+ }
115
+ // Set up config
116
+ this.setConfig(params);
117
+ }
118
+ Object.defineProperty(GT.prototype, "localeConfig", {
119
+ /** Runtime-safe locale and formatting helpers */
120
+ get: function () {
121
+ return this._localeConfig;
122
+ },
123
+ enumerable: false,
124
+ configurable: true
125
+ });
126
+ GT.prototype.setConfig = function (_a) {
127
+ var _b;
128
+ var apiKey = _a.apiKey, devApiKey = _a.devApiKey, sourceLocale = _a.sourceLocale, targetLocale = _a.targetLocale, locales = _a.locales, projectId = _a.projectId, customMapping = _a.customMapping, baseUrl = _a.baseUrl;
129
+ // ----- Environment properties ----- //
130
+ if (apiKey)
131
+ this.apiKey = apiKey;
132
+ if (devApiKey)
133
+ this.devApiKey = devApiKey;
134
+ if (projectId)
135
+ this.projectId = projectId;
136
+ // ----- Standardize locales ----- //
137
+ // source locale
138
+ if (sourceLocale) {
139
+ this.sourceLocale = _standardizeLocale(sourceLocale);
140
+ if (!_isValidLocale(this.sourceLocale, customMapping))
141
+ throw new Error(invalidLocaleError(this.sourceLocale));
142
+ }
143
+ // target locale
144
+ if (targetLocale) {
145
+ this.targetLocale = _standardizeLocale(targetLocale);
146
+ if (!_isValidLocale(this.targetLocale, customMapping))
147
+ throw new Error(invalidLocaleError(this.targetLocale));
148
+ }
149
+ // locales
150
+ if (locales) {
151
+ var result_1 = [];
152
+ var invalidLocales_1 = [];
153
+ locales.forEach(function (locale) {
154
+ var standardizedLocale = _standardizeLocale(locale);
155
+ if (_isValidLocale(standardizedLocale)) {
156
+ result_1.push(standardizedLocale);
157
+ }
158
+ else {
159
+ invalidLocales_1.push(locale);
160
+ }
161
+ });
162
+ if (invalidLocales_1.length > 0) {
163
+ throw new Error(invalidLocalesError(invalidLocales_1));
164
+ }
165
+ this.locales = result_1;
166
+ }
167
+ // ----- Other properties ----- //
168
+ if (baseUrl)
169
+ this.baseUrl = baseUrl;
170
+ if (customMapping) {
171
+ this.customMapping = customMapping;
172
+ this.reverseCustomMapping = Object.fromEntries(Object.entries(customMapping)
173
+ .filter(function (_a) {
174
+ var value = _a[1];
175
+ return value && typeof value === 'object' && 'code' in value;
176
+ })
177
+ .map(function (_a) {
178
+ var key = _a[0], value = _a[1];
179
+ return [value.code, key];
180
+ }));
181
+ }
182
+ this._localeConfig = new LocaleConfig({
183
+ defaultLocale: this.sourceLocale,
184
+ locales: (_b = this.locales) !== null && _b !== void 0 ? _b : [],
185
+ customMapping: this.customMapping,
186
+ });
187
+ };
188
+ // -------------- Private Methods -------------- //
189
+ GT.prototype._getTranslationConfig = function () {
190
+ return {
191
+ baseUrl: this.baseUrl,
192
+ apiKey: this.apiKey || this.devApiKey,
193
+ projectId: this.projectId || '',
194
+ };
195
+ };
196
+ GT.prototype._validateAuth = function (functionName) {
197
+ var errors = [];
198
+ if (!this.apiKey && !this.devApiKey) {
199
+ var error = noApiKeyProvidedError(functionName);
200
+ errors.push(error);
201
+ }
202
+ if (!this.projectId) {
203
+ var error = noProjectIdProvidedError(functionName);
204
+ errors.push(error);
205
+ }
206
+ if (errors.length) {
207
+ throw new Error(errors.join('\n'));
208
+ }
209
+ };
210
+ // -------------- Branch Methods -------------- //
211
+ /**
212
+ * Queries branch information from the API.
213
+ *
214
+ * @param {BranchQuery} query - Object mapping the current branch and incoming branches
215
+ * @returns {Promise<BranchDataResult>} The branch information.
216
+ */
217
+ GT.prototype.queryBranchData = function (query) {
218
+ return __awaiter(this, void 0, void 0, function () {
219
+ return __generator(this, function (_a) {
220
+ switch (_a.label) {
221
+ case 0:
222
+ this._validateAuth('queryBranchData');
223
+ return [4 /*yield*/, _queryBranchData(query, this._getTranslationConfig())];
224
+ case 1: return [2 /*return*/, _a.sent()];
225
+ }
226
+ });
227
+ });
228
+ };
229
+ /**
230
+ * Creates a new branch in the API. If the branch already exists, it will be returned.
231
+ *
232
+ * @param {CreateBranchQuery} query - Object mapping the branch name and default branch flag
233
+ * @returns {Promise<CreateBranchResult>} The created branch information.
234
+ */
235
+ GT.prototype.createBranch = function (query) {
236
+ return __awaiter(this, void 0, void 0, function () {
237
+ return __generator(this, function (_a) {
238
+ switch (_a.label) {
239
+ case 0:
240
+ this._validateAuth('createBranch');
241
+ return [4 /*yield*/, _createBranch(query, this._getTranslationConfig())];
242
+ case 1: return [2 /*return*/, _a.sent()];
243
+ }
244
+ });
245
+ });
246
+ };
247
+ /**
248
+ * Processes file moves by cloning source files and translations with new fileIds.
249
+ * This is called when files have been moved/renamed and we want to preserve translations.
250
+ *
251
+ * @param {MoveMapping[]} moves - Array of move mappings (old fileId to new fileId)
252
+ * @param {ProcessMovesOptions} options - Options including branchId and timeout
253
+ * @returns {Promise<ProcessMovesResponse>} The move processing results.
254
+ *
255
+ * @example
256
+ * const result = await gt.processFileMoves([
257
+ * { oldFileId: 'abc123', newFileId: 'def456', newFileName: 'locales/en.json' }
258
+ * ], { branchId: 'main' });
259
+ */
260
+ GT.prototype.processFileMoves = function (moves_1) {
261
+ return __awaiter(this, arguments, void 0, function (moves, options) {
262
+ if (options === void 0) { options = {}; }
263
+ return __generator(this, function (_a) {
264
+ switch (_a.label) {
265
+ case 0:
266
+ this._validateAuth('processFileMoves');
267
+ return [4 /*yield*/, _processFileMoves(moves, options, this._getTranslationConfig())];
268
+ case 1: return [2 /*return*/, _a.sent()];
269
+ }
270
+ });
271
+ });
272
+ };
273
+ /**
274
+ * Gets orphaned files for a branch - files that exist on the branch
275
+ * but whose fileIds are not in the provided list.
276
+ * Used for move detection.
277
+ *
278
+ * @param {string} branchId - The branch to check for orphaned files.
279
+ * @param {string[]} fileIds - List of current file IDs (files that are NOT orphaned)
280
+ * @param {Object} options - Options including timeout.
281
+ * @returns {Promise<GetOrphanedFilesResult>} The orphaned files.
282
+ *
283
+ * @example
284
+ * const result = await gt.getOrphanedFiles('branch-id', ['file-1', 'file-2']);
285
+ */
286
+ GT.prototype.getOrphanedFiles = function (branchId_1, fileIds_1) {
287
+ return __awaiter(this, arguments, void 0, function (branchId, fileIds, options) {
288
+ if (options === void 0) { options = {}; }
289
+ return __generator(this, function (_a) {
290
+ switch (_a.label) {
291
+ case 0:
292
+ this._validateAuth('getOrphanedFiles');
293
+ return [4 /*yield*/, _getOrphanedFiles(branchId, fileIds, options, this._getTranslationConfig())];
294
+ case 1: return [2 /*return*/, _a.sent()];
295
+ }
296
+ });
297
+ });
298
+ };
299
+ // -------------- Translation Methods -------------- //
300
+ /**
301
+ * Enqueues project setup job using the specified file references
302
+ *
303
+ * This method creates setup jobs that will process source file references
304
+ * and generate a project setup. The files parameter contains references (IDs) to source
305
+ * files that have already been uploaded via uploadSourceFiles. The setup jobs are queued
306
+ * for processing and will generate a project setup based on the source files.
307
+ *
308
+ * @param {FileReference[]} files - Array of file references containing IDs of previously uploaded source files
309
+ * @param {SetupProjectOptions} [options] - Optional settings for target locales and timeout.
310
+ * @returns {Promise<SetupProjectResult>} Object containing the jobId and status
311
+ */
312
+ GT.prototype.setupProject = function (files, options) {
313
+ return __awaiter(this, void 0, void 0, function () {
314
+ var _this = this;
315
+ var _a;
316
+ return __generator(this, function (_b) {
317
+ switch (_b.label) {
318
+ case 0:
319
+ this._validateAuth('setupProject');
320
+ options = __assign(__assign({}, options), { locales: (_a = options === null || options === void 0 ? void 0 : options.locales) === null || _a === void 0 ? void 0 : _a.map(function (locale) {
321
+ return _this.resolveCanonicalLocale(locale);
322
+ }) });
323
+ return [4 /*yield*/, _setupProject(files, this._getTranslationConfig(), options)];
324
+ case 1: return [2 /*return*/, _b.sent()];
325
+ }
326
+ });
327
+ });
328
+ };
329
+ /**
330
+ * Checks the current status of one or more project jobs by their unique identifiers.
331
+ *
332
+ * This method polls the API to determine whether one or more jobs are still running,
333
+ * have completed successfully, or have failed. Jobs are created after calling either enqueueFiles or setupProject.
334
+ *
335
+ * @param {string[]} jobIds - The unique identifiers of the jobs to check.
336
+ * @param {number} [timeoutMs] - Optional timeout in milliseconds for the API request.
337
+ * @returns {Promise<CheckJobStatusResult>} Object containing the job status.
338
+ *
339
+ * @example
340
+ * const result = await gt.checkJobStatus([
341
+ * 'job-123',
342
+ * 'job-456',
343
+ * ], {
344
+ * timeout: 10000,
345
+ * });
346
+ */
347
+ GT.prototype.checkJobStatus = function (jobIds, timeoutMs) {
348
+ return __awaiter(this, void 0, void 0, function () {
349
+ return __generator(this, function (_a) {
350
+ switch (_a.label) {
351
+ case 0:
352
+ this._validateAuth('checkJobStatus');
353
+ return [4 /*yield*/, _checkJobStatus(jobIds, this._getTranslationConfig(), timeoutMs)];
354
+ case 1: return [2 /*return*/, _a.sent()];
355
+ }
356
+ });
357
+ });
358
+ };
359
+ /**
360
+ * Polls job statuses until all jobs from enqueueFiles are finished or the timeout is reached.
361
+ *
362
+ * @param {EnqueueFilesResult} enqueueResult - The result returned from enqueueFiles.
363
+ * @param {AwaitJobsOptions} [options] - Polling configuration (interval, timeout).
364
+ * @returns {Promise<AwaitJobsResult>} The final status of all jobs and whether they all completed.
365
+ */
366
+ GT.prototype.awaitJobs = function (enqueueResult, options) {
367
+ return __awaiter(this, void 0, void 0, function () {
368
+ return __generator(this, function (_a) {
369
+ switch (_a.label) {
370
+ case 0:
371
+ this._validateAuth('awaitJobs');
372
+ return [4 /*yield*/, _awaitJobs(enqueueResult, options, this._getTranslationConfig())];
373
+ case 1: return [2 /*return*/, _a.sent()];
374
+ }
375
+ });
376
+ });
377
+ };
378
+ /**
379
+ * Enqueues translation jobs for previously uploaded source files.
380
+ *
381
+ * This method creates translation jobs that will process existing source files
382
+ * and generate translations in the specified target languages. The files parameter
383
+ * contains references (IDs) to source files that have already been uploaded via
384
+ * uploadSourceFiles. The translation jobs are queued for processing and will
385
+ * generate translated content based on the source files and target locales provided.
386
+ *
387
+ * @param {FileReferenceIds[]} files - Array of file references containing IDs of previously uploaded source files
388
+ * @param {EnqueueOptions} options - Configuration options including source locale, target locales, and job settings.
389
+ * @returns {Promise<EnqueueFilesResult>} Result containing job IDs, queue status, and processing information.
390
+ */
391
+ GT.prototype.enqueueFiles = function (files, options) {
392
+ return __awaiter(this, void 0, void 0, function () {
393
+ var mergedOptions, error, error;
394
+ var _this = this;
395
+ var _a, _b;
396
+ return __generator(this, function (_c) {
397
+ switch (_c.label) {
398
+ case 0:
399
+ // Validation
400
+ this._validateAuth('enqueueFiles');
401
+ mergedOptions = __assign(__assign({}, options), { sourceLocale: (_a = options.sourceLocale) !== null && _a !== void 0 ? _a : this.sourceLocale, targetLocales: (_b = options.targetLocales) !== null && _b !== void 0 ? _b : [this.targetLocale] });
402
+ // Require source locale
403
+ if (!mergedOptions.sourceLocale) {
404
+ error = noSourceLocaleProvidedError('enqueueFiles');
405
+ gtInstanceLogger.error(error);
406
+ throw new Error(error);
407
+ }
408
+ // Require target locale(s)
409
+ if (!mergedOptions.targetLocales ||
410
+ mergedOptions.targetLocales.length === 0) {
411
+ error = noTargetLocaleProvidedError('enqueueFiles');
412
+ gtInstanceLogger.error(error);
413
+ throw new Error(error);
414
+ }
415
+ // Replace target locales with canonical locales
416
+ mergedOptions = __assign(__assign({}, mergedOptions), { targetLocales: mergedOptions.targetLocales.map(function (locale) {
417
+ return _this.resolveCanonicalLocale(locale);
418
+ }) });
419
+ return [4 /*yield*/, _enqueueFiles(files, mergedOptions, this._getTranslationConfig())];
420
+ case 1: return [2 /*return*/, _c.sent()];
421
+ }
422
+ });
423
+ });
424
+ };
425
+ /**
426
+ * Creates or upserts a file tag, associating a set of source files
427
+ * with a user-defined tag ID and optional message.
428
+ *
429
+ * @param {CreateTagOptions} options - Tag creation options including tagId, sourceFileIds, and optional message
430
+ * @returns {Promise<CreateTagResult>} The created or updated tag.
431
+ */
432
+ GT.prototype.createTag = function (options) {
433
+ return __awaiter(this, void 0, void 0, function () {
434
+ return __generator(this, function (_a) {
435
+ switch (_a.label) {
436
+ case 0:
437
+ this._validateAuth('createTag');
438
+ return [4 /*yield*/, _createTag(options, this._getTranslationConfig())];
439
+ case 1: return [2 /*return*/, _a.sent()];
440
+ }
441
+ });
442
+ });
443
+ };
444
+ /**
445
+ * Publishes or unpublishes files on the CDN.
446
+ *
447
+ * @param {PublishFileEntry[]} files - Array of file entries with publish flags
448
+ * @returns {Promise<PublishFilesResult>} Result containing per-file success/failure
449
+ */
450
+ GT.prototype.publishFiles = function (files) {
451
+ return __awaiter(this, void 0, void 0, function () {
452
+ return __generator(this, function (_a) {
453
+ switch (_a.label) {
454
+ case 0:
455
+ this._validateAuth('publishFiles');
456
+ return [4 /*yield*/, _publishFiles(files, this._getTranslationConfig())];
457
+ case 1: return [2 /*return*/, _a.sent()];
458
+ }
459
+ });
460
+ });
461
+ };
462
+ /**
463
+ * Submits user edit diffs for existing translations so future generations preserve user intent.
464
+ *
465
+ * @param {SubmitUserEditDiffsPayload} payload - Project-scoped diff payload.
466
+ * @returns {Promise<void>} Resolves when submission succeeds.
467
+ */
468
+ GT.prototype.submitUserEditDiffs = function (payload) {
469
+ return __awaiter(this, void 0, void 0, function () {
470
+ var normalized;
471
+ var _this = this;
472
+ return __generator(this, function (_a) {
473
+ switch (_a.label) {
474
+ case 0:
475
+ this._validateAuth('submitUserEditDiffs');
476
+ normalized = __assign(__assign({}, payload), { diffs: (payload.diffs || []).map(function (d) { return (__assign(__assign({}, d), { locale: _this.resolveCanonicalLocale(d.locale) })); }) });
477
+ return [4 /*yield*/, _submitUserEditDiffs(normalized, this._getTranslationConfig())];
478
+ case 1:
479
+ _a.sent();
480
+ return [2 /*return*/];
481
+ }
482
+ });
483
+ });
484
+ };
485
+ /**
486
+ * Queries data about one or more source or translation files.
487
+ *
488
+ * @param {FileDataQuery} data - Object mapping source and translation file information.
489
+ * @param {CheckFileTranslationsOptions} options - Options for the API call.
490
+ * @returns {Promise<FileDataResult>} The source and translation file data information.
491
+ *
492
+ * @example
493
+ * const result = await gt.queryFileData({
494
+ * sourceFiles: [
495
+ * { fileId: '1234567890', versionId: '1234567890', branchId: '1234567890' },
496
+ * ],
497
+ * translatedFiles: [
498
+ * { fileId: '1234567890', versionId: '1234567890', branchId: '1234567890', locale: 'es-ES' },
499
+ * ],
500
+ * }, {
501
+ * timeout: 10000,
502
+ * });
503
+ *
504
+ */
505
+ GT.prototype.queryFileData = function (data_1) {
506
+ return __awaiter(this, arguments, void 0, function (data, options) {
507
+ var result;
508
+ var _this = this;
509
+ var _a, _b, _c;
510
+ if (options === void 0) { options = {}; }
511
+ return __generator(this, function (_d) {
512
+ switch (_d.label) {
513
+ case 0:
514
+ // Validation
515
+ this._validateAuth('queryFileData');
516
+ // Replace target locales with canonical locales
517
+ data.translatedFiles = (_a = data.translatedFiles) === null || _a === void 0 ? void 0 : _a.map(function (item) { return (__assign(__assign({}, item), { locale: _this.resolveCanonicalLocale(item.locale) })); });
518
+ return [4 /*yield*/, _queryFileData(data, options, this._getTranslationConfig())];
519
+ case 1:
520
+ result = _d.sent();
521
+ // Resolve canonical locales
522
+ result.translatedFiles = (_b = result.translatedFiles) === null || _b === void 0 ? void 0 : _b.map(function (item) { return (__assign(__assign({}, item), (item.locale && { locale: _this.resolveAliasLocale(item.locale) }))); });
523
+ result.sourceFiles = (_c = result.sourceFiles) === null || _c === void 0 ? void 0 : _c.map(function (item) { return (__assign(__assign(__assign({}, item), (item.sourceLocale && {
524
+ sourceLocale: _this.resolveAliasLocale(item.sourceLocale),
525
+ })), { locales: item.locales.map(function (locale) { return _this.resolveAliasLocale(locale); }) })); });
526
+ return [2 /*return*/, result];
527
+ }
528
+ });
529
+ });
530
+ };
531
+ /**
532
+ * Gets source and translation information for a given file ID and version ID.
533
+ *
534
+ * @param {FileQuery} data - File query containing file ID and version ID.
535
+ * @param {CheckFileTranslationsOptions} options - Options for getting source and translation information.
536
+ * @returns {Promise<FileQueryResult>} The source file and translation information.
537
+ *
538
+ * @example
539
+ * const result = await gt.querySourceFile(
540
+ * { fileId: '1234567890', versionId: '1234567890' },
541
+ * { timeout: 10000 }
542
+ * );
543
+ *
544
+ */
545
+ GT.prototype.querySourceFile = function (data_1) {
546
+ return __awaiter(this, arguments, void 0, function (data, options) {
547
+ var result;
548
+ var _this = this;
549
+ if (options === void 0) { options = {}; }
550
+ return __generator(this, function (_a) {
551
+ switch (_a.label) {
552
+ case 0:
553
+ // Validation
554
+ this._validateAuth('querySourceFile');
555
+ return [4 /*yield*/, _querySourceFile(data, options, this._getTranslationConfig())];
556
+ case 1:
557
+ result = _a.sent();
558
+ // Replace locales with canonical locales
559
+ result.translations = result.translations.map(function (item) { return (__assign(__assign({}, item), (item.locale && { locale: _this.resolveAliasLocale(item.locale) }))); });
560
+ result.sourceFile.locales = result.sourceFile.locales.map(function (locale) {
561
+ return _this.resolveAliasLocale(locale);
562
+ });
563
+ if (result.sourceFile.sourceLocale) {
564
+ result.sourceFile.sourceLocale = this.resolveAliasLocale(result.sourceFile.sourceLocale);
565
+ }
566
+ return [2 /*return*/, result];
567
+ }
568
+ });
569
+ });
570
+ };
571
+ /**
572
+ * Get project data for a given project ID.
573
+ *
574
+ * @param {string} projectId - The ID of the project to get the data for.
575
+ * @returns {Promise<ProjectData>} The project data.
576
+ *
577
+ * @example
578
+ * const result = await gt.getProjectData(
579
+ * '1234567890'
580
+ * );
581
+ *
582
+ */
583
+ GT.prototype.getProjectData = function (projectId_1) {
584
+ return __awaiter(this, arguments, void 0, function (projectId, options) {
585
+ var result;
586
+ var _this = this;
587
+ if (options === void 0) { options = {}; }
588
+ return __generator(this, function (_a) {
589
+ switch (_a.label) {
590
+ case 0:
591
+ // Validation
592
+ this._validateAuth('getProjectData');
593
+ return [4 /*yield*/, _getProjectData(projectId, options, this._getTranslationConfig())];
594
+ case 1:
595
+ result = _a.sent();
596
+ // Replace locales with canonical locales
597
+ result.currentLocales = result.currentLocales.map(function (item) {
598
+ return _this.resolveAliasLocale(item);
599
+ });
600
+ result.defaultLocale = this.resolveAliasLocale(result.defaultLocale);
601
+ return [2 /*return*/, result];
602
+ }
603
+ });
604
+ });
605
+ };
606
+ /**
607
+ * Downloads a single file.
608
+ *
609
+ * @param file - The file query object.
610
+ * @param {string} file.fileId - The ID of the file to download.
611
+ * @param {string} [file.branchId] - The ID of the branch to download the file from. If not provided, the default branch will be used.
612
+ * @param {string} [file.locale] - The locale to download the file for. If not provided, the source file will be downloaded.
613
+ * @param {string} [file.versionId] - The version ID to download the file from. If not provided, the latest version will be used.
614
+ * @param {DownloadFileOptions} options - Options for downloading the file.
615
+ * @returns {Promise<string>} The downloaded file content.
616
+ *
617
+ * @example
618
+ * const result = await gt.downloadFile({
619
+ * fileId: '1234567890',
620
+ * branchId: '1234567890',
621
+ * locale: 'es-ES',
622
+ * versionId: '1234567890',
623
+ * }, {
624
+ * timeout: 10000,
625
+ * });
626
+ */
627
+ GT.prototype.downloadFile = function (file_1) {
628
+ return __awaiter(this, arguments, void 0, function (file, options) {
629
+ var result;
630
+ var _a, _b, _c;
631
+ if (options === void 0) { options = {}; }
632
+ return __generator(this, function (_d) {
633
+ switch (_d.label) {
634
+ case 0:
635
+ // Validation
636
+ this._validateAuth('downloadTranslatedFile');
637
+ return [4 /*yield*/, _downloadFileBatch([
638
+ {
639
+ fileId: file.fileId,
640
+ branchId: file.branchId,
641
+ locale: file.locale
642
+ ? this.resolveCanonicalLocale(file.locale)
643
+ : undefined,
644
+ versionId: file.versionId,
645
+ useLatestAvailableVersion: file.useLatestAvailableVersion,
646
+ },
647
+ ], options, this._getTranslationConfig())];
648
+ case 1:
649
+ result = _d.sent();
650
+ return [2 /*return*/, (_c = (_b = (_a = result.data) === null || _a === void 0 ? void 0 : _a[0]) === null || _b === void 0 ? void 0 : _b.data) !== null && _c !== void 0 ? _c : ''];
651
+ }
652
+ });
653
+ });
654
+ };
655
+ /**
656
+ * Downloads multiple files in a batch.
657
+ *
658
+ * @param {DownloadFileBatchRequest} requests - Array of file query objects to download.
659
+ * @param {DownloadFileBatchOptions} options - Options for the batch download.
660
+ * @returns {Promise<DownloadFileBatchResult>} The batch download results.
661
+ *
662
+ * @example
663
+ * const result = await gt.downloadFileBatch([{
664
+ * fileId: '1234567890',
665
+ * locale: 'es-ES',
666
+ * versionId: '1234567890',
667
+ * }], {
668
+ * timeout: 10000,
669
+ * });
670
+ */
671
+ GT.prototype.downloadFileBatch = function (requests_1) {
672
+ return __awaiter(this, arguments, void 0, function (requests, options) {
673
+ var result;
674
+ var _this = this;
675
+ if (options === void 0) { options = {}; }
676
+ return __generator(this, function (_a) {
677
+ switch (_a.label) {
678
+ case 0:
679
+ // Validation
680
+ this._validateAuth('downloadFileBatch');
681
+ requests = requests.map(function (request) { return (__assign(__assign({}, request), { locale: request.locale
682
+ ? _this.resolveCanonicalLocale(request.locale)
683
+ : undefined })); });
684
+ return [4 /*yield*/, _downloadFileBatch(requests, options, this._getTranslationConfig())];
685
+ case 1:
686
+ result = _a.sent();
687
+ return [2 /*return*/, {
688
+ files: result.data.map(function (file) { return (__assign(__assign({}, file), (file.locale && {
689
+ locale: _this.resolveAliasLocale(file.locale),
690
+ }))); }),
691
+ count: result.count,
692
+ }];
693
+ }
694
+ });
695
+ });
696
+ };
697
+ /**
698
+ * Translates a single source string to the target locale.
699
+ * Routes through {@link translateMany} under the hood.
700
+ *
701
+ * @param {string} source - The source string to translate.
702
+ * @param {object} options - Translation options including targetLocale and optional entry metadata.
703
+ * @returns {Promise<TranslationResult | TranslationError>} The translated content.
704
+ *
705
+ * @example
706
+ * const result = await gt.translate('Hello, world!', { targetLocale: 'es' });
707
+ *
708
+ * @example
709
+ * const result = await gt.translate('Hello, world!', {
710
+ * targetLocale: 'es',
711
+ * dataFormat: 'ICU',
712
+ * context: 'A formal greeting',
713
+ * });
714
+ */
715
+ GT.prototype.translate = function (source, options, timeout) {
716
+ return __awaiter(this, void 0, void 0, function () {
717
+ var targetLocale, error, sourceLocale, results;
718
+ return __generator(this, function (_a) {
719
+ switch (_a.label) {
720
+ case 0:
721
+ // Normalize string shorthand to options object
722
+ if (typeof options === 'string') {
723
+ options = { targetLocale: options };
724
+ }
725
+ // Validation
726
+ this._validateAuth('translate');
727
+ targetLocale = (options === null || options === void 0 ? void 0 : options.targetLocale) || this.targetLocale;
728
+ if (!targetLocale) {
729
+ error = noTargetLocaleProvidedError('translate');
730
+ gtInstanceLogger.error(error);
731
+ throw new Error(error);
732
+ }
733
+ // Replace target locale with canonical locale
734
+ targetLocale = this.resolveCanonicalLocale(targetLocale);
735
+ sourceLocale = this.resolveCanonicalLocale((options === null || options === void 0 ? void 0 : options.sourceLocale) || this.sourceLocale || libraryDefaultLocale);
736
+ return [4 /*yield*/, _translateMany([source], __assign(__assign({}, options), { targetLocale: targetLocale, sourceLocale: sourceLocale }), this._getTranslationConfig(), timeout)];
737
+ case 1:
738
+ results = _a.sent();
739
+ return [2 /*return*/, results[0]];
740
+ }
741
+ });
742
+ });
743
+ };
744
+ GT.prototype.translateMany = function (sources, options, timeout) {
745
+ return __awaiter(this, void 0, void 0, function () {
746
+ var targetLocale, error, sourceLocale;
747
+ return __generator(this, function (_a) {
748
+ switch (_a.label) {
749
+ case 0:
750
+ // Normalize string shorthand to options object
751
+ if (typeof options === 'string') {
752
+ options = { targetLocale: options };
753
+ }
754
+ // Validation
755
+ this._validateAuth('translateMany');
756
+ targetLocale = (options === null || options === void 0 ? void 0 : options.targetLocale) || this.targetLocale;
757
+ if (!targetLocale) {
758
+ error = noTargetLocaleProvidedError('translateMany');
759
+ gtInstanceLogger.error(error);
760
+ throw new Error(error);
761
+ }
762
+ // Replace target locale with canonical locale
763
+ targetLocale = this.resolveCanonicalLocale(targetLocale);
764
+ sourceLocale = this.resolveCanonicalLocale((options === null || options === void 0 ? void 0 : options.sourceLocale) || this.sourceLocale || libraryDefaultLocale);
765
+ return [4 /*yield*/, _translateMany(sources, __assign(__assign({}, options), { targetLocale: targetLocale, sourceLocale: sourceLocale }), this._getTranslationConfig(), timeout)];
766
+ case 1:
767
+ // Request the translation.
768
+ return [2 /*return*/, _a.sent()];
769
+ }
770
+ });
771
+ });
772
+ };
773
+ /**
774
+ * Uploads source files to the translation service without any translation content.
775
+ *
776
+ * This method creates or replaces source file entries in your project. Each uploaded
777
+ * file becomes a source that can later be translated into target languages. The files
778
+ * are processed and stored as base entries that serve as the foundation for generating
779
+ * translations through the translation workflow.
780
+ *
781
+ * @param {Array<{source: FileUpload}>} files - Array of objects containing source file data to upload
782
+ * @param {UploadFilesOptions} options - Configuration options including source locale and other upload settings.
783
+ * @returns {Promise<UploadFilesResponse>} Upload result containing file IDs, version information, and upload status.
784
+ */
785
+ GT.prototype.uploadSourceFiles = function (files, options) {
786
+ return __awaiter(this, void 0, void 0, function () {
787
+ var mergedOptions, result;
788
+ var _this = this;
789
+ var _a, _b;
790
+ return __generator(this, function (_c) {
791
+ switch (_c.label) {
792
+ case 0:
793
+ // Validation
794
+ this._validateAuth('uploadSourceFiles');
795
+ mergedOptions = __assign(__assign({}, options), { sourceLocale: this.resolveCanonicalLocale((_b = (_a = options.sourceLocale) !== null && _a !== void 0 ? _a : this.sourceLocale) !== null && _b !== void 0 ? _b : libraryDefaultLocale) });
796
+ // resolve canonical locales
797
+ files = files.map(function (f) { return (__assign(__assign({}, f), { source: __assign(__assign({}, f.source), { locale: _this.resolveCanonicalLocale(f.source.locale) }) })); });
798
+ return [4 /*yield*/, _uploadSourceFiles(files, mergedOptions, this._getTranslationConfig())];
799
+ case 1:
800
+ result = _c.sent();
801
+ return [2 /*return*/, {
802
+ uploadedFiles: result.data,
803
+ count: result.count,
804
+ message: "Successfully uploaded ".concat(result.count, " files in ").concat(result.batchCount, " batch(es)"),
805
+ }];
806
+ }
807
+ });
808
+ });
809
+ };
810
+ /**
811
+ * Uploads translation files that correspond to previously uploaded source files.
812
+ *
813
+ * This method allows you to provide translated content for existing source files in your project.
814
+ * Each translation must reference an existing source file and include the translated content
815
+ * along with the target locale information. This is used when you have pre-existing translations
816
+ * that you want to upload directly rather than generating them through the translation service.
817
+ *
818
+ * @param {Array<{source: FileUpload, translations: FileUpload[]}>} files - Array of file objects where:
819
+ * - `source`: Reference to the existing source file (contains IDs but no content).
820
+ * - `translations`: Array of translated files, each containing content, locale, and reference IDs
821
+ * @param {UploadFilesOptions} options - Configuration options including source locale and upload settings.
822
+ * @returns {Promise<UploadFilesResponse>} Upload result containing translation IDs, status, and processing information.
823
+ */
824
+ GT.prototype.uploadTranslations = function (files, options) {
825
+ return __awaiter(this, void 0, void 0, function () {
826
+ var mergedOptions, error, targetFiles, result;
827
+ var _this = this;
828
+ var _a;
829
+ return __generator(this, function (_b) {
830
+ switch (_b.label) {
831
+ case 0:
832
+ // Validation
833
+ this._validateAuth('uploadTranslations');
834
+ mergedOptions = __assign(__assign({}, options), { sourceLocale: (_a = options.sourceLocale) !== null && _a !== void 0 ? _a : this.sourceLocale });
835
+ // Require source locale
836
+ if (!mergedOptions.sourceLocale) {
837
+ error = noSourceLocaleProvidedError('uploadTranslations');
838
+ gtInstanceLogger.error(error);
839
+ throw new Error(error);
840
+ }
841
+ targetFiles = files.map(function (f) { return (__assign(__assign({}, f), { translations: f.translations.map(function (t) { return (__assign(__assign({}, t), { locale: _this.resolveCanonicalLocale(t.locale) })); }) })); });
842
+ return [4 /*yield*/, _uploadTranslations(targetFiles, mergedOptions, this._getTranslationConfig())];
843
+ case 1:
844
+ result = _b.sent();
845
+ return [2 /*return*/, {
846
+ uploadedFiles: result.data,
847
+ count: result.count,
848
+ message: "Successfully uploaded ".concat(result.count, " files in ").concat(result.batchCount, " batch(es)"),
849
+ }];
850
+ }
851
+ });
852
+ });
853
+ };
854
+ // -------------- Formatting -------------- //
855
+ /**
856
+ * Formats a string with cutoff behavior, applying a terminator when the string exceeds the maximum character limit.
857
+ *
858
+ * This method uses the GT instance's rendering locales by default for locale-specific terminator selection,
859
+ * but can be overridden with custom locales in the options.
860
+ *
861
+ * @param {string} value - The string value to format with cutoff behavior.
862
+ * @param {Object} [options] - Configuration options for cutoff formatting.
863
+ * @param {string | string[]} [options.locales] - The locales to use for terminator selection. Defaults to instance's rendering locales.
864
+ * @param {number} [options.maxChars] - The maximum number of characters to display.
865
+ * - Undefined values are treated as no cutoff.
866
+ * - Negative values follow .slice() behavior and terminator will be added before the value.
867
+ * - 0 will result in an empty string.
868
+ * - If cutoff results in an empty string, no terminator is added.
869
+ * @param {CutoffFormatStyle} [options.style='ellipsis'] - The style of the terminator.
870
+ * @param {string} [options.terminator] - Optional override the terminator to use.
871
+ * @param {string} [options.separator] - Optional override the separator to use between the terminator and the value.
872
+ * - If no terminator is provided, then separator is ignored.
873
+ * @returns {string} The formatted string with terminator applied if cutoff occurs.
874
+ *
875
+ * @example
876
+ * const gt = new GT({ targetLocale: 'en-US' });
877
+ * gt.formatCutoff('Hello, world!', { maxChars: 8 });
878
+ * // Returns: 'Hello, w...'
879
+ *
880
+ * @example
881
+ * gt.formatCutoff('Hello, world!', { maxChars: -3 });
882
+ * // Returns: '...ld!'
883
+ */
884
+ GT.prototype.formatCutoff = function (value, options) {
885
+ return this.localeConfig.formatCutoff(value, this.targetLocale, options);
886
+ };
887
+ /**
888
+ * Formats a message according to the specified locales and options.
889
+ *
890
+ * @param {string} message - The message to format.
891
+ * @param {string | string[]} [locales='en'] - The locales to use for formatting.
892
+ * @param {FormatVariables} [variables={}] - The variables to use for formatting.
893
+ * @param {StringFormat} [dataFormat='ICU'] - The format of the message.
894
+ * @returns {string} The formatted message.
895
+ *
896
+ * @example
897
+ * gt.formatMessage('Hello {name}', { name: 'John' });
898
+ * // Returns: "Hello John"
899
+ *
900
+ * gt.formatMessage('Hello {name}', { name: 'John' }, { locales: ['fr'] });
901
+ * // Returns: "Bonjour John"
902
+ */
903
+ GT.prototype.formatMessage = function (message, options) {
904
+ return this.localeConfig.formatMessage(message, this.targetLocale, options);
905
+ };
906
+ /**
907
+ * Formats a number according to the specified locales and options.
908
+ *
909
+ * @param {number} number - The number to format.
910
+ * @param {Object} [options] - Additional options for number formatting.
911
+ * @param {string | string[]} [options.locales] - The locales to use for formatting.
912
+ * @param {Intl.NumberFormatOptions} [options] - Additional Intl.NumberFormat options.
913
+ * @returns {string} The formatted number.
914
+ *
915
+ * @example
916
+ * gt.formatNum(1234.56, { style: 'currency', currency: 'USD' });
917
+ * // Returns: "$1,234.56"
918
+ */
919
+ GT.prototype.formatNum = function (number, options) {
920
+ return this.localeConfig.formatNum(number, this.targetLocale, options);
921
+ };
922
+ /**
923
+ * Formats a date according to the specified locales and options.
924
+ *
925
+ * @param {Date} date - The date to format.
926
+ * @param {Object} [options] - Additional options for date formatting.
927
+ * @param {string | string[]} [options.locales] - The locales to use for formatting.
928
+ * @param {Intl.DateTimeFormatOptions} [options] - Additional Intl.DateTimeFormat options.
929
+ * @returns {string} The formatted date.
930
+ *
931
+ * @example
932
+ * gt.formatDateTime(new Date(), { dateStyle: 'full', timeStyle: 'long' });
933
+ * // Returns: "Thursday, March 14, 2024 at 2:30:45 PM GMT-7"
934
+ */
935
+ GT.prototype.formatDateTime = function (date, options) {
936
+ return this.localeConfig.formatDateTime(date, this.targetLocale, options);
937
+ };
938
+ /**
939
+ * Formats a currency value according to the specified locales and options.
940
+ *
941
+ * @param {number} value - The currency value to format.
942
+ * @param {string} currency - The currency code (e.g., 'USD', 'EUR')
943
+ * @param {Object} [options] - Additional options for currency formatting.
944
+ * @param {string | string[]} [options.locales] - The locales to use for formatting.
945
+ * @param {Intl.NumberFormatOptions} [options] - Additional Intl.NumberFormat options.
946
+ * @returns {string} The formatted currency value.
947
+ *
948
+ * @example
949
+ * gt.formatCurrency(1234.56, 'USD', { style: 'currency' });
950
+ * // Returns: "$1,234.56"
951
+ */
952
+ GT.prototype.formatCurrency = function (value, currency, options) {
953
+ return this.localeConfig.formatCurrency(value, currency, this.targetLocale, options);
954
+ };
955
+ /**
956
+ * Formats a list of items according to the specified locales and options.
957
+ *
958
+ * @param {Array<string | number>} array - The list of items to format.
959
+ * @param {Object} [options] - Additional options for list formatting.
960
+ * @param {string | string[]} [options.locales] - The locales to use for formatting.
961
+ * @param {Intl.ListFormatOptions} [options] - Additional Intl.ListFormat options.
962
+ * @returns {string} The formatted list.
963
+ *
964
+ * @example
965
+ * gt.formatList(['apple', 'banana', 'orange'], { type: 'conjunction' });
966
+ * // Returns: "apple, banana, and orange"
967
+ */
968
+ GT.prototype.formatList = function (array, options) {
969
+ return this.localeConfig.formatList(array, this.targetLocale, options);
970
+ };
971
+ /**
972
+ * Formats a list of items according to the specified locales and options.
973
+ * @param {Array<T>} array - The list of items to format.
974
+ * @param {Object} [options] - Additional options for list formatting.
975
+ * @param {string | string[]} [options.locales] - The locales to use for formatting.
976
+ * @param {Intl.ListFormatOptions} [options] - Additional Intl.ListFormat options.
977
+ * @returns {Array<T | string>} The formatted list parts.
978
+ *
979
+ * @example
980
+ * gt.formatListToParts(['apple', 42, { foo: 'bar' }], { type: 'conjunction', style: 'short', locales: ['en'] });
981
+ * // Returns: ['apple', ', ', 42, ' and ', '{ foo: "bar" }']
982
+ */
983
+ GT.prototype.formatListToParts = function (array, options) {
984
+ return this.localeConfig.formatListToParts(array, this.targetLocale, options);
985
+ };
986
+ /**
987
+ * Formats a relative time value according to the specified locales and options.
988
+ *
989
+ * @param {number} value - The relative time value to format.
990
+ * @param {Intl.RelativeTimeFormatUnit} unit - The unit of time (e.g., 'second', 'minute', 'hour', 'day', 'week', 'month', 'year')
991
+ * @param {Object} options - Additional options for relative time formatting.
992
+ * @param {string | string[]} [options.locales] - The locales to use for formatting.
993
+ * @param {Intl.RelativeTimeFormatOptions} [options] - Additional Intl.RelativeTimeFormat options.
994
+ * @returns {string} The formatted relative time string.
995
+ *
996
+ * @example
997
+ * gt.formatRelativeTime(-1, 'day', { locales: ['en-US'], numeric: 'auto' });
998
+ * // Returns: "yesterday"
999
+ */
1000
+ GT.prototype.formatRelativeTime = function (value, unit, options) {
1001
+ return this.localeConfig.formatRelativeTime(value, unit, this.targetLocale, options);
1002
+ };
1003
+ /**
1004
+ * Formats a relative time string from a Date, automatically selecting the best unit.
1005
+ *
1006
+ * @param {Date} date - The date to format relative to now.
1007
+ * @param {Object} [options] - Additional options for relative time formatting.
1008
+ * @param {string | string[]} [options.locales] - The locales to use for formatting.
1009
+ * @returns {string} The formatted relative time string (e.g., "2 hours ago", "in 3 days")
1010
+ *
1011
+ * @example
1012
+ * gt.formatRelativeTimeFromDate(new Date(Date.now() - 3600000));
1013
+ * // Returns: "1 hour ago"
1014
+ */
1015
+ GT.prototype.formatRelativeTimeFromDate = function (date, options) {
1016
+ return this.localeConfig.formatRelativeTimeFromDate(date, this.targetLocale, options);
1017
+ };
1018
+ // -------------- Locale Properties -------------- //
1019
+ /**
1020
+ * Retrieves the display name of a locale code using Intl.DisplayNames, returning an empty string if no name is found.
1021
+ *
1022
+ * @param {string} [locale=this.targetLocale] - A BCP-47 locale code.
1023
+ * @returns {string} The display name corresponding to the code.
1024
+ * @throws {Error} If no target locale is provided.
1025
+ *
1026
+ * @example
1027
+ * gt.getLocaleName('es-ES');
1028
+ * // Returns: "Spanish (Spain)"
1029
+ */
1030
+ GT.prototype.getLocaleName = function (locale) {
1031
+ if (locale === void 0) { locale = this.targetLocale; }
1032
+ if (!locale)
1033
+ throw new Error(noTargetLocaleProvidedError('getLocaleName'));
1034
+ return this.localeConfig.getLocaleName(locale);
1035
+ };
1036
+ /**
1037
+ * Retrieves an emoji based on a given locale code.
1038
+ * Uses the locale's region (if present) to select an emoji or falls back on default emojis.
1039
+ *
1040
+ * @param {string} [locale=this.targetLocale] - A BCP-47 locale code (e.g., 'en-US', 'fr-CA')
1041
+ * @returns {string} The emoji representing the locale or its region.
1042
+ * @throws {Error} If no target locale is provided.
1043
+ *
1044
+ * @example
1045
+ * gt.getLocaleEmoji('es-ES');
1046
+ * // Returns: "🇪🇸"
1047
+ */
1048
+ GT.prototype.getLocaleEmoji = function (locale) {
1049
+ if (locale === void 0) { locale = this.targetLocale; }
1050
+ if (!locale)
1051
+ throw new Error(noTargetLocaleProvidedError('getLocaleEmoji'));
1052
+ return this.localeConfig.getLocaleEmoji(locale);
1053
+ };
1054
+ /**
1055
+ * Generates linguistic details for a given locale code.
1056
+ *
1057
+ * This function returns information about the locale,
1058
+ * script, and region of a given language code both in a standard form and in a maximized form (with likely script and region).
1059
+ * The function provides these names in both your default language and native forms, and an associated emoji.
1060
+ *
1061
+ * @param {string} [locale=this.targetLocale] - The locale code to get properties for (e.g., "de-AT").
1062
+ * @returns {LocaleProperties} - An object containing detailed information about the locale.
1063
+ *
1064
+ * @property {string} code - The full locale code, e.g., "de-AT".
1065
+ * @property {string} name - Language name in the default display language, e.g., "Austrian German".
1066
+ * @property {string} nativeName - Language name in the locale's native language, e.g., "Österreichisches Deutsch".
1067
+ * @property {string} languageCode - The base language code, e.g., "de".
1068
+ * @property {string} languageName - The language name in the default display language, e.g., "German".
1069
+ * @property {string} nativeLanguageName - The language name in the native language, e.g., "Deutsch".
1070
+ * @property {string} nameWithRegionCode - Language name with region in the default language, e.g., "German (AT)".
1071
+ * @property {string} nativeNameWithRegionCode - Language name with region in the native language, e.g., "Deutsch (AT)".
1072
+ * @property {string} regionCode - The region code from maximization, e.g., "AT".
1073
+ * @property {string} regionName - The region name in the default display language, e.g., "Austria".
1074
+ * @property {string} nativeRegionName - The region name in the native language, e.g., "Österreich".
1075
+ * @property {string} scriptCode - The script code from maximization, e.g., "Latn".
1076
+ * @property {string} scriptName - The script name in the default display language, e.g., "Latin".
1077
+ * @property {string} nativeScriptName - The script name in the native language, e.g., "Lateinisch".
1078
+ * @property {string} maximizedCode - The maximized locale code, e.g., "de-Latn-AT".
1079
+ * @property {string} maximizedName - Maximized locale name with likely script in the default language, e.g., "Austrian German (Latin)".
1080
+ * @property {string} nativeMaximizedName - Maximized locale name in the native language, e.g., "Österreichisches Deutsch (Lateinisch)".
1081
+ * @property {string} minimizedCode - Minimized locale code, e.g., "de-AT" (or "de" for "de-DE").
1082
+ * @property {string} minimizedName - Minimized language name in the default language, e.g., "Austrian German".
1083
+ * @property {string} nativeMinimizedName - Minimized language name in the native language, e.g., "Österreichisches Deutsch".
1084
+ * @property {string} emoji - The emoji associated with the locale's region, if applicable.
1085
+ */
1086
+ GT.prototype.getLocaleProperties = function (locale) {
1087
+ if (locale === void 0) { locale = this.targetLocale; }
1088
+ if (!locale)
1089
+ throw new Error(noTargetLocaleProvidedError('getLocaleProperties'));
1090
+ return this.localeConfig.getLocaleProperties(locale);
1091
+ };
1092
+ /**
1093
+ * Retrieves multiple properties for a given region code, including:
1094
+ * - `code`: the original region code
1095
+ * - `name`: the localized display name
1096
+ * - `emoji`: the associated flag or symbol
1097
+ *
1098
+ * Behavior:
1099
+ * - Accepts ISO 3166-1 alpha-2 or UN M.49 region codes (e.g., `"US"`, `"FR"`, `"419"`).
1100
+ * - Uses the instance's `targetLocale` to localize the region name for the user.
1101
+ * - If `customMapping` contains a `name` or `emoji` for the region, those override the default values.
1102
+ * - Otherwise, uses `Intl.DisplayNames` to get the localized region name, falling back to `libraryDefaultLocale`.
1103
+ * - Falls back to the region code as `name` if display name resolution fails.
1104
+ * - Falls back to a default emoji if no emoji mapping is found in built-in data or `customMapping`.
1105
+ *
1106
+ * @param {string} [region=this.getLocaleProperties().regionCode] - The region code to look up (e.g., `"US"`, `"GB"`, `"DE"`).
1107
+ * @param {CustomRegionMapping} [customMapping] - Optional mapping of region codes to custom names and/or emojis.
1108
+ * @returns {{ code: string, name: string, emoji: string }} An object containing:
1109
+ * - `code`: the input region code
1110
+ * - `name`: the localized or custom region name
1111
+ * - `emoji`: the matching emoji flag or symbol
1112
+ *
1113
+ * @throws {Error} If no target locale is available to determine region properties.
1114
+ *
1115
+ * @example
1116
+ * const gt = new GT({ targetLocale: 'en-US' });
1117
+ * gt.getRegionProperties('US');
1118
+ * // => { code: 'US', name: 'United States', emoji: '🇺🇸' }
1119
+ *
1120
+ * @example
1121
+ * const gt = new GT({ targetLocale: 'fr-FR' });
1122
+ * gt.getRegionProperties('US');
1123
+ * // => { code: 'US', name: 'États-Unis', emoji: '🇺🇸' }
1124
+ *
1125
+ * @example
1126
+ * gt.getRegionProperties('US', { US: { name: 'USA', emoji: '🗽' } });
1127
+ * // => { code: 'US', name: 'USA', emoji: '🗽' }
1128
+ */
1129
+ GT.prototype.getRegionProperties = function (region, customMapping) {
1130
+ if (region === void 0) { region = this.getLocaleProperties().regionCode; }
1131
+ if (!customMapping) {
1132
+ if (this.customMapping && !this.customRegionMapping) {
1133
+ // Lazy derive custom region mapping from customMapping
1134
+ var customRegionMapping = {};
1135
+ for (var _i = 0, _a = Object.entries(this.customMapping); _i < _a.length; _i++) {
1136
+ var _b = _a[_i], locale = _b[0], lp = _b[1];
1137
+ if (lp &&
1138
+ typeof lp === 'object' &&
1139
+ lp.regionCode &&
1140
+ !customRegionMapping[lp.regionCode]) {
1141
+ var name = lp.regionName, emoji = lp.emoji;
1142
+ customRegionMapping[lp.regionCode] = __assign(__assign({ locale: locale }, (name && { name: name })), (emoji && { emoji: emoji }));
1143
+ }
1144
+ }
1145
+ this.customRegionMapping = customRegionMapping;
1146
+ }
1147
+ customMapping = this.customRegionMapping;
1148
+ }
1149
+ return _getRegionProperties(region, this.targetLocale, // this.targetLocale because we want it in the user's language
1150
+ customMapping);
1151
+ };
1152
+ /**
1153
+ * Determines whether a translation is required based on the source and target locales.
1154
+ *
1155
+ * @param {string} [sourceLocale=this.sourceLocale] - The locale code for the original content.
1156
+ * @param {string} [targetLocale=this.targetLocale] - The locale code to translate into.
1157
+ * @param {string[]} [approvedLocales=this.locales] - Optional array of approved target locales.
1158
+ * @returns {boolean} True if translation is required, false otherwise
1159
+ * @throws {Error} If no source locale is provided.
1160
+ * @throws {Error} If no target locale is provided.
1161
+ *
1162
+ * @example
1163
+ * gt.requiresTranslation('en-US', 'es-ES');
1164
+ * // Returns: true
1165
+ */
1166
+ GT.prototype.requiresTranslation = function (sourceLocale, targetLocale, approvedLocales, customMapping) {
1167
+ if (sourceLocale === void 0) { sourceLocale = this.sourceLocale; }
1168
+ if (targetLocale === void 0) { targetLocale = this.targetLocale; }
1169
+ if (approvedLocales === void 0) { approvedLocales = this.locales; }
1170
+ if (customMapping === void 0) { customMapping = this.customMapping; }
1171
+ if (!sourceLocale)
1172
+ throw new Error(noSourceLocaleProvidedError('requiresTranslation'));
1173
+ if (!targetLocale)
1174
+ throw new Error(noTargetLocaleProvidedError('requiresTranslation'));
1175
+ if (customMapping === this.customMapping) {
1176
+ return this.localeConfig.requiresTranslation(targetLocale, sourceLocale, approvedLocales);
1177
+ }
1178
+ return _requiresTranslation(sourceLocale, targetLocale, approvedLocales, customMapping);
1179
+ };
1180
+ /**
1181
+ * Determines the best matching locale from the provided approved locales list.
1182
+ *
1183
+ * @param {string | string[]} locales - A single locale or array of locales in preference order.
1184
+ * @param {string[]} [approvedLocales=this.locales] - Array of approved locales in preference order.
1185
+ * @returns {string | undefined} The best matching locale, or undefined if no match is found.
1186
+ *
1187
+ * @example
1188
+ * gt.determineLocale(['fr-CA', 'fr-FR'], ['en-US', 'fr-FR', 'es-ES']);
1189
+ * // Returns: "fr-FR"
1190
+ */
1191
+ GT.prototype.determineLocale = function (locales, approvedLocales, customMapping) {
1192
+ if (approvedLocales === void 0) { approvedLocales = this.locales || []; }
1193
+ if (customMapping === void 0) { customMapping = this.customMapping; }
1194
+ if (customMapping === this.customMapping) {
1195
+ return this.localeConfig.determineLocale(locales, approvedLocales !== null && approvedLocales !== void 0 ? approvedLocales : []);
1196
+ }
1197
+ return _determineLocale(locales, approvedLocales, customMapping);
1198
+ };
1199
+ /**
1200
+ * Gets the text direction for a given locale code.
1201
+ *
1202
+ * @param {string} [locale=this.targetLocale] - A BCP-47 locale code.
1203
+ * @returns {'ltr' | 'rtl'} 'rtl' if the locale is right-to-left; otherwise 'ltr'.
1204
+ * @throws {Error} If no target locale is provided.
1205
+ *
1206
+ * @example
1207
+ * gt.getLocaleDirection('ar-SA');
1208
+ * // Returns: "rtl"
1209
+ */
1210
+ GT.prototype.getLocaleDirection = function (locale) {
1211
+ if (locale === void 0) { locale = this.targetLocale; }
1212
+ if (!locale)
1213
+ throw new Error(noTargetLocaleProvidedError('getLocaleDirection'));
1214
+ return this.localeConfig.getLocaleDirection(locale);
1215
+ };
1216
+ /**
1217
+ * Checks if a given BCP 47 locale code is valid.
1218
+ *
1219
+ * @param {string} [locale=this.targetLocale] - The BCP 47 locale code to validate.
1220
+ * @param {CustomMapping} [customMapping=this.customMapping] - The custom mapping to use for validation.
1221
+ * @returns {boolean} True if the locale code is valid, false otherwise
1222
+ * @throws {Error} If no target locale is provided.
1223
+ *
1224
+ * @example
1225
+ * gt.isValidLocale('en-US');
1226
+ * // Returns: true
1227
+ */
1228
+ GT.prototype.isValidLocale = function (locale, customMapping) {
1229
+ if (locale === void 0) { locale = this.targetLocale; }
1230
+ if (customMapping === void 0) { customMapping = this.customMapping; }
1231
+ if (!locale)
1232
+ throw new Error(noTargetLocaleProvidedError('isValidLocale'));
1233
+ if (customMapping === this.customMapping) {
1234
+ return this.localeConfig.isValidLocale(locale);
1235
+ }
1236
+ return _isValidLocale(locale, customMapping);
1237
+ };
1238
+ /**
1239
+ * Resolves the canonical locale for a given locale.
1240
+ * @param locale - The locale to resolve the canonical locale for
1241
+ * @param customMapping - The custom mapping to use for resolving the canonical locale
1242
+ * @returns The canonical locale, or the input locale when no canonical mapping exists.
1243
+ */
1244
+ GT.prototype.resolveCanonicalLocale = function (locale, customMapping) {
1245
+ if (locale === void 0) { locale = this.targetLocale; }
1246
+ if (customMapping === void 0) { customMapping = this.customMapping; }
1247
+ if (!locale)
1248
+ throw new Error(noTargetLocaleProvidedError('resolveCanonicalLocale'));
1249
+ if (customMapping === this.customMapping) {
1250
+ return this.localeConfig.resolveCanonicalLocale(locale);
1251
+ }
1252
+ return _resolveCanonicalLocale(locale, customMapping);
1253
+ };
1254
+ /**
1255
+ * Resolves the alias locale for a given locale.
1256
+ * @param locale - The locale to resolve the alias locale for
1257
+ * @param customMapping - The custom mapping to use for resolving the alias locale
1258
+ * @returns The configured alias for a canonical locale, or the input locale when already an alias or no alias mapping exists.
1259
+ */
1260
+ GT.prototype.resolveAliasLocale = function (locale, customMapping) {
1261
+ if (customMapping === void 0) { customMapping = this.customMapping; }
1262
+ if (!locale)
1263
+ throw new Error(noTargetLocaleProvidedError('resolveAliasLocale'));
1264
+ if (customMapping === this.customMapping) {
1265
+ return this.localeConfig.resolveAliasLocale(locale);
1266
+ }
1267
+ return _resolveAliasLocale(locale, customMapping);
1268
+ };
1269
+ /**
1270
+ * Standardizes a BCP 47 locale code to ensure correct formatting.
1271
+ *
1272
+ * @param {string} [locale=this.targetLocale] - The BCP 47 locale code to standardize.
1273
+ * @returns {string} The standardized locale code, or the input string if it cannot be standardized.
1274
+ * @throws {Error} If no target locale is provided.
1275
+ *
1276
+ * @example
1277
+ * gt.standardizeLocale('en_us');
1278
+ * // Returns: "en-US"
1279
+ */
1280
+ GT.prototype.standardizeLocale = function (locale) {
1281
+ if (locale === void 0) { locale = this.targetLocale; }
1282
+ if (!locale)
1283
+ throw new Error(noTargetLocaleProvidedError('standardizeLocale'));
1284
+ return this.localeConfig.standardizeLocale(locale);
1285
+ };
1286
+ /**
1287
+ * Checks if multiple BCP 47 locale codes represent the same dialect.
1288
+ *
1289
+ * @param {...(string | string[])} locales - The BCP 47 locale codes to compare.
1290
+ * @returns {boolean} True if all codes represent the same dialect, false otherwise
1291
+ *
1292
+ * @example
1293
+ * gt.isSameDialect('en-US', 'en-GB');
1294
+ * // Returns: false
1295
+ *
1296
+ * gt.isSameDialect('en', 'en-US');
1297
+ * // Returns: true
1298
+ */
1299
+ GT.prototype.isSameDialect = function () {
1300
+ var _a;
1301
+ var locales = [];
1302
+ for (var _i = 0; _i < arguments.length; _i++) {
1303
+ locales[_i] = arguments[_i];
1304
+ }
1305
+ return (_a = this.localeConfig).isSameDialect.apply(_a, locales);
1306
+ };
1307
+ /**
1308
+ * Checks if multiple BCP 47 locale codes represent the same language.
1309
+ *
1310
+ * @param {...(string | string[])} locales - The BCP 47 locale codes to compare.
1311
+ * @returns {boolean} True if all codes represent the same language, false otherwise
1312
+ *
1313
+ * @example
1314
+ * gt.isSameLanguage('en-US', 'en-GB');
1315
+ * // Returns: true
1316
+ */
1317
+ GT.prototype.isSameLanguage = function () {
1318
+ var _a;
1319
+ var locales = [];
1320
+ for (var _i = 0; _i < arguments.length; _i++) {
1321
+ locales[_i] = arguments[_i];
1322
+ }
1323
+ return (_a = this.localeConfig).isSameLanguage.apply(_a, locales);
1324
+ };
1325
+ /**
1326
+ * Checks if a locale is a superset of another locale.
1327
+ *
1328
+ * @param {string} superLocale - The locale to check if it is a superset
1329
+ * @param {string} subLocale - The locale to check if it is a subset
1330
+ * @returns {boolean} True if superLocale is a superset of subLocale, false otherwise
1331
+ *
1332
+ * @example
1333
+ * gt.isSupersetLocale('en', 'en-US');
1334
+ * // Returns: true
1335
+ *
1336
+ * gt.isSupersetLocale('en-US', 'en');
1337
+ * // Returns: false
1338
+ */
1339
+ GT.prototype.isSupersetLocale = function (superLocale, subLocale) {
1340
+ return this.localeConfig.isSupersetLocale(superLocale, subLocale);
1341
+ };
1342
+ return GT;
1343
+ }());
1344
+ export { GT };
1345
+ export var API_VERSION = _API_VERSION;