generaltranslation 8.2.6 → 8.2.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 (162) hide show
  1. package/CHANGELOG.md +14 -0
  2. package/dist/ApiError-4zIP-twr.cjs +24 -0
  3. package/dist/ApiError-4zIP-twr.cjs.map +1 -0
  4. package/dist/ApiError-Bv7vlzyQ.mjs +19 -0
  5. package/dist/ApiError-Bv7vlzyQ.mjs.map +1 -0
  6. package/dist/errors.cjs +3 -0
  7. package/dist/errors.d.cts +11 -0
  8. package/dist/errors.d.mts +11 -0
  9. package/dist/errors.mjs +2 -0
  10. package/dist/id-CPbVYREY.mjs +74 -0
  11. package/dist/id-CPbVYREY.mjs.map +1 -0
  12. package/dist/id-VXBgyXu2.cjs +89 -0
  13. package/dist/id-VXBgyXu2.cjs.map +1 -0
  14. package/dist/id.cjs +5 -0
  15. package/dist/{id/hashSource.d.ts → id.d.cts} +20 -5
  16. package/dist/id.d.mts +40 -0
  17. package/dist/id.mjs +2 -0
  18. package/dist/index.cjs +3491 -0
  19. package/dist/index.cjs.map +1 -0
  20. package/dist/index.d.cts +1219 -0
  21. package/dist/index.d.mts +1219 -0
  22. package/dist/index.mjs +3441 -0
  23. package/dist/index.mjs.map +1 -0
  24. package/dist/internal-B3QbyI_5.mjs +820 -0
  25. package/dist/internal-B3QbyI_5.mjs.map +1 -0
  26. package/dist/internal-DIHQF9gs.cjs +1070 -0
  27. package/dist/internal-DIHQF9gs.cjs.map +1 -0
  28. package/dist/internal.cjs +45 -0
  29. package/dist/{internal.d.ts → internal.d.cts} +82 -113
  30. package/dist/internal.d.mts +263 -0
  31. package/dist/internal.mjs +3 -0
  32. package/dist/sha2-DKowBr6H.cjs +747 -0
  33. package/dist/sha2-DKowBr6H.cjs.map +1 -0
  34. package/dist/stableStringify-DgDlE_pD.mjs +53 -0
  35. package/dist/stableStringify-DgDlE_pD.mjs.map +1 -0
  36. package/dist/types-BJdoI1d1.d.cts +741 -0
  37. package/dist/types-DazaDJbs.d.mts +741 -0
  38. package/dist/types.cjs +17 -0
  39. package/dist/types.cjs.map +1 -0
  40. package/dist/types.d.cts +2 -0
  41. package/dist/types.d.mts +2 -0
  42. package/dist/types.mjs +16 -0
  43. package/dist/types.mjs.map +1 -0
  44. package/package.json +52 -32
  45. package/dist/backwards-compatability/dataConversion.d.ts +0 -23
  46. package/dist/backwards-compatability/oldHashJsxChildren.d.ts +0 -23
  47. package/dist/backwards-compatability/oldTypes.d.ts +0 -21
  48. package/dist/backwards-compatability/typeChecking.d.ts +0 -21
  49. package/dist/cache/IntlCache.d.ts +0 -26
  50. package/dist/cache/types.d.ts +0 -32
  51. package/dist/derive/condenseVars.d.ts +0 -7
  52. package/dist/derive/declareVar.d.ts +0 -26
  53. package/dist/derive/decodeVars.d.ts +0 -9
  54. package/dist/derive/derive.d.ts +0 -38
  55. package/dist/derive/extractVars.d.ts +0 -9
  56. package/dist/derive/index.d.ts +0 -7
  57. package/dist/derive/indexVars.d.ts +0 -6
  58. package/dist/derive/utils/constants.d.ts +0 -2
  59. package/dist/derive/utils/regex.d.ts +0 -2
  60. package/dist/derive/utils/sanitizeVar.d.ts +0 -12
  61. package/dist/derive/utils/traverseHelpers.d.ts +0 -4
  62. package/dist/derive/utils/traverseIcu.d.ts +0 -20
  63. package/dist/derive/utils/types.d.ts +0 -23
  64. package/dist/errors/ApiError.d.ts +0 -7
  65. package/dist/errors/formattingErrors.d.ts +0 -1
  66. package/dist/errors.cjs.min.cjs +0 -2
  67. package/dist/errors.cjs.min.cjs.map +0 -1
  68. package/dist/errors.d.ts +0 -9
  69. package/dist/errors.esm.min.mjs +0 -2
  70. package/dist/errors.esm.min.mjs.map +0 -1
  71. package/dist/formatting/custom-formats/CutoffFormat/CutoffFormat.d.ts +0 -59
  72. package/dist/formatting/custom-formats/CutoffFormat/constants.d.ts +0 -4
  73. package/dist/formatting/custom-formats/CutoffFormat/types.d.ts +0 -48
  74. package/dist/formatting/format.d.ts +0 -1
  75. package/dist/id/hashTemplate.d.ts +0 -4
  76. package/dist/id/types.d.ts +0 -7
  77. package/dist/id.cjs.min.cjs +0 -2
  78. package/dist/id.cjs.min.cjs.map +0 -1
  79. package/dist/id.d.ts +0 -86
  80. package/dist/id.esm.min.mjs +0 -2
  81. package/dist/id.esm.min.mjs.map +0 -1
  82. package/dist/index.cjs.min.cjs +0 -2
  83. package/dist/index.cjs.min.cjs.map +0 -1
  84. package/dist/index.d.ts +0 -1627
  85. package/dist/index.esm.min.mjs +0 -2
  86. package/dist/index.esm.min.mjs.map +0 -1
  87. package/dist/internal.cjs.min.cjs +0 -2
  88. package/dist/internal.cjs.min.cjs.map +0 -1
  89. package/dist/internal.esm.min.mjs +0 -2
  90. package/dist/internal.esm.min.mjs.map +0 -1
  91. package/dist/locales/customLocaleMapping.d.ts +0 -11
  92. package/dist/locales/determineLocale.d.ts +0 -1
  93. package/dist/locales/getLocaleDirection.d.ts +0 -1
  94. package/dist/locales/getLocaleEmoji.d.ts +0 -2
  95. package/dist/locales/getLocaleName.d.ts +0 -1
  96. package/dist/locales/getLocaleProperties.d.ts +0 -32
  97. package/dist/locales/getPluralForm.d.ts +0 -9
  98. package/dist/locales/getRegionProperties.d.ts +0 -7
  99. package/dist/locales/isSameDialect.d.ts +0 -1
  100. package/dist/locales/isSameLanguage.d.ts +0 -1
  101. package/dist/locales/isSupersetLocale.d.ts +0 -1
  102. package/dist/locales/isValidLocale.d.ts +0 -1
  103. package/dist/locales/requiresTranslation.d.ts +0 -1
  104. package/dist/locales/resolveAliasLocale.d.ts +0 -8
  105. package/dist/locales/resolveCanonicalLocale.d.ts +0 -8
  106. package/dist/logging/errors.d.ts +0 -10
  107. package/dist/logging/logger.d.ts +0 -117
  108. package/dist/logging/warnings.d.ts +0 -2
  109. package/dist/projects/getProjectData.d.ts +0 -1
  110. package/dist/settings/plurals.d.ts +0 -3
  111. package/dist/settings/settings.d.ts +0 -2
  112. package/dist/settings/settingsUrls.d.ts +0 -3
  113. package/dist/translate/api.d.ts +0 -1
  114. package/dist/translate/awaitJobs.d.ts +0 -19
  115. package/dist/translate/checkJobStatus.d.ts +0 -8
  116. package/dist/translate/createBranch.d.ts +0 -10
  117. package/dist/translate/createTag.d.ts +0 -19
  118. package/dist/translate/downloadFileBatch.d.ts +0 -1
  119. package/dist/translate/enqueueFiles.d.ts +0 -8
  120. package/dist/translate/getOrphanedFiles.d.ts +0 -8
  121. package/dist/translate/processFileMoves.d.ts +0 -25
  122. package/dist/translate/publishFiles.d.ts +0 -17
  123. package/dist/translate/queryBranchData.d.ts +0 -3
  124. package/dist/translate/queryFileData.d.ts +0 -42
  125. package/dist/translate/querySourceFile.d.ts +0 -1
  126. package/dist/translate/setupProject.d.ts +0 -11
  127. package/dist/translate/submitUserEditDiffs.d.ts +0 -12
  128. package/dist/translate/translateMany.d.ts +0 -1
  129. package/dist/translate/uploadSourceFiles.d.ts +0 -1
  130. package/dist/translate/uploadTranslations.d.ts +0 -1
  131. package/dist/translate/utils/apiRequest.d.ts +0 -1
  132. package/dist/translate/utils/batch.d.ts +0 -52
  133. package/dist/translate/utils/fetchWithTimeout.d.ts +0 -1
  134. package/dist/translate/utils/generateRequestHeaders.d.ts +0 -2
  135. package/dist/translate/utils/handleFetchError.d.ts +0 -1
  136. package/dist/translate/utils/validateResponse.d.ts +0 -1
  137. package/dist/types-dir/api/branch.d.ts +0 -10
  138. package/dist/types-dir/api/checkFileTranslations.d.ts +0 -37
  139. package/dist/types-dir/api/downloadFile.d.ts +0 -3
  140. package/dist/types-dir/api/downloadFileBatch.d.ts +0 -34
  141. package/dist/types-dir/api/enqueueEntries.d.ts +0 -21
  142. package/dist/types-dir/api/enqueueFiles.d.ts +0 -56
  143. package/dist/types-dir/api/entry.d.ts +0 -36
  144. package/dist/types-dir/api/fetchTranslations.d.ts +0 -11
  145. package/dist/types-dir/api/file.d.ts +0 -54
  146. package/dist/types-dir/api/project.d.ts +0 -7
  147. package/dist/types-dir/api/translate.d.ts +0 -34
  148. package/dist/types-dir/api/translateMany.d.ts +0 -5
  149. package/dist/types-dir/api/translationStatus.d.ts +0 -9
  150. package/dist/types-dir/api/uploadFiles.d.ts +0 -43
  151. package/dist/types-dir/jsx/content.d.ts +0 -61
  152. package/dist/types-dir/jsx/variables.d.ts +0 -9
  153. package/dist/types-dir/transformations.d.ts +0 -8
  154. package/dist/types.cjs.min.cjs +0 -2
  155. package/dist/types.cjs.min.cjs.map +0 -1
  156. package/dist/types.d.ts +0 -652
  157. package/dist/types.esm.min.mjs +0 -2
  158. package/dist/types.esm.min.mjs.map +0 -1
  159. package/dist/utils/base64.d.ts +0 -2
  160. package/dist/utils/isVariable.d.ts +0 -2
  161. package/dist/utils/minify.d.ts +0 -2
  162. package/dist/utils/stableStringify.d.ts +0 -1
package/dist/index.cjs ADDED
@@ -0,0 +1,3491 @@
1
+ Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
2
+ //#region \0rolldown/runtime.js
3
+ var __create = Object.create;
4
+ var __defProp = Object.defineProperty;
5
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
6
+ var __getOwnPropNames = Object.getOwnPropertyNames;
7
+ var __getProtoOf = Object.getPrototypeOf;
8
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
9
+ var __copyProps = (to, from, except, desc) => {
10
+ if (from && typeof from === "object" || typeof from === "function") for (var keys = __getOwnPropNames(from), i = 0, n = keys.length, key; i < n; i++) {
11
+ key = keys[i];
12
+ if (!__hasOwnProp.call(to, key) && key !== except) __defProp(to, key, {
13
+ get: ((k) => from[k]).bind(null, key),
14
+ enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable
15
+ });
16
+ }
17
+ return to;
18
+ };
19
+ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", {
20
+ value: mod,
21
+ enumerable: true
22
+ }) : target, mod));
23
+ //#endregion
24
+ const require_internal = require("./internal-DIHQF9gs.cjs");
25
+ const require_ApiError = require("./ApiError-4zIP-twr.cjs");
26
+ const require_id = require("./id-VXBgyXu2.cjs");
27
+ let intl_messageformat = require("intl-messageformat");
28
+ intl_messageformat = __toESM(intl_messageformat);
29
+ //#region src/locales/isValidLocale.ts
30
+ const scriptExceptions = [
31
+ "Cham",
32
+ "Jamo",
33
+ "Kawi",
34
+ "Lisu",
35
+ "Toto",
36
+ "Thai"
37
+ ];
38
+ const isCustomLanguage = (language) => {
39
+ return language >= "qaa" && language <= "qtz";
40
+ };
41
+ /**
42
+ * Checks if a given BCP 47 language code is valid.
43
+ * @param {string} code - The BCP 47 language code to validate.
44
+ * @param {CustomMapping} [customMapping] - The custom mapping to use for validation.
45
+ * @returns {boolean} True if the BCP 47 code is valid, false otherwise.
46
+ * @internal
47
+ */
48
+ const _isValidLocale = (locale, customMapping) => {
49
+ if (customMapping?.[locale] && typeof customMapping[locale] === "object" && "code" in customMapping[locale] && customMapping[locale].code) locale = customMapping[locale].code;
50
+ try {
51
+ const { language, region, script } = require_internal.intlCache.get("Locale", locale);
52
+ if (locale.split("-").length !== (() => {
53
+ let partCount = 1;
54
+ if (region) partCount += 1;
55
+ if (script) partCount += 1;
56
+ return partCount;
57
+ })()) return false;
58
+ if (require_internal.intlCache.get("DisplayNames", ["en"], { type: "language" }).of(language) === language && !isCustomLanguage(language)) return false;
59
+ if (region) {
60
+ if (require_internal.intlCache.get("DisplayNames", ["en"], { type: "region" }).of(region) === region) return false;
61
+ }
62
+ if (script) {
63
+ if (require_internal.intlCache.get("DisplayNames", ["en"], { type: "script" }).of(script) === script && !scriptExceptions.includes(script)) return false;
64
+ }
65
+ return true;
66
+ } catch {
67
+ return false;
68
+ }
69
+ };
70
+ /**
71
+ * Standardizes a BCP 47 locale to ensure correct formatting.
72
+ * @param {string} locale - The BCP 47 locale to standardize.
73
+ * @returns {string} The standardized BCP 47 locale, or an empty string if invalid.
74
+ * @internal
75
+ */
76
+ const _standardizeLocale = (locale) => {
77
+ try {
78
+ return Intl.getCanonicalLocales(locale)[0];
79
+ } catch {
80
+ return locale;
81
+ }
82
+ };
83
+ //#endregion
84
+ //#region src/locales/isSameDialect.ts
85
+ function checkTwoLocalesAreSameDialect(codeA, codeB) {
86
+ const { language: languageA, region: regionA, script: scriptA } = require_internal.intlCache.get("Locale", codeA);
87
+ const { language: languageB, region: regionB, script: scriptB } = require_internal.intlCache.get("Locale", codeB);
88
+ if (languageA !== languageB) return false;
89
+ if (regionA && regionB && regionA !== regionB) return false;
90
+ if (scriptA && scriptB && scriptA !== scriptB) return false;
91
+ return true;
92
+ }
93
+ /**
94
+ * Test two or more language codes to determine if they are exactly the same
95
+ * e.g. "en-US" and "en" would be exactly the same.
96
+ * "en-GB" and "en" would be exactly the same.
97
+ * "en-GB" and "en-US" would be different.
98
+ * @internal
99
+ */
100
+ function _isSameDialect(...locales) {
101
+ try {
102
+ const flattenedCodes = locales.flat().map(_standardizeLocale);
103
+ for (let i = 0; i < flattenedCodes.length; i++) for (let j = i + 1; j < flattenedCodes.length; j++) if (!checkTwoLocalesAreSameDialect(flattenedCodes[i], flattenedCodes[j])) return false;
104
+ return true;
105
+ } catch (error) {
106
+ console.error(error);
107
+ return false;
108
+ }
109
+ }
110
+ //#endregion
111
+ //#region src/locales/isSameLanguage.ts
112
+ /**
113
+ * @internal
114
+ */
115
+ function _isSameLanguage(...locales) {
116
+ try {
117
+ const languages = locales.flat().map((locale) => require_internal.intlCache.get("Locale", locale).language);
118
+ return languages.every((language) => language === languages[0]);
119
+ } catch (error) {
120
+ console.error(error);
121
+ return false;
122
+ }
123
+ }
124
+ //#endregion
125
+ //#region src/locales/requiresTranslation.ts
126
+ /**
127
+ * Given a target locale and a source locale, determines whether a translation is required
128
+ * If the target locale and the source locale are the same, returns false, otherwise returns true
129
+ * If a translation is not possible due to the target locale being outside of the optional approvedLanguages scope, also returns false
130
+ * @internal
131
+ */
132
+ function _requiresTranslation(sourceLocale, targetLocale, approvedLocales, customMapping) {
133
+ if (!_isValidLocale(sourceLocale, customMapping) || !_isValidLocale(targetLocale, customMapping) || approvedLocales && approvedLocales.some((approvedLocale) => !_isValidLocale(approvedLocale, customMapping))) return false;
134
+ if (_isSameDialect(sourceLocale, targetLocale)) return false;
135
+ if (approvedLocales && !approvedLocales.some((approvedLocale) => _isSameLanguage(targetLocale, approvedLocale))) return false;
136
+ return true;
137
+ }
138
+ //#endregion
139
+ //#region src/locales/customLocaleMapping.ts
140
+ const getCustomProperty = (customMapping, locale, property) => {
141
+ if (customMapping?.[locale]) {
142
+ if (typeof customMapping[locale] === "string") return property === "name" ? customMapping[locale] : void 0;
143
+ return customMapping[locale][property];
144
+ }
145
+ };
146
+ /**
147
+ * Checks if a given locale should use the canonical locale.
148
+ * @param locale - The locale to check if it should use the canonical locale
149
+ * @param customMapping - The custom mapping to use for checking if the locale should use the canonical locale
150
+ * @returns True if the locale should use the canonical locale, false otherwise
151
+ */
152
+ const shouldUseCanonicalLocale = (locale, customMapping) => {
153
+ return !!(customMapping?.[locale] && typeof customMapping[locale] === "object" && "code" in customMapping[locale] && customMapping[locale].code && _isValidLocale(customMapping[locale].code));
154
+ };
155
+ //#endregion
156
+ //#region src/locales/getLocaleEmoji.ts
157
+ /**
158
+ * @internal
159
+ */
160
+ function _getLocaleEmoji(locale, customMapping) {
161
+ const aliasedLocale = locale;
162
+ if (customMapping && shouldUseCanonicalLocale(locale, customMapping)) locale = customMapping[locale].code;
163
+ try {
164
+ const standardizedLocale = _standardizeLocale(locale);
165
+ const localeObject = require_internal.intlCache.get("Locale", standardizedLocale);
166
+ const { language, region } = localeObject;
167
+ if (customMapping) for (const l of [
168
+ aliasedLocale,
169
+ locale,
170
+ standardizedLocale,
171
+ language
172
+ ]) {
173
+ const customEmoji = getCustomProperty(customMapping, l, "emoji");
174
+ if (customEmoji) return customEmoji;
175
+ }
176
+ if (region && emojis[region]) return emojis[region];
177
+ const extrapolated = localeObject.maximize();
178
+ const extrapolatedRegion = extrapolated.region || "";
179
+ return exceptions[extrapolated.language] || emojis[extrapolatedRegion] || "🌍";
180
+ } catch {
181
+ return defaultEmoji;
182
+ }
183
+ }
184
+ const europeAfricaGlobe = "🌍";
185
+ const asiaAustraliaGlobe = "🌏";
186
+ const defaultEmoji = europeAfricaGlobe;
187
+ const exceptions = {
188
+ ca: europeAfricaGlobe,
189
+ eu: europeAfricaGlobe,
190
+ ku: europeAfricaGlobe,
191
+ bo: asiaAustraliaGlobe,
192
+ ug: asiaAustraliaGlobe,
193
+ gd: "🏴󠁧󠁢󠁳󠁣󠁴󠁿",
194
+ cy: "🏴󠁧󠁢󠁷󠁬󠁳󠁿",
195
+ gv: "🇮🇲",
196
+ grc: "🏺"
197
+ };
198
+ const emojis = {
199
+ AF: "🇦🇫",
200
+ AX: "🇦🇽",
201
+ AL: "🇦🇱",
202
+ DZ: "🇩🇿",
203
+ AS: "🇦🇸",
204
+ AD: "🇦🇩",
205
+ AO: "🇦🇴",
206
+ AI: "🇦🇮",
207
+ AQ: "🇦🇶",
208
+ AG: "🇦🇬",
209
+ AR: "🇦🇷",
210
+ AM: "🇦🇲",
211
+ AW: "🇦🇼",
212
+ AU: "🇦🇺",
213
+ AT: "🇦🇹",
214
+ AZ: "🇦🇿",
215
+ BS: "🇧🇸",
216
+ BH: "🇧🇭",
217
+ BD: "🇧🇩",
218
+ BB: "🇧🇧",
219
+ BY: "🇧🇾",
220
+ BE: "🇧🇪",
221
+ BZ: "🇧🇿",
222
+ BJ: "🇧🇯",
223
+ BM: "🇧🇲",
224
+ BT: "🇧🇹",
225
+ BO: "🇧🇴",
226
+ BQ: "🇧🇶",
227
+ BA: "🇧🇦",
228
+ BW: "🇧🇼",
229
+ BV: "🇧🇻",
230
+ BR: "🇧🇷",
231
+ IO: "🇮🇴",
232
+ BN: "🇧🇳",
233
+ BG: "🇧🇬",
234
+ BF: "🇧🇫",
235
+ BI: "🇧🇮",
236
+ CV: "🇨🇻",
237
+ KH: "🇰🇭",
238
+ CM: "🇨🇲",
239
+ CA: "🇨🇦",
240
+ KY: "🇰🇾",
241
+ CF: "🇨🇫",
242
+ TD: "🇹🇩",
243
+ CL: "🇨🇱",
244
+ CN: "🇨🇳",
245
+ CX: "🇨🇽",
246
+ CC: "🇨🇨",
247
+ CO: "🇨🇴",
248
+ KM: "🇰🇲",
249
+ CD: "🇨🇩",
250
+ CG: "🇨🇬",
251
+ CK: "🇨🇰",
252
+ CR: "🇨🇷",
253
+ CI: "🇨🇮",
254
+ HR: "🇭🇷",
255
+ CU: "🇨🇺",
256
+ CW: "🇨🇼",
257
+ CY: "🇨🇾",
258
+ CZ: "🇨🇿",
259
+ DK: "🇩🇰",
260
+ DJ: "🇩🇯",
261
+ DM: "🇩🇲",
262
+ DO: "🇩🇴",
263
+ EC: "🇪🇨",
264
+ EG: "🇪🇬",
265
+ SV: "🇸🇻",
266
+ GQ: "🇬🇶",
267
+ ER: "🇪🇷",
268
+ EE: "🇪🇪",
269
+ SZ: "🇸🇿",
270
+ ET: "🇪🇹",
271
+ FK: "🇫🇰",
272
+ FO: "🇫🇴",
273
+ FJ: "🇫🇯",
274
+ FI: "🇫🇮",
275
+ FR: "🇫🇷",
276
+ GF: "🇬🇫",
277
+ PF: "🇵🇫",
278
+ TF: "🇹🇫",
279
+ GA: "🇬🇦",
280
+ GM: "🇬🇲",
281
+ GE: "🇬🇪",
282
+ DE: "🇩🇪",
283
+ GH: "🇬🇭",
284
+ GI: "🇬🇮",
285
+ GR: "🇬🇷",
286
+ GL: "🇬🇱",
287
+ GD: "🇬🇩",
288
+ GP: "🇬🇵",
289
+ GU: "🇬🇺",
290
+ GT: "🇬🇹",
291
+ GG: "🇬🇬",
292
+ GN: "🇬🇳",
293
+ GW: "🇬🇼",
294
+ GY: "🇬🇾",
295
+ HT: "🇭🇹",
296
+ HM: "🇭🇲",
297
+ VA: "🇻🇦",
298
+ HN: "🇭🇳",
299
+ HK: "🇭🇰",
300
+ HU: "🇭🇺",
301
+ IS: "🇮🇸",
302
+ IN: "🇮🇳",
303
+ ID: "🇮🇩",
304
+ IR: "🇮🇷",
305
+ IQ: "🇮🇶",
306
+ IE: "🇮🇪",
307
+ IM: "🇮🇲",
308
+ IL: "🇮🇱",
309
+ IT: "🇮🇹",
310
+ JM: "🇯🇲",
311
+ JP: "🇯🇵",
312
+ JE: "🇯🇪",
313
+ JO: "🇯🇴",
314
+ KZ: "🇰🇿",
315
+ KE: "🇰🇪",
316
+ KI: "🇰🇮",
317
+ KP: "🇰🇵",
318
+ KR: "🇰🇷",
319
+ KW: "🇰🇼",
320
+ KG: "🇰🇬",
321
+ LA: "🇱🇦",
322
+ LV: "🇱🇻",
323
+ LB: "🇱🇧",
324
+ LS: "🇱🇸",
325
+ LR: "🇱🇷",
326
+ LY: "🇱🇾",
327
+ LI: "🇱🇮",
328
+ LT: "🇱🇹",
329
+ LU: "🇱🇺",
330
+ MO: "🇲🇴",
331
+ MG: "🇲🇬",
332
+ MW: "🇲🇼",
333
+ MY: "🇲🇾",
334
+ MV: "🇲🇻",
335
+ ML: "🇲🇱",
336
+ MT: "🇲🇹",
337
+ MH: "🇲🇭",
338
+ MQ: "🇲🇶",
339
+ MR: "🇲🇷",
340
+ MU: "🇲🇺",
341
+ YT: "🇾🇹",
342
+ MX: "🇲🇽",
343
+ FM: "🇫🇲",
344
+ MD: "🇲🇩",
345
+ MC: "🇲🇨",
346
+ MN: "🇲🇳",
347
+ ME: "🇲🇪",
348
+ MS: "🇲🇸",
349
+ MA: "🇲🇦",
350
+ MZ: "🇲🇿",
351
+ MM: "🇲🇲",
352
+ NA: "🇳🇦",
353
+ NR: "🇳🇷",
354
+ NP: "🇳🇵",
355
+ NL: "🇳🇱",
356
+ NC: "🇳🇨",
357
+ NZ: "🇳🇿",
358
+ NI: "🇳🇮",
359
+ NE: "🇳🇪",
360
+ NG: "🇳🇬",
361
+ NU: "🇳🇺",
362
+ NF: "🇳🇫",
363
+ MK: "🇲🇰",
364
+ MP: "🇲🇵",
365
+ NO: "🇳🇴",
366
+ OM: "🇴🇲",
367
+ PK: "🇵🇰",
368
+ PW: "🇵🇼",
369
+ PS: "🇵🇸",
370
+ PA: "🇵🇦",
371
+ PG: "🇵🇬",
372
+ PY: "🇵🇾",
373
+ PE: "🇵🇪",
374
+ PH: "🇵🇭",
375
+ PN: "🇵🇳",
376
+ PL: "🇵🇱",
377
+ PT: "🇵🇹",
378
+ PR: "🇵🇷",
379
+ QA: "🇶🇦",
380
+ RE: "🇷🇪",
381
+ RO: "🇷🇴",
382
+ RU: "🇷🇺",
383
+ RW: "🇷🇼",
384
+ BL: "🇧🇱",
385
+ SH: "🇸🇭",
386
+ KN: "🇰🇳",
387
+ LC: "🇱🇨",
388
+ MF: "🇲🇫",
389
+ PM: "🇵🇲",
390
+ VC: "🇻🇨",
391
+ WS: "🇼🇸",
392
+ SM: "🇸🇲",
393
+ ST: "🇸🇹",
394
+ SA: "🇸🇦",
395
+ SN: "🇸🇳",
396
+ RS: "🇷🇸",
397
+ SC: "🇸🇨",
398
+ SL: "🇸🇱",
399
+ SG: "🇸🇬",
400
+ SX: "🇸🇽",
401
+ SK: "🇸🇰",
402
+ SI: "🇸🇮",
403
+ SB: "🇸🇧",
404
+ SO: "🇸🇴",
405
+ ZA: "🇿🇦",
406
+ GS: "🇬🇸",
407
+ SS: "🇸🇸",
408
+ ES: "🇪🇸",
409
+ LK: "🇱🇰",
410
+ SD: "🇸🇩",
411
+ SR: "🇸🇷",
412
+ SJ: "🇸🇯",
413
+ SE: "🇸🇪",
414
+ CH: "🇨🇭",
415
+ SY: "🇸🇾",
416
+ TW: "🇹🇼",
417
+ TJ: "🇹🇯",
418
+ TZ: "🇹🇿",
419
+ TH: "🇹🇭",
420
+ TL: "🇹🇱",
421
+ TG: "🇹🇬",
422
+ TK: "🇹🇰",
423
+ TO: "🇹🇴",
424
+ TT: "🇹🇹",
425
+ TN: "🇹🇳",
426
+ TR: "🇹🇷",
427
+ TM: "🇹🇲",
428
+ TC: "🇹🇨",
429
+ TV: "🇹🇻",
430
+ UG: "🇺🇬",
431
+ UA: "🇺🇦",
432
+ AE: "🇦🇪",
433
+ GB: "🇬🇧",
434
+ US: "🇺🇸",
435
+ UM: "🇺🇲",
436
+ UY: "🇺🇾",
437
+ UZ: "🇺🇿",
438
+ VU: "🇻🇺",
439
+ VE: "🇻🇪",
440
+ VN: "🇻🇳",
441
+ VG: "🇻🇬",
442
+ VI: "🇻🇮",
443
+ WF: "🇼🇫",
444
+ EH: "🇪🇭",
445
+ YE: "🇾🇪",
446
+ ZM: "🇿🇲",
447
+ ZW: "🇿🇼",
448
+ EU: "🇪🇺",
449
+ "419": "🌎"
450
+ };
451
+ //#endregion
452
+ //#region src/locales/getLocaleProperties.ts
453
+ /**
454
+ * Creates a set of custom locale properties from a custom mapping.
455
+ *
456
+ * @param lArray - An array of locale codes to search for in the custom mapping.
457
+ * @param customMapping - Optional custom mapping of locale codes to names.
458
+ * @returns A partial set of locale properties, or undefined if no custom mapping is provided.
459
+ */
460
+ function createCustomLocaleProperties(lArray, customMapping) {
461
+ if (customMapping) {
462
+ let merged = {};
463
+ for (const l of lArray) {
464
+ const value = customMapping[l];
465
+ if (value) {
466
+ if (typeof value === "string") merged.name ||= value;
467
+ else if (value) merged = {
468
+ ...value,
469
+ ...merged
470
+ };
471
+ }
472
+ }
473
+ return merged;
474
+ }
475
+ }
476
+ /**
477
+ * @internal
478
+ */
479
+ function _getLocaleProperties(locale, defaultLocale = "en", customMapping) {
480
+ const aliasedLocale = locale;
481
+ if (customMapping && shouldUseCanonicalLocale(locale, customMapping)) locale = customMapping[locale].code;
482
+ defaultLocale ||= "en";
483
+ try {
484
+ const standardizedLocale = _standardizeLocale(locale);
485
+ const localeObject = require_internal.intlCache.get("Locale", locale);
486
+ const languageCode = localeObject.language;
487
+ const customLocaleProperties = createCustomLocaleProperties([
488
+ aliasedLocale,
489
+ locale,
490
+ standardizedLocale,
491
+ languageCode
492
+ ], customMapping);
493
+ const baseRegion = localeObject.region;
494
+ const maximizedLocale = localeObject.maximize();
495
+ const maximizedCode = maximizedLocale.toString();
496
+ const regionCode = localeObject.region || customLocaleProperties?.regionCode || maximizedLocale.region || "";
497
+ const scriptCode = localeObject.script || customLocaleProperties?.scriptCode || maximizedLocale.script || "";
498
+ const minimizedCode = localeObject.minimize().toString();
499
+ const defaultLanguageOrder = [
500
+ defaultLocale,
501
+ locale,
502
+ "en"
503
+ ];
504
+ const nativeLanguageOrder = [
505
+ locale,
506
+ defaultLocale,
507
+ "en"
508
+ ];
509
+ const languageNames = require_internal.intlCache.get("DisplayNames", defaultLanguageOrder, { type: "language" });
510
+ const nativeLanguageNames = require_internal.intlCache.get("DisplayNames", nativeLanguageOrder, { type: "language" });
511
+ const customName = customLocaleProperties?.name;
512
+ const customNativeName = customLocaleProperties?.nativeName || customLocaleProperties?.name;
513
+ const name = customName || languageNames.of(locale) || locale;
514
+ const nativeName = customNativeName || nativeLanguageNames.of(locale) || locale;
515
+ const maximizedName = customLocaleProperties?.maximizedName || customName || languageNames.of(maximizedCode) || locale;
516
+ const nativeMaximizedName = customLocaleProperties?.nativeMaximizedName || customNativeName || nativeLanguageNames.of(maximizedCode) || locale;
517
+ const minimizedName = customLocaleProperties?.minimizedName || customName || languageNames.of(minimizedCode) || locale;
518
+ const nativeMinimizedName = customLocaleProperties?.nativeMinimizedName || customNativeName || nativeLanguageNames.of(minimizedCode) || locale;
519
+ const languageName = customLocaleProperties?.languageName || customName || languageNames.of(languageCode) || locale;
520
+ const nativeLanguageName = customLocaleProperties?.nativeLanguageName || customNativeName || nativeLanguageNames.of(languageCode) || locale;
521
+ const nameWithRegionCode = customLocaleProperties?.nameWithRegionCode || baseRegion ? `${languageName} (${baseRegion})` : name;
522
+ const nativeNameWithRegionCode = customLocaleProperties?.nativeNameWithRegionCode || (baseRegion ? `${nativeLanguageName} (${baseRegion})` : nativeName) || nameWithRegionCode;
523
+ const regionNames = require_internal.intlCache.get("DisplayNames", defaultLanguageOrder, { type: "region" });
524
+ const nativeRegionNames = require_internal.intlCache.get("DisplayNames", nativeLanguageOrder, { type: "region" });
525
+ const regionName = customLocaleProperties?.regionName || (regionCode ? regionNames.of(regionCode) : "") || "";
526
+ const nativeRegionName = customLocaleProperties?.nativeRegionName || (regionCode ? nativeRegionNames.of(regionCode) : "") || "";
527
+ const scriptNames = require_internal.intlCache.get("DisplayNames", defaultLanguageOrder, { type: "script" });
528
+ const nativeScriptNames = require_internal.intlCache.get("DisplayNames", nativeLanguageOrder, { type: "script" });
529
+ return {
530
+ code: standardizedLocale,
531
+ name,
532
+ nativeName,
533
+ maximizedCode,
534
+ maximizedName,
535
+ nativeMaximizedName,
536
+ minimizedCode,
537
+ minimizedName,
538
+ nativeMinimizedName,
539
+ languageCode,
540
+ languageName,
541
+ nativeLanguageName,
542
+ nameWithRegionCode,
543
+ nativeNameWithRegionCode,
544
+ regionCode,
545
+ regionName,
546
+ nativeRegionName,
547
+ scriptCode,
548
+ scriptName: customLocaleProperties?.scriptName || (scriptCode ? scriptNames.of(scriptCode) : "") || "",
549
+ nativeScriptName: customLocaleProperties?.nativeScriptName || (scriptCode ? nativeScriptNames.of(scriptCode) : "") || "",
550
+ emoji: customLocaleProperties?.emoji || _getLocaleEmoji(standardizedLocale, customMapping)
551
+ };
552
+ } catch {
553
+ let code = _isValidLocale(locale) ? _standardizeLocale(locale) : locale;
554
+ const codeParts = code?.split("-");
555
+ let languageCode = codeParts?.[0] || code || "";
556
+ let regionCode = codeParts.length > 2 ? codeParts?.[2] : codeParts?.[1] || "";
557
+ let scriptCode = codeParts?.[3] || "";
558
+ const customLocaleProperties = createCustomLocaleProperties([code, languageCode], customMapping);
559
+ code = customLocaleProperties?.code || code;
560
+ const name = customLocaleProperties?.name || code;
561
+ const nativeName = customLocaleProperties?.nativeName || name;
562
+ const maximizedCode = customLocaleProperties?.maximizedCode || code;
563
+ const maximizedName = customLocaleProperties?.maximizedName || name;
564
+ const nativeMaximizedName = customLocaleProperties?.nativeMaximizedName || nativeName;
565
+ const minimizedCode = customLocaleProperties?.minimizedCode || code;
566
+ const minimizedName = customLocaleProperties?.minimizedName || name;
567
+ const nativeMinimizedName = customLocaleProperties?.nativeMinimizedName || nativeName;
568
+ languageCode = customLocaleProperties?.languageCode || languageCode;
569
+ const languageName = customLocaleProperties?.languageName || name;
570
+ const nativeLanguageName = customLocaleProperties?.nativeLanguageName || nativeName;
571
+ regionCode = customLocaleProperties?.regionCode || regionCode;
572
+ const regionName = customLocaleProperties?.regionName || "";
573
+ const nativeRegionName = customLocaleProperties?.nativeRegionName || "";
574
+ scriptCode = customLocaleProperties?.scriptCode || scriptCode;
575
+ const scriptName = customLocaleProperties?.scriptName || "";
576
+ const nativeScriptName = customLocaleProperties?.nativeScriptName || "";
577
+ const nameWithRegionCode = customLocaleProperties?.nameWithRegionCode || (regionName ? `${languageName} (${regionName})` : name);
578
+ const nativeNameWithRegionCode = customLocaleProperties?.nativeNameWithRegionCode || (nativeRegionName ? `${nativeLanguageName} (${nativeRegionName})` : nativeName);
579
+ const emoji = customLocaleProperties?.emoji || "🌍";
580
+ return {
581
+ code,
582
+ name,
583
+ nativeName,
584
+ maximizedCode,
585
+ maximizedName,
586
+ nativeMaximizedName,
587
+ minimizedCode,
588
+ minimizedName,
589
+ nativeMinimizedName,
590
+ languageCode,
591
+ languageName,
592
+ nativeLanguageName,
593
+ nameWithRegionCode,
594
+ nativeNameWithRegionCode,
595
+ regionCode,
596
+ regionName,
597
+ nativeRegionName,
598
+ scriptCode,
599
+ scriptName,
600
+ nativeScriptName,
601
+ emoji
602
+ };
603
+ }
604
+ }
605
+ //#endregion
606
+ //#region src/locales/determineLocale.ts
607
+ /**
608
+ * Given a list of locales and a list of approved locales, sorted in preference order
609
+ * Determines which locale is the best match among the approved locales, prioritizing exact matches and falling back to dialects of the same language
610
+ * @internal
611
+ */
612
+ function _determineLocale(locales, approvedLocales, customMapping) {
613
+ if (typeof locales === "string") locales = [locales];
614
+ locales = locales.filter((locale) => _isValidLocale(locale, customMapping)).map(_standardizeLocale);
615
+ approvedLocales = approvedLocales.filter((locale) => _isValidLocale(locale, customMapping)).map(_standardizeLocale);
616
+ for (const locale of locales) {
617
+ const candidates = approvedLocales.filter((approvedLocale) => _isSameLanguage(locale, approvedLocale));
618
+ const getMatchingCode = ({ locale, languageCode, minimizedCode, regionCode, scriptCode }) => {
619
+ const locales = [
620
+ locale,
621
+ `${languageCode}-${regionCode}`,
622
+ `${languageCode}-${scriptCode}`,
623
+ minimizedCode
624
+ ];
625
+ for (const l of locales) if (candidates.includes(l)) return l;
626
+ return null;
627
+ };
628
+ const { languageCode, ...codes } = _getLocaleProperties(locale);
629
+ const matchingCode = getMatchingCode({
630
+ locale,
631
+ languageCode,
632
+ ...codes
633
+ }) || getMatchingCode({
634
+ locale: languageCode,
635
+ ..._getLocaleProperties(languageCode)
636
+ });
637
+ if (matchingCode) return matchingCode;
638
+ }
639
+ }
640
+ //#endregion
641
+ //#region src/logging/logger.ts
642
+ const LOG_LEVELS = {
643
+ debug: 0,
644
+ info: 1,
645
+ warn: 2,
646
+ error: 3,
647
+ off: 4
648
+ };
649
+ const LOG_COLORS = {
650
+ debug: "\x1B[36m",
651
+ info: "\x1B[32m",
652
+ warn: "\x1B[33m",
653
+ error: "\x1B[31m",
654
+ off: ""
655
+ };
656
+ const RESET_COLOR = "\x1B[0m";
657
+ /**
658
+ * Get the configured log level from environment variable or default to 'warn'
659
+ */
660
+ function getConfiguredLogLevel() {
661
+ if (typeof process !== "undefined" && process.env?._GT_LOG_LEVEL) {
662
+ const envLevel = process.env._GT_LOG_LEVEL.toLowerCase();
663
+ if (envLevel in LOG_LEVELS) return envLevel;
664
+ }
665
+ return "warn";
666
+ }
667
+ /**
668
+ * Console log handler that outputs formatted messages to console
669
+ */
670
+ var ConsoleLogHandler = class {
671
+ constructor(config) {
672
+ this.config = config;
673
+ }
674
+ handle(entry) {
675
+ const parts = [];
676
+ if (this.config.includeTimestamp) parts.push(`[${entry.timestamp.toISOString()}]`);
677
+ const colorCode = LOG_COLORS[entry.level];
678
+ const levelText = `[${entry.level.toUpperCase()}]`;
679
+ parts.push(`${colorCode}${levelText}${RESET_COLOR}`);
680
+ if (this.config.prefix) parts.push(`[${this.config.prefix}]`);
681
+ if (this.config.includeContext && entry.context) parts.push(`[${entry.context}]`);
682
+ parts.push(entry.message);
683
+ if (entry.metadata && Object.keys(entry.metadata).length > 0) parts.push(`\n Metadata: ${JSON.stringify(entry.metadata, null, 2)}`);
684
+ const formattedMessage = parts.join(" ");
685
+ switch (entry.level) {
686
+ case "debug":
687
+ console.debug(formattedMessage);
688
+ break;
689
+ case "info":
690
+ console.info(formattedMessage);
691
+ break;
692
+ case "warn":
693
+ console.warn(formattedMessage);
694
+ break;
695
+ case "error":
696
+ console.error(formattedMessage);
697
+ break;
698
+ }
699
+ }
700
+ };
701
+ /**
702
+ * Main Logger class providing structured logging capabilities
703
+ */
704
+ var Logger = class {
705
+ constructor(config = {}) {
706
+ this.config = {
707
+ level: getConfiguredLogLevel(),
708
+ includeTimestamp: true,
709
+ includeContext: true,
710
+ enableConsole: true,
711
+ handlers: [],
712
+ ...config
713
+ };
714
+ this.handlers = [...this.config.handlers || []];
715
+ if (this.config.enableConsole) this.handlers.push(new ConsoleLogHandler(this.config));
716
+ }
717
+ /**
718
+ * Add a custom log handler
719
+ */
720
+ addHandler(handler) {
721
+ this.handlers.push(handler);
722
+ }
723
+ /**
724
+ * Remove a log handler
725
+ */
726
+ removeHandler(handler) {
727
+ const index = this.handlers.indexOf(handler);
728
+ if (index > -1) this.handlers.splice(index, 1);
729
+ }
730
+ /**
731
+ * Update logger configuration
732
+ */
733
+ configure(config) {
734
+ this.config = {
735
+ ...this.config,
736
+ ...config
737
+ };
738
+ }
739
+ /**
740
+ * Check if a log level should be output based on current configuration
741
+ */
742
+ shouldLog(level) {
743
+ return LOG_LEVELS[level] >= LOG_LEVELS[this.config.level];
744
+ }
745
+ /**
746
+ * Internal logging method that creates log entries and passes them to handlers
747
+ */
748
+ log(level, message, context, metadata) {
749
+ if (!this.shouldLog(level)) return;
750
+ const entry = {
751
+ level,
752
+ message,
753
+ timestamp: /* @__PURE__ */ new Date(),
754
+ context,
755
+ metadata
756
+ };
757
+ this.handlers.forEach((handler) => {
758
+ try {
759
+ handler.handle(entry);
760
+ } catch (error) {
761
+ console.error("Error in log handler:", error);
762
+ }
763
+ });
764
+ }
765
+ /**
766
+ * Log a debug message
767
+ * Used for detailed diagnostic information, typically of interest only when diagnosing problems
768
+ */
769
+ debug(message, context, metadata) {
770
+ this.log("debug", message, context, metadata);
771
+ }
772
+ /**
773
+ * Log an info message
774
+ * Used for general information about application operation
775
+ */
776
+ info(message, context, metadata) {
777
+ this.log("info", message, context, metadata);
778
+ }
779
+ /**
780
+ * Log a warning message
781
+ * Used for potentially problematic situations that don't prevent operation
782
+ */
783
+ warn(message, context, metadata) {
784
+ this.log("warn", message, context, metadata);
785
+ }
786
+ /**
787
+ * Log an error message
788
+ * Used for error events that might still allow the application to continue
789
+ */
790
+ error(message, context, metadata) {
791
+ this.log("error", message, context, metadata);
792
+ }
793
+ /**
794
+ * Create a child logger with a specific context
795
+ */
796
+ child(context) {
797
+ return new ContextLogger(this, context);
798
+ }
799
+ /**
800
+ * Get current logger configuration
801
+ */
802
+ getConfig() {
803
+ return { ...this.config };
804
+ }
805
+ };
806
+ /**
807
+ * Context logger that automatically includes context information
808
+ */
809
+ var ContextLogger = class ContextLogger {
810
+ constructor(logger, context) {
811
+ this.logger = logger;
812
+ this.context = context;
813
+ }
814
+ debug(message, metadata) {
815
+ this.logger.debug(message, this.context, metadata);
816
+ }
817
+ info(message, metadata) {
818
+ this.logger.info(message, this.context, metadata);
819
+ }
820
+ warn(message, metadata) {
821
+ this.logger.warn(message, this.context, metadata);
822
+ }
823
+ error(message, metadata) {
824
+ this.logger.error(message, this.context, metadata);
825
+ }
826
+ child(childContext) {
827
+ return new ContextLogger(this.logger, `${this.context}:${childContext}`);
828
+ }
829
+ };
830
+ const defaultLogger = new Logger({
831
+ level: getConfiguredLogLevel(),
832
+ includeTimestamp: true,
833
+ includeContext: true,
834
+ prefix: "GT"
835
+ });
836
+ const fetchLogger = defaultLogger.child("fetch");
837
+ defaultLogger.child("validation");
838
+ defaultLogger.child("formatting");
839
+ defaultLogger.child("locale");
840
+ const gtInstanceLogger = defaultLogger.child("GT instance");
841
+ //#endregion
842
+ //#region src/formatting/format.ts
843
+ /**
844
+ * Formats a string value with cutoff behavior according to the specified locales and options.
845
+ *
846
+ * @param {Object} params - The parameters for the cutoff formatting.
847
+ * @param {string} params.value - The string value to format with cutoff behavior.
848
+ * @param {string | string[]} [params.locales='en'] - The locales to use for formatting.
849
+ * @param {CutoffFormatOptions} [params.options={}] - Additional options for cutoff formatting.
850
+ * @param {number} [params.options.maxChars] - The maximum number of characters to display.
851
+ * @param {CutoffFormatStyle} [params.options.style='ellipsis'] - The style of the terminator.
852
+ * @param {string} [params.options.terminator] - Optional override for the terminator to use.
853
+ * @param {string} [params.options.separator] - Optional override for the separator between terminator and value.
854
+ *
855
+ * @returns {string} The formatted string with terminator applied if cutoff occurs.
856
+ * @internal
857
+ *
858
+ * @example
859
+ * _formatCutoff({ value: 'Hello, world!', options: { maxChars: 8 } }); // Returns 'Hello, w...'
860
+ *
861
+ * Will fallback to an empty string if formatting fails.
862
+ */
863
+ function _formatCutoff({ value, locales = "en", options = {} }) {
864
+ return require_internal.intlCache.get("CutoffFormat", locales, options).format(value);
865
+ }
866
+ /**
867
+ * Formats a message according to the specified locales and options.
868
+ *
869
+ * @param {string} message - The message to format.
870
+ * @param {string | string[]} [locales='en'] - The locales to use for formatting.
871
+ * @param {Record<string, any>} [variables={}] - The variables to use for formatting.
872
+ * @returns {string} The formatted message.
873
+ * @internal
874
+ *
875
+ * Will fallback to an empty string
876
+ * TODO: add this to custom formats
877
+ */
878
+ function _formatMessageICU(message, locales = "en", variables = {}) {
879
+ return new intl_messageformat.default(message, locales).format(variables)?.toString() ?? "";
880
+ }
881
+ /**
882
+ * Returns the message as-is without any formatting.
883
+ *
884
+ * @param {string} message - The message to return.
885
+ * @returns {string} The original message, unchanged.
886
+ * @internal
887
+ *
888
+ * TODO: add this to custom formats
889
+ */
890
+ function _formatMessageString(message) {
891
+ return message;
892
+ }
893
+ /**
894
+ * Formats a number according to the specified locales and options.
895
+ *
896
+ * @param {Object} params - The parameters for the number formatting.
897
+ * @param {number} params.value - The number to format.
898
+ * @param {string | string[]} [params.locales=['en']] - The locales to use for formatting.
899
+ * @param {Intl.NumberFormatOptions} [params.options={}] - Additional options for number formatting.
900
+ *
901
+ * @returns {string} The formatted number.
902
+ * @internal
903
+ */
904
+ function _formatNum({ value, locales = ["en"], options = {} }) {
905
+ return require_internal.intlCache.get("NumberFormat", locales, {
906
+ numberingSystem: "latn",
907
+ ...options
908
+ }).format(value);
909
+ }
910
+ /**
911
+ * Formats a date according to the specified locales and options.
912
+ *
913
+ * @param {Object} params - The parameters for the date formatting.
914
+ * @param {Date} params.value - The date to format.
915
+ * @param {string | string[]} [params.locales='en'] - The locales to use for formatting.
916
+ * @param {Intl.DateTimeFormatOptions} [params.options={}] - Additional options for date formatting.
917
+ *
918
+ * @returns {string} The formatted date.
919
+ * @internal
920
+ */
921
+ function _formatDateTime({ value, locales = ["en"], options = {} }) {
922
+ return require_internal.intlCache.get("DateTimeFormat", locales, {
923
+ calendar: "gregory",
924
+ numberingSystem: "latn",
925
+ ...options
926
+ }).format(value);
927
+ }
928
+ /**
929
+ * Formats a currency value according to the specified locales, currency, and options.
930
+ *
931
+ * @param {Object} params - The parameters for the currency formatting.
932
+ * @param {number} params.value - The currency value to format.
933
+ * @param {string} params.currency - The currency code (e.g., 'USD').
934
+ * @param {string | string[]} [params.locales=['en']] - The locales to use for formatting.
935
+ * @param {Intl.NumberFormatOptions} [params.options={}] - Additional options for currency formatting.
936
+ *
937
+ * @returns {string} The formatted currency value.
938
+ * @internal
939
+ */
940
+ function _formatCurrency({ value, locales = ["en"], currency = "USD", options = {} }) {
941
+ return require_internal.intlCache.get("NumberFormat", locales, {
942
+ style: "currency",
943
+ currency,
944
+ numberingSystem: "latn",
945
+ ...options
946
+ }).format(value);
947
+ }
948
+ /**
949
+ * Formats a list of items according to the specified locales and options.
950
+ *
951
+ * @param {Object} params - The parameters for the list formatting.
952
+ * @param {Array<string | number>} params.value - The list of items to format.
953
+ * @param {string | string[]} [params.locales=['en']] - The locales to use for formatting.
954
+ * @param {Intl.ListFormatOptions} [params.options={}] - Additional options for list formatting.
955
+ *
956
+ * @returns {string} The formatted list.
957
+ * @internal
958
+ */
959
+ function _formatList({ value, locales = ["en"], options = {} }) {
960
+ return require_internal.intlCache.get("ListFormat", locales, {
961
+ type: "conjunction",
962
+ style: "long",
963
+ ...options
964
+ }).format(value);
965
+ }
966
+ /**
967
+ * Formats a list of items according to the specified locales and options.
968
+ * @param {Object} params - The parameters for the list formatting.
969
+ * @param {Array<T>} params.value - The list of items to format.
970
+ * @param {string | string[]} [params.locales=['en']] - The locales to use for formatting.
971
+ * @param {Intl.ListFormatOptions} [params.options={}] - Additional options for list formatting.
972
+ * @returns {Array<T | string>} The formatted list parts.
973
+ * @internal
974
+ */
975
+ function _formatListToParts({ value, locales = ["en"], options = {} }) {
976
+ const formatListParts = require_internal.intlCache.get("ListFormat", locales, {
977
+ type: "conjunction",
978
+ style: "long",
979
+ ...options
980
+ }).formatToParts(value.map(() => "1"));
981
+ let partIndex = 0;
982
+ return formatListParts.map((part) => {
983
+ if (part.type === "element") return value[partIndex++];
984
+ return part.value;
985
+ });
986
+ }
987
+ /**
988
+ * Selects the best unit and computes the value for relative time formatting
989
+ * based on the difference between a date and a base date.
990
+ * @param {Date} date - The target date.
991
+ * @param {Date} baseDate - The base date to compute relative time from. Must be provided by the caller for hydration safety.
992
+ * @returns {{ value: number, unit: Intl.RelativeTimeFormatUnit }} The computed value and unit.
993
+ * @internal
994
+ */
995
+ function _selectRelativeTimeUnit(date, baseDate) {
996
+ const now = baseDate.getTime();
997
+ const diffMs = date.getTime() - now;
998
+ const absDiffMs = Math.abs(diffMs);
999
+ const sign = diffMs < 0 ? -1 : 1;
1000
+ const seconds = Math.floor(absDiffMs / 1e3);
1001
+ const minutes = Math.floor(absDiffMs / (1e3 * 60));
1002
+ const hours = Math.floor(absDiffMs / (1e3 * 60 * 60));
1003
+ const days = Math.floor(absDiffMs / (1e3 * 60 * 60 * 24));
1004
+ const weeks = Math.floor(absDiffMs / (1e3 * 60 * 60 * 24 * 7));
1005
+ const months = Math.floor(absDiffMs / (1e3 * 60 * 60 * 24 * 30));
1006
+ const years = Math.floor(absDiffMs / (1e3 * 60 * 60 * 24 * 365));
1007
+ if (seconds < 60) return {
1008
+ value: sign * seconds,
1009
+ unit: "second"
1010
+ };
1011
+ if (minutes < 60) return {
1012
+ value: sign * minutes,
1013
+ unit: "minute"
1014
+ };
1015
+ if (hours < 24) return {
1016
+ value: sign * hours,
1017
+ unit: "hour"
1018
+ };
1019
+ if (days < 7) return {
1020
+ value: sign * days,
1021
+ unit: "day"
1022
+ };
1023
+ if (days < 28) return {
1024
+ value: sign * weeks,
1025
+ unit: "week"
1026
+ };
1027
+ if (months < 1) return {
1028
+ value: sign * weeks,
1029
+ unit: "week"
1030
+ };
1031
+ if (months < 12) return {
1032
+ value: sign * months,
1033
+ unit: "month"
1034
+ };
1035
+ if (years < 1) return {
1036
+ value: sign * months,
1037
+ unit: "month"
1038
+ };
1039
+ return {
1040
+ value: sign * years,
1041
+ unit: "year"
1042
+ };
1043
+ }
1044
+ /**
1045
+ * Formats a relative time from a Date, automatically selecting the best unit.
1046
+ * @internal
1047
+ */
1048
+ function _formatRelativeTimeFromDate({ date, baseDate, locales = ["en"], options = {} }) {
1049
+ const { value, unit } = _selectRelativeTimeUnit(date, baseDate);
1050
+ return _formatRelativeTime({
1051
+ value,
1052
+ unit,
1053
+ locales,
1054
+ options
1055
+ });
1056
+ }
1057
+ /**
1058
+ * Formats a relative time value according to the specified locales and options.
1059
+ *
1060
+ * @param {Object} params - The parameters for the relative time formatting.
1061
+ * @param {number} params.value - The relative time value to format.
1062
+ * @param {Intl.RelativeTimeFormatUnit} params.unit - The unit of time (e.g., 'second', 'minute', 'hour', 'day', 'week', 'month', 'year').
1063
+ * @param {string | string[]} [params.locales=['en']] - The locales to use for formatting.
1064
+ * @param {Intl.RelativeTimeFormatOptions} [params.options={}] - Additional options for relative time formatting.
1065
+ *
1066
+ * @returns {string} The formatted relative time string.
1067
+ * @internal
1068
+ */
1069
+ function _formatRelativeTime({ value, unit, locales = ["en"], options = {} }) {
1070
+ return require_internal.intlCache.get("RelativeTimeFormat", locales, {
1071
+ style: "long",
1072
+ numeric: "auto",
1073
+ ...options
1074
+ }).format(value, unit);
1075
+ }
1076
+ //#endregion
1077
+ //#region src/locales/getLocaleName.ts
1078
+ /**
1079
+ * Retrieves the display name(s) of locale code(s) using Intl.DisplayNames.
1080
+ *
1081
+ * @param {string} locale - A BCP-47 locale code.
1082
+ * @param {string} [defaultLocale=libraryDefaultLocale] - The locale for display names.
1083
+ * @returns {string} The display name(s) corresponding to the code(s), or empty string(s) if invalid.
1084
+ * @internal
1085
+ */
1086
+ function _getLocaleName(locale, defaultLocale = "en", customMapping) {
1087
+ const aliasedLocale = locale;
1088
+ if (customMapping && shouldUseCanonicalLocale(locale, customMapping)) locale = customMapping[locale].code;
1089
+ defaultLocale ||= "en";
1090
+ try {
1091
+ const standardizedLocale = _standardizeLocale(locale);
1092
+ if (customMapping) for (const l of [
1093
+ aliasedLocale,
1094
+ locale,
1095
+ standardizedLocale,
1096
+ require_internal.intlCache.get("Locale", standardizedLocale).language
1097
+ ]) {
1098
+ const customName = getCustomProperty(customMapping, l, "name");
1099
+ if (customName) return customName;
1100
+ }
1101
+ return require_internal.intlCache.get("DisplayNames", [
1102
+ defaultLocale,
1103
+ standardizedLocale,
1104
+ "en"
1105
+ ], { type: "language" }).of(standardizedLocale) || "";
1106
+ } catch {
1107
+ return "";
1108
+ }
1109
+ }
1110
+ //#endregion
1111
+ //#region src/locales/getLocaleDirection.ts
1112
+ /**
1113
+ * Get the text direction for a given locale code using the Intl.Locale API.
1114
+ *
1115
+ * @param {string} code - The locale code to check.
1116
+ * @returns {string} - 'rtl' if the language is right-to-left, otherwise 'ltr'.
1117
+ * @internal
1118
+ */
1119
+ function _getLocaleDirection(code) {
1120
+ try {
1121
+ const textInfoDirection = extractDirectionWithTextInfo(require_internal.intlCache.get("Locale", code));
1122
+ if (textInfoDirection) return textInfoDirection;
1123
+ } catch {}
1124
+ const { scriptCode, languageCode } = _getLocaleProperties(code);
1125
+ if (scriptCode) return isRtlScript(scriptCode) ? "rtl" : "ltr";
1126
+ if (languageCode) return isRtlLanguage(languageCode) ? "rtl" : "ltr";
1127
+ return "ltr";
1128
+ }
1129
+ const RTL_SCRIPTS = new Set([
1130
+ "arab",
1131
+ "adlm",
1132
+ "hebr",
1133
+ "nkoo",
1134
+ "rohg",
1135
+ "samr",
1136
+ "syrc",
1137
+ "thaa",
1138
+ "yezi"
1139
+ ]);
1140
+ const RTL_LANGUAGES = new Set([
1141
+ "ar",
1142
+ "arc",
1143
+ "ckb",
1144
+ "dv",
1145
+ "fa",
1146
+ "he",
1147
+ "iw",
1148
+ "ku",
1149
+ "lrc",
1150
+ "nqo",
1151
+ "ps",
1152
+ "pnb",
1153
+ "sd",
1154
+ "syr",
1155
+ "ug",
1156
+ "ur",
1157
+ "yi"
1158
+ ]);
1159
+ /**
1160
+ * Handles extracting direction via textInfo property
1161
+ * @param Locale - Intl.Locale object
1162
+ * @returns {'ltr' | 'rtl'} - The direction of the locale
1163
+ *
1164
+ * Intl.Locale.prototype.getTextInfo() / textInfo property incorporated in ES2024 Specification.
1165
+ * This is not supported by all browsers yet.
1166
+ * See: {@link https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/Locale/getTextInfo#browser_compatibility}
1167
+ */
1168
+ function extractDirectionWithTextInfo(locale) {
1169
+ if ("textInfo" in locale && typeof locale.textInfo === "object" && locale.textInfo !== null && "direction" in locale.textInfo && (locale.textInfo?.direction === "rtl" || locale.textInfo?.direction === "ltr")) return locale.textInfo?.direction;
1170
+ }
1171
+ function isRtlScript(script) {
1172
+ return script ? RTL_SCRIPTS.has(script.toLowerCase()) : false;
1173
+ }
1174
+ function isRtlLanguage(language) {
1175
+ return language ? RTL_LANGUAGES.has(language.toLowerCase()) : false;
1176
+ }
1177
+ //#endregion
1178
+ //#region src/locales/isSupersetLocale.ts
1179
+ /**
1180
+ * @internal
1181
+ */
1182
+ function _isSupersetLocale(superLocale, subLocale) {
1183
+ try {
1184
+ const { language: languageSuper, region: regionSuper, script: scriptSuper } = require_internal.intlCache.get("Locale", _standardizeLocale(superLocale));
1185
+ const { language: languageSub, region: regionSub, script: scriptSub } = require_internal.intlCache.get("Locale", _standardizeLocale(subLocale));
1186
+ if (languageSuper !== languageSub) return false;
1187
+ if (regionSuper && regionSuper !== regionSub) return false;
1188
+ if (scriptSuper && scriptSuper !== scriptSub) return false;
1189
+ return true;
1190
+ } catch (error) {
1191
+ console.error(error);
1192
+ return false;
1193
+ }
1194
+ }
1195
+ //#endregion
1196
+ //#region src/logging/errors.ts
1197
+ const GT_ERROR_PREFIX = "GT Error:";
1198
+ const translationTimeoutError = (timeout) => `${GT_ERROR_PREFIX} Translation request timed out after ${timeout}ms.`;
1199
+ const translationRequestFailedError = (error) => `${GT_ERROR_PREFIX} Translation request failed. Error: ${error}`;
1200
+ const apiError = (status, statusText, error) => `${GT_ERROR_PREFIX} API returned error status. Status: ${status}, Status Text: ${statusText}, Error: ${error}`;
1201
+ `${GT_ERROR_PREFIX}`;
1202
+ const noTargetLocaleProvidedError = (functionName) => `${GT_ERROR_PREFIX} Cannot call \`${functionName}\` without a specified locale. Either pass a locale to the \`${functionName}\` function or specify a targetLocale in the GT constructor.`;
1203
+ const noSourceLocaleProvidedError = (functionName) => `${GT_ERROR_PREFIX} Cannot call \`${functionName}\` without a specified locale. Either pass a locale to the \`${functionName}\` function or specify a sourceLocale in the GT constructor.`;
1204
+ const noProjectIdProvidedError = (functionName) => `${GT_ERROR_PREFIX} Cannot call \`${functionName}\` without a specified project ID. Either pass a project ID to the \`${functionName}\` function or specify a projectId in the GT constructor.`;
1205
+ const noApiKeyProvidedError = (functionName) => `${GT_ERROR_PREFIX} Cannot call \`${functionName}\` without a specified API key. Either pass an API key to the \`${functionName}\` function or specify an apiKey in the GT constructor.`;
1206
+ const invalidLocaleError = (locale) => `${GT_ERROR_PREFIX} Invalid locale: ${locale}.`;
1207
+ const invalidLocalesError = (locales) => `${GT_ERROR_PREFIX} Invalid locales: ${locales.join(", ")}.`;
1208
+ //#endregion
1209
+ //#region src/translate/utils/fetchWithTimeout.ts
1210
+ /**
1211
+ * @internal
1212
+ *
1213
+ * Wraps the fetch function with a timeout.
1214
+ *
1215
+ * @param url - The URL to fetch.
1216
+ * @param options - The options to pass to the fetch function.
1217
+ * @param timeout - The timeout in milliseconds.
1218
+ * @returns The response from the fetch function.
1219
+ */
1220
+ async function fetchWithTimeout(url, options, timeout) {
1221
+ const controller = new AbortController();
1222
+ const signal = controller.signal;
1223
+ timeout = timeout ? timeout : require_internal.defaultTimeout;
1224
+ const timeoutId = timeout ? setTimeout(() => controller.abort(), timeout) : null;
1225
+ try {
1226
+ return await fetch(url, {
1227
+ ...options,
1228
+ signal
1229
+ });
1230
+ } catch (error) {
1231
+ if (error instanceof Error && error.name === "AbortError") throw translationTimeoutError(timeout);
1232
+ throw error;
1233
+ } finally {
1234
+ if (timeoutId) clearTimeout(timeoutId);
1235
+ }
1236
+ }
1237
+ //#endregion
1238
+ //#region src/translate/utils/validateResponse.ts
1239
+ async function validateResponse(response) {
1240
+ if (!response.ok) {
1241
+ let errorMsg = "Unknown error";
1242
+ try {
1243
+ const text = await response.text();
1244
+ try {
1245
+ errorMsg = JSON.parse(text).error;
1246
+ } catch {
1247
+ errorMsg = text || "Unknown error";
1248
+ }
1249
+ } catch {}
1250
+ throw new require_ApiError.ApiError(apiError(response.status, response.statusText, errorMsg), response.status, errorMsg);
1251
+ }
1252
+ }
1253
+ //#endregion
1254
+ //#region src/translate/utils/handleFetchError.ts
1255
+ function handleFetchError(error, timeout) {
1256
+ if (error instanceof Error && error.name === "AbortError") {
1257
+ const errorMessage = translationTimeoutError(timeout);
1258
+ fetchLogger.error(errorMessage);
1259
+ throw new Error(errorMessage);
1260
+ }
1261
+ const errorMessage = translationRequestFailedError(error instanceof Error ? error.message : String(error));
1262
+ fetchLogger.error(errorMessage);
1263
+ throw error;
1264
+ }
1265
+ //#endregion
1266
+ //#region src/translate/api.ts
1267
+ const API_VERSION$1 = "2026-03-06.v1";
1268
+ //#endregion
1269
+ //#region src/translate/utils/generateRequestHeaders.ts
1270
+ function generateRequestHeaders(config, excludeContentType = false) {
1271
+ const authHeaders = {
1272
+ ...!excludeContentType && { "Content-Type": "application/json" },
1273
+ "x-gt-project-id": config.projectId
1274
+ };
1275
+ if (config.apiKey) if (config.apiKey.startsWith("gtx-internal-")) authHeaders["x-gt-internal-api-key"] = config.apiKey;
1276
+ else authHeaders["x-gt-api-key"] = config.apiKey;
1277
+ authHeaders["gt-api-version"] = API_VERSION$1;
1278
+ return authHeaders;
1279
+ }
1280
+ //#endregion
1281
+ //#region src/translate/utils/apiRequest.ts
1282
+ const MAX_RETRIES = 3;
1283
+ const INITIAL_DELAY_MS = 500;
1284
+ function sleep(ms) {
1285
+ return new Promise((resolve) => setTimeout(resolve, ms));
1286
+ }
1287
+ function getRetryDelay(policy, attempt) {
1288
+ switch (policy) {
1289
+ case "linear": return INITIAL_DELAY_MS * (attempt + 1);
1290
+ case "exponential": return INITIAL_DELAY_MS * 2 ** attempt;
1291
+ default: return 0;
1292
+ }
1293
+ }
1294
+ /**
1295
+ * @internal
1296
+ *
1297
+ * Makes an API request with automatic retry for 5XX errors.
1298
+ *
1299
+ * Encapsulates URL construction, fetch with timeout, error handling,
1300
+ * response validation, and JSON parsing.
1301
+ *
1302
+ * @param config - The configuration for the API call
1303
+ * @param endpoint - The API endpoint path (e.g. '/v2/project/jobs/info')
1304
+ * @param options - Optional request options
1305
+ * @returns The parsed JSON response
1306
+ */
1307
+ async function apiRequest(config, endpoint, options) {
1308
+ const timeout = options?.timeout ?? 6e4;
1309
+ const url = `${config.baseUrl || "https://api2.gtx.dev"}${endpoint}`;
1310
+ const method = options?.method ?? "POST";
1311
+ const retryPolicy = options?.retryPolicy ?? "exponential";
1312
+ const maxRetries = retryPolicy === "none" ? 0 : MAX_RETRIES;
1313
+ const requestInit = {
1314
+ method,
1315
+ headers: generateRequestHeaders(config)
1316
+ };
1317
+ if (options?.body !== void 0) requestInit.body = JSON.stringify(options.body);
1318
+ for (let attempt = 0; attempt <= maxRetries; attempt++) {
1319
+ let response;
1320
+ try {
1321
+ response = await fetchWithTimeout(url, requestInit, timeout);
1322
+ } catch (error) {
1323
+ if (attempt < maxRetries) {
1324
+ await sleep(getRetryDelay(retryPolicy, attempt));
1325
+ continue;
1326
+ }
1327
+ handleFetchError(error, timeout);
1328
+ }
1329
+ if (response.status >= 500 && attempt < maxRetries) {
1330
+ await sleep(getRetryDelay(retryPolicy, attempt));
1331
+ continue;
1332
+ }
1333
+ await validateResponse(response);
1334
+ return await response.json();
1335
+ }
1336
+ throw new Error("Max retries exceeded");
1337
+ }
1338
+ //#endregion
1339
+ //#region src/translate/translateMany.ts
1340
+ async function _translateMany(requests, globalMetadata, config, timeout) {
1341
+ const isArray = Array.isArray(requests);
1342
+ const hashOrder = isArray ? [] : void 0;
1343
+ const requestsObject = {};
1344
+ const entries = isArray ? requests.map((r) => [void 0, r]) : Object.entries(requests);
1345
+ for (const [key, request] of entries) {
1346
+ const { source, metadata } = typeof request === "string" ? { source: request } : request;
1347
+ const hash = key ?? metadata?.hash ?? require_id.hashSource({
1348
+ source,
1349
+ dataFormat: metadata?.dataFormat ?? "STRING",
1350
+ ...metadata ?? {}
1351
+ });
1352
+ hashOrder?.push(hash);
1353
+ requestsObject[hash] = {
1354
+ source,
1355
+ metadata
1356
+ };
1357
+ }
1358
+ const response = await apiRequest({
1359
+ ...config,
1360
+ baseUrl: config.baseUrl || "https://runtime2.gtx.dev"
1361
+ }, `/v2/translate`, {
1362
+ body: {
1363
+ requests: requestsObject,
1364
+ targetLocale: globalMetadata.targetLocale,
1365
+ sourceLocale: globalMetadata.sourceLocale,
1366
+ metadata: globalMetadata
1367
+ },
1368
+ timeout,
1369
+ retryPolicy: "none"
1370
+ });
1371
+ if (hashOrder) return hashOrder.map((hash) => response[hash] ?? {
1372
+ success: false,
1373
+ error: "No translation returned",
1374
+ code: 500
1375
+ });
1376
+ return response;
1377
+ }
1378
+ //#endregion
1379
+ //#region src/translate/setupProject.ts
1380
+ /**
1381
+ * @internal
1382
+ * Enqueues files for project setup the General Translation API.
1383
+ * @param files - References of files to translate (file content already uploaded)
1384
+ * @param config - The configuration for the API call
1385
+ * @param timeoutMS - The timeout in milliseconds
1386
+ * @returns The result of the API call
1387
+ */
1388
+ async function _setupProject(files, config, options) {
1389
+ return apiRequest(config, "/v2/project/setup/generate", {
1390
+ body: {
1391
+ files: files.map((f) => ({
1392
+ branchId: f.branchId,
1393
+ fileId: f.fileId,
1394
+ versionId: f.versionId
1395
+ })),
1396
+ locales: options?.locales,
1397
+ force: options?.force
1398
+ },
1399
+ timeout: options?.timeoutMs
1400
+ });
1401
+ }
1402
+ //#endregion
1403
+ //#region src/translate/utils/batch.ts
1404
+ /**
1405
+ * Splits an array into batches of a specified size.
1406
+ * @param items - The array to split into batches
1407
+ * @param batchSize - The maximum size of each batch
1408
+ * @returns An array of batches
1409
+ */
1410
+ function createBatches(items, batchSize) {
1411
+ const batches = [];
1412
+ for (let i = 0; i < items.length; i += batchSize) batches.push(items.slice(i, i + batchSize));
1413
+ return batches;
1414
+ }
1415
+ /**
1416
+ * Processes items in batches using a provided processor function.
1417
+ *
1418
+ * @param items - The items to process
1419
+ * @param processor - Async function that processes a single batch and returns items
1420
+ * @param options - Optional configuration for batch processing
1421
+ * @returns Promise that resolves to a BatchList containing all processed items
1422
+ *
1423
+ * @example
1424
+ * ```typescript
1425
+ * const result = await processBatches(
1426
+ * files,
1427
+ * async (batch) => {
1428
+ * const response = await uploadFiles(batch);
1429
+ * return response.uploadedFiles;
1430
+ * },
1431
+ * { batchSize: 100 }
1432
+ * );
1433
+ *
1434
+ * console.log(result.data); // All items
1435
+ * console.log(result.count); // Total count
1436
+ * console.log(result.batchCount); // Number of batches processed
1437
+ * ```
1438
+ */
1439
+ async function processBatches(items, processor, options = {}) {
1440
+ const { batchSize = 100, parallel = true } = options;
1441
+ if (items.length === 0) return {
1442
+ data: [],
1443
+ count: 0,
1444
+ batchCount: 0
1445
+ };
1446
+ const batches = createBatches(items, batchSize);
1447
+ const allItems = [];
1448
+ if (parallel) {
1449
+ const results = await Promise.all(batches.map((batch) => processor(batch)));
1450
+ for (const result of results) if (result) allItems.push(...result);
1451
+ } else for (const batch of batches) {
1452
+ const result = await processor(batch);
1453
+ if (result) allItems.push(...result);
1454
+ }
1455
+ return {
1456
+ data: allItems,
1457
+ count: allItems.length,
1458
+ batchCount: batches.length
1459
+ };
1460
+ }
1461
+ //#endregion
1462
+ //#region src/translate/enqueueFiles.ts
1463
+ /**
1464
+ * @internal
1465
+ * Enqueues files for translation in the General Translation API.
1466
+ * @param files - References of files to translate (file content already uploaded)
1467
+ * @param options - The options for the API call
1468
+ * @param config - The configuration for the API call
1469
+ * @returns The result of the API call
1470
+ */
1471
+ async function _enqueueFiles(files, options, config) {
1472
+ require_internal.validateFileFormatTransforms(files);
1473
+ const result = await processBatches(files, async (batch) => {
1474
+ const apiResult = await apiRequest(config, "/v2/project/translations/enqueue", {
1475
+ body: {
1476
+ files: batch.map((f) => ({
1477
+ branchId: f.branchId,
1478
+ fileId: f.fileId,
1479
+ versionId: f.versionId,
1480
+ fileName: f.fileName,
1481
+ transformFormat: f.transformFormat
1482
+ })),
1483
+ targetLocales: options.targetLocales,
1484
+ sourceLocale: options.sourceLocale,
1485
+ requireApproval: options.requireApproval,
1486
+ modelProvider: options.modelProvider,
1487
+ force: options.force
1488
+ },
1489
+ timeout: options.timeout
1490
+ });
1491
+ return Array.from(Object.entries(apiResult.jobData));
1492
+ }, { batchSize: 100 });
1493
+ return {
1494
+ jobData: Object.fromEntries(result.data.map(([jobId, jobData]) => [jobId, jobData])),
1495
+ locales: options.targetLocales,
1496
+ message: `Successfully enqueued ${result.count} file translation jobs in ${result.batchCount} batch(es)`
1497
+ };
1498
+ }
1499
+ //#endregion
1500
+ //#region src/translate/createTag.ts
1501
+ /**
1502
+ * @internal
1503
+ * Creates or upserts a file tag in the General Translation API.
1504
+ * @param options - The tag creation options
1505
+ * @param config - The configuration for the API call
1506
+ * @returns The created or updated tag
1507
+ */
1508
+ async function _createTag(options, config) {
1509
+ return await apiRequest(config, "/v2/project/tags/create", { body: {
1510
+ tagId: options.tagId,
1511
+ files: options.files,
1512
+ ...options.message && { message: options.message }
1513
+ } });
1514
+ }
1515
+ //#endregion
1516
+ //#region src/translate/downloadFileBatch.ts
1517
+ /**
1518
+ * @internal
1519
+ * Downloads multiple translation files in batches.
1520
+ * @param files - Array of files to download
1521
+ * @param options - The options for the API call
1522
+ * @param config - The configuration for the request
1523
+ * @returns Promise resolving to a BatchList with all downloaded files
1524
+ */
1525
+ async function _downloadFileBatch(requests, options, config) {
1526
+ return processBatches(requests, async (batch) => {
1527
+ return (await apiRequest(config, "/v2/project/files/download", {
1528
+ body: batch,
1529
+ timeout: options.timeout
1530
+ })).files.map((file) => ({
1531
+ ...file,
1532
+ data: require_internal.decode(file.data)
1533
+ }));
1534
+ }, { batchSize: 100 });
1535
+ }
1536
+ //#endregion
1537
+ //#region src/translate/submitUserEditDiffs.ts
1538
+ /**
1539
+ * @internal
1540
+ * Submits user edit diffs so the service can learn/persist user-intended rules.
1541
+ */
1542
+ async function _submitUserEditDiffs(payload, config, options = {}) {
1543
+ await processBatches(payload.diffs, async (batch) => {
1544
+ await apiRequest(config, "/v2/project/files/diffs", {
1545
+ body: { diffs: batch },
1546
+ timeout: options.timeout
1547
+ });
1548
+ return [{ success: true }];
1549
+ }, { batchSize: 100 });
1550
+ return { success: true };
1551
+ }
1552
+ //#endregion
1553
+ //#region src/locales/getRegionProperties.ts
1554
+ /**
1555
+ * Retrieves multiple properties for a given region code, including:
1556
+ * - `code`: the original region code
1557
+ * - `name`: the localized display name
1558
+ * - `emoji`: the associated flag or symbol
1559
+ *
1560
+ * Behavior:
1561
+ * - Accepts ISO 3166-1 alpha-2 or UN M.49 region codes (e.g., `"US"`, `"FR"`, `"419"`).
1562
+ * - If `customMapping` contains a `name` or `emoji` for the region, those override the default values.
1563
+ * - Otherwise, uses `Intl.DisplayNames` to get the localized region name in the given `defaultLocale`,
1564
+ * falling back to `libraryDefaultLocale`.
1565
+ * - Falls back to the region code as `name` if display name resolution fails.
1566
+ * - Falls back to `defaultEmoji` if no emoji mapping is found in `emojis` or `customMapping`.
1567
+ *
1568
+ * @param {string} region - The region code to look up (e.g., `"US"`, `"GB"`, `"DE"`).
1569
+ * @param {string} [defaultLocale=libraryDefaultLocale] - The locale to use when localizing the region name.
1570
+ * @param {CustomRegionMapping} [customMapping] - Optional mapping of region codes to custom names and/or emojis.
1571
+ * @returns {{ code: string, name: string, emoji: string }} An object containing:
1572
+ * - `code`: the input region code
1573
+ * - `name`: the localized or custom region name
1574
+ * - `emoji`: the matching emoji flag or symbol
1575
+ * @internal
1576
+ *
1577
+ * @example
1578
+ * _getRegionProperties('US', 'en');
1579
+ * // => { code: 'US', name: 'United States', emoji: '🇺🇸' }
1580
+ *
1581
+ * @example
1582
+ * _getRegionProperties('US', 'fr');
1583
+ * // => { code: 'US', name: 'États-Unis', emoji: '🇺🇸' }
1584
+ *
1585
+ * @example
1586
+ * _getRegionProperties('US', 'en', { US: { name: 'USA', emoji: '🗽' } });
1587
+ * // => { code: 'US', name: 'USA', emoji: '🗽' }
1588
+ */
1589
+ function _getRegionProperties(region, defaultLocale = "en", customMapping) {
1590
+ defaultLocale ||= "en";
1591
+ try {
1592
+ return {
1593
+ code: region,
1594
+ name: require_internal.intlCache.get("DisplayNames", [defaultLocale, "en"], { type: "region" }).of(region) || region,
1595
+ emoji: emojis[region] || "🌍",
1596
+ ...customMapping?.[region]
1597
+ };
1598
+ } catch {
1599
+ return {
1600
+ code: region,
1601
+ name: region,
1602
+ emoji: defaultEmoji,
1603
+ ...customMapping?.[region]
1604
+ };
1605
+ }
1606
+ }
1607
+ //#endregion
1608
+ //#region src/locales/resolveAliasLocale.ts
1609
+ /**
1610
+ * Resolves the alias locale for a given locale.
1611
+ * @param locale - The locale to resolve the alias locale for
1612
+ * @param customMapping - The custom mapping to use for resolving the alias locale
1613
+ * @returns The alias locale
1614
+ */
1615
+ function _resolveAliasLocale(locale, customMapping) {
1616
+ let reverseCustomMapping;
1617
+ if (customMapping) reverseCustomMapping = Object.fromEntries(Object.entries(customMapping).filter(([, value]) => value && typeof value === "object" && "code" in value).map(([key, value]) => [value.code, key]));
1618
+ return reverseCustomMapping?.[locale] || locale;
1619
+ }
1620
+ //#endregion
1621
+ //#region src/locales/resolveCanonicalLocale.ts
1622
+ /**
1623
+ * Resolves the canonical locale for a given locale.
1624
+ * @param locale - The locale to resolve the canonical locale for
1625
+ * @param customMapping - The custom mapping to use for resolving the canonical locale
1626
+ * @returns The canonical locale
1627
+ */
1628
+ function _resolveCanonicalLocale(locale, customMapping) {
1629
+ if (customMapping && shouldUseCanonicalLocale(locale, customMapping)) return customMapping[locale].code;
1630
+ return locale;
1631
+ }
1632
+ //#endregion
1633
+ //#region src/translate/uploadSourceFiles.ts
1634
+ /**
1635
+ * @internal
1636
+ * Uploads source files to the General Translation API in batches.
1637
+ * @param files - The files to upload
1638
+ * @param options - The options for the API call
1639
+ * @param config - The configuration for the API call
1640
+ * @returns Promise resolving to a BatchList with all uploaded files
1641
+ */
1642
+ async function _uploadSourceFiles(files, options, config) {
1643
+ return processBatches(files, async (batch) => {
1644
+ return (await apiRequest(config, "/v2/project/files/upload-files", {
1645
+ body: {
1646
+ data: batch.map(({ source }) => ({ source: {
1647
+ content: require_internal.encode(source.content),
1648
+ fileName: source.fileName,
1649
+ fileFormat: source.fileFormat,
1650
+ locale: source.locale,
1651
+ dataFormat: source.dataFormat,
1652
+ formatMetadata: source.formatMetadata,
1653
+ fileId: source.fileId,
1654
+ versionId: source.versionId,
1655
+ branchId: source.branchId,
1656
+ incomingBranchId: source.incomingBranchId,
1657
+ checkedOutBranchId: source.checkedOutBranchId
1658
+ } })),
1659
+ sourceLocale: options.sourceLocale
1660
+ },
1661
+ timeout: options.timeout
1662
+ })).uploadedFiles || [];
1663
+ }, { batchSize: 100 });
1664
+ }
1665
+ //#endregion
1666
+ //#region src/translate/uploadTranslations.ts
1667
+ /**
1668
+ * @internal
1669
+ * Uploads multiple translations to the General Translation API in batches.
1670
+ * @param files - Translations to upload with their source
1671
+ * @param options - The options for the API call
1672
+ * @param config - The configuration for the API call
1673
+ * @returns Promise resolving to a BatchList with all uploaded files
1674
+ */
1675
+ async function _uploadTranslations(files, options, config) {
1676
+ require_internal.validateFileFormatTransforms(files.map(({ source }) => source));
1677
+ return processBatches(files, async (batch) => {
1678
+ return (await apiRequest(config, "/v2/project/files/upload-translations", {
1679
+ body: {
1680
+ data: batch.map(({ source, translations }) => ({
1681
+ source: {
1682
+ content: require_internal.encode(source.content),
1683
+ fileName: source.fileName,
1684
+ fileFormat: source.fileFormat,
1685
+ transformFormat: source.transformFormat,
1686
+ locale: source.locale,
1687
+ dataFormat: source.dataFormat,
1688
+ formatMetadata: source.formatMetadata,
1689
+ fileId: source.fileId,
1690
+ versionId: source.versionId,
1691
+ branchId: source.branchId
1692
+ },
1693
+ translations: translations.map((t) => ({
1694
+ content: require_internal.encode(t.content),
1695
+ fileName: t.fileName,
1696
+ fileFormat: t.fileFormat,
1697
+ locale: t.locale,
1698
+ dataFormat: t.dataFormat,
1699
+ fileId: t.fileId,
1700
+ versionId: t.versionId,
1701
+ branchId: t.branchId
1702
+ }))
1703
+ })),
1704
+ sourceLocale: options.sourceLocale
1705
+ },
1706
+ timeout: options.timeout
1707
+ })).uploadedFiles || [];
1708
+ }, { batchSize: 100 });
1709
+ }
1710
+ //#endregion
1711
+ //#region src/translate/querySourceFile.ts
1712
+ /**
1713
+ * @internal
1714
+ * Gets the source file and translation information for a given file ID and version ID.
1715
+ * @param query - The file ID and version ID to get the source file and translation information for
1716
+ * @param options - The options for the API call
1717
+ * @param config - The configuration for the request
1718
+ * @returns The source file and translation information for the given file ID and version ID
1719
+ */
1720
+ async function _querySourceFile(query, options, config) {
1721
+ const branchId = query.branchId;
1722
+ const versionId = query.versionId;
1723
+ const fileId = query.fileId;
1724
+ const searchParams = new URLSearchParams();
1725
+ if (branchId) searchParams.set("branchId", branchId);
1726
+ if (versionId) searchParams.set("versionId", versionId);
1727
+ return apiRequest(config, `/v2/project/translations/files/status/${encodeURIComponent(fileId)}?${searchParams.toString()}`, {
1728
+ method: "GET",
1729
+ timeout: options.timeout
1730
+ });
1731
+ }
1732
+ //#endregion
1733
+ //#region src/projects/getProjectData.ts
1734
+ /**
1735
+ * @internal
1736
+ * Gets the project data for a given project ID.
1737
+ * @param projectId - The project ID to get the project data for
1738
+ * @param options - The options for the API call
1739
+ * @param config - The configuration for the request
1740
+ * @returns The project data for the given project ID
1741
+ */
1742
+ async function _getProjectData(projectId, options, config) {
1743
+ const { baseUrl } = config;
1744
+ const timeout = options.timeout ? options.timeout : require_internal.defaultTimeout;
1745
+ const url = `${baseUrl || "https://api2.gtx.dev"}/v2/project/info/${encodeURIComponent(projectId)}`;
1746
+ let response;
1747
+ try {
1748
+ response = await fetchWithTimeout(url, {
1749
+ method: "GET",
1750
+ headers: generateRequestHeaders(config)
1751
+ }, timeout);
1752
+ } catch (error) {
1753
+ handleFetchError(error, timeout);
1754
+ }
1755
+ await validateResponse(response);
1756
+ return await response.json();
1757
+ }
1758
+ //#endregion
1759
+ //#region src/translate/checkJobStatus.ts
1760
+ /**
1761
+ * @internal
1762
+ * Queries job statuses for a project
1763
+ * @param jobIds - Job IDs
1764
+ * @param config - The configuration for the API call
1765
+ * @param timeoutMS - The timeout in milliseconds
1766
+ * @returns The result of the API call
1767
+ */
1768
+ async function _checkJobStatus(jobIds, config, timeoutMs) {
1769
+ return apiRequest(config, "/v2/project/jobs/info", {
1770
+ body: { jobIds },
1771
+ timeout: timeoutMs
1772
+ });
1773
+ }
1774
+ //#endregion
1775
+ //#region src/translate/awaitJobs.ts
1776
+ /**
1777
+ * @internal
1778
+ * Polls job statuses until all jobs are finished or the timeout is reached.
1779
+ * @param enqueueResult - The result from enqueueFiles
1780
+ * @param options - Polling configuration
1781
+ * @param config - API credentials and configuration
1782
+ * @returns The final status of all jobs
1783
+ */
1784
+ async function _awaitJobs(enqueueResult, options, config) {
1785
+ const pollingInterval = (options?.pollingIntervalSeconds ?? 5) * 1e3;
1786
+ const timeout = options?.timeoutSeconds !== void 0 ? options.timeoutSeconds * 1e3 : 600 * 1e3;
1787
+ const jobIds = Object.keys(enqueueResult.jobData);
1788
+ if (jobIds.length === 0) return {
1789
+ complete: true,
1790
+ jobs: []
1791
+ };
1792
+ const startTime = Date.now();
1793
+ const finalStatuses = new Map(jobIds.map((id) => [id, {
1794
+ jobId: id,
1795
+ status: "unknown"
1796
+ }]));
1797
+ const pendingJobIds = new Set(jobIds);
1798
+ while (pendingJobIds.size > 0) {
1799
+ const statuses = await _checkJobStatus(Array.from(pendingJobIds), config);
1800
+ for (const job of statuses) if (job.status === "completed" || job.status === "failed" || job.status === "unknown") {
1801
+ finalStatuses.set(job.jobId, {
1802
+ jobId: job.jobId,
1803
+ status: job.status,
1804
+ ...job.error ? { error: job.error } : {}
1805
+ });
1806
+ pendingJobIds.delete(job.jobId);
1807
+ } else finalStatuses.set(job.jobId, {
1808
+ jobId: job.jobId,
1809
+ status: job.status
1810
+ });
1811
+ if (pendingJobIds.size === 0) break;
1812
+ if (Date.now() - startTime >= timeout) break;
1813
+ await new Promise((resolve) => setTimeout(resolve, pollingInterval));
1814
+ }
1815
+ return {
1816
+ complete: pendingJobIds.size === 0,
1817
+ jobs: Array.from(finalStatuses.values())
1818
+ };
1819
+ }
1820
+ //#endregion
1821
+ //#region src/translate/queryFileData.ts
1822
+ /**
1823
+ * @internal
1824
+ * Queries data about one or more source or translation files.
1825
+ * @param data - Object mapping source or translation file information
1826
+ * @param options - The options for the API call
1827
+ * @param config - The configuration for the API call
1828
+ * @returns The file data
1829
+ */
1830
+ async function _queryFileData(data, options = {}, config) {
1831
+ return apiRequest(config, "/v2/project/files/info", {
1832
+ body: {
1833
+ sourceFiles: data.sourceFiles?.map((item) => ({
1834
+ fileId: item.fileId,
1835
+ versionId: item.versionId,
1836
+ branchId: item.branchId
1837
+ })),
1838
+ translatedFiles: data.translatedFiles?.map((item) => ({
1839
+ fileId: item.fileId,
1840
+ versionId: item.versionId,
1841
+ branchId: item.branchId,
1842
+ locale: item.locale
1843
+ }))
1844
+ },
1845
+ timeout: options.timeout
1846
+ });
1847
+ }
1848
+ //#endregion
1849
+ //#region src/translate/queryBranchData.ts
1850
+ /**
1851
+ * @internal
1852
+ * Queries branch information from the API.
1853
+ * @param query - Object mapping the current branch and incoming branches
1854
+ * @param config - The configuration for the API call
1855
+ * @returns The branch information
1856
+ */
1857
+ async function _queryBranchData(query, config) {
1858
+ return apiRequest(config, "/v2/project/branches/info", { body: query });
1859
+ }
1860
+ //#endregion
1861
+ //#region src/translate/createBranch.ts
1862
+ /**
1863
+ * @internal
1864
+ * Creates a new branch in the API.
1865
+ * @param query - Object mapping the branch name and default branch flag
1866
+ * @param config - The configuration for the API call
1867
+ * @returns The created branch information
1868
+ */
1869
+ async function _createBranch(query, config) {
1870
+ return apiRequest(config, "/v2/project/branches/create", { body: query });
1871
+ }
1872
+ //#endregion
1873
+ //#region src/translate/processFileMoves.ts
1874
+ /**
1875
+ * @internal
1876
+ * Processes file moves by cloning source files and translations with new fileIds.
1877
+ * Called when the CLI detects that files have been moved/renamed.
1878
+ * @param moves - Array of move mappings (old fileId to new fileId)
1879
+ * @param options - Options including branchId and timeout
1880
+ * @param config - The configuration for the API call
1881
+ * @returns Promise resolving to the move results
1882
+ */
1883
+ async function _processFileMoves(moves, options, config) {
1884
+ if (moves.length === 0) return {
1885
+ results: [],
1886
+ summary: {
1887
+ total: 0,
1888
+ succeeded: 0,
1889
+ failed: 0
1890
+ }
1891
+ };
1892
+ const batchResult = await processBatches(moves, async (batch) => {
1893
+ return (await apiRequest(config, "/v2/project/files/moves", {
1894
+ body: {
1895
+ branchId: options.branchId,
1896
+ moves: batch
1897
+ },
1898
+ timeout: options.timeout
1899
+ })).results;
1900
+ }, { batchSize: 100 });
1901
+ const succeeded = batchResult.data.filter((r) => r.success).length;
1902
+ const failed = batchResult.data.filter((r) => !r.success).length;
1903
+ return {
1904
+ results: batchResult.data,
1905
+ summary: {
1906
+ total: moves.length,
1907
+ succeeded,
1908
+ failed
1909
+ }
1910
+ };
1911
+ }
1912
+ //#endregion
1913
+ //#region src/translate/getOrphanedFiles.ts
1914
+ /**
1915
+ * @internal
1916
+ * Gets orphaned files for a branch - files that exist on the branch
1917
+ * but whose fileIds are not in the provided list.
1918
+ * Used for move detection.
1919
+ * @param branchId - The branch to check for orphaned files
1920
+ * @param fileIds - List of current file IDs (files that are NOT orphaned)
1921
+ * @param options - The options for the API call
1922
+ * @param config - The configuration for the API call
1923
+ * @returns The orphaned files
1924
+ */
1925
+ async function _getOrphanedFiles(branchId, fileIds, options = {}, config) {
1926
+ const makeRequest = (batchFileIds) => apiRequest(config, "/v2/project/files/orphaned", {
1927
+ body: {
1928
+ branchId,
1929
+ fileIds: batchFileIds
1930
+ },
1931
+ timeout: options.timeout
1932
+ });
1933
+ if (fileIds.length === 0) return makeRequest([]);
1934
+ const batches = createBatches(fileIds, 100);
1935
+ const batchResults = await Promise.all(batches.map((batch) => makeRequest(batch)));
1936
+ if (batchResults.length === 1) return batchResults[0];
1937
+ const orphanedFileMap = /* @__PURE__ */ new Map();
1938
+ for (const orphan of batchResults[0].orphanedFiles) orphanedFileMap.set(orphan.fileId, orphan);
1939
+ for (let i = 1; i < batchResults.length; i++) {
1940
+ const batchOrphanIds = new Set(batchResults[i].orphanedFiles.map((f) => f.fileId));
1941
+ Array.from(orphanedFileMap.keys()).forEach((fileId) => {
1942
+ if (!batchOrphanIds.has(fileId)) orphanedFileMap.delete(fileId);
1943
+ });
1944
+ }
1945
+ return { orphanedFiles: Array.from(orphanedFileMap.values()) };
1946
+ }
1947
+ //#endregion
1948
+ //#region src/translate/publishFiles.ts
1949
+ /**
1950
+ * @internal
1951
+ * Publishes or unpublishes files on the CDN.
1952
+ * @param files - Array of file entries with publish flags
1953
+ * @param config - The configuration for the API call
1954
+ * @returns The result of the API call
1955
+ */
1956
+ async function _publishFiles(files, config) {
1957
+ return await apiRequest(config, "/v2/project/files/publish", { body: { files } });
1958
+ }
1959
+ //#endregion
1960
+ //#region src/LocaleConfig.ts
1961
+ /**
1962
+ * LocaleConfig is a client-safe locale and formatting helper.
1963
+ *
1964
+ * It intentionally does not store project IDs, API keys, runtime URLs, or any
1965
+ * translation credentials. It only stores locale metadata needed to resolve
1966
+ * aliases, choose formatting fallbacks, and format values with Intl.
1967
+ */
1968
+ var LocaleConfig = class {
1969
+ constructor({ defaultLocale = "en", locales = [], customMapping } = {}) {
1970
+ this.defaultLocale = defaultLocale;
1971
+ this.locales = locales;
1972
+ this.customMapping = customMapping;
1973
+ }
1974
+ get translationLocales() {
1975
+ return this.locales.length ? this.locales : void 0;
1976
+ }
1977
+ resolveCanonicalLocaleList(locales) {
1978
+ return locales.map((locale) => this.resolveCanonicalLocale(locale));
1979
+ }
1980
+ resolveCanonicalLocaleArgs(locales) {
1981
+ return locales.map((locale) => Array.isArray(locale) ? this.resolveCanonicalLocaleList(locale) : this.resolveCanonicalLocale(locale));
1982
+ }
1983
+ toLocaleList(locales) {
1984
+ return Array.isArray(locales) ? locales : [locales];
1985
+ }
1986
+ getFormattingLocales(targetLocale, locales) {
1987
+ return (locales !== void 0 ? this.toLocaleList(locales) : [
1988
+ targetLocale,
1989
+ this.defaultLocale,
1990
+ "en"
1991
+ ]).filter((locale) => !!locale).map((locale) => this.resolveCanonicalLocale(locale));
1992
+ }
1993
+ formatNum(value, targetLocale, options = {}) {
1994
+ const { locales, ...intlOptions } = options;
1995
+ return _formatNum({
1996
+ value,
1997
+ locales: this.getFormattingLocales(targetLocale, locales),
1998
+ options: intlOptions
1999
+ });
2000
+ }
2001
+ formatDateTime(value, targetLocale, options = {}) {
2002
+ const { locales, ...intlOptions } = options;
2003
+ return _formatDateTime({
2004
+ value,
2005
+ locales: this.getFormattingLocales(targetLocale, locales),
2006
+ options: intlOptions
2007
+ });
2008
+ }
2009
+ formatCurrency(value, currency, targetLocale, options = {}) {
2010
+ const { locales, ...intlOptions } = options;
2011
+ return _formatCurrency({
2012
+ value,
2013
+ currency,
2014
+ locales: this.getFormattingLocales(targetLocale, locales),
2015
+ options: intlOptions
2016
+ });
2017
+ }
2018
+ formatRelativeTime(value, unit, targetLocale, options = {}) {
2019
+ const { locales, ...intlOptions } = options;
2020
+ return _formatRelativeTime({
2021
+ value,
2022
+ unit,
2023
+ locales: this.getFormattingLocales(targetLocale, locales),
2024
+ options: intlOptions
2025
+ });
2026
+ }
2027
+ formatRelativeTimeFromDate(date, targetLocale, options = {}) {
2028
+ const { locales, baseDate, ...intlOptions } = options;
2029
+ return _formatRelativeTimeFromDate({
2030
+ date,
2031
+ baseDate: baseDate ?? /* @__PURE__ */ new Date(),
2032
+ locales: this.getFormattingLocales(targetLocale, locales),
2033
+ options: intlOptions
2034
+ });
2035
+ }
2036
+ formatCutoff(value, targetLocale, options = {}) {
2037
+ const { locales, ...formatOptions } = options;
2038
+ return _formatCutoff({
2039
+ value,
2040
+ locales: this.getFormattingLocales(targetLocale, locales),
2041
+ options: formatOptions
2042
+ });
2043
+ }
2044
+ formatMessage(message, targetLocale, options = {}) {
2045
+ const { locales, variables, dataFormat } = options;
2046
+ if (dataFormat === "STRING") return _formatMessageString(message);
2047
+ return _formatMessageICU(message, this.getFormattingLocales(targetLocale, locales), variables);
2048
+ }
2049
+ formatList(array, targetLocale, options = {}) {
2050
+ const { locales, ...intlOptions } = options;
2051
+ return _formatList({
2052
+ value: array,
2053
+ locales: this.getFormattingLocales(targetLocale, locales),
2054
+ options: intlOptions
2055
+ });
2056
+ }
2057
+ formatListToParts(array, targetLocale, options = {}) {
2058
+ const { locales, ...intlOptions } = options;
2059
+ return _formatListToParts({
2060
+ value: array,
2061
+ locales: this.getFormattingLocales(targetLocale, locales),
2062
+ options: intlOptions
2063
+ });
2064
+ }
2065
+ getLocaleName(locale) {
2066
+ return _getLocaleName(locale, this.defaultLocale, this.customMapping);
2067
+ }
2068
+ getLocaleEmoji(locale) {
2069
+ return _getLocaleEmoji(locale, this.customMapping);
2070
+ }
2071
+ getLocaleProperties(locale) {
2072
+ return _getLocaleProperties(locale, this.defaultLocale, this.customMapping);
2073
+ }
2074
+ requiresTranslation(targetLocale, sourceLocale = this.defaultLocale, approvedLocales = this.translationLocales) {
2075
+ return _requiresTranslation(this.resolveCanonicalLocale(sourceLocale), this.resolveCanonicalLocale(targetLocale), approvedLocales ? this.resolveCanonicalLocaleList(approvedLocales) : void 0, this.customMapping);
2076
+ }
2077
+ determineLocale(locales, approvedLocales = this.locales) {
2078
+ const approvedLocalePairs = approvedLocales.map((locale) => ({
2079
+ locale,
2080
+ canonicalLocale: this.resolveCanonicalLocale(locale)
2081
+ }));
2082
+ const resolvedLocale = _determineLocale(Array.isArray(locales) ? this.resolveCanonicalLocaleList(locales) : this.resolveCanonicalLocale(locales), approvedLocalePairs.map(({ canonicalLocale }) => canonicalLocale), this.customMapping);
2083
+ if (!resolvedLocale) return void 0;
2084
+ return approvedLocalePairs.find(({ canonicalLocale }) => canonicalLocale === resolvedLocale)?.locale || this.resolveAliasLocale(resolvedLocale);
2085
+ }
2086
+ getLocaleDirection(locale) {
2087
+ return _getLocaleDirection(this.resolveCanonicalLocale(locale));
2088
+ }
2089
+ isValidLocale(locale) {
2090
+ return _isValidLocale(locale, this.customMapping);
2091
+ }
2092
+ resolveCanonicalLocale(locale) {
2093
+ return _resolveCanonicalLocale(locale, this.customMapping);
2094
+ }
2095
+ resolveAliasLocale(locale) {
2096
+ return _resolveAliasLocale(locale, this.customMapping);
2097
+ }
2098
+ standardizeLocale(locale) {
2099
+ return _standardizeLocale(locale);
2100
+ }
2101
+ isSameDialect(...locales) {
2102
+ return _isSameDialect(...this.resolveCanonicalLocaleArgs(locales));
2103
+ }
2104
+ isSameLanguage(...locales) {
2105
+ return _isSameLanguage(...this.resolveCanonicalLocaleArgs(locales));
2106
+ }
2107
+ isSupersetLocale(superLocale, subLocale) {
2108
+ return _isSupersetLocale(this.resolveCanonicalLocale(superLocale), this.resolveCanonicalLocale(subLocale));
2109
+ }
2110
+ };
2111
+ //#endregion
2112
+ //#region src/index.ts
2113
+ /**
2114
+ * GT is the core driver for the General Translation library.
2115
+ * This class provides functionality for locale management, formatting, and translation operations.
2116
+ *
2117
+ * @class GT
2118
+ * @description A comprehensive toolkit for handling internationalization and localization.
2119
+ *
2120
+ * @example
2121
+ * const gt = new GT({
2122
+ * sourceLocale: 'en-US',
2123
+ * targetLocale: 'es-ES',
2124
+ * locales: ['en-US', 'es-ES', 'fr-FR']
2125
+ * });
2126
+ */
2127
+ var GT = class {
2128
+ /** Client-safe locale and formatting helpers */
2129
+ get localeConfig() {
2130
+ return this._localeConfig;
2131
+ }
2132
+ /**
2133
+ * Constructs an instance of the GT class.
2134
+ *
2135
+ * @param {GTConstructorParams} [params] - The parameters for initializing the GT instance
2136
+ * @throws {Error} If an invalid locale is provided
2137
+ * @throws {Error} If any of the provided locales are invalid
2138
+ *
2139
+ * @example
2140
+ * const gt = new GT({
2141
+ * apiKey: 'your-api-key',
2142
+ * sourceLocale: 'en-US',
2143
+ * targetLocale: 'es-ES',
2144
+ * locales: ['en-US', 'es-ES', 'fr-FR']
2145
+ * });
2146
+ */
2147
+ constructor(params = {}) {
2148
+ if (typeof process !== "undefined") {
2149
+ this.apiKey ||= process.env?.GT_API_KEY;
2150
+ this.devApiKey ||= process.env?.GT_DEV_API_KEY;
2151
+ this.projectId ||= process.env?.GT_PROJECT_ID;
2152
+ }
2153
+ this.setConfig(params);
2154
+ }
2155
+ setConfig({ apiKey, devApiKey, sourceLocale, targetLocale, locales, projectId, customMapping, baseUrl }) {
2156
+ if (apiKey) this.apiKey = apiKey;
2157
+ if (devApiKey) this.devApiKey = devApiKey;
2158
+ if (projectId) this.projectId = projectId;
2159
+ if (sourceLocale) {
2160
+ this.sourceLocale = _standardizeLocale(sourceLocale);
2161
+ if (!_isValidLocale(this.sourceLocale, customMapping)) throw new Error(invalidLocaleError(this.sourceLocale));
2162
+ }
2163
+ if (targetLocale) {
2164
+ this.targetLocale = _standardizeLocale(targetLocale);
2165
+ if (!_isValidLocale(this.targetLocale, customMapping)) throw new Error(invalidLocaleError(this.targetLocale));
2166
+ }
2167
+ if (locales) {
2168
+ const result = [];
2169
+ const invalidLocales = [];
2170
+ locales.forEach((locale) => {
2171
+ const standardizedLocale = _standardizeLocale(locale);
2172
+ if (_isValidLocale(standardizedLocale)) result.push(standardizedLocale);
2173
+ else invalidLocales.push(locale);
2174
+ });
2175
+ if (invalidLocales.length > 0) throw new Error(invalidLocalesError(invalidLocales));
2176
+ this.locales = result;
2177
+ }
2178
+ if (baseUrl) this.baseUrl = baseUrl;
2179
+ if (customMapping) {
2180
+ this.customMapping = customMapping;
2181
+ this.reverseCustomMapping = Object.fromEntries(Object.entries(customMapping).filter(([, value]) => value && typeof value === "object" && "code" in value).map(([key, value]) => [value.code, key]));
2182
+ }
2183
+ this._localeConfig = new LocaleConfig({
2184
+ defaultLocale: this.sourceLocale,
2185
+ locales: this.locales ?? [],
2186
+ customMapping: this.customMapping
2187
+ });
2188
+ }
2189
+ _getTranslationConfig() {
2190
+ return {
2191
+ baseUrl: this.baseUrl,
2192
+ apiKey: this.apiKey || this.devApiKey,
2193
+ projectId: this.projectId || ""
2194
+ };
2195
+ }
2196
+ _validateAuth(functionName) {
2197
+ const errors = [];
2198
+ if (!this.apiKey && !this.devApiKey) {
2199
+ const error = noApiKeyProvidedError(functionName);
2200
+ errors.push(error);
2201
+ }
2202
+ if (!this.projectId) {
2203
+ const error = noProjectIdProvidedError(functionName);
2204
+ errors.push(error);
2205
+ }
2206
+ if (errors.length) throw new Error(errors.join("\n"));
2207
+ }
2208
+ /**
2209
+ * Queries branch information from the API.
2210
+ *
2211
+ * @param {BranchQuery} query - Object mapping the current branch and incoming branches
2212
+ * @returns {Promise<BranchDataResult>} The branch information
2213
+ */
2214
+ async queryBranchData(query) {
2215
+ this._validateAuth("queryBranchData");
2216
+ return await _queryBranchData(query, this._getTranslationConfig());
2217
+ }
2218
+ /**
2219
+ * Creates a new branch in the API. If the branch already exists, it will be returned.
2220
+ *
2221
+ * @param {CreateBranchQuery} query - Object mapping the branch name and default branch flag
2222
+ * @returns {Promise<CreateBranchResult>} The created branch information
2223
+ */
2224
+ async createBranch(query) {
2225
+ this._validateAuth("createBranch");
2226
+ return await _createBranch(query, this._getTranslationConfig());
2227
+ }
2228
+ /**
2229
+ * Processes file moves by cloning source files and translations with new fileIds.
2230
+ * This is called when files have been moved/renamed and we want to preserve translations.
2231
+ *
2232
+ * @param {MoveMapping[]} moves - Array of move mappings (old fileId to new fileId)
2233
+ * @param {ProcessMovesOptions} options - Options including branchId and timeout
2234
+ * @returns {Promise<ProcessMovesResponse>} The move processing results
2235
+ *
2236
+ * @example
2237
+ * const result = await gt.processFileMoves([
2238
+ * { oldFileId: 'abc123', newFileId: 'def456', newFileName: 'locales/en.json' }
2239
+ * ], { branchId: 'main' });
2240
+ */
2241
+ async processFileMoves(moves, options = {}) {
2242
+ this._validateAuth("processFileMoves");
2243
+ return await _processFileMoves(moves, options, this._getTranslationConfig());
2244
+ }
2245
+ /**
2246
+ * Gets orphaned files for a branch - files that exist on the branch
2247
+ * but whose fileIds are not in the provided list.
2248
+ * Used for move detection.
2249
+ *
2250
+ * @param {string} branchId - The branch to check for orphaned files
2251
+ * @param {string[]} fileIds - List of current file IDs (files that are NOT orphaned)
2252
+ * @param {Object} options - Options including timeout
2253
+ * @returns {Promise<GetOrphanedFilesResult>} The orphaned files
2254
+ *
2255
+ * @example
2256
+ * const result = await gt.getOrphanedFiles('branch-id', ['file-1', 'file-2']);
2257
+ */
2258
+ async getOrphanedFiles(branchId, fileIds, options = {}) {
2259
+ this._validateAuth("getOrphanedFiles");
2260
+ return await _getOrphanedFiles(branchId, fileIds, options, this._getTranslationConfig());
2261
+ }
2262
+ /**
2263
+ * Enqueues project setup job using the specified file references
2264
+ *
2265
+ * This method creates setup jobs that will process source file references
2266
+ * and generate a project setup. The files parameter contains references (IDs) to source
2267
+ * files that have already been uploaded via uploadSourceFiles. The setup jobs are queued
2268
+ * for processing and will generate a project setup based on the source files.
2269
+ *
2270
+ * @param {FileReference[]} files - Array of file references containing IDs of previously uploaded source files
2271
+ * @param {SetupProjectOptions} [options] - Optional settings for target locales and timeout
2272
+ * @returns {Promise<SetupProjectResult>} Object containing the jobId and status
2273
+ */
2274
+ async setupProject(files, options) {
2275
+ this._validateAuth("setupProject");
2276
+ options = {
2277
+ ...options,
2278
+ locales: options?.locales?.map((locale) => this.resolveCanonicalLocale(locale))
2279
+ };
2280
+ return await _setupProject(files, this._getTranslationConfig(), options);
2281
+ }
2282
+ /**
2283
+ * Checks the current status of one or more project jobs by their unique identifiers.
2284
+ *
2285
+ * This method polls the API to determine whether one or more jobs are still running,
2286
+ * have completed successfully, or have failed. Jobs are created after calling either enqueueFiles or setupProject.
2287
+ *
2288
+ * @param {string[]} jobIds - The unique identifiers of the jobs to check
2289
+ * @param {number} [timeoutMs] - Optional timeout in milliseconds for the API request
2290
+ * @returns {Promise<CheckJobStatusResult>} Object containing the job status
2291
+ *
2292
+ * @example
2293
+ * const result = await gt.checkJobStatus([
2294
+ * 'job-123',
2295
+ * 'job-456',
2296
+ * ], {
2297
+ * timeout: 10000,
2298
+ * });
2299
+ */
2300
+ async checkJobStatus(jobIds, timeoutMs) {
2301
+ this._validateAuth("checkJobStatus");
2302
+ return await _checkJobStatus(jobIds, this._getTranslationConfig(), timeoutMs);
2303
+ }
2304
+ /**
2305
+ * Polls job statuses until all jobs from enqueueFiles are finished or the timeout is reached.
2306
+ *
2307
+ * @param {EnqueueFilesResult} enqueueResult - The result returned from enqueueFiles
2308
+ * @param {AwaitJobsOptions} [options] - Polling configuration (interval, timeout)
2309
+ * @returns {Promise<AwaitJobsResult>} The final status of all jobs and whether they all completed
2310
+ */
2311
+ async awaitJobs(enqueueResult, options) {
2312
+ this._validateAuth("awaitJobs");
2313
+ return await _awaitJobs(enqueueResult, options, this._getTranslationConfig());
2314
+ }
2315
+ /**
2316
+ * Enqueues translation jobs for previously uploaded source files.
2317
+ *
2318
+ * This method creates translation jobs that will process existing source files
2319
+ * and generate translations in the specified target languages. The files parameter
2320
+ * contains references (IDs) to source files that have already been uploaded via
2321
+ * uploadSourceFiles. The translation jobs are queued for processing and will
2322
+ * generate translated content based on the source files and target locales provided.
2323
+ *
2324
+ * @param {FileReferenceIds[]} files - Array of file references containing IDs of previously uploaded source files
2325
+ * @param {EnqueueOptions} options - Configuration options including source locale, target locales, and job settings
2326
+ * @returns {Promise<EnqueueFilesResult>} Result containing job IDs, queue status, and processing information
2327
+ */
2328
+ async enqueueFiles(files, options) {
2329
+ this._validateAuth("enqueueFiles");
2330
+ let mergedOptions = {
2331
+ ...options,
2332
+ sourceLocale: options.sourceLocale ?? this.sourceLocale,
2333
+ targetLocales: options.targetLocales ?? [this.targetLocale]
2334
+ };
2335
+ if (!mergedOptions.sourceLocale) {
2336
+ const error = noSourceLocaleProvidedError("enqueueFiles");
2337
+ gtInstanceLogger.error(error);
2338
+ throw new Error(error);
2339
+ }
2340
+ if (!mergedOptions.targetLocales || mergedOptions.targetLocales.length === 0) {
2341
+ const error = noTargetLocaleProvidedError("enqueueFiles");
2342
+ gtInstanceLogger.error(error);
2343
+ throw new Error(error);
2344
+ }
2345
+ mergedOptions = {
2346
+ ...mergedOptions,
2347
+ targetLocales: mergedOptions.targetLocales.map((locale) => this.resolveCanonicalLocale(locale))
2348
+ };
2349
+ return await _enqueueFiles(files, mergedOptions, this._getTranslationConfig());
2350
+ }
2351
+ /**
2352
+ * Creates or upserts a file tag, associating a set of source files
2353
+ * with a user-defined tag ID and optional message.
2354
+ *
2355
+ * @param {CreateTagOptions} options - Tag creation options including tagId, sourceFileIds, and optional message
2356
+ * @returns {Promise<CreateTagResult>} The created or updated tag
2357
+ */
2358
+ async createTag(options) {
2359
+ this._validateAuth("createTag");
2360
+ return await _createTag(options, this._getTranslationConfig());
2361
+ }
2362
+ /**
2363
+ * Publishes or unpublishes files on the CDN.
2364
+ *
2365
+ * @param {PublishFileEntry[]} files - Array of file entries with publish flags
2366
+ * @returns {Promise<PublishFilesResult>} Result containing per-file success/failure
2367
+ */
2368
+ async publishFiles(files) {
2369
+ this._validateAuth("publishFiles");
2370
+ return await _publishFiles(files, this._getTranslationConfig());
2371
+ }
2372
+ /**
2373
+ * Submits user edit diffs for existing translations so future generations preserve user intent.
2374
+ *
2375
+ * @param {SubmitUserEditDiffsPayload} payload - Project-scoped diff payload.
2376
+ * @returns {Promise<void>} Resolves when submission succeeds.
2377
+ */
2378
+ async submitUserEditDiffs(payload) {
2379
+ this._validateAuth("submitUserEditDiffs");
2380
+ await _submitUserEditDiffs({
2381
+ ...payload,
2382
+ diffs: (payload.diffs || []).map((d) => ({
2383
+ ...d,
2384
+ locale: this.resolveCanonicalLocale(d.locale)
2385
+ }))
2386
+ }, this._getTranslationConfig());
2387
+ }
2388
+ /**
2389
+ * Queries data about one or more source or translation files.
2390
+ *
2391
+ * @param {FileDataQuery} data - Object mapping source and translation file information.
2392
+ * @param {CheckFileTranslationsOptions} options - Options for the API call.
2393
+ * @returns {Promise<FileDataResult>} The source and translation file data information.
2394
+ *
2395
+ * @example
2396
+ * const result = await gt.queryFileData({
2397
+ * sourceFiles: [
2398
+ * { fileId: '1234567890', versionId: '1234567890', branchId: '1234567890' },
2399
+ * ],
2400
+ * translatedFiles: [
2401
+ * { fileId: '1234567890', versionId: '1234567890', branchId: '1234567890', locale: 'es-ES' },
2402
+ * ],
2403
+ * }, {
2404
+ * timeout: 10000,
2405
+ * });
2406
+ *
2407
+ */
2408
+ async queryFileData(data, options = {}) {
2409
+ this._validateAuth("queryFileData");
2410
+ data.translatedFiles = data.translatedFiles?.map((item) => ({
2411
+ ...item,
2412
+ locale: this.resolveCanonicalLocale(item.locale)
2413
+ }));
2414
+ const result = await _queryFileData(data, options, this._getTranslationConfig());
2415
+ result.translatedFiles = result.translatedFiles?.map((item) => ({
2416
+ ...item,
2417
+ ...item.locale && { locale: this.resolveAliasLocale(item.locale) }
2418
+ }));
2419
+ result.sourceFiles = result.sourceFiles?.map((item) => ({
2420
+ ...item,
2421
+ ...item.sourceLocale && { sourceLocale: this.resolveAliasLocale(item.sourceLocale) },
2422
+ locales: item.locales.map((locale) => this.resolveAliasLocale(locale))
2423
+ }));
2424
+ return result;
2425
+ }
2426
+ /**
2427
+ * Gets source and translation information for a given file ID and version ID.
2428
+ *
2429
+ * @param {FileQuery} data - File query containing file ID and version ID.
2430
+ * @param {CheckFileTranslationsOptions} options - Options for getting source and translation information.
2431
+ * @returns {Promise<FileQueryResult>} The source file and translation information.
2432
+ *
2433
+ * @example
2434
+ * const result = await gt.querySourceFile(
2435
+ * { fileId: '1234567890', versionId: '1234567890' },
2436
+ * { timeout: 10000 }
2437
+ * );
2438
+ *
2439
+ */
2440
+ async querySourceFile(data, options = {}) {
2441
+ this._validateAuth("querySourceFile");
2442
+ const result = await _querySourceFile(data, options, this._getTranslationConfig());
2443
+ result.translations = result.translations.map((item) => ({
2444
+ ...item,
2445
+ ...item.locale && { locale: this.resolveAliasLocale(item.locale) }
2446
+ }));
2447
+ result.sourceFile.locales = result.sourceFile.locales.map((locale) => this.resolveAliasLocale(locale));
2448
+ if (result.sourceFile.sourceLocale) result.sourceFile.sourceLocale = this.resolveAliasLocale(result.sourceFile.sourceLocale);
2449
+ return result;
2450
+ }
2451
+ /**
2452
+ * Get project data for a given project ID.
2453
+ *
2454
+ * @param {string} projectId - The ID of the project to get the data for.
2455
+ * @returns {Promise<ProjectData>} The project data.
2456
+ *
2457
+ * @example
2458
+ * const result = await gt.getProjectData(
2459
+ * '1234567890'
2460
+ * );
2461
+ *
2462
+ */
2463
+ async getProjectData(projectId, options = {}) {
2464
+ this._validateAuth("getProjectData");
2465
+ const result = await _getProjectData(projectId, options, this._getTranslationConfig());
2466
+ result.currentLocales = result.currentLocales.map((item) => this.resolveAliasLocale(item));
2467
+ result.defaultLocale = this.resolveAliasLocale(result.defaultLocale);
2468
+ return result;
2469
+ }
2470
+ /**
2471
+ * Downloads a single file.
2472
+ *
2473
+ * @param file - The file query object.
2474
+ * @param {string} file.fileId - The ID of the file to download.
2475
+ * @param {string} [file.branchId] - The ID of the branch to download the file from. If not provided, the default branch will be used.
2476
+ * @param {string} [file.locale] - The locale to download the file for. If not provided, the source file will be downloaded.
2477
+ * @param {string} [file.versionId] - The version ID to download the file from. If not provided, the latest version will be used.
2478
+ * @param {DownloadFileOptions} options - Options for downloading the file.
2479
+ * @returns {Promise<string>} The downloaded file content.
2480
+ *
2481
+ * @example
2482
+ * const result = await gt.downloadFile({
2483
+ * fileId: '1234567890',
2484
+ * branchId: '1234567890',
2485
+ * locale: 'es-ES',
2486
+ * versionId: '1234567890',
2487
+ * }, {
2488
+ * timeout: 10000,
2489
+ * });
2490
+ */
2491
+ async downloadFile(file, options = {}) {
2492
+ this._validateAuth("downloadTranslatedFile");
2493
+ return (await _downloadFileBatch([{
2494
+ fileId: file.fileId,
2495
+ branchId: file.branchId,
2496
+ locale: file.locale ? this.resolveCanonicalLocale(file.locale) : void 0,
2497
+ versionId: file.versionId,
2498
+ useLatestAvailableVersion: file.useLatestAvailableVersion
2499
+ }], options, this._getTranslationConfig())).data?.[0]?.data ?? "";
2500
+ }
2501
+ /**
2502
+ * Downloads multiple files in a batch.
2503
+ *
2504
+ * @param {DownloadFileBatchRequest} requests - Array of file query objects to download.
2505
+ * @param {DownloadFileBatchOptions} options - Options for the batch download.
2506
+ * @returns {Promise<DownloadFileBatchResult>} The batch download results.
2507
+ *
2508
+ * @example
2509
+ * const result = await gt.downloadFileBatch([{
2510
+ * fileId: '1234567890',
2511
+ * locale: 'es-ES',
2512
+ * versionId: '1234567890',
2513
+ * }], {
2514
+ * timeout: 10000,
2515
+ * });
2516
+ */
2517
+ async downloadFileBatch(requests, options = {}) {
2518
+ this._validateAuth("downloadFileBatch");
2519
+ requests = requests.map((request) => ({
2520
+ ...request,
2521
+ locale: request.locale ? this.resolveCanonicalLocale(request.locale) : void 0
2522
+ }));
2523
+ const result = await _downloadFileBatch(requests, options, this._getTranslationConfig());
2524
+ return {
2525
+ files: result.data.map((file) => ({
2526
+ ...file,
2527
+ ...file.locale && { locale: this.resolveAliasLocale(file.locale) }
2528
+ })),
2529
+ count: result.count
2530
+ };
2531
+ }
2532
+ /**
2533
+ * Translates a single source string to the target locale.
2534
+ * Routes through {@link translateMany} under the hood.
2535
+ *
2536
+ * @param {string} source - The source string to translate.
2537
+ * @param {object} options - Translation options including targetLocale and optional entry metadata.
2538
+ * @returns {Promise<TranslationResult | TranslationError>} The translated content.
2539
+ *
2540
+ * @example
2541
+ * const result = await gt.translate('Hello, world!', { targetLocale: 'es' });
2542
+ *
2543
+ * @example
2544
+ * const result = await gt.translate('Hello, world!', {
2545
+ * targetLocale: 'es',
2546
+ * dataFormat: 'ICU',
2547
+ * context: 'A formal greeting',
2548
+ * });
2549
+ */
2550
+ async translate(source, options, timeout) {
2551
+ if (typeof options === "string") options = { targetLocale: options };
2552
+ this._validateAuth("translate");
2553
+ let targetLocale = options?.targetLocale || this.targetLocale;
2554
+ if (!targetLocale) {
2555
+ const error = noTargetLocaleProvidedError("translate");
2556
+ gtInstanceLogger.error(error);
2557
+ throw new Error(error);
2558
+ }
2559
+ targetLocale = this.resolveCanonicalLocale(targetLocale);
2560
+ const sourceLocale = this.resolveCanonicalLocale(options?.sourceLocale || this.sourceLocale || "en");
2561
+ return (await _translateMany([source], {
2562
+ ...options,
2563
+ targetLocale,
2564
+ sourceLocale
2565
+ }, this._getTranslationConfig(), timeout))[0];
2566
+ }
2567
+ async translateMany(sources, options, timeout) {
2568
+ if (typeof options === "string") options = { targetLocale: options };
2569
+ this._validateAuth("translateMany");
2570
+ let targetLocale = options?.targetLocale || this.targetLocale;
2571
+ if (!targetLocale) {
2572
+ const error = noTargetLocaleProvidedError("translateMany");
2573
+ gtInstanceLogger.error(error);
2574
+ throw new Error(error);
2575
+ }
2576
+ targetLocale = this.resolveCanonicalLocale(targetLocale);
2577
+ const sourceLocale = this.resolveCanonicalLocale(options?.sourceLocale || this.sourceLocale || "en");
2578
+ return await _translateMany(sources, {
2579
+ ...options,
2580
+ targetLocale,
2581
+ sourceLocale
2582
+ }, this._getTranslationConfig(), timeout);
2583
+ }
2584
+ /**
2585
+ * Uploads source files to the translation service without any translation content.
2586
+ *
2587
+ * This method creates or replaces source file entries in your project. Each uploaded
2588
+ * file becomes a source that can later be translated into target languages. The files
2589
+ * are processed and stored as base entries that serve as the foundation for generating
2590
+ * translations through the translation workflow.
2591
+ *
2592
+ * @param {Array<{source: FileUpload}>} files - Array of objects containing source file data to upload
2593
+ * @param {UploadFilesOptions} options - Configuration options including source locale and other upload settings
2594
+ * @returns {Promise<UploadFilesResponse>} Upload result containing file IDs, version information, and upload status
2595
+ */
2596
+ async uploadSourceFiles(files, options) {
2597
+ this._validateAuth("uploadSourceFiles");
2598
+ const mergedOptions = {
2599
+ ...options,
2600
+ sourceLocale: this.resolveCanonicalLocale(options.sourceLocale ?? this.sourceLocale ?? "en")
2601
+ };
2602
+ files = files.map((f) => ({
2603
+ ...f,
2604
+ source: {
2605
+ ...f.source,
2606
+ locale: this.resolveCanonicalLocale(f.source.locale)
2607
+ }
2608
+ }));
2609
+ const result = await _uploadSourceFiles(files, mergedOptions, this._getTranslationConfig());
2610
+ return {
2611
+ uploadedFiles: result.data,
2612
+ count: result.count,
2613
+ message: `Successfully uploaded ${result.count} files in ${result.batchCount} batch(es)`
2614
+ };
2615
+ }
2616
+ /**
2617
+ * Uploads translation files that correspond to previously uploaded source files.
2618
+ *
2619
+ * This method allows you to provide translated content for existing source files in your project.
2620
+ * Each translation must reference an existing source file and include the translated content
2621
+ * along with the target locale information. This is used when you have pre-existing translations
2622
+ * that you want to upload directly rather than generating them through the translation service.
2623
+ *
2624
+ * @param {Array<{source: FileUpload, translations: FileUpload[]}>} files - Array of file objects where:
2625
+ * - `source`: Reference to the existing source file (contains IDs but no content)
2626
+ * - `translations`: Array of translated files, each containing content, locale, and reference IDs
2627
+ * @param {UploadFilesOptions} options - Configuration options including source locale and upload settings
2628
+ * @returns {Promise<UploadFilesResponse>} Upload result containing translation IDs, status, and processing information
2629
+ */
2630
+ async uploadTranslations(files, options) {
2631
+ this._validateAuth("uploadTranslations");
2632
+ const mergedOptions = {
2633
+ ...options,
2634
+ sourceLocale: options.sourceLocale ?? this.sourceLocale
2635
+ };
2636
+ if (!mergedOptions.sourceLocale) {
2637
+ const error = noSourceLocaleProvidedError("uploadTranslations");
2638
+ gtInstanceLogger.error(error);
2639
+ throw new Error(error);
2640
+ }
2641
+ const result = await _uploadTranslations(files.map((f) => ({
2642
+ ...f,
2643
+ translations: f.translations.map((t) => ({
2644
+ ...t,
2645
+ locale: this.resolveCanonicalLocale(t.locale)
2646
+ }))
2647
+ })), mergedOptions, this._getTranslationConfig());
2648
+ return {
2649
+ uploadedFiles: result.data,
2650
+ count: result.count,
2651
+ message: `Successfully uploaded ${result.count} files in ${result.batchCount} batch(es)`
2652
+ };
2653
+ }
2654
+ /**
2655
+ * Formats a string with cutoff behavior, applying a terminator when the string exceeds the maximum character limit.
2656
+ *
2657
+ * This method uses the GT instance's rendering locales by default for locale-specific terminator selection,
2658
+ * but can be overridden with custom locales in the options.
2659
+ *
2660
+ * @param {string} value - The string value to format with cutoff behavior.
2661
+ * @param {Object} [options] - Configuration options for cutoff formatting.
2662
+ * @param {string | string[]} [options.locales] - The locales to use for terminator selection. Defaults to instance's rendering locales.
2663
+ * @param {number} [options.maxChars] - The maximum number of characters to display.
2664
+ * - Undefined values are treated as no cutoff.
2665
+ * - Negative values follow .slice() behavior and terminator will be added before the value.
2666
+ * - 0 will result in an empty string.
2667
+ * - If cutoff results in an empty string, no terminator is added.
2668
+ * @param {CutoffFormatStyle} [options.style='ellipsis'] - The style of the terminator.
2669
+ * @param {string} [options.terminator] - Optional override the terminator to use.
2670
+ * @param {string} [options.separator] - Optional override the separator to use between the terminator and the value.
2671
+ * - If no terminator is provided, then separator is ignored.
2672
+ * @returns {string} The formatted string with terminator applied if cutoff occurs.
2673
+ *
2674
+ * @example
2675
+ * const gt = new GT({ targetLocale: 'en-US' });
2676
+ * gt.formatCutoff('Hello, world!', { maxChars: 8 });
2677
+ * // Returns: 'Hello, w...'
2678
+ *
2679
+ * @example
2680
+ * gt.formatCutoff('Hello, world!', { maxChars: -3 });
2681
+ * // Returns: '...ld!'
2682
+ */
2683
+ formatCutoff(value, options) {
2684
+ return this.localeConfig.formatCutoff(value, this.targetLocale, options);
2685
+ }
2686
+ /**
2687
+ * Formats a message according to the specified locales and options.
2688
+ *
2689
+ * @param {string} message - The message to format.
2690
+ * @param {string | string[]} [locales='en'] - The locales to use for formatting.
2691
+ * @param {FormatVariables} [variables={}] - The variables to use for formatting.
2692
+ * @param {StringFormat} [dataFormat='ICU'] - The format of the message.
2693
+ * @returns {string} The formatted message.
2694
+ *
2695
+ * @example
2696
+ * gt.formatMessage('Hello {name}', { name: 'John' });
2697
+ * // Returns: "Hello John"
2698
+ *
2699
+ * gt.formatMessage('Hello {name}', { name: 'John' }, { locales: ['fr'] });
2700
+ * // Returns: "Bonjour John"
2701
+ */
2702
+ formatMessage(message, options) {
2703
+ return this.localeConfig.formatMessage(message, this.targetLocale, options);
2704
+ }
2705
+ /**
2706
+ * Formats a number according to the specified locales and options.
2707
+ *
2708
+ * @param {number} number - The number to format
2709
+ * @param {Object} [options] - Additional options for number formatting
2710
+ * @param {string | string[]} [options.locales] - The locales to use for formatting
2711
+ * @param {Intl.NumberFormatOptions} [options] - Additional Intl.NumberFormat options
2712
+ * @returns {string} The formatted number
2713
+ *
2714
+ * @example
2715
+ * gt.formatNum(1234.56, { style: 'currency', currency: 'USD' });
2716
+ * // Returns: "$1,234.56"
2717
+ */
2718
+ formatNum(number, options) {
2719
+ return this.localeConfig.formatNum(number, this.targetLocale, options);
2720
+ }
2721
+ /**
2722
+ * Formats a date according to the specified locales and options.
2723
+ *
2724
+ * @param {Date} date - The date to format
2725
+ * @param {Object} [options] - Additional options for date formatting
2726
+ * @param {string | string[]} [options.locales] - The locales to use for formatting
2727
+ * @param {Intl.DateTimeFormatOptions} [options] - Additional Intl.DateTimeFormat options
2728
+ * @returns {string} The formatted date
2729
+ *
2730
+ * @example
2731
+ * gt.formatDateTime(new Date(), { dateStyle: 'full', timeStyle: 'long' });
2732
+ * // Returns: "Thursday, March 14, 2024 at 2:30:45 PM GMT-7"
2733
+ */
2734
+ formatDateTime(date, options) {
2735
+ return this.localeConfig.formatDateTime(date, this.targetLocale, options);
2736
+ }
2737
+ /**
2738
+ * Formats a currency value according to the specified locales and options.
2739
+ *
2740
+ * @param {number} value - The currency value to format
2741
+ * @param {string} currency - The currency code (e.g., 'USD', 'EUR')
2742
+ * @param {Object} [options] - Additional options for currency formatting
2743
+ * @param {string | string[]} [options.locales] - The locales to use for formatting
2744
+ * @param {Intl.NumberFormatOptions} [options] - Additional Intl.NumberFormat options
2745
+ * @returns {string} The formatted currency value
2746
+ *
2747
+ * @example
2748
+ * gt.formatCurrency(1234.56, 'USD', { style: 'currency' });
2749
+ * // Returns: "$1,234.56"
2750
+ */
2751
+ formatCurrency(value, currency, options) {
2752
+ return this.localeConfig.formatCurrency(value, currency, this.targetLocale, options);
2753
+ }
2754
+ /**
2755
+ * Formats a list of items according to the specified locales and options.
2756
+ *
2757
+ * @param {Array<string | number>} array - The list of items to format
2758
+ * @param {Object} [options] - Additional options for list formatting
2759
+ * @param {string | string[]} [options.locales] - The locales to use for formatting
2760
+ * @param {Intl.ListFormatOptions} [options] - Additional Intl.ListFormat options
2761
+ * @returns {string} The formatted list
2762
+ *
2763
+ * @example
2764
+ * gt.formatList(['apple', 'banana', 'orange'], { type: 'conjunction' });
2765
+ * // Returns: "apple, banana, and orange"
2766
+ */
2767
+ formatList(array, options) {
2768
+ return this.localeConfig.formatList(array, this.targetLocale, options);
2769
+ }
2770
+ /**
2771
+ * Formats a list of items according to the specified locales and options.
2772
+ * @param {Array<T>} array - The list of items to format
2773
+ * @param {Object} [options] - Additional options for list formatting
2774
+ * @param {string | string[]} [options.locales] - The locales to use for formatting
2775
+ * @param {Intl.ListFormatOptions} [options] - Additional Intl.ListFormat options
2776
+ * @returns {Array<T | string>} The formatted list parts
2777
+ *
2778
+ * @example
2779
+ * gt.formatListToParts(['apple', 42, { foo: 'bar' }], { type: 'conjunction', style: 'short', locales: ['en'] });
2780
+ * // Returns: ['apple', ', ', 42, ' and ', '{ foo: "bar" }']
2781
+ */
2782
+ formatListToParts(array, options) {
2783
+ return this.localeConfig.formatListToParts(array, this.targetLocale, options);
2784
+ }
2785
+ /**
2786
+ * Formats a relative time value according to the specified locales and options.
2787
+ *
2788
+ * @param {number} value - The relative time value to format
2789
+ * @param {Intl.RelativeTimeFormatUnit} unit - The unit of time (e.g., 'second', 'minute', 'hour', 'day', 'week', 'month', 'year')
2790
+ * @param {Object} options - Additional options for relative time formatting
2791
+ * @param {string | string[]} [options.locales] - The locales to use for formatting
2792
+ * @param {Intl.RelativeTimeFormatOptions} [options] - Additional Intl.RelativeTimeFormat options
2793
+ * @returns {string} The formatted relative time string
2794
+ *
2795
+ * @example
2796
+ * gt.formatRelativeTime(-1, 'day', { locales: ['en-US'], numeric: 'auto' });
2797
+ * // Returns: "yesterday"
2798
+ */
2799
+ formatRelativeTime(value, unit, options) {
2800
+ return this.localeConfig.formatRelativeTime(value, unit, this.targetLocale, options);
2801
+ }
2802
+ /**
2803
+ * Formats a relative time string from a Date, automatically selecting the best unit.
2804
+ *
2805
+ * @param {Date} date - The date to format relative to now
2806
+ * @param {Object} [options] - Additional options for relative time formatting
2807
+ * @param {string | string[]} [options.locales] - The locales to use for formatting
2808
+ * @returns {string} The formatted relative time string (e.g., "2 hours ago", "in 3 days")
2809
+ *
2810
+ * @example
2811
+ * gt.formatRelativeTimeFromDate(new Date(Date.now() - 3600000));
2812
+ * // Returns: "1 hour ago"
2813
+ */
2814
+ formatRelativeTimeFromDate(date, options) {
2815
+ return this.localeConfig.formatRelativeTimeFromDate(date, this.targetLocale, options);
2816
+ }
2817
+ /**
2818
+ * Retrieves the display name of a locale code using Intl.DisplayNames, returning an empty string if no name is found.
2819
+ *
2820
+ * @param {string} [locale=this.targetLocale] - A BCP-47 locale code
2821
+ * @returns {string} The display name corresponding to the code
2822
+ * @throws {Error} If no target locale is provided
2823
+ *
2824
+ * @example
2825
+ * gt.getLocaleName('es-ES');
2826
+ * // Returns: "Spanish (Spain)"
2827
+ */
2828
+ getLocaleName(locale = this.targetLocale) {
2829
+ if (!locale) throw new Error(noTargetLocaleProvidedError("getLocaleName"));
2830
+ return this.localeConfig.getLocaleName(locale);
2831
+ }
2832
+ /**
2833
+ * Retrieves an emoji based on a given locale code.
2834
+ * Uses the locale's region (if present) to select an emoji or falls back on default emojis.
2835
+ *
2836
+ * @param {string} [locale=this.targetLocale] - A BCP-47 locale code (e.g., 'en-US', 'fr-CA')
2837
+ * @returns {string} The emoji representing the locale or its region
2838
+ * @throws {Error} If no target locale is provided
2839
+ *
2840
+ * @example
2841
+ * gt.getLocaleEmoji('es-ES');
2842
+ * // Returns: "🇪🇸"
2843
+ */
2844
+ getLocaleEmoji(locale = this.targetLocale) {
2845
+ if (!locale) throw new Error(noTargetLocaleProvidedError("getLocaleEmoji"));
2846
+ return this.localeConfig.getLocaleEmoji(locale);
2847
+ }
2848
+ /**
2849
+ * Generates linguistic details for a given locale code.
2850
+ *
2851
+ * This function returns information about the locale,
2852
+ * script, and region of a given language code both in a standard form and in a maximized form (with likely script and region).
2853
+ * The function provides these names in both your default language and native forms, and an associated emoji.
2854
+ *
2855
+ * @param {string} [locale=this.targetLocale] - The locale code to get properties for (e.g., "de-AT").
2856
+ * @returns {LocaleProperties} - An object containing detailed information about the locale.
2857
+ *
2858
+ * @property {string} code - The full locale code, e.g., "de-AT".
2859
+ * @property {string} name - Language name in the default display language, e.g., "Austrian German".
2860
+ * @property {string} nativeName - Language name in the locale's native language, e.g., "Österreichisches Deutsch".
2861
+ * @property {string} languageCode - The base language code, e.g., "de".
2862
+ * @property {string} languageName - The language name in the default display language, e.g., "German".
2863
+ * @property {string} nativeLanguageName - The language name in the native language, e.g., "Deutsch".
2864
+ * @property {string} nameWithRegionCode - Language name with region in the default language, e.g., "German (AT)".
2865
+ * @property {string} nativeNameWithRegionCode - Language name with region in the native language, e.g., "Deutsch (AT)".
2866
+ * @property {string} regionCode - The region code from maximization, e.g., "AT".
2867
+ * @property {string} regionName - The region name in the default display language, e.g., "Austria".
2868
+ * @property {string} nativeRegionName - The region name in the native language, e.g., "Österreich".
2869
+ * @property {string} scriptCode - The script code from maximization, e.g., "Latn".
2870
+ * @property {string} scriptName - The script name in the default display language, e.g., "Latin".
2871
+ * @property {string} nativeScriptName - The script name in the native language, e.g., "Lateinisch".
2872
+ * @property {string} maximizedCode - The maximized locale code, e.g., "de-Latn-AT".
2873
+ * @property {string} maximizedName - Maximized locale name with likely script in the default language, e.g., "Austrian German (Latin)".
2874
+ * @property {string} nativeMaximizedName - Maximized locale name in the native language, e.g., "Österreichisches Deutsch (Lateinisch)".
2875
+ * @property {string} minimizedCode - Minimized locale code, e.g., "de-AT" (or "de" for "de-DE").
2876
+ * @property {string} minimizedName - Minimized language name in the default language, e.g., "Austrian German".
2877
+ * @property {string} nativeMinimizedName - Minimized language name in the native language, e.g., "Österreichisches Deutsch".
2878
+ * @property {string} emoji - The emoji associated with the locale's region, if applicable.
2879
+ */
2880
+ getLocaleProperties(locale = this.targetLocale) {
2881
+ if (!locale) throw new Error(noTargetLocaleProvidedError("getLocaleProperties"));
2882
+ return this.localeConfig.getLocaleProperties(locale);
2883
+ }
2884
+ /**
2885
+ * Retrieves multiple properties for a given region code, including:
2886
+ * - `code`: the original region code
2887
+ * - `name`: the localized display name
2888
+ * - `emoji`: the associated flag or symbol
2889
+ *
2890
+ * Behavior:
2891
+ * - Accepts ISO 3166-1 alpha-2 or UN M.49 region codes (e.g., `"US"`, `"FR"`, `"419"`).
2892
+ * - Uses the instance's `targetLocale` to localize the region name for the user.
2893
+ * - If `customMapping` contains a `name` or `emoji` for the region, those override the default values.
2894
+ * - Otherwise, uses `Intl.DisplayNames` to get the localized region name, falling back to `libraryDefaultLocale`.
2895
+ * - Falls back to the region code as `name` if display name resolution fails.
2896
+ * - Falls back to a default emoji if no emoji mapping is found in built-in data or `customMapping`.
2897
+ *
2898
+ * @param {string} [region=this.getLocaleProperties().regionCode] - The region code to look up (e.g., `"US"`, `"GB"`, `"DE"`).
2899
+ * @param {CustomRegionMapping} [customMapping] - Optional mapping of region codes to custom names and/or emojis.
2900
+ * @returns {{ code: string, name: string, emoji: string }} An object containing:
2901
+ * - `code`: the input region code
2902
+ * - `name`: the localized or custom region name
2903
+ * - `emoji`: the matching emoji flag or symbol
2904
+ *
2905
+ * @throws {Error} If no target locale is available to determine region properties.
2906
+ *
2907
+ * @example
2908
+ * const gt = new GT({ targetLocale: 'en-US' });
2909
+ * gt.getRegionProperties('US');
2910
+ * // => { code: 'US', name: 'United States', emoji: '🇺🇸' }
2911
+ *
2912
+ * @example
2913
+ * const gt = new GT({ targetLocale: 'fr-FR' });
2914
+ * gt.getRegionProperties('US');
2915
+ * // => { code: 'US', name: 'États-Unis', emoji: '🇺🇸' }
2916
+ *
2917
+ * @example
2918
+ * gt.getRegionProperties('US', { US: { name: 'USA', emoji: '🗽' } });
2919
+ * // => { code: 'US', name: 'USA', emoji: '🗽' }
2920
+ */
2921
+ getRegionProperties(region = this.getLocaleProperties().regionCode, customMapping) {
2922
+ if (!customMapping) {
2923
+ if (this.customMapping && !this.customRegionMapping) {
2924
+ const customRegionMapping = {};
2925
+ for (const [locale, lp] of Object.entries(this.customMapping)) if (lp && typeof lp === "object" && lp.regionCode && !customRegionMapping[lp.regionCode]) {
2926
+ const { regionName: name, emoji } = lp;
2927
+ customRegionMapping[lp.regionCode] = {
2928
+ locale,
2929
+ ...name && { name },
2930
+ ...emoji && { emoji }
2931
+ };
2932
+ }
2933
+ this.customRegionMapping = customRegionMapping;
2934
+ }
2935
+ customMapping = this.customRegionMapping;
2936
+ }
2937
+ return _getRegionProperties(region, this.targetLocale, customMapping);
2938
+ }
2939
+ /**
2940
+ * Determines whether a translation is required based on the source and target locales.
2941
+ *
2942
+ * @param {string} [sourceLocale=this.sourceLocale] - The locale code for the original content
2943
+ * @param {string} [targetLocale=this.targetLocale] - The locale code to translate into
2944
+ * @param {string[]} [approvedLocales=this.locales] - Optional array of approved target locales
2945
+ * @returns {boolean} True if translation is required, false otherwise
2946
+ * @throws {Error} If no source locale is provided
2947
+ * @throws {Error} If no target locale is provided
2948
+ *
2949
+ * @example
2950
+ * gt.requiresTranslation('en-US', 'es-ES');
2951
+ * // Returns: true
2952
+ */
2953
+ requiresTranslation(sourceLocale = this.sourceLocale, targetLocale = this.targetLocale, approvedLocales = this.locales, customMapping = this.customMapping) {
2954
+ if (!sourceLocale) throw new Error(noSourceLocaleProvidedError("requiresTranslation"));
2955
+ if (!targetLocale) throw new Error(noTargetLocaleProvidedError("requiresTranslation"));
2956
+ if (customMapping === this.customMapping) return this.localeConfig.requiresTranslation(targetLocale, sourceLocale, approvedLocales);
2957
+ return _requiresTranslation(sourceLocale, targetLocale, approvedLocales, customMapping);
2958
+ }
2959
+ /**
2960
+ * Determines the best matching locale from the provided approved locales list.
2961
+ *
2962
+ * @param {string | string[]} locales - A single locale or array of locales in preference order
2963
+ * @param {string[]} [approvedLocales=this.locales] - Array of approved locales in preference order
2964
+ * @returns {string | undefined} The best matching locale or undefined if no match is found
2965
+ *
2966
+ * @example
2967
+ * gt.determineLocale(['fr-CA', 'fr-FR'], ['en-US', 'fr-FR', 'es-ES']);
2968
+ * // Returns: "fr-FR"
2969
+ */
2970
+ determineLocale(locales, approvedLocales = this.locales || [], customMapping = this.customMapping) {
2971
+ if (customMapping === this.customMapping) return this.localeConfig.determineLocale(locales, approvedLocales ?? []);
2972
+ return _determineLocale(locales, approvedLocales, customMapping);
2973
+ }
2974
+ /**
2975
+ * Gets the text direction for a given locale code.
2976
+ *
2977
+ * @param {string} [locale=this.targetLocale] - A BCP-47 locale code
2978
+ * @returns {'ltr' | 'rtl'} 'rtl' if the locale is right-to-left, otherwise 'ltr'
2979
+ * @throws {Error} If no target locale is provided
2980
+ *
2981
+ * @example
2982
+ * gt.getLocaleDirection('ar-SA');
2983
+ * // Returns: "rtl"
2984
+ */
2985
+ getLocaleDirection(locale = this.targetLocale) {
2986
+ if (!locale) throw new Error(noTargetLocaleProvidedError("getLocaleDirection"));
2987
+ return this.localeConfig.getLocaleDirection(locale);
2988
+ }
2989
+ /**
2990
+ * Checks if a given BCP 47 locale code is valid.
2991
+ *
2992
+ * @param {string} [locale=this.targetLocale] - The BCP 47 locale code to validate
2993
+ * @param {customMapping} [customMapping=this.customMapping] - The custom mapping to use for validation
2994
+ * @returns {boolean} True if the locale code is valid, false otherwise
2995
+ * @throws {Error} If no target locale is provided
2996
+ *
2997
+ * @example
2998
+ * gt.isValidLocale('en-US');
2999
+ * // Returns: true
3000
+ */
3001
+ isValidLocale(locale = this.targetLocale, customMapping = this.customMapping) {
3002
+ if (!locale) throw new Error(noTargetLocaleProvidedError("isValidLocale"));
3003
+ if (customMapping === this.customMapping) return this.localeConfig.isValidLocale(locale);
3004
+ return _isValidLocale(locale, customMapping);
3005
+ }
3006
+ /**
3007
+ * Resolves the canonical locale for a given locale.
3008
+ * @param locale - The locale to resolve the canonical locale for
3009
+ * @param customMapping - The custom mapping to use for resolving the canonical locale
3010
+ * @returns The canonical locale
3011
+ */
3012
+ resolveCanonicalLocale(locale = this.targetLocale, customMapping = this.customMapping) {
3013
+ if (!locale) throw new Error(noTargetLocaleProvidedError("resolveCanonicalLocale"));
3014
+ if (customMapping === this.customMapping) return this.localeConfig.resolveCanonicalLocale(locale);
3015
+ return _resolveCanonicalLocale(locale, customMapping);
3016
+ }
3017
+ /**
3018
+ * Resolves the alias locale for a given locale.
3019
+ * @param locale - The locale to resolve the alias locale for
3020
+ * @param customMapping - The custom mapping to use for resolving the alias locale
3021
+ * @returns The alias locale
3022
+ */
3023
+ resolveAliasLocale(locale, customMapping = this.customMapping) {
3024
+ if (!locale) throw new Error(noTargetLocaleProvidedError("resolveAliasLocale"));
3025
+ if (customMapping === this.customMapping) return this.localeConfig.resolveAliasLocale(locale);
3026
+ return _resolveAliasLocale(locale, customMapping);
3027
+ }
3028
+ /**
3029
+ * Standardizes a BCP 47 locale code to ensure correct formatting.
3030
+ *
3031
+ * @param {string} [locale=this.targetLocale] - The BCP 47 locale code to standardize
3032
+ * @returns {string} The standardized locale code or empty string if invalid
3033
+ * @throws {Error} If no target locale is provided
3034
+ *
3035
+ * @example
3036
+ * gt.standardizeLocale('en_us');
3037
+ * // Returns: "en-US"
3038
+ */
3039
+ standardizeLocale(locale = this.targetLocale) {
3040
+ if (!locale) throw new Error(noTargetLocaleProvidedError("standardizeLocale"));
3041
+ return this.localeConfig.standardizeLocale(locale);
3042
+ }
3043
+ /**
3044
+ * Checks if multiple BCP 47 locale codes represent the same dialect.
3045
+ *
3046
+ * @param {...(string | string[])} locales - The BCP 47 locale codes to compare
3047
+ * @returns {boolean} True if all codes represent the same dialect, false otherwise
3048
+ *
3049
+ * @example
3050
+ * gt.isSameDialect('en-US', 'en-GB');
3051
+ * // Returns: false
3052
+ *
3053
+ * gt.isSameDialect('en', 'en-US');
3054
+ * // Returns: true
3055
+ */
3056
+ isSameDialect(...locales) {
3057
+ return this.localeConfig.isSameDialect(...locales);
3058
+ }
3059
+ /**
3060
+ * Checks if multiple BCP 47 locale codes represent the same language.
3061
+ *
3062
+ * @param {...(string | string[])} locales - The BCP 47 locale codes to compare
3063
+ * @returns {boolean} True if all codes represent the same language, false otherwise
3064
+ *
3065
+ * @example
3066
+ * gt.isSameLanguage('en-US', 'en-GB');
3067
+ * // Returns: true
3068
+ */
3069
+ isSameLanguage(...locales) {
3070
+ return this.localeConfig.isSameLanguage(...locales);
3071
+ }
3072
+ /**
3073
+ * Checks if a locale is a superset of another locale.
3074
+ *
3075
+ * @param {string} superLocale - The locale to check if it is a superset
3076
+ * @param {string} subLocale - The locale to check if it is a subset
3077
+ * @returns {boolean} True if superLocale is a superset of subLocale, false otherwise
3078
+ *
3079
+ * @example
3080
+ * gt.isSupersetLocale('en', 'en-US');
3081
+ * // Returns: true
3082
+ *
3083
+ * gt.isSupersetLocale('en-US', 'en');
3084
+ * // Returns: false
3085
+ */
3086
+ isSupersetLocale(superLocale, subLocale) {
3087
+ return this.localeConfig.isSupersetLocale(superLocale, subLocale);
3088
+ }
3089
+ };
3090
+ /**
3091
+ * Formats a string with cutoff behavior, applying a terminator when the string exceeds the maximum character limit.
3092
+ *
3093
+ * This standalone function provides cutoff formatting functionality without requiring a GT instance.
3094
+ * The locales parameter is required for proper terminator selection based on the target language.
3095
+ *
3096
+ * @param {string} value - The string value to format with cutoff behavior.
3097
+ * @param {Object} [options] - Configuration options for cutoff formatting.
3098
+ * @param {string | string[]} [options.locales] - The locales to use for terminator selection.
3099
+ * @param {number} [options.maxChars] - The maximum number of characters to display.
3100
+ * - Undefined values are treated as no cutoff.
3101
+ * - Negative values follow .slice() behavior and terminator will be added before the value.
3102
+ * - 0 will result in an empty string.
3103
+ * - If cutoff results in an empty string, no terminator is added.
3104
+ * @param {CutoffFormatStyle} [options.style='ellipsis'] - The style of the terminator.
3105
+ * @param {string} [options.terminator] - Optional override the terminator to use.
3106
+ * @param {string} [options.separator] - Optional override the separator to use between the terminator and the value.
3107
+ * - If no terminator is provided, then separator is ignored.
3108
+ * @returns {string} The formatted string with terminator applied if cutoff occurs.
3109
+ *
3110
+ * @example
3111
+ * formatCutoff('Hello, world!', { locales: 'en-US', maxChars: 8 });
3112
+ * // Returns: 'Hello, w...'
3113
+ *
3114
+ * @example
3115
+ * formatCutoff('Hello, world!', { locales: 'en-US', maxChars: -3 });
3116
+ * // Returns: '...ld!'
3117
+ *
3118
+ * @example
3119
+ * formatCutoff('Very long text that needs cutting', {
3120
+ * locales: 'en-US',
3121
+ * maxChars: 15,
3122
+ * style: 'ellipsis',
3123
+ * separator: ' '
3124
+ * });
3125
+ * // Returns: 'Very long text ...'
3126
+ */
3127
+ function formatCutoff(value, options) {
3128
+ return _formatCutoff({
3129
+ value,
3130
+ locales: options?.locales,
3131
+ options
3132
+ });
3133
+ }
3134
+ /**
3135
+ * Formats a message according to the specified locales and options.
3136
+ *
3137
+ * @param {string} message - The message to format.
3138
+ * @param {string | string[]} [locales='en'] - The locales to use for formatting.
3139
+ * @param {FormatVariables} [variables={}] - The variables to use for formatting.
3140
+ * @param {StringFormat} [dataFormat='ICU'] - The format of the message. (When STRING, the message is returned as is)
3141
+ * @returns {string} The formatted message.
3142
+ *
3143
+ * @example
3144
+ * formatMessage('Hello {name}', { name: 'John' });
3145
+ * // Returns: "Hello John"
3146
+ *
3147
+ * formatMessage('Hello {name}', { name: 'John' }, { locales: ['fr'] });
3148
+ * // Returns: "Bonjour John"
3149
+ */
3150
+ function formatMessage(message, options) {
3151
+ switch (options?.dataFormat) {
3152
+ case "STRING": return _formatMessageString(message);
3153
+ default: return _formatMessageICU(message, options?.locales, options?.variables);
3154
+ }
3155
+ }
3156
+ /**
3157
+ * Formats a number according to the specified locales and options.
3158
+ * @param {Object} params - The parameters for the number formatting.
3159
+ * @param {number} params.value - The number to format.
3160
+ * @param {Intl.NumberFormatOptions} [params.options] - Additional options for number formatting.
3161
+ * @param {string | string[]} [params.options.locales] - The locales to use for formatting.
3162
+ * @returns {string} The formatted number.
3163
+ */
3164
+ function formatNum(number, options) {
3165
+ return _formatNum({
3166
+ value: number,
3167
+ locales: options.locales,
3168
+ options
3169
+ });
3170
+ }
3171
+ /**
3172
+ * Formats a date according to the specified languages and options.
3173
+ * @param {Object} params - The parameters for the date formatting.
3174
+ * @param {Date} params.value - The date to format.
3175
+ * @param {Intl.DateTimeFormatOptions} [params.options] - Additional options for date formatting.
3176
+ * @param {string | string[]} [params.options.locales] - The languages to use for formatting.
3177
+ * @returns {string} The formatted date.
3178
+ */
3179
+ function formatDateTime(date, options) {
3180
+ return _formatDateTime({
3181
+ value: date,
3182
+ locales: options?.locales,
3183
+ options
3184
+ });
3185
+ }
3186
+ /**
3187
+ * Formats a currency value according to the specified languages, currency, and options.
3188
+ * @param {Object} params - The parameters for the currency formatting.
3189
+ * @param {number} params.value - The currency value to format.
3190
+ * @param {string} params.currency - The currency code (e.g., 'USD').
3191
+ * @param {Intl.NumberFormatOptions} [params.options={}] - Additional options for currency formatting.
3192
+ * @param {string | string[]} [params.options.locales] - The locale codes to use for formatting.
3193
+ * @returns {string} The formatted currency value.
3194
+ */
3195
+ function formatCurrency(value, currency, options) {
3196
+ return _formatCurrency({
3197
+ value,
3198
+ currency,
3199
+ locales: options.locales,
3200
+ options
3201
+ });
3202
+ }
3203
+ /**
3204
+ * Formats a list of items according to the specified locales and options.
3205
+ * @param {Object} params - The parameters for the list formatting.
3206
+ * @param {Array<string | number>} params.value - The list of items to format.
3207
+ * @param {Intl.ListFormatOptions} [params.options={}] - Additional options for list formatting.
3208
+ * @param {string | string[]} [params.options.locales] - The locales to use for formatting.
3209
+ * @returns {string} The formatted list.
3210
+ */
3211
+ function formatList(array, options) {
3212
+ return _formatList({
3213
+ value: array,
3214
+ locales: options.locales,
3215
+ options
3216
+ });
3217
+ }
3218
+ /**
3219
+ * Formats a list of items according to the specified locales and options.
3220
+ * @param {Array<T>} array - The list of items to format
3221
+ * @param {Object} [options] - Additional options for list formatting
3222
+ * @param {string | string[]} [options.locales] - The locales to use for formatting
3223
+ * @param {Intl.ListFormatOptions} [options] - Additional Intl.ListFormat options
3224
+ * @returns {Array<T | string>} The formatted list parts
3225
+ */
3226
+ function formatListToParts(array, options) {
3227
+ return _formatListToParts({
3228
+ value: array,
3229
+ locales: options?.locales,
3230
+ options
3231
+ });
3232
+ }
3233
+ /**
3234
+ * Formats a relative time value according to the specified locales and options.
3235
+ * @param {Object} params - The parameters for the relative time formatting.
3236
+ * @param {number} params.value - The relative time value to format.
3237
+ * @param {Intl.RelativeTimeFormatUnit} params.unit - The unit of time (e.g., 'second', 'minute', 'hour', 'day', 'week', 'month', 'year').
3238
+ * @param {Intl.RelativeTimeFormatOptions} [params.options={}] - Additional options for relative time formatting.
3239
+ * @param {string | string[]} [params.options.locales] - The locales to use for formatting.
3240
+ * @returns {string} The formatted relative time string.
3241
+ */
3242
+ function formatRelativeTime(value, unit, options) {
3243
+ return _formatRelativeTime({
3244
+ value,
3245
+ unit,
3246
+ locales: options.locales,
3247
+ options
3248
+ });
3249
+ }
3250
+ /**
3251
+ * Formats a relative time string from a Date, automatically selecting the best unit.
3252
+ * @param {Date} date - The date to format relative to now.
3253
+ * @param {Object} options - Formatting options.
3254
+ * @param {string | string[]} options.locales - The locales to use for formatting.
3255
+ * @param {Intl.RelativeTimeFormatOptions} [options] - Additional Intl.RelativeTimeFormat options.
3256
+ * @returns {string} The formatted relative time string (e.g., "2 hours ago", "in 3 days").
3257
+ */
3258
+ function formatRelativeTimeFromDate(date, options) {
3259
+ const { locales, baseDate, ...intlOptions } = options;
3260
+ return _formatRelativeTimeFromDate({
3261
+ date,
3262
+ baseDate: baseDate ?? /* @__PURE__ */ new Date(),
3263
+ locales,
3264
+ options: intlOptions
3265
+ });
3266
+ }
3267
+ /**
3268
+ * Retrieves the display name of locale code using Intl.DisplayNames.
3269
+ *
3270
+ * @param {string} locale - A BCP-47 locale code.
3271
+ * @param {string} [defaultLocale] - The default locale to use for formatting.
3272
+ * @param {CustomMapping} [customMapping] - A custom mapping of locale codes to their names.
3273
+ * @returns {string} The display name corresponding to the code.
3274
+ */
3275
+ function getLocaleName(locale, defaultLocale, customMapping) {
3276
+ return _getLocaleName(locale, defaultLocale, customMapping);
3277
+ }
3278
+ /**
3279
+ * Retrieves an emoji based on a given locale code, taking into account region, language, and specific exceptions.
3280
+ *
3281
+ * This function uses the locale's region (if present) to select an emoji or falls back on default emojis for certain languages.
3282
+ *
3283
+ * @param locale - A string representing the locale code (e.g., 'en-US', 'fr-CA').
3284
+ * @param {CustomMapping} [customMapping] - A custom mapping of locale codes to their names.
3285
+ * @returns The emoji representing the locale or its region, or a default emoji if no specific match is found.
3286
+ */
3287
+ function getLocaleEmoji(locale, customMapping) {
3288
+ return _getLocaleEmoji(locale, customMapping);
3289
+ }
3290
+ /**
3291
+ * Generates linguistic details for a given locale code.
3292
+ *
3293
+ * This function returns information about the locale,
3294
+ * script, and region of a given language code both in a standard form and in a maximized form (with likely script and region).
3295
+ * The function provides these names in both your default language and native forms, and an associated emoji.
3296
+ *
3297
+ * @param {string} locale - The locale code to get properties for (e.g., "de-AT").
3298
+ * @param {string} [defaultLocale] - The default locale to use for formatting.
3299
+ * @param {CustomMapping} [customMapping] - A custom mapping of locale codes to their names.
3300
+ * @returns {LocaleProperties} - An object containing detailed information about the locale.
3301
+ *
3302
+ * @property {string} code - The full locale code, e.g., "de-AT".
3303
+ * @property {string} name - Language name in the default display language, e.g., "Austrian German".
3304
+ * @property {string} nativeName - Language name in the locale's native language, e.g., "Österreichisches Deutsch".
3305
+ * @property {string} languageCode - The base language code, e.g., "de".
3306
+ * @property {string} languageName - The language name in the default display language, e.g., "German".
3307
+ * @property {string} nativeLanguageName - The language name in the native language, e.g., "Deutsch".
3308
+ * @property {string} nameWithRegionCode - Language name with region in the default language, e.g., "German (AT)".
3309
+ * @property {string} nativeNameWithRegionCode - Language name with region in the native language, e.g., "Deutsch (AT)".
3310
+ * @property {string} regionCode - The region code from maximization, e.g., "AT".
3311
+ * @property {string} regionName - The region name in the default display language, e.g., "Austria".
3312
+ * @property {string} nativeRegionName - The region name in the native language, e.g., "Österreich".
3313
+ * @property {string} scriptCode - The script code from maximization, e.g., "Latn".
3314
+ * @property {string} scriptName - The script name in the default display language, e.g., "Latin".
3315
+ * @property {string} nativeScriptName - The script name in the native language, e.g., "Lateinisch".
3316
+ * @property {string} maximizedCode - The maximized locale code, e.g., "de-Latn-AT".
3317
+ * @property {string} maximizedName - Maximized locale name with likely script in the default language, e.g., "Austrian German (Latin)".
3318
+ * @property {string} nativeMaximizedName - Maximized locale name in the native language, e.g., "Österreichisches Deutsch (Lateinisch)".
3319
+ * @property {string} minimizedCode - Minimized locale code, e.g., "de-AT" (or "de" for "de-DE").
3320
+ * @property {string} minimizedName - Minimized language name in the default language, e.g., "Austrian German".
3321
+ * @property {string} nativeMinimizedName - Minimized language name in the native language, e.g., "Österreichisches Deutsch".
3322
+ * @property {string} emoji - The emoji associated with the locale's region, if applicable.
3323
+ */
3324
+ function getLocaleProperties(locale, defaultLocale, customMapping) {
3325
+ return _getLocaleProperties(locale, defaultLocale, customMapping);
3326
+ }
3327
+ /**
3328
+ * Retrieves multiple properties for a given region code, including:
3329
+ * - `code`: the original region code
3330
+ * - `name`: the localized display name
3331
+ * - `emoji`: the associated flag or symbol
3332
+ *
3333
+ * Behavior:
3334
+ * - Accepts ISO 3166-1 alpha-2 or UN M.49 region codes (e.g., `"US"`, `"FR"`, `"419"`).
3335
+ * - If `customMapping` contains a `name` or `emoji` for the region, those override the default values.
3336
+ * - Otherwise, uses `Intl.DisplayNames` to get the localized region name in the given `defaultLocale`,
3337
+ * falling back to `libraryDefaultLocale`.
3338
+ * - Falls back to the region code as `name` if display name resolution fails.
3339
+ * - Falls back to `defaultEmoji` if no emoji mapping is found in `emojis` or `customMapping`.
3340
+ *
3341
+ * @param {string} region - The region code to look up (e.g., `"US"`, `"GB"`, `"DE"`).
3342
+ * @param {string} [defaultLocale=libraryDefaultLocale] - The locale to use when localizing the region name.
3343
+ * @param {CustomRegionMapping} [customMapping] - Optional mapping of region codes to custom names and/or emojis.
3344
+ * @returns {{ code: string, name: string, emoji: string }} An object containing:
3345
+ * - `code`: the input region code
3346
+ * - `name`: the localized or custom region name
3347
+ * - `emoji`: the matching emoji flag or symbol
3348
+ *
3349
+ * @example
3350
+ * getRegionProperties('US', 'en');
3351
+ * // => { code: 'US', name: 'United States', emoji: '🇺🇸' }
3352
+ *
3353
+ * @example
3354
+ * getRegionProperties('US', 'fr');
3355
+ * // => { code: 'US', name: 'États-Unis', emoji: '🇺🇸' }
3356
+ *
3357
+ * @example
3358
+ * getRegionProperties('US', 'en', { US: { name: 'USA', emoji: '🗽' } });
3359
+ * // => { code: 'US', name: 'USA', emoji: '🗽' }
3360
+ */
3361
+ function getRegionProperties(region, defaultLocale, customMapping) {
3362
+ return _getRegionProperties(region, defaultLocale, customMapping);
3363
+ }
3364
+ /**
3365
+ * Determines whether a translation is required based on the source and target locales.
3366
+ *
3367
+ * - If the target locale is not specified, the function returns `false`, as translation is not needed.
3368
+ * - If the source and target locale are the same, returns `false`, indicating that no translation is necessary.
3369
+ * - If the `approvedLocales` array is provided, and the target locale is not within that array, the function also returns `false`.
3370
+ * - Otherwise, it returns `true`, meaning that a translation is required.
3371
+ *
3372
+ * @param {string} sourceLocale - The locale code for the original content (BCP 47 locale code).
3373
+ * @param {string} targetLocale - The locale code of the language to translate the content into (BCP 47 locale code).
3374
+ * @param {string[]} [approvedLocale] - An optional array of approved target locales.
3375
+ *
3376
+ * @returns {boolean} - Returns `true` if translation is required, otherwise `false`.
3377
+ */
3378
+ function requiresTranslation(sourceLocale, targetLocale, approvedLocales, customMapping) {
3379
+ return _requiresTranslation(sourceLocale, targetLocale, approvedLocales, customMapping);
3380
+ }
3381
+ /**
3382
+ * Determines the best matching locale from the provided approved locales list.
3383
+ * @param {string | string[]} locales - A single locale or an array of locales sorted in preference order.
3384
+ * @param {string[]} [approvedLocales=this.locales] - An array of approved locales, also sorted by preference.
3385
+ * @returns {string | undefined} - The best matching locale from the approvedLocales list, or undefined if no match is found.
3386
+ */
3387
+ function determineLocale(locales, approvedLocales = [], customMapping = void 0) {
3388
+ return _determineLocale(locales, approvedLocales, customMapping);
3389
+ }
3390
+ /**
3391
+ * Get the text direction for a given locale code using the Intl.Locale API.
3392
+ *
3393
+ * @param {string} locale - A BCP-47 locale code.
3394
+ * @returns {string} - 'rtl' if the locale is right-to-left, otherwise 'ltr'.
3395
+ */
3396
+ function getLocaleDirection(locale) {
3397
+ return _getLocaleDirection(locale);
3398
+ }
3399
+ /**
3400
+ * Checks if a given BCP 47 locale code is valid.
3401
+ * @param {string} locale - The BCP 47 locale code to validate.
3402
+ * @param {CustomMapping} [customMapping] - The custom mapping to use for validation.
3403
+ * @returns {boolean} True if the BCP 47 code is valid, false otherwise.
3404
+ */
3405
+ function isValidLocale(locale, customMapping) {
3406
+ return _isValidLocale(locale, customMapping);
3407
+ }
3408
+ /**
3409
+ * Resolves the alias locale for a given locale.
3410
+ * @param {string} locale - The locale to resolve the alias locale for
3411
+ * @param {CustomMapping} [customMapping] - The custom mapping to use for resolving the alias locale
3412
+ * @returns {string} The alias locale
3413
+ */
3414
+ function resolveAliasLocale(locale, customMapping) {
3415
+ return _resolveAliasLocale(locale, customMapping);
3416
+ }
3417
+ /**
3418
+ * Resolves the canonical locale for a given locale.
3419
+ * @param {string} locale - The locale to resolve the canonical locale for
3420
+ * @param {CustomMapping} [customMapping] - The custom mapping to use for resolving the canonical locale
3421
+ * @returns {string} The canonical locale
3422
+ */
3423
+ function resolveCanonicalLocale(locale, customMapping) {
3424
+ return _resolveCanonicalLocale(locale, customMapping);
3425
+ }
3426
+ /**
3427
+ * Standardizes a BCP 47 locale code to ensure correct formatting.
3428
+ * @param {string} locale - The BCP 47 locale code to standardize.
3429
+ * @returns {string} The standardized BCP 47 locale code or an empty string if it is an invalid code.
3430
+ */
3431
+ function standardizeLocale(locale) {
3432
+ return _standardizeLocale(locale);
3433
+ }
3434
+ /**
3435
+ * Checks if multiple BCP 47 locale codes represent the same dialect.
3436
+ * @param {string[]} locales - The BCP 47 locale codes to compare.
3437
+ * @returns {boolean} True if all BCP 47 codes represent the same dialect, false otherwise.
3438
+ */
3439
+ function isSameDialect(...locales) {
3440
+ return _isSameDialect(...locales);
3441
+ }
3442
+ /**
3443
+ * Checks if multiple BCP 47 locale codes represent the same language.
3444
+ * @param {string[]} locales - The BCP 47 locale codes to compare.
3445
+ * @returns {boolean} True if all BCP 47 codes represent the same language, false otherwise.
3446
+ */
3447
+ function isSameLanguage(...locales) {
3448
+ return _isSameLanguage(...locales);
3449
+ }
3450
+ /**
3451
+ * Checks if a locale is a superset of another locale.
3452
+ * A subLocale is a subset of superLocale if it is an extension of superLocale or are otherwise identical.
3453
+ *
3454
+ * @param {string} superLocale - The locale to check if it is a superset of the other locale.
3455
+ * @param {string} subLocale - The locale to check if it is a subset of the other locale.
3456
+ * @returns {boolean} True if the first locale is a superset of the second locale, false otherwise.
3457
+ */
3458
+ function isSupersetLocale(superLocale, subLocale) {
3459
+ return _isSupersetLocale(superLocale, subLocale);
3460
+ }
3461
+ const API_VERSION = API_VERSION$1;
3462
+ //#endregion
3463
+ exports.API_VERSION = API_VERSION;
3464
+ exports.GT = GT;
3465
+ exports.LocaleConfig = LocaleConfig;
3466
+ exports.__toESM = __toESM;
3467
+ exports.determineLocale = determineLocale;
3468
+ exports.formatCurrency = formatCurrency;
3469
+ exports.formatCutoff = formatCutoff;
3470
+ exports.formatDateTime = formatDateTime;
3471
+ exports.formatList = formatList;
3472
+ exports.formatListToParts = formatListToParts;
3473
+ exports.formatMessage = formatMessage;
3474
+ exports.formatNum = formatNum;
3475
+ exports.formatRelativeTime = formatRelativeTime;
3476
+ exports.formatRelativeTimeFromDate = formatRelativeTimeFromDate;
3477
+ exports.getLocaleDirection = getLocaleDirection;
3478
+ exports.getLocaleEmoji = getLocaleEmoji;
3479
+ exports.getLocaleName = getLocaleName;
3480
+ exports.getLocaleProperties = getLocaleProperties;
3481
+ exports.getRegionProperties = getRegionProperties;
3482
+ exports.isSameDialect = isSameDialect;
3483
+ exports.isSameLanguage = isSameLanguage;
3484
+ exports.isSupersetLocale = isSupersetLocale;
3485
+ exports.isValidLocale = isValidLocale;
3486
+ exports.requiresTranslation = requiresTranslation;
3487
+ exports.resolveAliasLocale = resolveAliasLocale;
3488
+ exports.resolveCanonicalLocale = resolveCanonicalLocale;
3489
+ exports.standardizeLocale = standardizeLocale;
3490
+
3491
+ //# sourceMappingURL=index.cjs.map