generaltranslation 8.2.7 → 8.2.9

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (60) hide show
  1. package/CHANGELOG.md +12 -0
  2. package/dist/{ApiError-4zIP-twr.cjs → ApiError-CZ45tkW6.cjs} +1 -1
  3. package/dist/{ApiError-4zIP-twr.cjs.map → ApiError-CZ45tkW6.cjs.map} +1 -1
  4. package/dist/{ApiError-Bv7vlzyQ.mjs → ApiError-IYfaOR30.mjs} +1 -1
  5. package/dist/{ApiError-Bv7vlzyQ.mjs.map → ApiError-IYfaOR30.mjs.map} +1 -1
  6. package/dist/IntlCache-Ccg_cQPR.mjs +195 -0
  7. package/dist/IntlCache-Ccg_cQPR.mjs.map +1 -0
  8. package/dist/IntlCache-k2qfrDqB.cjs +212 -0
  9. package/dist/IntlCache-k2qfrDqB.cjs.map +1 -0
  10. package/dist/base64-C1sogiix.mjs +70 -0
  11. package/dist/base64-C1sogiix.mjs.map +1 -0
  12. package/dist/base64-CUcEPEC5.cjs +111 -0
  13. package/dist/base64-CUcEPEC5.cjs.map +1 -0
  14. package/dist/core-CJMv4fMa.d.cts +209 -0
  15. package/dist/core-DOrYXXpO.mjs +1487 -0
  16. package/dist/core-DOrYXXpO.mjs.map +1 -0
  17. package/dist/core-DtPj_ruw.d.mts +209 -0
  18. package/dist/core-LS3Pia40.cjs +1666 -0
  19. package/dist/core-LS3Pia40.cjs.map +1 -0
  20. package/dist/core.cjs +8 -0
  21. package/dist/core.d.cts +2 -0
  22. package/dist/core.d.mts +2 -0
  23. package/dist/core.mjs +2 -0
  24. package/dist/errors.cjs +1 -1
  25. package/dist/errors.mjs +1 -1
  26. package/dist/{id-CPbVYREY.mjs → id-BmOyfaug.mjs} +2 -2
  27. package/dist/{id-CPbVYREY.mjs.map → id-BmOyfaug.mjs.map} +1 -1
  28. package/dist/{id-VXBgyXu2.cjs → id-COlX5v3V.cjs} +6 -6
  29. package/dist/{id-VXBgyXu2.cjs.map → id-COlX5v3V.cjs.map} +1 -1
  30. package/dist/id.cjs +1 -1
  31. package/dist/id.d.cts +1 -1
  32. package/dist/id.d.mts +1 -1
  33. package/dist/id.mjs +1 -1
  34. package/dist/index.cjs +91 -1413
  35. package/dist/index.cjs.map +1 -1
  36. package/dist/index.d.cts +7 -103
  37. package/dist/index.d.mts +7 -103
  38. package/dist/index.mjs +43 -1342
  39. package/dist/index.mjs.map +1 -1
  40. package/dist/internal.cjs +602 -42
  41. package/dist/internal.cjs.map +1 -0
  42. package/dist/internal.d.cts +23 -2
  43. package/dist/internal.d.mts +23 -2
  44. package/dist/internal.mjs +563 -3
  45. package/dist/internal.mjs.map +1 -0
  46. package/dist/{sha2-DKowBr6H.cjs → isVariable-B08mggBy.cjs} +18 -18
  47. package/dist/isVariable-B08mggBy.cjs.map +1 -0
  48. package/dist/{stableStringify-DgDlE_pD.mjs → isVariable-CYsKFHvR.mjs} +19 -19
  49. package/dist/isVariable-CYsKFHvR.mjs.map +1 -0
  50. package/dist/{types-fUW4_Ole.d.mts → types-Dfy_sRLD.d.mts} +6 -2
  51. package/dist/{types-D2fTTTvZ.d.cts → types-mZeu4HS3.d.cts} +6 -2
  52. package/dist/types.d.cts +1 -1
  53. package/dist/types.d.mts +1 -1
  54. package/package.json +17 -1
  55. package/dist/internal-CTeI8uLd.mjs +0 -774
  56. package/dist/internal-CTeI8uLd.mjs.map +0 -1
  57. package/dist/internal-PCKq4YMW.cjs +0 -1012
  58. package/dist/internal-PCKq4YMW.cjs.map +0 -1
  59. package/dist/sha2-DKowBr6H.cjs.map +0 -1
  60. package/dist/stableStringify-DgDlE_pD.mjs.map +0 -1
package/dist/index.cjs CHANGED
@@ -1,1198 +1,9 @@
1
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-PCKq4YMW.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
2
+ const require_IntlCache = require("./IntlCache-k2qfrDqB.cjs");
3
+ const require_core = require("./core-LS3Pia40.cjs");
4
+ const require_base64 = require("./base64-CUcEPEC5.cjs");
5
+ const require_ApiError = require("./ApiError-CZ45tkW6.cjs");
6
+ const require_id = require("./id-COlX5v3V.cjs");
1196
7
  //#region src/logging/errors.ts
1197
8
  const GT_ERROR_PREFIX = "GT Error:";
1198
9
  const translationTimeoutError = (timeout) => `${GT_ERROR_PREFIX} Translation request timed out after ${timeout}ms.`;
@@ -1220,7 +31,7 @@ const invalidLocalesError = (locales) => `${GT_ERROR_PREFIX} Invalid locales: ${
1220
31
  async function fetchWithTimeout(url, options, timeout) {
1221
32
  const controller = new AbortController();
1222
33
  const signal = controller.signal;
1223
- timeout = timeout ? timeout : require_internal.defaultTimeout;
34
+ timeout = timeout ? timeout : require_IntlCache.defaultTimeout;
1224
35
  const timeoutId = timeout ? setTimeout(() => controller.abort(), timeout) : null;
1225
36
  try {
1226
37
  return await fetch(url, {
@@ -1255,11 +66,11 @@ async function validateResponse(response) {
1255
66
  function handleFetchError(error, timeout) {
1256
67
  if (error instanceof Error && error.name === "AbortError") {
1257
68
  const errorMessage = translationTimeoutError(timeout);
1258
- fetchLogger.error(errorMessage);
69
+ require_core.fetchLogger.error(errorMessage);
1259
70
  throw new Error(errorMessage);
1260
71
  }
1261
72
  const errorMessage = translationRequestFailedError(error instanceof Error ? error.message : String(error));
1262
- fetchLogger.error(errorMessage);
73
+ require_core.fetchLogger.error(errorMessage);
1263
74
  throw error;
1264
75
  }
1265
76
  //#endregion
@@ -1469,6 +280,7 @@ async function processBatches(items, processor, options = {}) {
1469
280
  * @returns The result of the API call
1470
281
  */
1471
282
  async function _enqueueFiles(files, options, config) {
283
+ require_base64.validateFileFormatTransforms(files);
1472
284
  const result = await processBatches(files, async (batch) => {
1473
285
  const apiResult = await apiRequest(config, "/v2/project/translations/enqueue", {
1474
286
  body: {
@@ -1476,7 +288,8 @@ async function _enqueueFiles(files, options, config) {
1476
288
  branchId: f.branchId,
1477
289
  fileId: f.fileId,
1478
290
  versionId: f.versionId,
1479
- fileName: f.fileName
291
+ fileName: f.fileName,
292
+ transformFormat: f.transformFormat
1480
293
  })),
1481
294
  targetLocales: options.targetLocales,
1482
295
  sourceLocale: options.sourceLocale,
@@ -1527,7 +340,7 @@ async function _downloadFileBatch(requests, options, config) {
1527
340
  timeout: options.timeout
1528
341
  })).files.map((file) => ({
1529
342
  ...file,
1530
- data: require_internal.decode(file.data)
343
+ data: require_base64.decode(file.data)
1531
344
  }));
1532
345
  }, { batchSize: 100 });
1533
346
  }
@@ -1589,45 +402,20 @@ function _getRegionProperties(region, defaultLocale = "en", customMapping) {
1589
402
  try {
1590
403
  return {
1591
404
  code: region,
1592
- name: require_internal.intlCache.get("DisplayNames", [defaultLocale, "en"], { type: "region" }).of(region) || region,
1593
- emoji: emojis[region] || "🌍",
405
+ name: require_IntlCache.intlCache.get("DisplayNames", [defaultLocale, "en"], { type: "region" }).of(region) || region,
406
+ emoji: require_core.emojis[region] || "🌍",
1594
407
  ...customMapping?.[region]
1595
408
  };
1596
409
  } catch {
1597
410
  return {
1598
411
  code: region,
1599
412
  name: region,
1600
- emoji: defaultEmoji,
413
+ emoji: require_core.defaultEmoji,
1601
414
  ...customMapping?.[region]
1602
415
  };
1603
416
  }
1604
417
  }
1605
418
  //#endregion
1606
- //#region src/locales/resolveAliasLocale.ts
1607
- /**
1608
- * Resolves the alias locale for a given locale.
1609
- * @param locale - The locale to resolve the alias locale for
1610
- * @param customMapping - The custom mapping to use for resolving the alias locale
1611
- * @returns The alias locale
1612
- */
1613
- function _resolveAliasLocale(locale, customMapping) {
1614
- let reverseCustomMapping;
1615
- if (customMapping) reverseCustomMapping = Object.fromEntries(Object.entries(customMapping).filter(([, value]) => value && typeof value === "object" && "code" in value).map(([key, value]) => [value.code, key]));
1616
- return reverseCustomMapping?.[locale] || locale;
1617
- }
1618
- //#endregion
1619
- //#region src/locales/resolveCanonicalLocale.ts
1620
- /**
1621
- * Resolves the canonical locale for a given locale.
1622
- * @param locale - The locale to resolve the canonical locale for
1623
- * @param customMapping - The custom mapping to use for resolving the canonical locale
1624
- * @returns The canonical locale
1625
- */
1626
- function _resolveCanonicalLocale(locale, customMapping) {
1627
- if (customMapping && shouldUseCanonicalLocale(locale, customMapping)) return customMapping[locale].code;
1628
- return locale;
1629
- }
1630
- //#endregion
1631
419
  //#region src/translate/uploadSourceFiles.ts
1632
420
  /**
1633
421
  * @internal
@@ -1642,7 +430,7 @@ async function _uploadSourceFiles(files, options, config) {
1642
430
  return (await apiRequest(config, "/v2/project/files/upload-files", {
1643
431
  body: {
1644
432
  data: batch.map(({ source }) => ({ source: {
1645
- content: require_internal.encode(source.content),
433
+ content: require_base64.encode(source.content),
1646
434
  fileName: source.fileName,
1647
435
  fileFormat: source.fileFormat,
1648
436
  locale: source.locale,
@@ -1671,14 +459,16 @@ async function _uploadSourceFiles(files, options, config) {
1671
459
  * @returns Promise resolving to a BatchList with all uploaded files
1672
460
  */
1673
461
  async function _uploadTranslations(files, options, config) {
462
+ require_base64.validateFileFormatTransforms(files.map(({ source }) => source));
1674
463
  return processBatches(files, async (batch) => {
1675
464
  return (await apiRequest(config, "/v2/project/files/upload-translations", {
1676
465
  body: {
1677
466
  data: batch.map(({ source, translations }) => ({
1678
467
  source: {
1679
- content: require_internal.encode(source.content),
468
+ content: require_base64.encode(source.content),
1680
469
  fileName: source.fileName,
1681
470
  fileFormat: source.fileFormat,
471
+ transformFormat: source.transformFormat,
1682
472
  locale: source.locale,
1683
473
  dataFormat: source.dataFormat,
1684
474
  formatMetadata: source.formatMetadata,
@@ -1687,7 +477,7 @@ async function _uploadTranslations(files, options, config) {
1687
477
  branchId: source.branchId
1688
478
  },
1689
479
  translations: translations.map((t) => ({
1690
- content: require_internal.encode(t.content),
480
+ content: require_base64.encode(t.content),
1691
481
  fileName: t.fileName,
1692
482
  fileFormat: t.fileFormat,
1693
483
  locale: t.locale,
@@ -1737,7 +527,7 @@ async function _querySourceFile(query, options, config) {
1737
527
  */
1738
528
  async function _getProjectData(projectId, options, config) {
1739
529
  const { baseUrl } = config;
1740
- const timeout = options.timeout ? options.timeout : require_internal.defaultTimeout;
530
+ const timeout = options.timeout ? options.timeout : require_IntlCache.defaultTimeout;
1741
531
  const url = `${baseUrl || "https://api2.gtx.dev"}/v2/project/info/${encodeURIComponent(projectId)}`;
1742
532
  let response;
1743
533
  try {
@@ -1969,6 +759,10 @@ async function _publishFiles(files, config) {
1969
759
  * });
1970
760
  */
1971
761
  var GT = class {
762
+ /** Runtime-safe locale and formatting helpers */
763
+ get localeConfig() {
764
+ return this._localeConfig;
765
+ }
1972
766
  /**
1973
767
  * Constructs an instance of the GT class.
1974
768
  *
@@ -1985,7 +779,6 @@ var GT = class {
1985
779
  * });
1986
780
  */
1987
781
  constructor(params = {}) {
1988
- this._renderingLocales = [];
1989
782
  if (typeof process !== "undefined") {
1990
783
  this.apiKey ||= process.env?.GT_API_KEY;
1991
784
  this.devApiKey ||= process.env?.GT_DEV_API_KEY;
@@ -1998,23 +791,19 @@ var GT = class {
1998
791
  if (devApiKey) this.devApiKey = devApiKey;
1999
792
  if (projectId) this.projectId = projectId;
2000
793
  if (sourceLocale) {
2001
- this.sourceLocale = _standardizeLocale(sourceLocale);
2002
- if (!_isValidLocale(this.sourceLocale, customMapping)) throw new Error(invalidLocaleError(this.sourceLocale));
794
+ this.sourceLocale = require_core._standardizeLocale(sourceLocale);
795
+ if (!require_core._isValidLocale(this.sourceLocale, customMapping)) throw new Error(invalidLocaleError(this.sourceLocale));
2003
796
  }
2004
797
  if (targetLocale) {
2005
- this.targetLocale = _standardizeLocale(targetLocale);
2006
- if (!_isValidLocale(this.targetLocale, customMapping)) throw new Error(invalidLocaleError(this.targetLocale));
798
+ this.targetLocale = require_core._standardizeLocale(targetLocale);
799
+ if (!require_core._isValidLocale(this.targetLocale, customMapping)) throw new Error(invalidLocaleError(this.targetLocale));
2007
800
  }
2008
- this._renderingLocales = [];
2009
- if (this.sourceLocale) this._renderingLocales.push(this.sourceLocale);
2010
- if (this.targetLocale) this._renderingLocales.push(this.targetLocale);
2011
- this._renderingLocales.push("en");
2012
801
  if (locales) {
2013
802
  const result = [];
2014
803
  const invalidLocales = [];
2015
804
  locales.forEach((locale) => {
2016
- const standardizedLocale = _standardizeLocale(locale);
2017
- if (_isValidLocale(standardizedLocale)) result.push(standardizedLocale);
805
+ const standardizedLocale = require_core._standardizeLocale(locale);
806
+ if (require_core._isValidLocale(standardizedLocale)) result.push(standardizedLocale);
2018
807
  else invalidLocales.push(locale);
2019
808
  });
2020
809
  if (invalidLocales.length > 0) throw new Error(invalidLocalesError(invalidLocales));
@@ -2025,6 +814,11 @@ var GT = class {
2025
814
  this.customMapping = customMapping;
2026
815
  this.reverseCustomMapping = Object.fromEntries(Object.entries(customMapping).filter(([, value]) => value && typeof value === "object" && "code" in value).map(([key, value]) => [value.code, key]));
2027
816
  }
817
+ this._localeConfig = new require_core.LocaleConfig({
818
+ defaultLocale: this.sourceLocale,
819
+ locales: this.locales ?? [],
820
+ customMapping: this.customMapping
821
+ });
2028
822
  }
2029
823
  _getTranslationConfig() {
2030
824
  return {
@@ -2174,12 +968,12 @@ var GT = class {
2174
968
  };
2175
969
  if (!mergedOptions.sourceLocale) {
2176
970
  const error = noSourceLocaleProvidedError("enqueueFiles");
2177
- gtInstanceLogger.error(error);
971
+ require_core.gtInstanceLogger.error(error);
2178
972
  throw new Error(error);
2179
973
  }
2180
974
  if (!mergedOptions.targetLocales || mergedOptions.targetLocales.length === 0) {
2181
975
  const error = noTargetLocaleProvidedError("enqueueFiles");
2182
- gtInstanceLogger.error(error);
976
+ require_core.gtInstanceLogger.error(error);
2183
977
  throw new Error(error);
2184
978
  }
2185
979
  mergedOptions = {
@@ -2393,7 +1187,7 @@ var GT = class {
2393
1187
  let targetLocale = options?.targetLocale || this.targetLocale;
2394
1188
  if (!targetLocale) {
2395
1189
  const error = noTargetLocaleProvidedError("translate");
2396
- gtInstanceLogger.error(error);
1190
+ require_core.gtInstanceLogger.error(error);
2397
1191
  throw new Error(error);
2398
1192
  }
2399
1193
  targetLocale = this.resolveCanonicalLocale(targetLocale);
@@ -2410,7 +1204,7 @@ var GT = class {
2410
1204
  let targetLocale = options?.targetLocale || this.targetLocale;
2411
1205
  if (!targetLocale) {
2412
1206
  const error = noTargetLocaleProvidedError("translateMany");
2413
- gtInstanceLogger.error(error);
1207
+ require_core.gtInstanceLogger.error(error);
2414
1208
  throw new Error(error);
2415
1209
  }
2416
1210
  targetLocale = this.resolveCanonicalLocale(targetLocale);
@@ -2475,7 +1269,7 @@ var GT = class {
2475
1269
  };
2476
1270
  if (!mergedOptions.sourceLocale) {
2477
1271
  const error = noSourceLocaleProvidedError("uploadTranslations");
2478
- gtInstanceLogger.error(error);
1272
+ require_core.gtInstanceLogger.error(error);
2479
1273
  throw new Error(error);
2480
1274
  }
2481
1275
  const result = await _uploadTranslations(files.map((f) => ({
@@ -2521,10 +1315,7 @@ var GT = class {
2521
1315
  * // Returns: '...ld!'
2522
1316
  */
2523
1317
  formatCutoff(value, options) {
2524
- return formatCutoff(value, {
2525
- locales: this._renderingLocales,
2526
- ...options
2527
- });
1318
+ return this.localeConfig.formatCutoff(value, this.targetLocale, options);
2528
1319
  }
2529
1320
  /**
2530
1321
  * Formats a message according to the specified locales and options.
@@ -2543,10 +1334,7 @@ var GT = class {
2543
1334
  * // Returns: "Bonjour John"
2544
1335
  */
2545
1336
  formatMessage(message, options) {
2546
- return formatMessage(message, {
2547
- locales: this._renderingLocales,
2548
- ...options
2549
- });
1337
+ return this.localeConfig.formatMessage(message, this.targetLocale, options);
2550
1338
  }
2551
1339
  /**
2552
1340
  * Formats a number according to the specified locales and options.
@@ -2562,10 +1350,7 @@ var GT = class {
2562
1350
  * // Returns: "$1,234.56"
2563
1351
  */
2564
1352
  formatNum(number, options) {
2565
- return formatNum(number, {
2566
- locales: this._renderingLocales,
2567
- ...options
2568
- });
1353
+ return this.localeConfig.formatNum(number, this.targetLocale, options);
2569
1354
  }
2570
1355
  /**
2571
1356
  * Formats a date according to the specified locales and options.
@@ -2581,10 +1366,7 @@ var GT = class {
2581
1366
  * // Returns: "Thursday, March 14, 2024 at 2:30:45 PM GMT-7"
2582
1367
  */
2583
1368
  formatDateTime(date, options) {
2584
- return formatDateTime(date, {
2585
- locales: this._renderingLocales,
2586
- ...options
2587
- });
1369
+ return this.localeConfig.formatDateTime(date, this.targetLocale, options);
2588
1370
  }
2589
1371
  /**
2590
1372
  * Formats a currency value according to the specified locales and options.
@@ -2601,10 +1383,7 @@ var GT = class {
2601
1383
  * // Returns: "$1,234.56"
2602
1384
  */
2603
1385
  formatCurrency(value, currency, options) {
2604
- return formatCurrency(value, currency, {
2605
- locales: this._renderingLocales,
2606
- ...options
2607
- });
1386
+ return this.localeConfig.formatCurrency(value, currency, this.targetLocale, options);
2608
1387
  }
2609
1388
  /**
2610
1389
  * Formats a list of items according to the specified locales and options.
@@ -2620,11 +1399,7 @@ var GT = class {
2620
1399
  * // Returns: "apple, banana, and orange"
2621
1400
  */
2622
1401
  formatList(array, options) {
2623
- return _formatList({
2624
- value: array,
2625
- locales: options?.locales || this._renderingLocales,
2626
- options
2627
- });
1402
+ return this.localeConfig.formatList(array, this.targetLocale, options);
2628
1403
  }
2629
1404
  /**
2630
1405
  * Formats a list of items according to the specified locales and options.
@@ -2639,11 +1414,7 @@ var GT = class {
2639
1414
  * // Returns: ['apple', ', ', 42, ' and ', '{ foo: "bar" }']
2640
1415
  */
2641
1416
  formatListToParts(array, options) {
2642
- return _formatListToParts({
2643
- value: array,
2644
- locales: options?.locales || this._renderingLocales,
2645
- options
2646
- });
1417
+ return this.localeConfig.formatListToParts(array, this.targetLocale, options);
2647
1418
  }
2648
1419
  /**
2649
1420
  * Formats a relative time value according to the specified locales and options.
@@ -2660,10 +1431,7 @@ var GT = class {
2660
1431
  * // Returns: "yesterday"
2661
1432
  */
2662
1433
  formatRelativeTime(value, unit, options) {
2663
- return formatRelativeTime(value, unit, {
2664
- locales: this._renderingLocales,
2665
- ...options
2666
- });
1434
+ return this.localeConfig.formatRelativeTime(value, unit, this.targetLocale, options);
2667
1435
  }
2668
1436
  /**
2669
1437
  * Formats a relative time string from a Date, automatically selecting the best unit.
@@ -2678,10 +1446,7 @@ var GT = class {
2678
1446
  * // Returns: "1 hour ago"
2679
1447
  */
2680
1448
  formatRelativeTimeFromDate(date, options) {
2681
- return formatRelativeTimeFromDate(date, {
2682
- locales: this._renderingLocales,
2683
- ...options
2684
- });
1449
+ return this.localeConfig.formatRelativeTimeFromDate(date, this.targetLocale, options);
2685
1450
  }
2686
1451
  /**
2687
1452
  * Retrieves the display name of a locale code using Intl.DisplayNames, returning an empty string if no name is found.
@@ -2696,7 +1461,7 @@ var GT = class {
2696
1461
  */
2697
1462
  getLocaleName(locale = this.targetLocale) {
2698
1463
  if (!locale) throw new Error(noTargetLocaleProvidedError("getLocaleName"));
2699
- return _getLocaleName(locale, this.sourceLocale, this.customMapping);
1464
+ return this.localeConfig.getLocaleName(locale);
2700
1465
  }
2701
1466
  /**
2702
1467
  * Retrieves an emoji based on a given locale code.
@@ -2712,7 +1477,7 @@ var GT = class {
2712
1477
  */
2713
1478
  getLocaleEmoji(locale = this.targetLocale) {
2714
1479
  if (!locale) throw new Error(noTargetLocaleProvidedError("getLocaleEmoji"));
2715
- return getLocaleEmoji(locale, this.customMapping);
1480
+ return this.localeConfig.getLocaleEmoji(locale);
2716
1481
  }
2717
1482
  /**
2718
1483
  * Generates linguistic details for a given locale code.
@@ -2748,7 +1513,7 @@ var GT = class {
2748
1513
  */
2749
1514
  getLocaleProperties(locale = this.targetLocale) {
2750
1515
  if (!locale) throw new Error(noTargetLocaleProvidedError("getLocaleProperties"));
2751
- return getLocaleProperties(locale, this.sourceLocale, this.customMapping);
1516
+ return this.localeConfig.getLocaleProperties(locale);
2752
1517
  }
2753
1518
  /**
2754
1519
  * Retrieves multiple properties for a given region code, including:
@@ -2822,7 +1587,8 @@ var GT = class {
2822
1587
  requiresTranslation(sourceLocale = this.sourceLocale, targetLocale = this.targetLocale, approvedLocales = this.locales, customMapping = this.customMapping) {
2823
1588
  if (!sourceLocale) throw new Error(noSourceLocaleProvidedError("requiresTranslation"));
2824
1589
  if (!targetLocale) throw new Error(noTargetLocaleProvidedError("requiresTranslation"));
2825
- return _requiresTranslation(sourceLocale, targetLocale, approvedLocales, customMapping);
1590
+ if (customMapping === this.customMapping) return this.localeConfig.requiresTranslation(targetLocale, sourceLocale, approvedLocales);
1591
+ return require_core._requiresTranslation(sourceLocale, targetLocale, approvedLocales, customMapping);
2826
1592
  }
2827
1593
  /**
2828
1594
  * Determines the best matching locale from the provided approved locales list.
@@ -2836,7 +1602,8 @@ var GT = class {
2836
1602
  * // Returns: "fr-FR"
2837
1603
  */
2838
1604
  determineLocale(locales, approvedLocales = this.locales || [], customMapping = this.customMapping) {
2839
- return _determineLocale(locales, approvedLocales, customMapping);
1605
+ if (customMapping === this.customMapping) return this.localeConfig.determineLocale(locales, approvedLocales ?? []);
1606
+ return require_core._determineLocale(locales, approvedLocales, customMapping);
2840
1607
  }
2841
1608
  /**
2842
1609
  * Gets the text direction for a given locale code.
@@ -2851,7 +1618,7 @@ var GT = class {
2851
1618
  */
2852
1619
  getLocaleDirection(locale = this.targetLocale) {
2853
1620
  if (!locale) throw new Error(noTargetLocaleProvidedError("getLocaleDirection"));
2854
- return getLocaleDirection(locale);
1621
+ return this.localeConfig.getLocaleDirection(locale);
2855
1622
  }
2856
1623
  /**
2857
1624
  * Checks if a given BCP 47 locale code is valid.
@@ -2867,7 +1634,8 @@ var GT = class {
2867
1634
  */
2868
1635
  isValidLocale(locale = this.targetLocale, customMapping = this.customMapping) {
2869
1636
  if (!locale) throw new Error(noTargetLocaleProvidedError("isValidLocale"));
2870
- return isValidLocale(locale, customMapping);
1637
+ if (customMapping === this.customMapping) return this.localeConfig.isValidLocale(locale);
1638
+ return require_core._isValidLocale(locale, customMapping);
2871
1639
  }
2872
1640
  /**
2873
1641
  * Resolves the canonical locale for a given locale.
@@ -2877,7 +1645,8 @@ var GT = class {
2877
1645
  */
2878
1646
  resolveCanonicalLocale(locale = this.targetLocale, customMapping = this.customMapping) {
2879
1647
  if (!locale) throw new Error(noTargetLocaleProvidedError("resolveCanonicalLocale"));
2880
- return _resolveCanonicalLocale(locale, customMapping);
1648
+ if (customMapping === this.customMapping) return this.localeConfig.resolveCanonicalLocale(locale);
1649
+ return require_core._resolveCanonicalLocale(locale, customMapping);
2881
1650
  }
2882
1651
  /**
2883
1652
  * Resolves the alias locale for a given locale.
@@ -2887,7 +1656,8 @@ var GT = class {
2887
1656
  */
2888
1657
  resolveAliasLocale(locale, customMapping = this.customMapping) {
2889
1658
  if (!locale) throw new Error(noTargetLocaleProvidedError("resolveAliasLocale"));
2890
- return _resolveAliasLocale(locale, customMapping);
1659
+ if (customMapping === this.customMapping) return this.localeConfig.resolveAliasLocale(locale);
1660
+ return require_core._resolveAliasLocale(locale, customMapping);
2891
1661
  }
2892
1662
  /**
2893
1663
  * Standardizes a BCP 47 locale code to ensure correct formatting.
@@ -2902,7 +1672,7 @@ var GT = class {
2902
1672
  */
2903
1673
  standardizeLocale(locale = this.targetLocale) {
2904
1674
  if (!locale) throw new Error(noTargetLocaleProvidedError("standardizeLocale"));
2905
- return _standardizeLocale(locale);
1675
+ return this.localeConfig.standardizeLocale(locale);
2906
1676
  }
2907
1677
  /**
2908
1678
  * Checks if multiple BCP 47 locale codes represent the same dialect.
@@ -2918,7 +1688,7 @@ var GT = class {
2918
1688
  * // Returns: true
2919
1689
  */
2920
1690
  isSameDialect(...locales) {
2921
- return isSameDialect(...locales);
1691
+ return this.localeConfig.isSameDialect(...locales);
2922
1692
  }
2923
1693
  /**
2924
1694
  * Checks if multiple BCP 47 locale codes represent the same language.
@@ -2931,7 +1701,7 @@ var GT = class {
2931
1701
  * // Returns: true
2932
1702
  */
2933
1703
  isSameLanguage(...locales) {
2934
- return _isSameLanguage(...locales);
1704
+ return this.localeConfig.isSameLanguage(...locales);
2935
1705
  }
2936
1706
  /**
2937
1707
  * Checks if a locale is a superset of another locale.
@@ -2948,76 +1718,10 @@ var GT = class {
2948
1718
  * // Returns: false
2949
1719
  */
2950
1720
  isSupersetLocale(superLocale, subLocale) {
2951
- return isSupersetLocale(superLocale, subLocale);
1721
+ return this.localeConfig.isSupersetLocale(superLocale, subLocale);
2952
1722
  }
2953
1723
  };
2954
1724
  /**
2955
- * Formats a string with cutoff behavior, applying a terminator when the string exceeds the maximum character limit.
2956
- *
2957
- * This standalone function provides cutoff formatting functionality without requiring a GT instance.
2958
- * The locales parameter is required for proper terminator selection based on the target language.
2959
- *
2960
- * @param {string} value - The string value to format with cutoff behavior.
2961
- * @param {Object} [options] - Configuration options for cutoff formatting.
2962
- * @param {string | string[]} [options.locales] - The locales to use for terminator selection.
2963
- * @param {number} [options.maxChars] - The maximum number of characters to display.
2964
- * - Undefined values are treated as no cutoff.
2965
- * - Negative values follow .slice() behavior and terminator will be added before the value.
2966
- * - 0 will result in an empty string.
2967
- * - If cutoff results in an empty string, no terminator is added.
2968
- * @param {CutoffFormatStyle} [options.style='ellipsis'] - The style of the terminator.
2969
- * @param {string} [options.terminator] - Optional override the terminator to use.
2970
- * @param {string} [options.separator] - Optional override the separator to use between the terminator and the value.
2971
- * - If no terminator is provided, then separator is ignored.
2972
- * @returns {string} The formatted string with terminator applied if cutoff occurs.
2973
- *
2974
- * @example
2975
- * formatCutoff('Hello, world!', { locales: 'en-US', maxChars: 8 });
2976
- * // Returns: 'Hello, w...'
2977
- *
2978
- * @example
2979
- * formatCutoff('Hello, world!', { locales: 'en-US', maxChars: -3 });
2980
- * // Returns: '...ld!'
2981
- *
2982
- * @example
2983
- * formatCutoff('Very long text that needs cutting', {
2984
- * locales: 'en-US',
2985
- * maxChars: 15,
2986
- * style: 'ellipsis',
2987
- * separator: ' '
2988
- * });
2989
- * // Returns: 'Very long text ...'
2990
- */
2991
- function formatCutoff(value, options) {
2992
- return _formatCutoff({
2993
- value,
2994
- locales: options?.locales,
2995
- options
2996
- });
2997
- }
2998
- /**
2999
- * Formats a message according to the specified locales and options.
3000
- *
3001
- * @param {string} message - The message to format.
3002
- * @param {string | string[]} [locales='en'] - The locales to use for formatting.
3003
- * @param {FormatVariables} [variables={}] - The variables to use for formatting.
3004
- * @param {StringFormat} [dataFormat='ICU'] - The format of the message. (When STRING, the message is returned as is)
3005
- * @returns {string} The formatted message.
3006
- *
3007
- * @example
3008
- * formatMessage('Hello {name}', { name: 'John' });
3009
- * // Returns: "Hello John"
3010
- *
3011
- * formatMessage('Hello {name}', { name: 'John' }, { locales: ['fr'] });
3012
- * // Returns: "Bonjour John"
3013
- */
3014
- function formatMessage(message, options) {
3015
- switch (options?.dataFormat) {
3016
- case "STRING": return _formatMessageString(message);
3017
- default: return _formatMessageICU(message, options?.locales, options?.variables);
3018
- }
3019
- }
3020
- /**
3021
1725
  * Formats a number according to the specified locales and options.
3022
1726
  * @param {Object} params - The parameters for the number formatting.
3023
1727
  * @param {number} params.value - The number to format.
@@ -3026,7 +1730,7 @@ function formatMessage(message, options) {
3026
1730
  * @returns {string} The formatted number.
3027
1731
  */
3028
1732
  function formatNum(number, options) {
3029
- return _formatNum({
1733
+ return require_core._formatNum({
3030
1734
  value: number,
3031
1735
  locales: options.locales,
3032
1736
  options
@@ -3041,7 +1745,7 @@ function formatNum(number, options) {
3041
1745
  * @returns {string} The formatted date.
3042
1746
  */
3043
1747
  function formatDateTime(date, options) {
3044
- return _formatDateTime({
1748
+ return require_core._formatDateTime({
3045
1749
  value: date,
3046
1750
  locales: options?.locales,
3047
1751
  options
@@ -3057,7 +1761,7 @@ function formatDateTime(date, options) {
3057
1761
  * @returns {string} The formatted currency value.
3058
1762
  */
3059
1763
  function formatCurrency(value, currency, options) {
3060
- return _formatCurrency({
1764
+ return require_core._formatCurrency({
3061
1765
  value,
3062
1766
  currency,
3063
1767
  locales: options.locales,
@@ -3073,7 +1777,7 @@ function formatCurrency(value, currency, options) {
3073
1777
  * @returns {string} The formatted list.
3074
1778
  */
3075
1779
  function formatList(array, options) {
3076
- return _formatList({
1780
+ return require_core._formatList({
3077
1781
  value: array,
3078
1782
  locales: options.locales,
3079
1783
  options
@@ -3088,7 +1792,7 @@ function formatList(array, options) {
3088
1792
  * @returns {Array<T | string>} The formatted list parts
3089
1793
  */
3090
1794
  function formatListToParts(array, options) {
3091
- return _formatListToParts({
1795
+ return require_core._formatListToParts({
3092
1796
  value: array,
3093
1797
  locales: options?.locales,
3094
1798
  options
@@ -3104,7 +1808,7 @@ function formatListToParts(array, options) {
3104
1808
  * @returns {string} The formatted relative time string.
3105
1809
  */
3106
1810
  function formatRelativeTime(value, unit, options) {
3107
- return _formatRelativeTime({
1811
+ return require_core._formatRelativeTime({
3108
1812
  value,
3109
1813
  unit,
3110
1814
  locales: options.locales,
@@ -3121,7 +1825,7 @@ function formatRelativeTime(value, unit, options) {
3121
1825
  */
3122
1826
  function formatRelativeTimeFromDate(date, options) {
3123
1827
  const { locales, baseDate, ...intlOptions } = options;
3124
- return _formatRelativeTimeFromDate({
1828
+ return require_core._formatRelativeTimeFromDate({
3125
1829
  date,
3126
1830
  baseDate: baseDate ?? /* @__PURE__ */ new Date(),
3127
1831
  locales,
@@ -3137,7 +1841,7 @@ function formatRelativeTimeFromDate(date, options) {
3137
1841
  * @returns {string} The display name corresponding to the code.
3138
1842
  */
3139
1843
  function getLocaleName(locale, defaultLocale, customMapping) {
3140
- return _getLocaleName(locale, defaultLocale, customMapping);
1844
+ return require_core._getLocaleName(locale, defaultLocale, customMapping);
3141
1845
  }
3142
1846
  /**
3143
1847
  * Retrieves an emoji based on a given locale code, taking into account region, language, and specific exceptions.
@@ -3149,7 +1853,7 @@ function getLocaleName(locale, defaultLocale, customMapping) {
3149
1853
  * @returns The emoji representing the locale or its region, or a default emoji if no specific match is found.
3150
1854
  */
3151
1855
  function getLocaleEmoji(locale, customMapping) {
3152
- return _getLocaleEmoji(locale, customMapping);
1856
+ return require_core._getLocaleEmoji(locale, customMapping);
3153
1857
  }
3154
1858
  /**
3155
1859
  * Generates linguistic details for a given locale code.
@@ -3186,7 +1890,7 @@ function getLocaleEmoji(locale, customMapping) {
3186
1890
  * @property {string} emoji - The emoji associated with the locale's region, if applicable.
3187
1891
  */
3188
1892
  function getLocaleProperties(locale, defaultLocale, customMapping) {
3189
- return _getLocaleProperties(locale, defaultLocale, customMapping);
1893
+ return require_core._getLocaleProperties(locale, defaultLocale, customMapping);
3190
1894
  }
3191
1895
  /**
3192
1896
  * Retrieves multiple properties for a given region code, including:
@@ -3240,7 +1944,7 @@ function getRegionProperties(region, defaultLocale, customMapping) {
3240
1944
  * @returns {boolean} - Returns `true` if translation is required, otherwise `false`.
3241
1945
  */
3242
1946
  function requiresTranslation(sourceLocale, targetLocale, approvedLocales, customMapping) {
3243
- return _requiresTranslation(sourceLocale, targetLocale, approvedLocales, customMapping);
1947
+ return require_core._requiresTranslation(sourceLocale, targetLocale, approvedLocales, customMapping);
3244
1948
  }
3245
1949
  /**
3246
1950
  * Determines the best matching locale from the provided approved locales list.
@@ -3249,7 +1953,7 @@ function requiresTranslation(sourceLocale, targetLocale, approvedLocales, custom
3249
1953
  * @returns {string | undefined} - The best matching locale from the approvedLocales list, or undefined if no match is found.
3250
1954
  */
3251
1955
  function determineLocale(locales, approvedLocales = [], customMapping = void 0) {
3252
- return _determineLocale(locales, approvedLocales, customMapping);
1956
+ return require_core._determineLocale(locales, approvedLocales, customMapping);
3253
1957
  }
3254
1958
  /**
3255
1959
  * Get the text direction for a given locale code using the Intl.Locale API.
@@ -3258,16 +1962,7 @@ function determineLocale(locales, approvedLocales = [], customMapping = void 0)
3258
1962
  * @returns {string} - 'rtl' if the locale is right-to-left, otherwise 'ltr'.
3259
1963
  */
3260
1964
  function getLocaleDirection(locale) {
3261
- return _getLocaleDirection(locale);
3262
- }
3263
- /**
3264
- * Checks if a given BCP 47 locale code is valid.
3265
- * @param {string} locale - The BCP 47 locale code to validate.
3266
- * @param {CustomMapping} [customMapping] - The custom mapping to use for validation.
3267
- * @returns {boolean} True if the BCP 47 code is valid, false otherwise.
3268
- */
3269
- function isValidLocale(locale, customMapping) {
3270
- return _isValidLocale(locale, customMapping);
1965
+ return require_core._getLocaleDirection(locale);
3271
1966
  }
3272
1967
  /**
3273
1968
  * Resolves the alias locale for a given locale.
@@ -3276,24 +1971,7 @@ function isValidLocale(locale, customMapping) {
3276
1971
  * @returns {string} The alias locale
3277
1972
  */
3278
1973
  function resolveAliasLocale(locale, customMapping) {
3279
- return _resolveAliasLocale(locale, customMapping);
3280
- }
3281
- /**
3282
- * Resolves the canonical locale for a given locale.
3283
- * @param {string} locale - The locale to resolve the canonical locale for
3284
- * @param {CustomMapping} [customMapping] - The custom mapping to use for resolving the canonical locale
3285
- * @returns {string} The canonical locale
3286
- */
3287
- function resolveCanonicalLocale(locale, customMapping) {
3288
- return _resolveCanonicalLocale(locale, customMapping);
3289
- }
3290
- /**
3291
- * Standardizes a BCP 47 locale code to ensure correct formatting.
3292
- * @param {string} locale - The BCP 47 locale code to standardize.
3293
- * @returns {string} The standardized BCP 47 locale code or an empty string if it is an invalid code.
3294
- */
3295
- function standardizeLocale(locale) {
3296
- return _standardizeLocale(locale);
1974
+ return require_core._resolveAliasLocale(locale, customMapping);
3297
1975
  }
3298
1976
  /**
3299
1977
  * Checks if multiple BCP 47 locale codes represent the same dialect.
@@ -3301,7 +1979,7 @@ function standardizeLocale(locale) {
3301
1979
  * @returns {boolean} True if all BCP 47 codes represent the same dialect, false otherwise.
3302
1980
  */
3303
1981
  function isSameDialect(...locales) {
3304
- return _isSameDialect(...locales);
1982
+ return require_core._isSameDialect(...locales);
3305
1983
  }
3306
1984
  /**
3307
1985
  * Checks if multiple BCP 47 locale codes represent the same language.
@@ -3309,7 +1987,7 @@ function isSameDialect(...locales) {
3309
1987
  * @returns {boolean} True if all BCP 47 codes represent the same language, false otherwise.
3310
1988
  */
3311
1989
  function isSameLanguage(...locales) {
3312
- return _isSameLanguage(...locales);
1990
+ return require_core._isSameLanguage(...locales);
3313
1991
  }
3314
1992
  /**
3315
1993
  * Checks if a locale is a superset of another locale.
@@ -3320,20 +1998,20 @@ function isSameLanguage(...locales) {
3320
1998
  * @returns {boolean} True if the first locale is a superset of the second locale, false otherwise.
3321
1999
  */
3322
2000
  function isSupersetLocale(superLocale, subLocale) {
3323
- return _isSupersetLocale(superLocale, subLocale);
2001
+ return require_core._isSupersetLocale(superLocale, subLocale);
3324
2002
  }
3325
2003
  const API_VERSION = API_VERSION$1;
3326
2004
  //#endregion
3327
2005
  exports.API_VERSION = API_VERSION;
3328
2006
  exports.GT = GT;
3329
- exports.__toESM = __toESM;
2007
+ exports.LocaleConfig = require_core.LocaleConfig;
3330
2008
  exports.determineLocale = determineLocale;
3331
2009
  exports.formatCurrency = formatCurrency;
3332
- exports.formatCutoff = formatCutoff;
2010
+ exports.formatCutoff = require_core.formatCutoff;
3333
2011
  exports.formatDateTime = formatDateTime;
3334
2012
  exports.formatList = formatList;
3335
2013
  exports.formatListToParts = formatListToParts;
3336
- exports.formatMessage = formatMessage;
2014
+ exports.formatMessage = require_core.formatMessage;
3337
2015
  exports.formatNum = formatNum;
3338
2016
  exports.formatRelativeTime = formatRelativeTime;
3339
2017
  exports.formatRelativeTimeFromDate = formatRelativeTimeFromDate;
@@ -3345,10 +2023,10 @@ exports.getRegionProperties = getRegionProperties;
3345
2023
  exports.isSameDialect = isSameDialect;
3346
2024
  exports.isSameLanguage = isSameLanguage;
3347
2025
  exports.isSupersetLocale = isSupersetLocale;
3348
- exports.isValidLocale = isValidLocale;
2026
+ exports.isValidLocale = require_core.isValidLocale;
3349
2027
  exports.requiresTranslation = requiresTranslation;
3350
2028
  exports.resolveAliasLocale = resolveAliasLocale;
3351
- exports.resolveCanonicalLocale = resolveCanonicalLocale;
3352
- exports.standardizeLocale = standardizeLocale;
2029
+ exports.resolveCanonicalLocale = require_core.resolveCanonicalLocale;
2030
+ exports.standardizeLocale = require_core.standardizeLocale;
3353
2031
 
3354
2032
  //# sourceMappingURL=index.cjs.map