generaltranslation 8.2.8 → 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 +6 -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 +59 -1518
  35. package/dist/index.cjs.map +1 -1
  36. package/dist/index.d.cts +4 -162
  37. package/dist/index.d.mts +4 -162
  38. package/dist/index.mjs +6 -1441
  39. package/dist/index.mjs.map +1 -1
  40. package/dist/internal.cjs +602 -44
  41. package/dist/internal.cjs.map +1 -0
  42. package/dist/internal.d.cts +1 -1
  43. package/dist/internal.d.mts +1 -1
  44. package/dist/internal.mjs +562 -2
  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-DazaDJbs.d.mts → types-Dfy_sRLD.d.mts} +1 -1
  51. package/dist/{types-BJdoI1d1.d.cts → types-mZeu4HS3.d.cts} +1 -1
  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-B3QbyI_5.mjs +0 -820
  56. package/dist/internal-B3QbyI_5.mjs.map +0 -1
  57. package/dist/internal-DIHQF9gs.cjs +0 -1070
  58. package/dist/internal-DIHQF9gs.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.mjs CHANGED
@@ -1,1174 +1,8 @@
1
- import { B as intlCache, M as encode, V as defaultTimeout, j as decode, k as validateFileFormatTransforms } from "./internal-B3QbyI_5.mjs";
2
- import { t as ApiError } from "./ApiError-Bv7vlzyQ.mjs";
3
- import { n as hashSource } from "./id-CPbVYREY.mjs";
4
- import IntlMessageFormat from "intl-messageformat";
5
- //#region src/locales/isValidLocale.ts
6
- const scriptExceptions = [
7
- "Cham",
8
- "Jamo",
9
- "Kawi",
10
- "Lisu",
11
- "Toto",
12
- "Thai"
13
- ];
14
- const isCustomLanguage = (language) => {
15
- return language >= "qaa" && language <= "qtz";
16
- };
17
- /**
18
- * Checks if a given BCP 47 language code is valid.
19
- * @param {string} code - The BCP 47 language code to validate.
20
- * @param {CustomMapping} [customMapping] - The custom mapping to use for validation.
21
- * @returns {boolean} True if the BCP 47 code is valid, false otherwise.
22
- * @internal
23
- */
24
- const _isValidLocale = (locale, customMapping) => {
25
- if (customMapping?.[locale] && typeof customMapping[locale] === "object" && "code" in customMapping[locale] && customMapping[locale].code) locale = customMapping[locale].code;
26
- try {
27
- const { language, region, script } = intlCache.get("Locale", locale);
28
- if (locale.split("-").length !== (() => {
29
- let partCount = 1;
30
- if (region) partCount += 1;
31
- if (script) partCount += 1;
32
- return partCount;
33
- })()) return false;
34
- if (intlCache.get("DisplayNames", ["en"], { type: "language" }).of(language) === language && !isCustomLanguage(language)) return false;
35
- if (region) {
36
- if (intlCache.get("DisplayNames", ["en"], { type: "region" }).of(region) === region) return false;
37
- }
38
- if (script) {
39
- if (intlCache.get("DisplayNames", ["en"], { type: "script" }).of(script) === script && !scriptExceptions.includes(script)) return false;
40
- }
41
- return true;
42
- } catch {
43
- return false;
44
- }
45
- };
46
- /**
47
- * Standardizes a BCP 47 locale to ensure correct formatting.
48
- * @param {string} locale - The BCP 47 locale to standardize.
49
- * @returns {string} The standardized BCP 47 locale, or an empty string if invalid.
50
- * @internal
51
- */
52
- const _standardizeLocale = (locale) => {
53
- try {
54
- return Intl.getCanonicalLocales(locale)[0];
55
- } catch {
56
- return locale;
57
- }
58
- };
59
- //#endregion
60
- //#region src/locales/isSameDialect.ts
61
- function checkTwoLocalesAreSameDialect(codeA, codeB) {
62
- const { language: languageA, region: regionA, script: scriptA } = intlCache.get("Locale", codeA);
63
- const { language: languageB, region: regionB, script: scriptB } = intlCache.get("Locale", codeB);
64
- if (languageA !== languageB) return false;
65
- if (regionA && regionB && regionA !== regionB) return false;
66
- if (scriptA && scriptB && scriptA !== scriptB) return false;
67
- return true;
68
- }
69
- /**
70
- * Test two or more language codes to determine if they are exactly the same
71
- * e.g. "en-US" and "en" would be exactly the same.
72
- * "en-GB" and "en" would be exactly the same.
73
- * "en-GB" and "en-US" would be different.
74
- * @internal
75
- */
76
- function _isSameDialect(...locales) {
77
- try {
78
- const flattenedCodes = locales.flat().map(_standardizeLocale);
79
- 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;
80
- return true;
81
- } catch (error) {
82
- console.error(error);
83
- return false;
84
- }
85
- }
86
- //#endregion
87
- //#region src/locales/isSameLanguage.ts
88
- /**
89
- * @internal
90
- */
91
- function _isSameLanguage(...locales) {
92
- try {
93
- const languages = locales.flat().map((locale) => intlCache.get("Locale", locale).language);
94
- return languages.every((language) => language === languages[0]);
95
- } catch (error) {
96
- console.error(error);
97
- return false;
98
- }
99
- }
100
- //#endregion
101
- //#region src/locales/requiresTranslation.ts
102
- /**
103
- * Given a target locale and a source locale, determines whether a translation is required
104
- * If the target locale and the source locale are the same, returns false, otherwise returns true
105
- * If a translation is not possible due to the target locale being outside of the optional approvedLanguages scope, also returns false
106
- * @internal
107
- */
108
- function _requiresTranslation(sourceLocale, targetLocale, approvedLocales, customMapping) {
109
- if (!_isValidLocale(sourceLocale, customMapping) || !_isValidLocale(targetLocale, customMapping) || approvedLocales && approvedLocales.some((approvedLocale) => !_isValidLocale(approvedLocale, customMapping))) return false;
110
- if (_isSameDialect(sourceLocale, targetLocale)) return false;
111
- if (approvedLocales && !approvedLocales.some((approvedLocale) => _isSameLanguage(targetLocale, approvedLocale))) return false;
112
- return true;
113
- }
114
- //#endregion
115
- //#region src/locales/customLocaleMapping.ts
116
- const getCustomProperty = (customMapping, locale, property) => {
117
- if (customMapping?.[locale]) {
118
- if (typeof customMapping[locale] === "string") return property === "name" ? customMapping[locale] : void 0;
119
- return customMapping[locale][property];
120
- }
121
- };
122
- /**
123
- * Checks if a given locale should use the canonical locale.
124
- * @param locale - The locale to check if it should use the canonical locale
125
- * @param customMapping - The custom mapping to use for checking if the locale should use the canonical locale
126
- * @returns True if the locale should use the canonical locale, false otherwise
127
- */
128
- const shouldUseCanonicalLocale = (locale, customMapping) => {
129
- return !!(customMapping?.[locale] && typeof customMapping[locale] === "object" && "code" in customMapping[locale] && customMapping[locale].code && _isValidLocale(customMapping[locale].code));
130
- };
131
- //#endregion
132
- //#region src/locales/getLocaleEmoji.ts
133
- /**
134
- * @internal
135
- */
136
- function _getLocaleEmoji(locale, customMapping) {
137
- const aliasedLocale = locale;
138
- if (customMapping && shouldUseCanonicalLocale(locale, customMapping)) locale = customMapping[locale].code;
139
- try {
140
- const standardizedLocale = _standardizeLocale(locale);
141
- const localeObject = intlCache.get("Locale", standardizedLocale);
142
- const { language, region } = localeObject;
143
- if (customMapping) for (const l of [
144
- aliasedLocale,
145
- locale,
146
- standardizedLocale,
147
- language
148
- ]) {
149
- const customEmoji = getCustomProperty(customMapping, l, "emoji");
150
- if (customEmoji) return customEmoji;
151
- }
152
- if (region && emojis[region]) return emojis[region];
153
- const extrapolated = localeObject.maximize();
154
- const extrapolatedRegion = extrapolated.region || "";
155
- return exceptions[extrapolated.language] || emojis[extrapolatedRegion] || "🌍";
156
- } catch {
157
- return defaultEmoji;
158
- }
159
- }
160
- const europeAfricaGlobe = "🌍";
161
- const asiaAustraliaGlobe = "🌏";
162
- const defaultEmoji = europeAfricaGlobe;
163
- const exceptions = {
164
- ca: europeAfricaGlobe,
165
- eu: europeAfricaGlobe,
166
- ku: europeAfricaGlobe,
167
- bo: asiaAustraliaGlobe,
168
- ug: asiaAustraliaGlobe,
169
- gd: "🏴󠁧󠁢󠁳󠁣󠁴󠁿",
170
- cy: "🏴󠁧󠁢󠁷󠁬󠁳󠁿",
171
- gv: "🇮🇲",
172
- grc: "🏺"
173
- };
174
- const emojis = {
175
- AF: "🇦🇫",
176
- AX: "🇦🇽",
177
- AL: "🇦🇱",
178
- DZ: "🇩🇿",
179
- AS: "🇦🇸",
180
- AD: "🇦🇩",
181
- AO: "🇦🇴",
182
- AI: "🇦🇮",
183
- AQ: "🇦🇶",
184
- AG: "🇦🇬",
185
- AR: "🇦🇷",
186
- AM: "🇦🇲",
187
- AW: "🇦🇼",
188
- AU: "🇦🇺",
189
- AT: "🇦🇹",
190
- AZ: "🇦🇿",
191
- BS: "🇧🇸",
192
- BH: "🇧🇭",
193
- BD: "🇧🇩",
194
- BB: "🇧🇧",
195
- BY: "🇧🇾",
196
- BE: "🇧🇪",
197
- BZ: "🇧🇿",
198
- BJ: "🇧🇯",
199
- BM: "🇧🇲",
200
- BT: "🇧🇹",
201
- BO: "🇧🇴",
202
- BQ: "🇧🇶",
203
- BA: "🇧🇦",
204
- BW: "🇧🇼",
205
- BV: "🇧🇻",
206
- BR: "🇧🇷",
207
- IO: "🇮🇴",
208
- BN: "🇧🇳",
209
- BG: "🇧🇬",
210
- BF: "🇧🇫",
211
- BI: "🇧🇮",
212
- CV: "🇨🇻",
213
- KH: "🇰🇭",
214
- CM: "🇨🇲",
215
- CA: "🇨🇦",
216
- KY: "🇰🇾",
217
- CF: "🇨🇫",
218
- TD: "🇹🇩",
219
- CL: "🇨🇱",
220
- CN: "🇨🇳",
221
- CX: "🇨🇽",
222
- CC: "🇨🇨",
223
- CO: "🇨🇴",
224
- KM: "🇰🇲",
225
- CD: "🇨🇩",
226
- CG: "🇨🇬",
227
- CK: "🇨🇰",
228
- CR: "🇨🇷",
229
- CI: "🇨🇮",
230
- HR: "🇭🇷",
231
- CU: "🇨🇺",
232
- CW: "🇨🇼",
233
- CY: "🇨🇾",
234
- CZ: "🇨🇿",
235
- DK: "🇩🇰",
236
- DJ: "🇩🇯",
237
- DM: "🇩🇲",
238
- DO: "🇩🇴",
239
- EC: "🇪🇨",
240
- EG: "🇪🇬",
241
- SV: "🇸🇻",
242
- GQ: "🇬🇶",
243
- ER: "🇪🇷",
244
- EE: "🇪🇪",
245
- SZ: "🇸🇿",
246
- ET: "🇪🇹",
247
- FK: "🇫🇰",
248
- FO: "🇫🇴",
249
- FJ: "🇫🇯",
250
- FI: "🇫🇮",
251
- FR: "🇫🇷",
252
- GF: "🇬🇫",
253
- PF: "🇵🇫",
254
- TF: "🇹🇫",
255
- GA: "🇬🇦",
256
- GM: "🇬🇲",
257
- GE: "🇬🇪",
258
- DE: "🇩🇪",
259
- GH: "🇬🇭",
260
- GI: "🇬🇮",
261
- GR: "🇬🇷",
262
- GL: "🇬🇱",
263
- GD: "🇬🇩",
264
- GP: "🇬🇵",
265
- GU: "🇬🇺",
266
- GT: "🇬🇹",
267
- GG: "🇬🇬",
268
- GN: "🇬🇳",
269
- GW: "🇬🇼",
270
- GY: "🇬🇾",
271
- HT: "🇭🇹",
272
- HM: "🇭🇲",
273
- VA: "🇻🇦",
274
- HN: "🇭🇳",
275
- HK: "🇭🇰",
276
- HU: "🇭🇺",
277
- IS: "🇮🇸",
278
- IN: "🇮🇳",
279
- ID: "🇮🇩",
280
- IR: "🇮🇷",
281
- IQ: "🇮🇶",
282
- IE: "🇮🇪",
283
- IM: "🇮🇲",
284
- IL: "🇮🇱",
285
- IT: "🇮🇹",
286
- JM: "🇯🇲",
287
- JP: "🇯🇵",
288
- JE: "🇯🇪",
289
- JO: "🇯🇴",
290
- KZ: "🇰🇿",
291
- KE: "🇰🇪",
292
- KI: "🇰🇮",
293
- KP: "🇰🇵",
294
- KR: "🇰🇷",
295
- KW: "🇰🇼",
296
- KG: "🇰🇬",
297
- LA: "🇱🇦",
298
- LV: "🇱🇻",
299
- LB: "🇱🇧",
300
- LS: "🇱🇸",
301
- LR: "🇱🇷",
302
- LY: "🇱🇾",
303
- LI: "🇱🇮",
304
- LT: "🇱🇹",
305
- LU: "🇱🇺",
306
- MO: "🇲🇴",
307
- MG: "🇲🇬",
308
- MW: "🇲🇼",
309
- MY: "🇲🇾",
310
- MV: "🇲🇻",
311
- ML: "🇲🇱",
312
- MT: "🇲🇹",
313
- MH: "🇲🇭",
314
- MQ: "🇲🇶",
315
- MR: "🇲🇷",
316
- MU: "🇲🇺",
317
- YT: "🇾🇹",
318
- MX: "🇲🇽",
319
- FM: "🇫🇲",
320
- MD: "🇲🇩",
321
- MC: "🇲🇨",
322
- MN: "🇲🇳",
323
- ME: "🇲🇪",
324
- MS: "🇲🇸",
325
- MA: "🇲🇦",
326
- MZ: "🇲🇿",
327
- MM: "🇲🇲",
328
- NA: "🇳🇦",
329
- NR: "🇳🇷",
330
- NP: "🇳🇵",
331
- NL: "🇳🇱",
332
- NC: "🇳🇨",
333
- NZ: "🇳🇿",
334
- NI: "🇳🇮",
335
- NE: "🇳🇪",
336
- NG: "🇳🇬",
337
- NU: "🇳🇺",
338
- NF: "🇳🇫",
339
- MK: "🇲🇰",
340
- MP: "🇲🇵",
341
- NO: "🇳🇴",
342
- OM: "🇴🇲",
343
- PK: "🇵🇰",
344
- PW: "🇵🇼",
345
- PS: "🇵🇸",
346
- PA: "🇵🇦",
347
- PG: "🇵🇬",
348
- PY: "🇵🇾",
349
- PE: "🇵🇪",
350
- PH: "🇵🇭",
351
- PN: "🇵🇳",
352
- PL: "🇵🇱",
353
- PT: "🇵🇹",
354
- PR: "🇵🇷",
355
- QA: "🇶🇦",
356
- RE: "🇷🇪",
357
- RO: "🇷🇴",
358
- RU: "🇷🇺",
359
- RW: "🇷🇼",
360
- BL: "🇧🇱",
361
- SH: "🇸🇭",
362
- KN: "🇰🇳",
363
- LC: "🇱🇨",
364
- MF: "🇲🇫",
365
- PM: "🇵🇲",
366
- VC: "🇻🇨",
367
- WS: "🇼🇸",
368
- SM: "🇸🇲",
369
- ST: "🇸🇹",
370
- SA: "🇸🇦",
371
- SN: "🇸🇳",
372
- RS: "🇷🇸",
373
- SC: "🇸🇨",
374
- SL: "🇸🇱",
375
- SG: "🇸🇬",
376
- SX: "🇸🇽",
377
- SK: "🇸🇰",
378
- SI: "🇸🇮",
379
- SB: "🇸🇧",
380
- SO: "🇸🇴",
381
- ZA: "🇿🇦",
382
- GS: "🇬🇸",
383
- SS: "🇸🇸",
384
- ES: "🇪🇸",
385
- LK: "🇱🇰",
386
- SD: "🇸🇩",
387
- SR: "🇸🇷",
388
- SJ: "🇸🇯",
389
- SE: "🇸🇪",
390
- CH: "🇨🇭",
391
- SY: "🇸🇾",
392
- TW: "🇹🇼",
393
- TJ: "🇹🇯",
394
- TZ: "🇹🇿",
395
- TH: "🇹🇭",
396
- TL: "🇹🇱",
397
- TG: "🇹🇬",
398
- TK: "🇹🇰",
399
- TO: "🇹🇴",
400
- TT: "🇹🇹",
401
- TN: "🇹🇳",
402
- TR: "🇹🇷",
403
- TM: "🇹🇲",
404
- TC: "🇹🇨",
405
- TV: "🇹🇻",
406
- UG: "🇺🇬",
407
- UA: "🇺🇦",
408
- AE: "🇦🇪",
409
- GB: "🇬🇧",
410
- US: "🇺🇸",
411
- UM: "🇺🇲",
412
- UY: "🇺🇾",
413
- UZ: "🇺🇿",
414
- VU: "🇻🇺",
415
- VE: "🇻🇪",
416
- VN: "🇻🇳",
417
- VG: "🇻🇬",
418
- VI: "🇻🇮",
419
- WF: "🇼🇫",
420
- EH: "🇪🇭",
421
- YE: "🇾🇪",
422
- ZM: "🇿🇲",
423
- ZW: "🇿🇼",
424
- EU: "🇪🇺",
425
- "419": "🌎"
426
- };
427
- //#endregion
428
- //#region src/locales/getLocaleProperties.ts
429
- /**
430
- * Creates a set of custom locale properties from a custom mapping.
431
- *
432
- * @param lArray - An array of locale codes to search for in the custom mapping.
433
- * @param customMapping - Optional custom mapping of locale codes to names.
434
- * @returns A partial set of locale properties, or undefined if no custom mapping is provided.
435
- */
436
- function createCustomLocaleProperties(lArray, customMapping) {
437
- if (customMapping) {
438
- let merged = {};
439
- for (const l of lArray) {
440
- const value = customMapping[l];
441
- if (value) {
442
- if (typeof value === "string") merged.name ||= value;
443
- else if (value) merged = {
444
- ...value,
445
- ...merged
446
- };
447
- }
448
- }
449
- return merged;
450
- }
451
- }
452
- /**
453
- * @internal
454
- */
455
- function _getLocaleProperties(locale, defaultLocale = "en", customMapping) {
456
- const aliasedLocale = locale;
457
- if (customMapping && shouldUseCanonicalLocale(locale, customMapping)) locale = customMapping[locale].code;
458
- defaultLocale ||= "en";
459
- try {
460
- const standardizedLocale = _standardizeLocale(locale);
461
- const localeObject = intlCache.get("Locale", locale);
462
- const languageCode = localeObject.language;
463
- const customLocaleProperties = createCustomLocaleProperties([
464
- aliasedLocale,
465
- locale,
466
- standardizedLocale,
467
- languageCode
468
- ], customMapping);
469
- const baseRegion = localeObject.region;
470
- const maximizedLocale = localeObject.maximize();
471
- const maximizedCode = maximizedLocale.toString();
472
- const regionCode = localeObject.region || customLocaleProperties?.regionCode || maximizedLocale.region || "";
473
- const scriptCode = localeObject.script || customLocaleProperties?.scriptCode || maximizedLocale.script || "";
474
- const minimizedCode = localeObject.minimize().toString();
475
- const defaultLanguageOrder = [
476
- defaultLocale,
477
- locale,
478
- "en"
479
- ];
480
- const nativeLanguageOrder = [
481
- locale,
482
- defaultLocale,
483
- "en"
484
- ];
485
- const languageNames = intlCache.get("DisplayNames", defaultLanguageOrder, { type: "language" });
486
- const nativeLanguageNames = intlCache.get("DisplayNames", nativeLanguageOrder, { type: "language" });
487
- const customName = customLocaleProperties?.name;
488
- const customNativeName = customLocaleProperties?.nativeName || customLocaleProperties?.name;
489
- const name = customName || languageNames.of(locale) || locale;
490
- const nativeName = customNativeName || nativeLanguageNames.of(locale) || locale;
491
- const maximizedName = customLocaleProperties?.maximizedName || customName || languageNames.of(maximizedCode) || locale;
492
- const nativeMaximizedName = customLocaleProperties?.nativeMaximizedName || customNativeName || nativeLanguageNames.of(maximizedCode) || locale;
493
- const minimizedName = customLocaleProperties?.minimizedName || customName || languageNames.of(minimizedCode) || locale;
494
- const nativeMinimizedName = customLocaleProperties?.nativeMinimizedName || customNativeName || nativeLanguageNames.of(minimizedCode) || locale;
495
- const languageName = customLocaleProperties?.languageName || customName || languageNames.of(languageCode) || locale;
496
- const nativeLanguageName = customLocaleProperties?.nativeLanguageName || customNativeName || nativeLanguageNames.of(languageCode) || locale;
497
- const nameWithRegionCode = customLocaleProperties?.nameWithRegionCode || baseRegion ? `${languageName} (${baseRegion})` : name;
498
- const nativeNameWithRegionCode = customLocaleProperties?.nativeNameWithRegionCode || (baseRegion ? `${nativeLanguageName} (${baseRegion})` : nativeName) || nameWithRegionCode;
499
- const regionNames = intlCache.get("DisplayNames", defaultLanguageOrder, { type: "region" });
500
- const nativeRegionNames = intlCache.get("DisplayNames", nativeLanguageOrder, { type: "region" });
501
- const regionName = customLocaleProperties?.regionName || (regionCode ? regionNames.of(regionCode) : "") || "";
502
- const nativeRegionName = customLocaleProperties?.nativeRegionName || (regionCode ? nativeRegionNames.of(regionCode) : "") || "";
503
- const scriptNames = intlCache.get("DisplayNames", defaultLanguageOrder, { type: "script" });
504
- const nativeScriptNames = intlCache.get("DisplayNames", nativeLanguageOrder, { type: "script" });
505
- return {
506
- code: standardizedLocale,
507
- name,
508
- nativeName,
509
- maximizedCode,
510
- maximizedName,
511
- nativeMaximizedName,
512
- minimizedCode,
513
- minimizedName,
514
- nativeMinimizedName,
515
- languageCode,
516
- languageName,
517
- nativeLanguageName,
518
- nameWithRegionCode,
519
- nativeNameWithRegionCode,
520
- regionCode,
521
- regionName,
522
- nativeRegionName,
523
- scriptCode,
524
- scriptName: customLocaleProperties?.scriptName || (scriptCode ? scriptNames.of(scriptCode) : "") || "",
525
- nativeScriptName: customLocaleProperties?.nativeScriptName || (scriptCode ? nativeScriptNames.of(scriptCode) : "") || "",
526
- emoji: customLocaleProperties?.emoji || _getLocaleEmoji(standardizedLocale, customMapping)
527
- };
528
- } catch {
529
- let code = _isValidLocale(locale) ? _standardizeLocale(locale) : locale;
530
- const codeParts = code?.split("-");
531
- let languageCode = codeParts?.[0] || code || "";
532
- let regionCode = codeParts.length > 2 ? codeParts?.[2] : codeParts?.[1] || "";
533
- let scriptCode = codeParts?.[3] || "";
534
- const customLocaleProperties = createCustomLocaleProperties([code, languageCode], customMapping);
535
- code = customLocaleProperties?.code || code;
536
- const name = customLocaleProperties?.name || code;
537
- const nativeName = customLocaleProperties?.nativeName || name;
538
- const maximizedCode = customLocaleProperties?.maximizedCode || code;
539
- const maximizedName = customLocaleProperties?.maximizedName || name;
540
- const nativeMaximizedName = customLocaleProperties?.nativeMaximizedName || nativeName;
541
- const minimizedCode = customLocaleProperties?.minimizedCode || code;
542
- const minimizedName = customLocaleProperties?.minimizedName || name;
543
- const nativeMinimizedName = customLocaleProperties?.nativeMinimizedName || nativeName;
544
- languageCode = customLocaleProperties?.languageCode || languageCode;
545
- const languageName = customLocaleProperties?.languageName || name;
546
- const nativeLanguageName = customLocaleProperties?.nativeLanguageName || nativeName;
547
- regionCode = customLocaleProperties?.regionCode || regionCode;
548
- const regionName = customLocaleProperties?.regionName || "";
549
- const nativeRegionName = customLocaleProperties?.nativeRegionName || "";
550
- scriptCode = customLocaleProperties?.scriptCode || scriptCode;
551
- const scriptName = customLocaleProperties?.scriptName || "";
552
- const nativeScriptName = customLocaleProperties?.nativeScriptName || "";
553
- const nameWithRegionCode = customLocaleProperties?.nameWithRegionCode || (regionName ? `${languageName} (${regionName})` : name);
554
- const nativeNameWithRegionCode = customLocaleProperties?.nativeNameWithRegionCode || (nativeRegionName ? `${nativeLanguageName} (${nativeRegionName})` : nativeName);
555
- const emoji = customLocaleProperties?.emoji || "🌍";
556
- return {
557
- code,
558
- name,
559
- nativeName,
560
- maximizedCode,
561
- maximizedName,
562
- nativeMaximizedName,
563
- minimizedCode,
564
- minimizedName,
565
- nativeMinimizedName,
566
- languageCode,
567
- languageName,
568
- nativeLanguageName,
569
- nameWithRegionCode,
570
- nativeNameWithRegionCode,
571
- regionCode,
572
- regionName,
573
- nativeRegionName,
574
- scriptCode,
575
- scriptName,
576
- nativeScriptName,
577
- emoji
578
- };
579
- }
580
- }
581
- //#endregion
582
- //#region src/locales/determineLocale.ts
583
- /**
584
- * Given a list of locales and a list of approved locales, sorted in preference order
585
- * Determines which locale is the best match among the approved locales, prioritizing exact matches and falling back to dialects of the same language
586
- * @internal
587
- */
588
- function _determineLocale(locales, approvedLocales, customMapping) {
589
- if (typeof locales === "string") locales = [locales];
590
- locales = locales.filter((locale) => _isValidLocale(locale, customMapping)).map(_standardizeLocale);
591
- approvedLocales = approvedLocales.filter((locale) => _isValidLocale(locale, customMapping)).map(_standardizeLocale);
592
- for (const locale of locales) {
593
- const candidates = approvedLocales.filter((approvedLocale) => _isSameLanguage(locale, approvedLocale));
594
- const getMatchingCode = ({ locale, languageCode, minimizedCode, regionCode, scriptCode }) => {
595
- const locales = [
596
- locale,
597
- `${languageCode}-${regionCode}`,
598
- `${languageCode}-${scriptCode}`,
599
- minimizedCode
600
- ];
601
- for (const l of locales) if (candidates.includes(l)) return l;
602
- return null;
603
- };
604
- const { languageCode, ...codes } = _getLocaleProperties(locale);
605
- const matchingCode = getMatchingCode({
606
- locale,
607
- languageCode,
608
- ...codes
609
- }) || getMatchingCode({
610
- locale: languageCode,
611
- ..._getLocaleProperties(languageCode)
612
- });
613
- if (matchingCode) return matchingCode;
614
- }
615
- }
616
- //#endregion
617
- //#region src/logging/logger.ts
618
- const LOG_LEVELS = {
619
- debug: 0,
620
- info: 1,
621
- warn: 2,
622
- error: 3,
623
- off: 4
624
- };
625
- const LOG_COLORS = {
626
- debug: "\x1B[36m",
627
- info: "\x1B[32m",
628
- warn: "\x1B[33m",
629
- error: "\x1B[31m",
630
- off: ""
631
- };
632
- const RESET_COLOR = "\x1B[0m";
633
- /**
634
- * Get the configured log level from environment variable or default to 'warn'
635
- */
636
- function getConfiguredLogLevel() {
637
- if (typeof process !== "undefined" && process.env?._GT_LOG_LEVEL) {
638
- const envLevel = process.env._GT_LOG_LEVEL.toLowerCase();
639
- if (envLevel in LOG_LEVELS) return envLevel;
640
- }
641
- return "warn";
642
- }
643
- /**
644
- * Console log handler that outputs formatted messages to console
645
- */
646
- var ConsoleLogHandler = class {
647
- constructor(config) {
648
- this.config = config;
649
- }
650
- handle(entry) {
651
- const parts = [];
652
- if (this.config.includeTimestamp) parts.push(`[${entry.timestamp.toISOString()}]`);
653
- const colorCode = LOG_COLORS[entry.level];
654
- const levelText = `[${entry.level.toUpperCase()}]`;
655
- parts.push(`${colorCode}${levelText}${RESET_COLOR}`);
656
- if (this.config.prefix) parts.push(`[${this.config.prefix}]`);
657
- if (this.config.includeContext && entry.context) parts.push(`[${entry.context}]`);
658
- parts.push(entry.message);
659
- if (entry.metadata && Object.keys(entry.metadata).length > 0) parts.push(`\n Metadata: ${JSON.stringify(entry.metadata, null, 2)}`);
660
- const formattedMessage = parts.join(" ");
661
- switch (entry.level) {
662
- case "debug":
663
- console.debug(formattedMessage);
664
- break;
665
- case "info":
666
- console.info(formattedMessage);
667
- break;
668
- case "warn":
669
- console.warn(formattedMessage);
670
- break;
671
- case "error":
672
- console.error(formattedMessage);
673
- break;
674
- }
675
- }
676
- };
677
- /**
678
- * Main Logger class providing structured logging capabilities
679
- */
680
- var Logger = class {
681
- constructor(config = {}) {
682
- this.config = {
683
- level: getConfiguredLogLevel(),
684
- includeTimestamp: true,
685
- includeContext: true,
686
- enableConsole: true,
687
- handlers: [],
688
- ...config
689
- };
690
- this.handlers = [...this.config.handlers || []];
691
- if (this.config.enableConsole) this.handlers.push(new ConsoleLogHandler(this.config));
692
- }
693
- /**
694
- * Add a custom log handler
695
- */
696
- addHandler(handler) {
697
- this.handlers.push(handler);
698
- }
699
- /**
700
- * Remove a log handler
701
- */
702
- removeHandler(handler) {
703
- const index = this.handlers.indexOf(handler);
704
- if (index > -1) this.handlers.splice(index, 1);
705
- }
706
- /**
707
- * Update logger configuration
708
- */
709
- configure(config) {
710
- this.config = {
711
- ...this.config,
712
- ...config
713
- };
714
- }
715
- /**
716
- * Check if a log level should be output based on current configuration
717
- */
718
- shouldLog(level) {
719
- return LOG_LEVELS[level] >= LOG_LEVELS[this.config.level];
720
- }
721
- /**
722
- * Internal logging method that creates log entries and passes them to handlers
723
- */
724
- log(level, message, context, metadata) {
725
- if (!this.shouldLog(level)) return;
726
- const entry = {
727
- level,
728
- message,
729
- timestamp: /* @__PURE__ */ new Date(),
730
- context,
731
- metadata
732
- };
733
- this.handlers.forEach((handler) => {
734
- try {
735
- handler.handle(entry);
736
- } catch (error) {
737
- console.error("Error in log handler:", error);
738
- }
739
- });
740
- }
741
- /**
742
- * Log a debug message
743
- * Used for detailed diagnostic information, typically of interest only when diagnosing problems
744
- */
745
- debug(message, context, metadata) {
746
- this.log("debug", message, context, metadata);
747
- }
748
- /**
749
- * Log an info message
750
- * Used for general information about application operation
751
- */
752
- info(message, context, metadata) {
753
- this.log("info", message, context, metadata);
754
- }
755
- /**
756
- * Log a warning message
757
- * Used for potentially problematic situations that don't prevent operation
758
- */
759
- warn(message, context, metadata) {
760
- this.log("warn", message, context, metadata);
761
- }
762
- /**
763
- * Log an error message
764
- * Used for error events that might still allow the application to continue
765
- */
766
- error(message, context, metadata) {
767
- this.log("error", message, context, metadata);
768
- }
769
- /**
770
- * Create a child logger with a specific context
771
- */
772
- child(context) {
773
- return new ContextLogger(this, context);
774
- }
775
- /**
776
- * Get current logger configuration
777
- */
778
- getConfig() {
779
- return { ...this.config };
780
- }
781
- };
782
- /**
783
- * Context logger that automatically includes context information
784
- */
785
- var ContextLogger = class ContextLogger {
786
- constructor(logger, context) {
787
- this.logger = logger;
788
- this.context = context;
789
- }
790
- debug(message, metadata) {
791
- this.logger.debug(message, this.context, metadata);
792
- }
793
- info(message, metadata) {
794
- this.logger.info(message, this.context, metadata);
795
- }
796
- warn(message, metadata) {
797
- this.logger.warn(message, this.context, metadata);
798
- }
799
- error(message, metadata) {
800
- this.logger.error(message, this.context, metadata);
801
- }
802
- child(childContext) {
803
- return new ContextLogger(this.logger, `${this.context}:${childContext}`);
804
- }
805
- };
806
- const defaultLogger = new Logger({
807
- level: getConfiguredLogLevel(),
808
- includeTimestamp: true,
809
- includeContext: true,
810
- prefix: "GT"
811
- });
812
- const fetchLogger = defaultLogger.child("fetch");
813
- defaultLogger.child("validation");
814
- defaultLogger.child("formatting");
815
- defaultLogger.child("locale");
816
- const gtInstanceLogger = defaultLogger.child("GT instance");
817
- //#endregion
818
- //#region src/formatting/format.ts
819
- /**
820
- * Formats a string value with cutoff behavior according to the specified locales and options.
821
- *
822
- * @param {Object} params - The parameters for the cutoff formatting.
823
- * @param {string} params.value - The string value to format with cutoff behavior.
824
- * @param {string | string[]} [params.locales='en'] - The locales to use for formatting.
825
- * @param {CutoffFormatOptions} [params.options={}] - Additional options for cutoff formatting.
826
- * @param {number} [params.options.maxChars] - The maximum number of characters to display.
827
- * @param {CutoffFormatStyle} [params.options.style='ellipsis'] - The style of the terminator.
828
- * @param {string} [params.options.terminator] - Optional override for the terminator to use.
829
- * @param {string} [params.options.separator] - Optional override for the separator between terminator and value.
830
- *
831
- * @returns {string} The formatted string with terminator applied if cutoff occurs.
832
- * @internal
833
- *
834
- * @example
835
- * _formatCutoff({ value: 'Hello, world!', options: { maxChars: 8 } }); // Returns 'Hello, w...'
836
- *
837
- * Will fallback to an empty string if formatting fails.
838
- */
839
- function _formatCutoff({ value, locales = "en", options = {} }) {
840
- return intlCache.get("CutoffFormat", locales, options).format(value);
841
- }
842
- /**
843
- * Formats a message according to the specified locales and options.
844
- *
845
- * @param {string} message - The message to format.
846
- * @param {string | string[]} [locales='en'] - The locales to use for formatting.
847
- * @param {Record<string, any>} [variables={}] - The variables to use for formatting.
848
- * @returns {string} The formatted message.
849
- * @internal
850
- *
851
- * Will fallback to an empty string
852
- * TODO: add this to custom formats
853
- */
854
- function _formatMessageICU(message, locales = "en", variables = {}) {
855
- return new IntlMessageFormat(message, locales).format(variables)?.toString() ?? "";
856
- }
857
- /**
858
- * Returns the message as-is without any formatting.
859
- *
860
- * @param {string} message - The message to return.
861
- * @returns {string} The original message, unchanged.
862
- * @internal
863
- *
864
- * TODO: add this to custom formats
865
- */
866
- function _formatMessageString(message) {
867
- return message;
868
- }
869
- /**
870
- * Formats a number according to the specified locales and options.
871
- *
872
- * @param {Object} params - The parameters for the number formatting.
873
- * @param {number} params.value - The number to format.
874
- * @param {string | string[]} [params.locales=['en']] - The locales to use for formatting.
875
- * @param {Intl.NumberFormatOptions} [params.options={}] - Additional options for number formatting.
876
- *
877
- * @returns {string} The formatted number.
878
- * @internal
879
- */
880
- function _formatNum({ value, locales = ["en"], options = {} }) {
881
- return intlCache.get("NumberFormat", locales, {
882
- numberingSystem: "latn",
883
- ...options
884
- }).format(value);
885
- }
886
- /**
887
- * Formats a date according to the specified locales and options.
888
- *
889
- * @param {Object} params - The parameters for the date formatting.
890
- * @param {Date} params.value - The date to format.
891
- * @param {string | string[]} [params.locales='en'] - The locales to use for formatting.
892
- * @param {Intl.DateTimeFormatOptions} [params.options={}] - Additional options for date formatting.
893
- *
894
- * @returns {string} The formatted date.
895
- * @internal
896
- */
897
- function _formatDateTime({ value, locales = ["en"], options = {} }) {
898
- return intlCache.get("DateTimeFormat", locales, {
899
- calendar: "gregory",
900
- numberingSystem: "latn",
901
- ...options
902
- }).format(value);
903
- }
904
- /**
905
- * Formats a currency value according to the specified locales, currency, and options.
906
- *
907
- * @param {Object} params - The parameters for the currency formatting.
908
- * @param {number} params.value - The currency value to format.
909
- * @param {string} params.currency - The currency code (e.g., 'USD').
910
- * @param {string | string[]} [params.locales=['en']] - The locales to use for formatting.
911
- * @param {Intl.NumberFormatOptions} [params.options={}] - Additional options for currency formatting.
912
- *
913
- * @returns {string} The formatted currency value.
914
- * @internal
915
- */
916
- function _formatCurrency({ value, locales = ["en"], currency = "USD", options = {} }) {
917
- return intlCache.get("NumberFormat", locales, {
918
- style: "currency",
919
- currency,
920
- numberingSystem: "latn",
921
- ...options
922
- }).format(value);
923
- }
924
- /**
925
- * Formats a list of items according to the specified locales and options.
926
- *
927
- * @param {Object} params - The parameters for the list formatting.
928
- * @param {Array<string | number>} params.value - The list of items to format.
929
- * @param {string | string[]} [params.locales=['en']] - The locales to use for formatting.
930
- * @param {Intl.ListFormatOptions} [params.options={}] - Additional options for list formatting.
931
- *
932
- * @returns {string} The formatted list.
933
- * @internal
934
- */
935
- function _formatList({ value, locales = ["en"], options = {} }) {
936
- return intlCache.get("ListFormat", locales, {
937
- type: "conjunction",
938
- style: "long",
939
- ...options
940
- }).format(value);
941
- }
942
- /**
943
- * Formats a list of items according to the specified locales and options.
944
- * @param {Object} params - The parameters for the list formatting.
945
- * @param {Array<T>} params.value - The list of items to format.
946
- * @param {string | string[]} [params.locales=['en']] - The locales to use for formatting.
947
- * @param {Intl.ListFormatOptions} [params.options={}] - Additional options for list formatting.
948
- * @returns {Array<T | string>} The formatted list parts.
949
- * @internal
950
- */
951
- function _formatListToParts({ value, locales = ["en"], options = {} }) {
952
- const formatListParts = intlCache.get("ListFormat", locales, {
953
- type: "conjunction",
954
- style: "long",
955
- ...options
956
- }).formatToParts(value.map(() => "1"));
957
- let partIndex = 0;
958
- return formatListParts.map((part) => {
959
- if (part.type === "element") return value[partIndex++];
960
- return part.value;
961
- });
962
- }
963
- /**
964
- * Selects the best unit and computes the value for relative time formatting
965
- * based on the difference between a date and a base date.
966
- * @param {Date} date - The target date.
967
- * @param {Date} baseDate - The base date to compute relative time from. Must be provided by the caller for hydration safety.
968
- * @returns {{ value: number, unit: Intl.RelativeTimeFormatUnit }} The computed value and unit.
969
- * @internal
970
- */
971
- function _selectRelativeTimeUnit(date, baseDate) {
972
- const now = baseDate.getTime();
973
- const diffMs = date.getTime() - now;
974
- const absDiffMs = Math.abs(diffMs);
975
- const sign = diffMs < 0 ? -1 : 1;
976
- const seconds = Math.floor(absDiffMs / 1e3);
977
- const minutes = Math.floor(absDiffMs / (1e3 * 60));
978
- const hours = Math.floor(absDiffMs / (1e3 * 60 * 60));
979
- const days = Math.floor(absDiffMs / (1e3 * 60 * 60 * 24));
980
- const weeks = Math.floor(absDiffMs / (1e3 * 60 * 60 * 24 * 7));
981
- const months = Math.floor(absDiffMs / (1e3 * 60 * 60 * 24 * 30));
982
- const years = Math.floor(absDiffMs / (1e3 * 60 * 60 * 24 * 365));
983
- if (seconds < 60) return {
984
- value: sign * seconds,
985
- unit: "second"
986
- };
987
- if (minutes < 60) return {
988
- value: sign * minutes,
989
- unit: "minute"
990
- };
991
- if (hours < 24) return {
992
- value: sign * hours,
993
- unit: "hour"
994
- };
995
- if (days < 7) return {
996
- value: sign * days,
997
- unit: "day"
998
- };
999
- if (days < 28) return {
1000
- value: sign * weeks,
1001
- unit: "week"
1002
- };
1003
- if (months < 1) return {
1004
- value: sign * weeks,
1005
- unit: "week"
1006
- };
1007
- if (months < 12) return {
1008
- value: sign * months,
1009
- unit: "month"
1010
- };
1011
- if (years < 1) return {
1012
- value: sign * months,
1013
- unit: "month"
1014
- };
1015
- return {
1016
- value: sign * years,
1017
- unit: "year"
1018
- };
1019
- }
1020
- /**
1021
- * Formats a relative time from a Date, automatically selecting the best unit.
1022
- * @internal
1023
- */
1024
- function _formatRelativeTimeFromDate({ date, baseDate, locales = ["en"], options = {} }) {
1025
- const { value, unit } = _selectRelativeTimeUnit(date, baseDate);
1026
- return _formatRelativeTime({
1027
- value,
1028
- unit,
1029
- locales,
1030
- options
1031
- });
1032
- }
1033
- /**
1034
- * Formats a relative time value according to the specified locales and options.
1035
- *
1036
- * @param {Object} params - The parameters for the relative time formatting.
1037
- * @param {number} params.value - The relative time value to format.
1038
- * @param {Intl.RelativeTimeFormatUnit} params.unit - The unit of time (e.g., 'second', 'minute', 'hour', 'day', 'week', 'month', 'year').
1039
- * @param {string | string[]} [params.locales=['en']] - The locales to use for formatting.
1040
- * @param {Intl.RelativeTimeFormatOptions} [params.options={}] - Additional options for relative time formatting.
1041
- *
1042
- * @returns {string} The formatted relative time string.
1043
- * @internal
1044
- */
1045
- function _formatRelativeTime({ value, unit, locales = ["en"], options = {} }) {
1046
- return intlCache.get("RelativeTimeFormat", locales, {
1047
- style: "long",
1048
- numeric: "auto",
1049
- ...options
1050
- }).format(value, unit);
1051
- }
1052
- //#endregion
1053
- //#region src/locales/getLocaleName.ts
1054
- /**
1055
- * Retrieves the display name(s) of locale code(s) using Intl.DisplayNames.
1056
- *
1057
- * @param {string} locale - A BCP-47 locale code.
1058
- * @param {string} [defaultLocale=libraryDefaultLocale] - The locale for display names.
1059
- * @returns {string} The display name(s) corresponding to the code(s), or empty string(s) if invalid.
1060
- * @internal
1061
- */
1062
- function _getLocaleName(locale, defaultLocale = "en", customMapping) {
1063
- const aliasedLocale = locale;
1064
- if (customMapping && shouldUseCanonicalLocale(locale, customMapping)) locale = customMapping[locale].code;
1065
- defaultLocale ||= "en";
1066
- try {
1067
- const standardizedLocale = _standardizeLocale(locale);
1068
- if (customMapping) for (const l of [
1069
- aliasedLocale,
1070
- locale,
1071
- standardizedLocale,
1072
- intlCache.get("Locale", standardizedLocale).language
1073
- ]) {
1074
- const customName = getCustomProperty(customMapping, l, "name");
1075
- if (customName) return customName;
1076
- }
1077
- return intlCache.get("DisplayNames", [
1078
- defaultLocale,
1079
- standardizedLocale,
1080
- "en"
1081
- ], { type: "language" }).of(standardizedLocale) || "";
1082
- } catch {
1083
- return "";
1084
- }
1085
- }
1086
- //#endregion
1087
- //#region src/locales/getLocaleDirection.ts
1088
- /**
1089
- * Get the text direction for a given locale code using the Intl.Locale API.
1090
- *
1091
- * @param {string} code - The locale code to check.
1092
- * @returns {string} - 'rtl' if the language is right-to-left, otherwise 'ltr'.
1093
- * @internal
1094
- */
1095
- function _getLocaleDirection(code) {
1096
- try {
1097
- const textInfoDirection = extractDirectionWithTextInfo(intlCache.get("Locale", code));
1098
- if (textInfoDirection) return textInfoDirection;
1099
- } catch {}
1100
- const { scriptCode, languageCode } = _getLocaleProperties(code);
1101
- if (scriptCode) return isRtlScript(scriptCode) ? "rtl" : "ltr";
1102
- if (languageCode) return isRtlLanguage(languageCode) ? "rtl" : "ltr";
1103
- return "ltr";
1104
- }
1105
- const RTL_SCRIPTS = new Set([
1106
- "arab",
1107
- "adlm",
1108
- "hebr",
1109
- "nkoo",
1110
- "rohg",
1111
- "samr",
1112
- "syrc",
1113
- "thaa",
1114
- "yezi"
1115
- ]);
1116
- const RTL_LANGUAGES = new Set([
1117
- "ar",
1118
- "arc",
1119
- "ckb",
1120
- "dv",
1121
- "fa",
1122
- "he",
1123
- "iw",
1124
- "ku",
1125
- "lrc",
1126
- "nqo",
1127
- "ps",
1128
- "pnb",
1129
- "sd",
1130
- "syr",
1131
- "ug",
1132
- "ur",
1133
- "yi"
1134
- ]);
1135
- /**
1136
- * Handles extracting direction via textInfo property
1137
- * @param Locale - Intl.Locale object
1138
- * @returns {'ltr' | 'rtl'} - The direction of the locale
1139
- *
1140
- * Intl.Locale.prototype.getTextInfo() / textInfo property incorporated in ES2024 Specification.
1141
- * This is not supported by all browsers yet.
1142
- * See: {@link https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/Locale/getTextInfo#browser_compatibility}
1143
- */
1144
- function extractDirectionWithTextInfo(locale) {
1145
- 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;
1146
- }
1147
- function isRtlScript(script) {
1148
- return script ? RTL_SCRIPTS.has(script.toLowerCase()) : false;
1149
- }
1150
- function isRtlLanguage(language) {
1151
- return language ? RTL_LANGUAGES.has(language.toLowerCase()) : false;
1152
- }
1153
- //#endregion
1154
- //#region src/locales/isSupersetLocale.ts
1155
- /**
1156
- * @internal
1157
- */
1158
- function _isSupersetLocale(superLocale, subLocale) {
1159
- try {
1160
- const { language: languageSuper, region: regionSuper, script: scriptSuper } = intlCache.get("Locale", _standardizeLocale(superLocale));
1161
- const { language: languageSub, region: regionSub, script: scriptSub } = intlCache.get("Locale", _standardizeLocale(subLocale));
1162
- if (languageSuper !== languageSub) return false;
1163
- if (regionSuper && regionSuper !== regionSub) return false;
1164
- if (scriptSuper && scriptSuper !== scriptSub) return false;
1165
- return true;
1166
- } catch (error) {
1167
- console.error(error);
1168
- return false;
1169
- }
1170
- }
1171
- //#endregion
1
+ import { n as defaultTimeout, t as intlCache } from "./IntlCache-Ccg_cQPR.mjs";
2
+ import { A as _standardizeLocale, C as _getLocaleEmoji, D as _isSameLanguage, E as _requiresTranslation, O as _isSameDialect, S as _getLocaleProperties, T as emojis, _ as _formatRelativeTime, a as standardizeLocale, b as gtInstanceLogger, c as _resolveAliasLocale, d as _getLocaleName, f as _formatCurrency, g as _formatNum, h as _formatListToParts, i as resolveCanonicalLocale, k as _isValidLocale, l as _isSupersetLocale, m as _formatList, n as formatMessage, o as LocaleConfig, p as _formatDateTime, r as isValidLocale, s as _resolveCanonicalLocale, t as formatCutoff, u as _getLocaleDirection, v as _formatRelativeTimeFromDate, w as defaultEmoji, x as _determineLocale, y as fetchLogger } from "./core-DOrYXXpO.mjs";
3
+ import { n as encode, r as validateFileFormatTransforms, t as decode } from "./base64-C1sogiix.mjs";
4
+ import { t as ApiError } from "./ApiError-IYfaOR30.mjs";
5
+ import { n as hashSource } from "./id-BmOyfaug.mjs";
1172
6
  //#region src/logging/errors.ts
1173
7
  const GT_ERROR_PREFIX = "GT Error:";
1174
8
  const translationTimeoutError = (timeout) => `${GT_ERROR_PREFIX} Translation request timed out after ${timeout}ms.`;
@@ -1581,31 +415,6 @@ function _getRegionProperties(region, defaultLocale = "en", customMapping) {
1581
415
  }
1582
416
  }
1583
417
  //#endregion
1584
- //#region src/locales/resolveAliasLocale.ts
1585
- /**
1586
- * Resolves the alias locale for a given locale.
1587
- * @param locale - The locale to resolve the alias locale for
1588
- * @param customMapping - The custom mapping to use for resolving the alias locale
1589
- * @returns The alias locale
1590
- */
1591
- function _resolveAliasLocale(locale, customMapping) {
1592
- let reverseCustomMapping;
1593
- if (customMapping) reverseCustomMapping = Object.fromEntries(Object.entries(customMapping).filter(([, value]) => value && typeof value === "object" && "code" in value).map(([key, value]) => [value.code, key]));
1594
- return reverseCustomMapping?.[locale] || locale;
1595
- }
1596
- //#endregion
1597
- //#region src/locales/resolveCanonicalLocale.ts
1598
- /**
1599
- * Resolves the canonical locale for a given locale.
1600
- * @param locale - The locale to resolve the canonical locale for
1601
- * @param customMapping - The custom mapping to use for resolving the canonical locale
1602
- * @returns The canonical locale
1603
- */
1604
- function _resolveCanonicalLocale(locale, customMapping) {
1605
- if (customMapping && shouldUseCanonicalLocale(locale, customMapping)) return customMapping[locale].code;
1606
- return locale;
1607
- }
1608
- //#endregion
1609
418
  //#region src/translate/uploadSourceFiles.ts
1610
419
  /**
1611
420
  * @internal
@@ -1933,158 +742,6 @@ async function _publishFiles(files, config) {
1933
742
  return await apiRequest(config, "/v2/project/files/publish", { body: { files } });
1934
743
  }
1935
744
  //#endregion
1936
- //#region src/LocaleConfig.ts
1937
- /**
1938
- * LocaleConfig is a client-safe locale and formatting helper.
1939
- *
1940
- * It intentionally does not store project IDs, API keys, runtime URLs, or any
1941
- * translation credentials. It only stores locale metadata needed to resolve
1942
- * aliases, choose formatting fallbacks, and format values with Intl.
1943
- */
1944
- var LocaleConfig = class {
1945
- constructor({ defaultLocale = "en", locales = [], customMapping } = {}) {
1946
- this.defaultLocale = defaultLocale;
1947
- this.locales = locales;
1948
- this.customMapping = customMapping;
1949
- }
1950
- get translationLocales() {
1951
- return this.locales.length ? this.locales : void 0;
1952
- }
1953
- resolveCanonicalLocaleList(locales) {
1954
- return locales.map((locale) => this.resolveCanonicalLocale(locale));
1955
- }
1956
- resolveCanonicalLocaleArgs(locales) {
1957
- return locales.map((locale) => Array.isArray(locale) ? this.resolveCanonicalLocaleList(locale) : this.resolveCanonicalLocale(locale));
1958
- }
1959
- toLocaleList(locales) {
1960
- return Array.isArray(locales) ? locales : [locales];
1961
- }
1962
- getFormattingLocales(targetLocale, locales) {
1963
- return (locales !== void 0 ? this.toLocaleList(locales) : [
1964
- targetLocale,
1965
- this.defaultLocale,
1966
- "en"
1967
- ]).filter((locale) => !!locale).map((locale) => this.resolveCanonicalLocale(locale));
1968
- }
1969
- formatNum(value, targetLocale, options = {}) {
1970
- const { locales, ...intlOptions } = options;
1971
- return _formatNum({
1972
- value,
1973
- locales: this.getFormattingLocales(targetLocale, locales),
1974
- options: intlOptions
1975
- });
1976
- }
1977
- formatDateTime(value, targetLocale, options = {}) {
1978
- const { locales, ...intlOptions } = options;
1979
- return _formatDateTime({
1980
- value,
1981
- locales: this.getFormattingLocales(targetLocale, locales),
1982
- options: intlOptions
1983
- });
1984
- }
1985
- formatCurrency(value, currency, targetLocale, options = {}) {
1986
- const { locales, ...intlOptions } = options;
1987
- return _formatCurrency({
1988
- value,
1989
- currency,
1990
- locales: this.getFormattingLocales(targetLocale, locales),
1991
- options: intlOptions
1992
- });
1993
- }
1994
- formatRelativeTime(value, unit, targetLocale, options = {}) {
1995
- const { locales, ...intlOptions } = options;
1996
- return _formatRelativeTime({
1997
- value,
1998
- unit,
1999
- locales: this.getFormattingLocales(targetLocale, locales),
2000
- options: intlOptions
2001
- });
2002
- }
2003
- formatRelativeTimeFromDate(date, targetLocale, options = {}) {
2004
- const { locales, baseDate, ...intlOptions } = options;
2005
- return _formatRelativeTimeFromDate({
2006
- date,
2007
- baseDate: baseDate ?? /* @__PURE__ */ new Date(),
2008
- locales: this.getFormattingLocales(targetLocale, locales),
2009
- options: intlOptions
2010
- });
2011
- }
2012
- formatCutoff(value, targetLocale, options = {}) {
2013
- const { locales, ...formatOptions } = options;
2014
- return _formatCutoff({
2015
- value,
2016
- locales: this.getFormattingLocales(targetLocale, locales),
2017
- options: formatOptions
2018
- });
2019
- }
2020
- formatMessage(message, targetLocale, options = {}) {
2021
- const { locales, variables, dataFormat } = options;
2022
- if (dataFormat === "STRING") return _formatMessageString(message);
2023
- return _formatMessageICU(message, this.getFormattingLocales(targetLocale, locales), variables);
2024
- }
2025
- formatList(array, targetLocale, options = {}) {
2026
- const { locales, ...intlOptions } = options;
2027
- return _formatList({
2028
- value: array,
2029
- locales: this.getFormattingLocales(targetLocale, locales),
2030
- options: intlOptions
2031
- });
2032
- }
2033
- formatListToParts(array, targetLocale, options = {}) {
2034
- const { locales, ...intlOptions } = options;
2035
- return _formatListToParts({
2036
- value: array,
2037
- locales: this.getFormattingLocales(targetLocale, locales),
2038
- options: intlOptions
2039
- });
2040
- }
2041
- getLocaleName(locale) {
2042
- return _getLocaleName(locale, this.defaultLocale, this.customMapping);
2043
- }
2044
- getLocaleEmoji(locale) {
2045
- return _getLocaleEmoji(locale, this.customMapping);
2046
- }
2047
- getLocaleProperties(locale) {
2048
- return _getLocaleProperties(locale, this.defaultLocale, this.customMapping);
2049
- }
2050
- requiresTranslation(targetLocale, sourceLocale = this.defaultLocale, approvedLocales = this.translationLocales) {
2051
- return _requiresTranslation(this.resolveCanonicalLocale(sourceLocale), this.resolveCanonicalLocale(targetLocale), approvedLocales ? this.resolveCanonicalLocaleList(approvedLocales) : void 0, this.customMapping);
2052
- }
2053
- determineLocale(locales, approvedLocales = this.locales) {
2054
- const approvedLocalePairs = approvedLocales.map((locale) => ({
2055
- locale,
2056
- canonicalLocale: this.resolveCanonicalLocale(locale)
2057
- }));
2058
- const resolvedLocale = _determineLocale(Array.isArray(locales) ? this.resolveCanonicalLocaleList(locales) : this.resolveCanonicalLocale(locales), approvedLocalePairs.map(({ canonicalLocale }) => canonicalLocale), this.customMapping);
2059
- if (!resolvedLocale) return void 0;
2060
- return approvedLocalePairs.find(({ canonicalLocale }) => canonicalLocale === resolvedLocale)?.locale || this.resolveAliasLocale(resolvedLocale);
2061
- }
2062
- getLocaleDirection(locale) {
2063
- return _getLocaleDirection(this.resolveCanonicalLocale(locale));
2064
- }
2065
- isValidLocale(locale) {
2066
- return _isValidLocale(locale, this.customMapping);
2067
- }
2068
- resolveCanonicalLocale(locale) {
2069
- return _resolveCanonicalLocale(locale, this.customMapping);
2070
- }
2071
- resolveAliasLocale(locale) {
2072
- return _resolveAliasLocale(locale, this.customMapping);
2073
- }
2074
- standardizeLocale(locale) {
2075
- return _standardizeLocale(locale);
2076
- }
2077
- isSameDialect(...locales) {
2078
- return _isSameDialect(...this.resolveCanonicalLocaleArgs(locales));
2079
- }
2080
- isSameLanguage(...locales) {
2081
- return _isSameLanguage(...this.resolveCanonicalLocaleArgs(locales));
2082
- }
2083
- isSupersetLocale(superLocale, subLocale) {
2084
- return _isSupersetLocale(this.resolveCanonicalLocale(superLocale), this.resolveCanonicalLocale(subLocale));
2085
- }
2086
- };
2087
- //#endregion
2088
745
  //#region src/index.ts
2089
746
  /**
2090
747
  * GT is the core driver for the General Translation library.
@@ -2101,7 +758,7 @@ var LocaleConfig = class {
2101
758
  * });
2102
759
  */
2103
760
  var GT = class {
2104
- /** Client-safe locale and formatting helpers */
761
+ /** Runtime-safe locale and formatting helpers */
2105
762
  get localeConfig() {
2106
763
  return this._localeConfig;
2107
764
  }
@@ -3064,72 +1721,6 @@ var GT = class {
3064
1721
  }
3065
1722
  };
3066
1723
  /**
3067
- * Formats a string with cutoff behavior, applying a terminator when the string exceeds the maximum character limit.
3068
- *
3069
- * This standalone function provides cutoff formatting functionality without requiring a GT instance.
3070
- * The locales parameter is required for proper terminator selection based on the target language.
3071
- *
3072
- * @param {string} value - The string value to format with cutoff behavior.
3073
- * @param {Object} [options] - Configuration options for cutoff formatting.
3074
- * @param {string | string[]} [options.locales] - The locales to use for terminator selection.
3075
- * @param {number} [options.maxChars] - The maximum number of characters to display.
3076
- * - Undefined values are treated as no cutoff.
3077
- * - Negative values follow .slice() behavior and terminator will be added before the value.
3078
- * - 0 will result in an empty string.
3079
- * - If cutoff results in an empty string, no terminator is added.
3080
- * @param {CutoffFormatStyle} [options.style='ellipsis'] - The style of the terminator.
3081
- * @param {string} [options.terminator] - Optional override the terminator to use.
3082
- * @param {string} [options.separator] - Optional override the separator to use between the terminator and the value.
3083
- * - If no terminator is provided, then separator is ignored.
3084
- * @returns {string} The formatted string with terminator applied if cutoff occurs.
3085
- *
3086
- * @example
3087
- * formatCutoff('Hello, world!', { locales: 'en-US', maxChars: 8 });
3088
- * // Returns: 'Hello, w...'
3089
- *
3090
- * @example
3091
- * formatCutoff('Hello, world!', { locales: 'en-US', maxChars: -3 });
3092
- * // Returns: '...ld!'
3093
- *
3094
- * @example
3095
- * formatCutoff('Very long text that needs cutting', {
3096
- * locales: 'en-US',
3097
- * maxChars: 15,
3098
- * style: 'ellipsis',
3099
- * separator: ' '
3100
- * });
3101
- * // Returns: 'Very long text ...'
3102
- */
3103
- function formatCutoff(value, options) {
3104
- return _formatCutoff({
3105
- value,
3106
- locales: options?.locales,
3107
- options
3108
- });
3109
- }
3110
- /**
3111
- * Formats a message according to the specified locales and options.
3112
- *
3113
- * @param {string} message - The message to format.
3114
- * @param {string | string[]} [locales='en'] - The locales to use for formatting.
3115
- * @param {FormatVariables} [variables={}] - The variables to use for formatting.
3116
- * @param {StringFormat} [dataFormat='ICU'] - The format of the message. (When STRING, the message is returned as is)
3117
- * @returns {string} The formatted message.
3118
- *
3119
- * @example
3120
- * formatMessage('Hello {name}', { name: 'John' });
3121
- * // Returns: "Hello John"
3122
- *
3123
- * formatMessage('Hello {name}', { name: 'John' }, { locales: ['fr'] });
3124
- * // Returns: "Bonjour John"
3125
- */
3126
- function formatMessage(message, options) {
3127
- switch (options?.dataFormat) {
3128
- case "STRING": return _formatMessageString(message);
3129
- default: return _formatMessageICU(message, options?.locales, options?.variables);
3130
- }
3131
- }
3132
- /**
3133
1724
  * Formats a number according to the specified locales and options.
3134
1725
  * @param {Object} params - The parameters for the number formatting.
3135
1726
  * @param {number} params.value - The number to format.
@@ -3373,15 +1964,6 @@ function getLocaleDirection(locale) {
3373
1964
  return _getLocaleDirection(locale);
3374
1965
  }
3375
1966
  /**
3376
- * Checks if a given BCP 47 locale code is valid.
3377
- * @param {string} locale - The BCP 47 locale code to validate.
3378
- * @param {CustomMapping} [customMapping] - The custom mapping to use for validation.
3379
- * @returns {boolean} True if the BCP 47 code is valid, false otherwise.
3380
- */
3381
- function isValidLocale(locale, customMapping) {
3382
- return _isValidLocale(locale, customMapping);
3383
- }
3384
- /**
3385
1967
  * Resolves the alias locale for a given locale.
3386
1968
  * @param {string} locale - The locale to resolve the alias locale for
3387
1969
  * @param {CustomMapping} [customMapping] - The custom mapping to use for resolving the alias locale
@@ -3391,23 +1973,6 @@ function resolveAliasLocale(locale, customMapping) {
3391
1973
  return _resolveAliasLocale(locale, customMapping);
3392
1974
  }
3393
1975
  /**
3394
- * Resolves the canonical locale for a given locale.
3395
- * @param {string} locale - The locale to resolve the canonical locale for
3396
- * @param {CustomMapping} [customMapping] - The custom mapping to use for resolving the canonical locale
3397
- * @returns {string} The canonical locale
3398
- */
3399
- function resolveCanonicalLocale(locale, customMapping) {
3400
- return _resolveCanonicalLocale(locale, customMapping);
3401
- }
3402
- /**
3403
- * Standardizes a BCP 47 locale code to ensure correct formatting.
3404
- * @param {string} locale - The BCP 47 locale code to standardize.
3405
- * @returns {string} The standardized BCP 47 locale code or an empty string if it is an invalid code.
3406
- */
3407
- function standardizeLocale(locale) {
3408
- return _standardizeLocale(locale);
3409
- }
3410
- /**
3411
1976
  * Checks if multiple BCP 47 locale codes represent the same dialect.
3412
1977
  * @param {string[]} locales - The BCP 47 locale codes to compare.
3413
1978
  * @returns {boolean} True if all BCP 47 codes represent the same dialect, false otherwise.