generaltranslation 8.2.13 → 8.2.14

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (127) hide show
  1. package/CHANGELOG.md +11 -0
  2. package/dist/{ApiError-IYfaOR30.mjs → ApiError-0DxxIHLp.mjs} +1 -1
  3. package/dist/{ApiError-CZ45tkW6.cjs.map → ApiError-0DxxIHLp.mjs.map} +1 -1
  4. package/dist/{ApiError-CZ45tkW6.cjs → ApiError-D-IBuHj6.cjs} +1 -1
  5. package/dist/{ApiError-IYfaOR30.mjs.map → ApiError-D-IBuHj6.cjs.map} +1 -1
  6. package/dist/LocaleConfig.d.ts +1 -59
  7. package/dist/LocaleConfig.js +1 -225
  8. package/dist/{base64-2fu94Klt.cjs → base64-C6BHySOc.cjs} +17 -1
  9. package/dist/base64-C6BHySOc.cjs.map +1 -0
  10. package/dist/{base64-DH0STixb.mjs → base64-CWITCfhU.mjs} +6 -2
  11. package/dist/base64-CWITCfhU.mjs.map +1 -0
  12. package/dist/core.cjs +9 -8
  13. package/dist/core.d.cts +1 -2
  14. package/dist/core.d.mts +1 -2
  15. package/dist/core.d.ts +1 -128
  16. package/dist/core.js +1 -137
  17. package/dist/core.mjs +2 -2
  18. package/dist/derive/indexVars.d.ts +1 -1
  19. package/dist/errors.cjs +1 -1
  20. package/dist/errors.mjs +1 -1
  21. package/dist/id/types.d.ts +1 -1
  22. package/dist/{id-CyiXsQrY.cjs → id-C2orn1MA.cjs} +2 -2
  23. package/dist/{id-CyiXsQrY.cjs.map → id-C2orn1MA.cjs.map} +1 -1
  24. package/dist/{id-DbD7K-HL.mjs → id-DEaFhGqX.mjs} +2 -2
  25. package/dist/{id-DbD7K-HL.mjs.map → id-DEaFhGqX.mjs.map} +1 -1
  26. package/dist/id.cjs +1 -1
  27. package/dist/id.d.cts +1 -1
  28. package/dist/id.d.mts +1 -1
  29. package/dist/id.mjs +1 -1
  30. package/dist/index.cjs +368 -385
  31. package/dist/index.cjs.map +1 -1
  32. package/dist/index.d.cts +4 -242
  33. package/dist/index.d.mts +4 -242
  34. package/dist/index.d.ts +5 -238
  35. package/dist/index.js +3 -322
  36. package/dist/index.mjs +215 -352
  37. package/dist/index.mjs.map +1 -1
  38. package/dist/internal.cjs +6 -6
  39. package/dist/internal.cjs.map +1 -1
  40. package/dist/internal.d.cts +6 -5
  41. package/dist/internal.d.mts +6 -5
  42. package/dist/internal.mjs +4 -4
  43. package/dist/internal.mjs.map +1 -1
  44. package/dist/{isVariable-B08mggBy.cjs → isVariable-Ba1gLXdB.cjs} +1 -1
  45. package/dist/{isVariable-B08mggBy.cjs.map → isVariable-Ba1gLXdB.cjs.map} +1 -1
  46. package/dist/{isVariable-CYsKFHvR.mjs → isVariable-fAKEB7gF.mjs} +1 -1
  47. package/dist/{isVariable-CYsKFHvR.mjs.map → isVariable-fAKEB7gF.mjs.map} +1 -1
  48. package/dist/locales/getPluralForm.js +2 -2
  49. package/dist/logging/logger.d.ts +0 -3
  50. package/dist/logging/logger.js +0 -3
  51. package/dist/{types-AHtYZIP-.d.mts → types-73XFwmhH.d.mts} +7 -106
  52. package/dist/{types-Bf8_Apq_.d.cts → types-YrrGRHBP.d.cts} +7 -106
  53. package/dist/types-dir/api/enqueueEntries.d.ts +1 -1
  54. package/dist/types-dir/api/enqueueFiles.d.ts +1 -1
  55. package/dist/types-dir/api/fetchTranslations.d.ts +1 -1
  56. package/dist/types-dir/api/file.d.ts +1 -1
  57. package/dist/types-dir/api/translate.d.ts +1 -1
  58. package/dist/types-dir/api/uploadFiles.d.ts +1 -1
  59. package/dist/types.cjs +7 -16
  60. package/dist/types.d.cts +2 -2
  61. package/dist/types.d.mts +2 -2
  62. package/dist/types.d.ts +10 -12
  63. package/dist/types.js +1 -2
  64. package/dist/types.mjs +1 -15
  65. package/package.json +3 -2
  66. package/dist/IntlCache-CAW8tKhd.cjs +0 -212
  67. package/dist/IntlCache-CAW8tKhd.cjs.map +0 -1
  68. package/dist/IntlCache-WZk0rKvj.mjs +0 -195
  69. package/dist/IntlCache-WZk0rKvj.mjs.map +0 -1
  70. package/dist/base64-2fu94Klt.cjs.map +0 -1
  71. package/dist/base64-DH0STixb.mjs.map +0 -1
  72. package/dist/cache/IntlCache.d.ts +0 -26
  73. package/dist/cache/IntlCache.js +0 -84
  74. package/dist/cache/types.d.ts +0 -32
  75. package/dist/cache/types.js +0 -1
  76. package/dist/core-7RP541eY.cjs +0 -1677
  77. package/dist/core-7RP541eY.cjs.map +0 -1
  78. package/dist/core-I9pWGafA.d.mts +0 -209
  79. package/dist/core-TLJoDpJP.d.cts +0 -209
  80. package/dist/core-isLphYAZ.mjs +0 -1498
  81. package/dist/core-isLphYAZ.mjs.map +0 -1
  82. package/dist/errors/formattingErrors.d.ts +0 -1
  83. package/dist/errors/formattingErrors.js +0 -3
  84. package/dist/formatting/custom-formats/CutoffFormat/CutoffFormat.d.ts +0 -59
  85. package/dist/formatting/custom-formats/CutoffFormat/CutoffFormat.js +0 -147
  86. package/dist/formatting/custom-formats/CutoffFormat/constants.d.ts +0 -4
  87. package/dist/formatting/custom-formats/CutoffFormat/constants.js +0 -30
  88. package/dist/formatting/custom-formats/CutoffFormat/types.d.ts +0 -48
  89. package/dist/formatting/custom-formats/CutoffFormat/types.js +0 -2
  90. package/dist/formatting/format.d.ts +0 -1
  91. package/dist/formatting/format.js +0 -257
  92. package/dist/locales/customLocaleMapping.d.ts +0 -11
  93. package/dist/locales/customLocaleMapping.js +0 -23
  94. package/dist/locales/determineLocale.d.ts +0 -1
  95. package/dist/locales/determineLocale.js +0 -72
  96. package/dist/locales/getLocaleDirection.d.ts +0 -1
  97. package/dist/locales/getLocaleDirection.js +0 -89
  98. package/dist/locales/getLocaleEmoji.d.ts +0 -2
  99. package/dist/locales/getLocaleEmoji.js +0 -319
  100. package/dist/locales/getLocaleName.d.ts +0 -1
  101. package/dist/locales/getLocaleName.js +0 -45
  102. package/dist/locales/getLocaleProperties.d.ts +0 -32
  103. package/dist/locales/getLocaleProperties.js +0 -220
  104. package/dist/locales/getRegionProperties.d.ts +0 -7
  105. package/dist/locales/getRegionProperties.js +0 -61
  106. package/dist/locales/isSameDialect.d.ts +0 -1
  107. package/dist/locales/isSameDialect.js +0 -41
  108. package/dist/locales/isSameLanguage.d.ts +0 -1
  109. package/dist/locales/isSameLanguage.js +0 -20
  110. package/dist/locales/isSupersetLocale.d.ts +0 -1
  111. package/dist/locales/isSupersetLocale.js +0 -22
  112. package/dist/locales/isValidLocale.d.ts +0 -1
  113. package/dist/locales/isValidLocale.js +0 -75
  114. package/dist/locales/requiresTranslation.d.ts +0 -1
  115. package/dist/locales/requiresTranslation.js +0 -32
  116. package/dist/locales/resolveAliasLocale.d.ts +0 -8
  117. package/dist/locales/resolveAliasLocale.js +0 -21
  118. package/dist/locales/resolveCanonicalLocale.d.ts +0 -8
  119. package/dist/locales/resolveCanonicalLocale.js +0 -13
  120. package/dist/logging/warnings.d.ts +0 -2
  121. package/dist/logging/warnings.js +0 -2
  122. package/dist/types-dir/jsx/content.d.ts +0 -61
  123. package/dist/types-dir/jsx/content.js +0 -11
  124. package/dist/types-dir/jsx/variables.d.ts +0 -9
  125. package/dist/types-dir/jsx/variables.js +0 -1
  126. package/dist/types.cjs.map +0 -1
  127. package/dist/types.mjs.map +0 -1
@@ -1,1677 +0,0 @@
1
- const require_IntlCache = require("./IntlCache-CAW8tKhd.cjs");
2
- let intl_messageformat = require("intl-messageformat");
3
- //#region src/locales/isValidLocale.ts
4
- const scriptExceptions = [
5
- "Cham",
6
- "Jamo",
7
- "Kawi",
8
- "Lisu",
9
- "Toto",
10
- "Thai"
11
- ];
12
- const isCustomLanguage = (language) => {
13
- return language >= "qaa" && language <= "qtz";
14
- };
15
- /**
16
- * Checks if a given BCP 47 language code is valid.
17
- * @param {string} code - The BCP 47 language code to validate.
18
- * @param {CustomMapping} [customMapping] - The custom mapping to use for validation.
19
- * @returns {boolean} True if the BCP 47 code is valid, false otherwise.
20
- * @internal
21
- */
22
- const _isValidLocale = (locale, customMapping) => {
23
- if (customMapping?.[locale] && typeof customMapping[locale] === "object" && "code" in customMapping[locale] && customMapping[locale].code) locale = customMapping[locale].code;
24
- try {
25
- const { language, region, script } = require_IntlCache.intlCache.get("Locale", locale);
26
- if (locale.split("-").length !== (() => {
27
- let partCount = 1;
28
- if (region) partCount += 1;
29
- if (script) partCount += 1;
30
- return partCount;
31
- })()) return false;
32
- if (require_IntlCache.intlCache.get("DisplayNames", ["en"], { type: "language" }).of(language) === language && !isCustomLanguage(language)) return false;
33
- if (region) {
34
- if (require_IntlCache.intlCache.get("DisplayNames", ["en"], { type: "region" }).of(region) === region) return false;
35
- }
36
- if (script) {
37
- if (require_IntlCache.intlCache.get("DisplayNames", ["en"], { type: "script" }).of(script) === script && !scriptExceptions.includes(script)) return false;
38
- }
39
- return true;
40
- } catch {
41
- return false;
42
- }
43
- };
44
- /**
45
- * Standardizes a BCP 47 locale to ensure correct formatting.
46
- * @param {string} locale - The BCP 47 locale to standardize.
47
- * @returns {string} The standardized BCP 47 locale, or the input string if it cannot be standardized.
48
- * @internal
49
- */
50
- const _standardizeLocale = (locale) => {
51
- try {
52
- return Intl.getCanonicalLocales(locale)[0];
53
- } catch {
54
- return locale;
55
- }
56
- };
57
- //#endregion
58
- //#region src/locales/isSameDialect.ts
59
- function checkTwoLocalesAreSameDialect(codeA, codeB) {
60
- const { language: languageA, region: regionA, script: scriptA } = require_IntlCache.intlCache.get("Locale", codeA);
61
- const { language: languageB, region: regionB, script: scriptB } = require_IntlCache.intlCache.get("Locale", codeB);
62
- if (languageA !== languageB) return false;
63
- if (regionA && regionB && regionA !== regionB) return false;
64
- if (scriptA && scriptB && scriptA !== scriptB) return false;
65
- return true;
66
- }
67
- /**
68
- * Test two or more language codes to determine if they are exactly the same
69
- * e.g. "en-US" and "en" would be exactly the same.
70
- * "en-GB" and "en" would be exactly the same.
71
- * "en-GB" and "en-US" would be different.
72
- * @internal
73
- */
74
- function _isSameDialect(...locales) {
75
- try {
76
- const flattenedCodes = locales.flat().map(_standardizeLocale);
77
- 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;
78
- return true;
79
- } catch (error) {
80
- console.error(error);
81
- return false;
82
- }
83
- }
84
- //#endregion
85
- //#region src/locales/isSameLanguage.ts
86
- /**
87
- * @internal
88
- */
89
- function _isSameLanguage(...locales) {
90
- try {
91
- const languages = locales.flat().map((locale) => require_IntlCache.intlCache.get("Locale", locale).language);
92
- return languages.every((language) => language === languages[0]);
93
- } catch (error) {
94
- console.error(error);
95
- return false;
96
- }
97
- }
98
- //#endregion
99
- //#region src/locales/requiresTranslation.ts
100
- /**
101
- * Given a target locale and a source locale, determines whether a translation is required
102
- * If the target locale and the source locale are the same, returns false, otherwise returns true
103
- * If a translation is not possible due to the target locale being outside of the optional approvedLanguages scope, also returns false
104
- * @internal
105
- */
106
- function _requiresTranslation(sourceLocale, targetLocale, approvedLocales, customMapping) {
107
- if (!_isValidLocale(sourceLocale, customMapping) || !_isValidLocale(targetLocale, customMapping) || approvedLocales && approvedLocales.some((approvedLocale) => !_isValidLocale(approvedLocale, customMapping))) return false;
108
- if (_isSameDialect(sourceLocale, targetLocale)) return false;
109
- if (approvedLocales && !approvedLocales.some((approvedLocale) => _isSameLanguage(targetLocale, approvedLocale))) return false;
110
- return true;
111
- }
112
- //#endregion
113
- //#region src/locales/customLocaleMapping.ts
114
- const getCustomProperty = (customMapping, locale, property) => {
115
- if (customMapping?.[locale]) {
116
- if (typeof customMapping[locale] === "string") return property === "name" ? customMapping[locale] : void 0;
117
- return customMapping[locale][property];
118
- }
119
- };
120
- /**
121
- * Checks if a given locale should use the canonical locale.
122
- * @param locale - The locale to check if it should use the canonical locale
123
- * @param customMapping - The custom mapping to use for checking if the locale should use the canonical locale
124
- * @returns True if the locale should use the canonical locale, false otherwise
125
- */
126
- const shouldUseCanonicalLocale = (locale, customMapping) => {
127
- return !!(customMapping?.[locale] && typeof customMapping[locale] === "object" && "code" in customMapping[locale] && customMapping[locale].code && _isValidLocale(customMapping[locale].code));
128
- };
129
- //#endregion
130
- //#region src/locales/getLocaleEmoji.ts
131
- /**
132
- * @internal
133
- */
134
- function _getLocaleEmoji(locale, customMapping) {
135
- const aliasedLocale = locale;
136
- if (customMapping && shouldUseCanonicalLocale(locale, customMapping)) locale = customMapping[locale].code;
137
- try {
138
- const standardizedLocale = _standardizeLocale(locale);
139
- const localeObject = require_IntlCache.intlCache.get("Locale", standardizedLocale);
140
- const { language, region } = localeObject;
141
- if (customMapping) for (const l of [
142
- aliasedLocale,
143
- locale,
144
- standardizedLocale,
145
- language
146
- ]) {
147
- const customEmoji = getCustomProperty(customMapping, l, "emoji");
148
- if (customEmoji) return customEmoji;
149
- }
150
- const regionEmoji = region && getSupportedRegionEmoji(region);
151
- if (regionEmoji) return regionEmoji;
152
- const extrapolated = localeObject.maximize();
153
- return exceptions[extrapolated.language] || getRegionEmoji(extrapolated.region || "");
154
- } catch {
155
- return defaultEmoji;
156
- }
157
- }
158
- const europeAfricaGlobe = "🌍";
159
- const asiaAustraliaGlobe = "🌏";
160
- const defaultEmoji = europeAfricaGlobe;
161
- const exceptions = {
162
- ca: europeAfricaGlobe,
163
- eu: europeAfricaGlobe,
164
- ku: europeAfricaGlobe,
165
- bo: asiaAustraliaGlobe,
166
- ug: asiaAustraliaGlobe,
167
- gd: "🏴󠁧󠁢󠁳󠁣󠁴󠁿",
168
- cy: "🏴󠁧󠁢󠁷󠁬󠁳󠁿",
169
- gv: "🇮🇲",
170
- grc: "🏺"
171
- };
172
- const specialRegionEmojis = {
173
- EU: "🇪🇺",
174
- "419": "🌎"
175
- };
176
- const flagRegions = new Set([
177
- "AF",
178
- "AX",
179
- "AL",
180
- "DZ",
181
- "AS",
182
- "AD",
183
- "AO",
184
- "AI",
185
- "AQ",
186
- "AG",
187
- "AR",
188
- "AM",
189
- "AW",
190
- "AU",
191
- "AT",
192
- "AZ",
193
- "BS",
194
- "BH",
195
- "BD",
196
- "BB",
197
- "BY",
198
- "BE",
199
- "BZ",
200
- "BJ",
201
- "BM",
202
- "BT",
203
- "BO",
204
- "BQ",
205
- "BA",
206
- "BW",
207
- "BV",
208
- "BR",
209
- "IO",
210
- "BN",
211
- "BG",
212
- "BF",
213
- "BI",
214
- "CV",
215
- "KH",
216
- "CM",
217
- "CA",
218
- "KY",
219
- "CF",
220
- "TD",
221
- "CL",
222
- "CN",
223
- "CX",
224
- "CC",
225
- "CO",
226
- "KM",
227
- "CD",
228
- "CG",
229
- "CK",
230
- "CR",
231
- "CI",
232
- "HR",
233
- "CU",
234
- "CW",
235
- "CY",
236
- "CZ",
237
- "DK",
238
- "DJ",
239
- "DM",
240
- "DO",
241
- "EC",
242
- "EG",
243
- "SV",
244
- "GQ",
245
- "ER",
246
- "EE",
247
- "SZ",
248
- "ET",
249
- "FK",
250
- "FO",
251
- "FJ",
252
- "FI",
253
- "FR",
254
- "GF",
255
- "PF",
256
- "TF",
257
- "GA",
258
- "GM",
259
- "GE",
260
- "DE",
261
- "GH",
262
- "GI",
263
- "GR",
264
- "GL",
265
- "GD",
266
- "GP",
267
- "GU",
268
- "GT",
269
- "GG",
270
- "GN",
271
- "GW",
272
- "GY",
273
- "HT",
274
- "HM",
275
- "VA",
276
- "HN",
277
- "HK",
278
- "HU",
279
- "IS",
280
- "IN",
281
- "ID",
282
- "IR",
283
- "IQ",
284
- "IE",
285
- "IM",
286
- "IL",
287
- "IT",
288
- "JM",
289
- "JP",
290
- "JE",
291
- "JO",
292
- "KZ",
293
- "KE",
294
- "KI",
295
- "KP",
296
- "KR",
297
- "KW",
298
- "KG",
299
- "LA",
300
- "LV",
301
- "LB",
302
- "LS",
303
- "LR",
304
- "LY",
305
- "LI",
306
- "LT",
307
- "LU",
308
- "MO",
309
- "MG",
310
- "MW",
311
- "MY",
312
- "MV",
313
- "ML",
314
- "MT",
315
- "MH",
316
- "MQ",
317
- "MR",
318
- "MU",
319
- "YT",
320
- "MX",
321
- "FM",
322
- "MD",
323
- "MC",
324
- "MN",
325
- "ME",
326
- "MS",
327
- "MA",
328
- "MZ",
329
- "MM",
330
- "NA",
331
- "NR",
332
- "NP",
333
- "NL",
334
- "NC",
335
- "NZ",
336
- "NI",
337
- "NE",
338
- "NG",
339
- "NU",
340
- "NF",
341
- "MK",
342
- "MP",
343
- "NO",
344
- "OM",
345
- "PK",
346
- "PW",
347
- "PS",
348
- "PA",
349
- "PG",
350
- "PY",
351
- "PE",
352
- "PH",
353
- "PN",
354
- "PL",
355
- "PT",
356
- "PR",
357
- "QA",
358
- "RE",
359
- "RO",
360
- "RU",
361
- "RW",
362
- "BL",
363
- "SH",
364
- "KN",
365
- "LC",
366
- "MF",
367
- "PM",
368
- "VC",
369
- "WS",
370
- "SM",
371
- "ST",
372
- "SA",
373
- "SN",
374
- "RS",
375
- "SC",
376
- "SL",
377
- "SG",
378
- "SX",
379
- "SK",
380
- "SI",
381
- "SB",
382
- "SO",
383
- "ZA",
384
- "GS",
385
- "SS",
386
- "ES",
387
- "LK",
388
- "SD",
389
- "SR",
390
- "SJ",
391
- "SE",
392
- "CH",
393
- "SY",
394
- "TW",
395
- "TJ",
396
- "TZ",
397
- "TH",
398
- "TL",
399
- "TG",
400
- "TK",
401
- "TO",
402
- "TT",
403
- "TN",
404
- "TR",
405
- "TM",
406
- "TC",
407
- "TV",
408
- "UG",
409
- "UA",
410
- "AE",
411
- "GB",
412
- "US",
413
- "UM",
414
- "UY",
415
- "UZ",
416
- "VU",
417
- "VE",
418
- "VN",
419
- "VG",
420
- "VI",
421
- "WF",
422
- "EH",
423
- "YE",
424
- "ZM",
425
- "ZW"
426
- ]);
427
- const regionalIndicatorOffset = 127462 - "A".charCodeAt(0);
428
- function getRegionEmoji(region) {
429
- return getSupportedRegionEmoji(region) || "🌍";
430
- }
431
- function getSupportedRegionEmoji(region) {
432
- const normalizedRegion = region.toUpperCase();
433
- const specialEmoji = specialRegionEmojis[normalizedRegion];
434
- if (specialEmoji) return specialEmoji;
435
- if (!flagRegions.has(normalizedRegion)) return void 0;
436
- return String.fromCodePoint(normalizedRegion.charCodeAt(0) + regionalIndicatorOffset, normalizedRegion.charCodeAt(1) + regionalIndicatorOffset);
437
- }
438
- //#endregion
439
- //#region src/locales/getLocaleProperties.ts
440
- /**
441
- * Creates a set of custom locale properties from a custom mapping.
442
- *
443
- * @param lArray - An array of locale codes to search for in the custom mapping.
444
- * @param customMapping - Optional custom mapping of locale codes to names.
445
- * @returns A partial set of locale properties, or undefined if no custom mapping is provided.
446
- */
447
- function createCustomLocaleProperties(lArray, customMapping) {
448
- if (customMapping) {
449
- let merged = {};
450
- for (const l of lArray) {
451
- const value = customMapping[l];
452
- if (value) {
453
- if (typeof value === "string") merged.name ||= value;
454
- else if (value) merged = {
455
- ...value,
456
- ...merged
457
- };
458
- }
459
- }
460
- return merged;
461
- }
462
- }
463
- /**
464
- * @internal
465
- */
466
- function _getLocaleProperties(locale, defaultLocale = "en", customMapping) {
467
- const aliasedLocale = locale;
468
- if (customMapping && shouldUseCanonicalLocale(locale, customMapping)) locale = customMapping[locale].code;
469
- defaultLocale ||= "en";
470
- try {
471
- const standardizedLocale = _standardizeLocale(locale);
472
- const localeObject = require_IntlCache.intlCache.get("Locale", locale);
473
- const languageCode = localeObject.language;
474
- const customLocaleProperties = createCustomLocaleProperties([
475
- aliasedLocale,
476
- locale,
477
- standardizedLocale,
478
- languageCode
479
- ], customMapping);
480
- const baseRegion = localeObject.region;
481
- const maximizedLocale = localeObject.maximize();
482
- const maximizedCode = maximizedLocale.toString();
483
- const regionCode = localeObject.region || customLocaleProperties?.regionCode || maximizedLocale.region || "";
484
- const scriptCode = localeObject.script || customLocaleProperties?.scriptCode || maximizedLocale.script || "";
485
- const minimizedCode = localeObject.minimize().toString();
486
- const defaultLanguageOrder = [
487
- defaultLocale,
488
- locale,
489
- "en"
490
- ];
491
- const nativeLanguageOrder = [
492
- locale,
493
- defaultLocale,
494
- "en"
495
- ];
496
- const languageNames = require_IntlCache.intlCache.get("DisplayNames", defaultLanguageOrder, { type: "language" });
497
- const nativeLanguageNames = require_IntlCache.intlCache.get("DisplayNames", nativeLanguageOrder, { type: "language" });
498
- const customName = customLocaleProperties?.name;
499
- const customNativeName = customLocaleProperties?.nativeName || customLocaleProperties?.name;
500
- const name = customName || languageNames.of(locale) || locale;
501
- const nativeName = customNativeName || nativeLanguageNames.of(locale) || locale;
502
- const maximizedName = customLocaleProperties?.maximizedName || customName || languageNames.of(maximizedCode) || locale;
503
- const nativeMaximizedName = customLocaleProperties?.nativeMaximizedName || customNativeName || nativeLanguageNames.of(maximizedCode) || locale;
504
- const minimizedName = customLocaleProperties?.minimizedName || customName || languageNames.of(minimizedCode) || locale;
505
- const nativeMinimizedName = customLocaleProperties?.nativeMinimizedName || customNativeName || nativeLanguageNames.of(minimizedCode) || locale;
506
- const languageName = customLocaleProperties?.languageName || customName || languageNames.of(languageCode) || locale;
507
- const nativeLanguageName = customLocaleProperties?.nativeLanguageName || customNativeName || nativeLanguageNames.of(languageCode) || locale;
508
- const nameWithRegionCode = customLocaleProperties?.nameWithRegionCode || baseRegion ? `${languageName} (${baseRegion})` : name;
509
- const nativeNameWithRegionCode = customLocaleProperties?.nativeNameWithRegionCode || (baseRegion ? `${nativeLanguageName} (${baseRegion})` : nativeName) || nameWithRegionCode;
510
- const regionNames = require_IntlCache.intlCache.get("DisplayNames", defaultLanguageOrder, { type: "region" });
511
- const nativeRegionNames = require_IntlCache.intlCache.get("DisplayNames", nativeLanguageOrder, { type: "region" });
512
- const regionName = customLocaleProperties?.regionName || (regionCode ? regionNames.of(regionCode) : "") || "";
513
- const nativeRegionName = customLocaleProperties?.nativeRegionName || (regionCode ? nativeRegionNames.of(regionCode) : "") || "";
514
- const scriptNames = require_IntlCache.intlCache.get("DisplayNames", defaultLanguageOrder, { type: "script" });
515
- const nativeScriptNames = require_IntlCache.intlCache.get("DisplayNames", nativeLanguageOrder, { type: "script" });
516
- return {
517
- code: standardizedLocale,
518
- name,
519
- nativeName,
520
- maximizedCode,
521
- maximizedName,
522
- nativeMaximizedName,
523
- minimizedCode,
524
- minimizedName,
525
- nativeMinimizedName,
526
- languageCode,
527
- languageName,
528
- nativeLanguageName,
529
- nameWithRegionCode,
530
- nativeNameWithRegionCode,
531
- regionCode,
532
- regionName,
533
- nativeRegionName,
534
- scriptCode,
535
- scriptName: customLocaleProperties?.scriptName || (scriptCode ? scriptNames.of(scriptCode) : "") || "",
536
- nativeScriptName: customLocaleProperties?.nativeScriptName || (scriptCode ? nativeScriptNames.of(scriptCode) : "") || "",
537
- emoji: customLocaleProperties?.emoji || _getLocaleEmoji(standardizedLocale, customMapping)
538
- };
539
- } catch {
540
- let code = _isValidLocale(locale) ? _standardizeLocale(locale) : locale;
541
- const codeParts = code?.split("-");
542
- let languageCode = codeParts?.[0] || code || "";
543
- let regionCode = codeParts.length > 2 ? codeParts?.[2] : codeParts?.[1] || "";
544
- let scriptCode = codeParts?.[3] || "";
545
- const customLocaleProperties = createCustomLocaleProperties([code, languageCode], customMapping);
546
- code = customLocaleProperties?.code || code;
547
- const name = customLocaleProperties?.name || code;
548
- const nativeName = customLocaleProperties?.nativeName || name;
549
- const maximizedCode = customLocaleProperties?.maximizedCode || code;
550
- const maximizedName = customLocaleProperties?.maximizedName || name;
551
- const nativeMaximizedName = customLocaleProperties?.nativeMaximizedName || nativeName;
552
- const minimizedCode = customLocaleProperties?.minimizedCode || code;
553
- const minimizedName = customLocaleProperties?.minimizedName || name;
554
- const nativeMinimizedName = customLocaleProperties?.nativeMinimizedName || nativeName;
555
- languageCode = customLocaleProperties?.languageCode || languageCode;
556
- const languageName = customLocaleProperties?.languageName || name;
557
- const nativeLanguageName = customLocaleProperties?.nativeLanguageName || nativeName;
558
- regionCode = customLocaleProperties?.regionCode || regionCode;
559
- const regionName = customLocaleProperties?.regionName || "";
560
- const nativeRegionName = customLocaleProperties?.nativeRegionName || "";
561
- scriptCode = customLocaleProperties?.scriptCode || scriptCode;
562
- const scriptName = customLocaleProperties?.scriptName || "";
563
- const nativeScriptName = customLocaleProperties?.nativeScriptName || "";
564
- const nameWithRegionCode = customLocaleProperties?.nameWithRegionCode || (regionName ? `${languageName} (${regionName})` : name);
565
- const nativeNameWithRegionCode = customLocaleProperties?.nativeNameWithRegionCode || (nativeRegionName ? `${nativeLanguageName} (${nativeRegionName})` : nativeName);
566
- const emoji = customLocaleProperties?.emoji || "🌍";
567
- return {
568
- code,
569
- name,
570
- nativeName,
571
- maximizedCode,
572
- maximizedName,
573
- nativeMaximizedName,
574
- minimizedCode,
575
- minimizedName,
576
- nativeMinimizedName,
577
- languageCode,
578
- languageName,
579
- nativeLanguageName,
580
- nameWithRegionCode,
581
- nativeNameWithRegionCode,
582
- regionCode,
583
- regionName,
584
- nativeRegionName,
585
- scriptCode,
586
- scriptName,
587
- nativeScriptName,
588
- emoji
589
- };
590
- }
591
- }
592
- //#endregion
593
- //#region src/locales/determineLocale.ts
594
- /**
595
- * Given a list of locales and a list of approved locales, sorted in preference order
596
- * Determines which locale is the best match among the approved locales, prioritizing exact matches and falling back to dialects of the same language
597
- * @internal
598
- */
599
- function _determineLocale(locales, approvedLocales, customMapping) {
600
- if (typeof locales === "string") locales = [locales];
601
- locales = locales.filter((locale) => _isValidLocale(locale, customMapping)).map(_standardizeLocale);
602
- approvedLocales = approvedLocales.filter((locale) => _isValidLocale(locale, customMapping)).map(_standardizeLocale);
603
- for (const locale of locales) {
604
- const candidates = approvedLocales.filter((approvedLocale) => _isSameLanguage(locale, approvedLocale));
605
- const getMatchingCode = ({ locale, languageCode, minimizedCode, regionCode, scriptCode }) => {
606
- const locales = [
607
- locale,
608
- `${languageCode}-${regionCode}`,
609
- `${languageCode}-${scriptCode}`,
610
- minimizedCode
611
- ];
612
- for (const l of locales) if (candidates.includes(l)) return l;
613
- return null;
614
- };
615
- const { languageCode, ...codes } = _getLocaleProperties(locale);
616
- const matchingCode = getMatchingCode({
617
- locale,
618
- languageCode,
619
- ...codes
620
- }) || getMatchingCode({
621
- locale: languageCode,
622
- ..._getLocaleProperties(languageCode)
623
- });
624
- if (matchingCode) return matchingCode;
625
- }
626
- }
627
- //#endregion
628
- //#region src/logging/logger.ts
629
- const LOG_LEVELS = {
630
- debug: 0,
631
- info: 1,
632
- warn: 2,
633
- error: 3,
634
- off: 4
635
- };
636
- const LOG_COLORS = {
637
- debug: "\x1B[36m",
638
- info: "\x1B[32m",
639
- warn: "\x1B[33m",
640
- error: "\x1B[31m",
641
- off: ""
642
- };
643
- const RESET_COLOR = "\x1B[0m";
644
- /**
645
- * Get the configured log level from environment variable or default to 'warn'
646
- */
647
- function getConfiguredLogLevel() {
648
- if (typeof process !== "undefined" && process.env?._GT_LOG_LEVEL) {
649
- const envLevel = process.env._GT_LOG_LEVEL.toLowerCase();
650
- if (envLevel in LOG_LEVELS) return envLevel;
651
- }
652
- return "warn";
653
- }
654
- /**
655
- * Console log handler that outputs formatted messages to console
656
- */
657
- var ConsoleLogHandler = class {
658
- constructor(config) {
659
- this.config = config;
660
- }
661
- handle(entry) {
662
- const parts = [];
663
- if (this.config.includeTimestamp) parts.push(`[${entry.timestamp.toISOString()}]`);
664
- const colorCode = LOG_COLORS[entry.level];
665
- const levelText = `[${entry.level.toUpperCase()}]`;
666
- parts.push(`${colorCode}${levelText}${RESET_COLOR}`);
667
- if (this.config.prefix) parts.push(`[${this.config.prefix}]`);
668
- if (this.config.includeContext && entry.context) parts.push(`[${entry.context}]`);
669
- parts.push(entry.message);
670
- if (entry.metadata && Object.keys(entry.metadata).length > 0) parts.push(`\n Metadata: ${JSON.stringify(entry.metadata, null, 2)}`);
671
- const formattedMessage = parts.join(" ");
672
- switch (entry.level) {
673
- case "debug":
674
- console.debug(formattedMessage);
675
- break;
676
- case "info":
677
- console.info(formattedMessage);
678
- break;
679
- case "warn":
680
- console.warn(formattedMessage);
681
- break;
682
- case "error":
683
- console.error(formattedMessage);
684
- break;
685
- }
686
- }
687
- };
688
- /**
689
- * Main Logger class providing structured logging capabilities.
690
- */
691
- var Logger = class {
692
- constructor(config = {}) {
693
- this.config = {
694
- level: getConfiguredLogLevel(),
695
- includeTimestamp: true,
696
- includeContext: true,
697
- enableConsole: true,
698
- handlers: [],
699
- ...config
700
- };
701
- this.handlers = [...this.config.handlers || []];
702
- if (this.config.enableConsole) this.handlers.push(new ConsoleLogHandler(this.config));
703
- }
704
- /**
705
- * Add a custom log handler
706
- */
707
- addHandler(handler) {
708
- this.handlers.push(handler);
709
- }
710
- /**
711
- * Remove a log handler
712
- */
713
- removeHandler(handler) {
714
- const index = this.handlers.indexOf(handler);
715
- if (index > -1) this.handlers.splice(index, 1);
716
- }
717
- /**
718
- * Update logger configuration
719
- */
720
- configure(config) {
721
- this.config = {
722
- ...this.config,
723
- ...config
724
- };
725
- }
726
- /**
727
- * Check if a log level should be output based on current configuration
728
- */
729
- shouldLog(level) {
730
- return LOG_LEVELS[level] >= LOG_LEVELS[this.config.level];
731
- }
732
- /**
733
- * Internal logging method that creates log entries and passes them to handlers
734
- */
735
- log(level, message, context, metadata) {
736
- if (!this.shouldLog(level)) return;
737
- const entry = {
738
- level,
739
- message,
740
- timestamp: /* @__PURE__ */ new Date(),
741
- context,
742
- metadata
743
- };
744
- this.handlers.forEach((handler) => {
745
- try {
746
- handler.handle(entry);
747
- } catch (error) {
748
- console.error("Error in log handler:", error);
749
- }
750
- });
751
- }
752
- /**
753
- * Log a debug message
754
- * Used for detailed diagnostic information, typically of interest only when diagnosing problems
755
- */
756
- debug(message, context, metadata) {
757
- this.log("debug", message, context, metadata);
758
- }
759
- /**
760
- * Log an info message
761
- * Used for general information about application operation.
762
- */
763
- info(message, context, metadata) {
764
- this.log("info", message, context, metadata);
765
- }
766
- /**
767
- * Log a warning message
768
- * Used for potentially problematic situations that don't prevent operation
769
- */
770
- warn(message, context, metadata) {
771
- this.log("warn", message, context, metadata);
772
- }
773
- /**
774
- * Log an error message
775
- * Used for error events that might still allow the application to continue.
776
- */
777
- error(message, context, metadata) {
778
- this.log("error", message, context, metadata);
779
- }
780
- /**
781
- * Create a child logger with a specific context
782
- */
783
- child(context) {
784
- return new ContextLogger(this, context);
785
- }
786
- /**
787
- * Get current logger configuration
788
- */
789
- getConfig() {
790
- return { ...this.config };
791
- }
792
- };
793
- /**
794
- * Context logger that automatically includes context information.
795
- */
796
- var ContextLogger = class ContextLogger {
797
- constructor(logger, context) {
798
- this.logger = logger;
799
- this.context = context;
800
- }
801
- debug(message, metadata) {
802
- this.logger.debug(message, this.context, metadata);
803
- }
804
- info(message, metadata) {
805
- this.logger.info(message, this.context, metadata);
806
- }
807
- warn(message, metadata) {
808
- this.logger.warn(message, this.context, metadata);
809
- }
810
- error(message, metadata) {
811
- this.logger.error(message, this.context, metadata);
812
- }
813
- child(childContext) {
814
- return new ContextLogger(this.logger, `${this.context}:${childContext}`);
815
- }
816
- };
817
- const defaultLogger = new Logger({
818
- level: getConfiguredLogLevel(),
819
- includeTimestamp: true,
820
- includeContext: true,
821
- prefix: "GT"
822
- });
823
- const fetchLogger = defaultLogger.child("fetch");
824
- defaultLogger.child("validation");
825
- defaultLogger.child("formatting");
826
- defaultLogger.child("locale");
827
- const gtInstanceLogger = defaultLogger.child("GT instance");
828
- //#endregion
829
- //#region src/formatting/format.ts
830
- /**
831
- * Formats a string value with cutoff behavior according to the specified locales and options.
832
- *
833
- * @param {Object} params - The parameters for the cutoff formatting.
834
- * @param {string} params.value - The string value to format with cutoff behavior.
835
- * @param {string | string[]} [params.locales='en'] - The locales to use for formatting.
836
- * @param {CutoffFormatOptions} [params.options={}] - Additional options for cutoff formatting.
837
- * @param {number} [params.options.maxChars] - The maximum number of characters to display.
838
- * @param {CutoffFormatStyle} [params.options.style='ellipsis'] - The style of the terminator.
839
- * @param {string} [params.options.terminator] - Optional override for the terminator to use.
840
- * @param {string} [params.options.separator] - Optional override for the separator between terminator and value.
841
- *
842
- * @returns {string} The formatted string with terminator applied if cutoff occurs.
843
- * @internal
844
- *
845
- * @example
846
- * _formatCutoff({ value: 'Hello, world!', options: { maxChars: 8 } }); // Returns 'Hello, w...'
847
- */
848
- function _formatCutoff({ value, locales = "en", options = {} }) {
849
- return require_IntlCache.intlCache.get("CutoffFormat", locales, options).format(value);
850
- }
851
- /**
852
- * Formats a message according to the specified locales and options.
853
- *
854
- * @param {string} message - The message to format.
855
- * @param {string | string[]} [locales='en'] - The locales to use for formatting.
856
- * @param {Record<string, any>} [variables={}] - The variables to use for formatting.
857
- * @returns {string} The formatted message.
858
- * @internal
859
- *
860
- * Returns an empty string if IntlMessageFormat produces no output.
861
- * TODO: Add this to custom formats.
862
- */
863
- function _formatMessageICU(message, locales = "en", variables = {}) {
864
- return new intl_messageformat.IntlMessageFormat(message, locales).format(variables)?.toString() ?? "";
865
- }
866
- /**
867
- * Returns the message as-is without any formatting.
868
- *
869
- * @param {string} message - The message to return.
870
- * @returns {string} The original message, unchanged.
871
- * @internal
872
- *
873
- * TODO: Add this to custom formats.
874
- */
875
- function _formatMessageString(message) {
876
- return message;
877
- }
878
- /**
879
- * Formats a number according to the specified locales and options.
880
- *
881
- * @param {Object} params - The parameters for the number formatting.
882
- * @param {number} params.value - The number to format.
883
- * @param {string | string[]} [params.locales=['en']] - The locales to use for formatting.
884
- * @param {Intl.NumberFormatOptions} [params.options={}] - Additional options for number formatting.
885
- *
886
- * @returns {string} The formatted number.
887
- * @internal
888
- */
889
- function _formatNum({ value, locales = ["en"], options = {} }) {
890
- return require_IntlCache.intlCache.get("NumberFormat", locales, {
891
- numberingSystem: "latn",
892
- ...options
893
- }).format(value);
894
- }
895
- /**
896
- * Formats a date according to the specified locales and options.
897
- *
898
- * @param {Object} params - The parameters for the date formatting.
899
- * @param {Date} params.value - The date to format.
900
- * @param {string | string[]} [params.locales='en'] - The locales to use for formatting.
901
- * @param {Intl.DateTimeFormatOptions} [params.options={}] - Additional options for date formatting.
902
- *
903
- * @returns {string} The formatted date.
904
- * @internal
905
- */
906
- function _formatDateTime({ value, locales = ["en"], options = {} }) {
907
- return require_IntlCache.intlCache.get("DateTimeFormat", locales, {
908
- calendar: "gregory",
909
- numberingSystem: "latn",
910
- ...options
911
- }).format(value);
912
- }
913
- /**
914
- * Formats a currency value according to the specified locales, currency, and options.
915
- *
916
- * @param {Object} params - The parameters for the currency formatting.
917
- * @param {number} params.value - The currency value to format.
918
- * @param {string} params.currency - The currency code (e.g., 'USD').
919
- * @param {string | string[]} [params.locales=['en']] - The locales to use for formatting.
920
- * @param {Intl.NumberFormatOptions} [params.options={}] - Additional options for currency formatting.
921
- *
922
- * @returns {string} The formatted currency value.
923
- * @internal
924
- */
925
- function _formatCurrency({ value, locales = ["en"], currency = "USD", options = {} }) {
926
- return require_IntlCache.intlCache.get("NumberFormat", locales, {
927
- style: "currency",
928
- currency,
929
- numberingSystem: "latn",
930
- ...options
931
- }).format(value);
932
- }
933
- /**
934
- * Formats a list of items according to the specified locales and options.
935
- *
936
- * @param {Object} params - The parameters for the list formatting.
937
- * @param {Array<string | number>} params.value - The list of items to format.
938
- * @param {string | string[]} [params.locales=['en']] - The locales to use for formatting.
939
- * @param {Intl.ListFormatOptions} [params.options={}] - Additional options for list formatting.
940
- *
941
- * @returns {string} The formatted list.
942
- * @internal
943
- */
944
- function _formatList({ value, locales = ["en"], options = {} }) {
945
- return require_IntlCache.intlCache.get("ListFormat", locales, {
946
- type: "conjunction",
947
- style: "long",
948
- ...options
949
- }).format(value.map(String));
950
- }
951
- /**
952
- * Formats a list of items according to the specified locales and options.
953
- * @param {Object} params - The parameters for the list formatting.
954
- * @param {Array<T>} params.value - The list of items to format.
955
- * @param {string | string[]} [params.locales=['en']] - The locales to use for formatting.
956
- * @param {Intl.ListFormatOptions} [params.options={}] - Additional options for list formatting.
957
- * @returns {Array<T | string>} The formatted list parts.
958
- * @internal
959
- */
960
- function _formatListToParts({ value, locales = ["en"], options = {} }) {
961
- const formatListParts = require_IntlCache.intlCache.get("ListFormat", locales, {
962
- type: "conjunction",
963
- style: "long",
964
- ...options
965
- }).formatToParts(value.map(() => "1"));
966
- let partIndex = 0;
967
- return formatListParts.map((part) => {
968
- if (part.type === "element") return value[partIndex++];
969
- return part.value;
970
- });
971
- }
972
- /**
973
- * Selects the best unit and computes the value for relative time formatting
974
- * based on the difference between a date and a base date.
975
- * @param {Date} date - The target date.
976
- * @param {Date} baseDate - The base date to compute relative time from. Must be provided by the caller for hydration safety.
977
- * @returns {{ value: number, unit: Intl.RelativeTimeFormatUnit }} The computed value and unit.
978
- * @internal
979
- */
980
- function _selectRelativeTimeUnit(date, baseDate) {
981
- const now = baseDate.getTime();
982
- const diffMs = date.getTime() - now;
983
- const absDiffMs = Math.abs(diffMs);
984
- const sign = diffMs < 0 ? -1 : 1;
985
- const seconds = Math.floor(absDiffMs / 1e3);
986
- const minutes = Math.floor(absDiffMs / (1e3 * 60));
987
- const hours = Math.floor(absDiffMs / (1e3 * 60 * 60));
988
- const days = Math.floor(absDiffMs / (1e3 * 60 * 60 * 24));
989
- const weeks = Math.floor(absDiffMs / (1e3 * 60 * 60 * 24 * 7));
990
- const months = Math.floor(absDiffMs / (1e3 * 60 * 60 * 24 * 30));
991
- const years = Math.floor(absDiffMs / (1e3 * 60 * 60 * 24 * 365));
992
- if (seconds < 60) return {
993
- value: sign * seconds,
994
- unit: "second"
995
- };
996
- if (minutes < 60) return {
997
- value: sign * minutes,
998
- unit: "minute"
999
- };
1000
- if (hours < 24) return {
1001
- value: sign * hours,
1002
- unit: "hour"
1003
- };
1004
- if (days < 7) return {
1005
- value: sign * days,
1006
- unit: "day"
1007
- };
1008
- if (days < 28) return {
1009
- value: sign * weeks,
1010
- unit: "week"
1011
- };
1012
- if (months < 1) return {
1013
- value: sign * weeks,
1014
- unit: "week"
1015
- };
1016
- if (months < 12) return {
1017
- value: sign * months,
1018
- unit: "month"
1019
- };
1020
- if (years < 1) return {
1021
- value: sign * months,
1022
- unit: "month"
1023
- };
1024
- return {
1025
- value: sign * years,
1026
- unit: "year"
1027
- };
1028
- }
1029
- /**
1030
- * Formats a relative time from a Date, automatically selecting the best unit.
1031
- * @internal
1032
- */
1033
- function _formatRelativeTimeFromDate({ date, baseDate, locales = ["en"], options = {} }) {
1034
- const { value, unit } = _selectRelativeTimeUnit(date, baseDate);
1035
- return _formatRelativeTime({
1036
- value,
1037
- unit,
1038
- locales,
1039
- options
1040
- });
1041
- }
1042
- /**
1043
- * Formats a relative time value according to the specified locales and options.
1044
- *
1045
- * @param {Object} params - The parameters for the relative time formatting.
1046
- * @param {number} params.value - The relative time value to format.
1047
- * @param {Intl.RelativeTimeFormatUnit} params.unit - The unit of time (e.g., 'second', 'minute', 'hour', 'day', 'week', 'month', 'year').
1048
- * @param {string | string[]} [params.locales=['en']] - The locales to use for formatting.
1049
- * @param {Intl.RelativeTimeFormatOptions} [params.options={}] - Additional options for relative time formatting.
1050
- *
1051
- * @returns {string} The formatted relative time string.
1052
- * @internal
1053
- */
1054
- function _formatRelativeTime({ value, unit, locales = ["en"], options = {} }) {
1055
- return require_IntlCache.intlCache.get("RelativeTimeFormat", locales, {
1056
- style: "long",
1057
- numeric: "auto",
1058
- ...options
1059
- }).format(value, unit);
1060
- }
1061
- //#endregion
1062
- //#region src/locales/getLocaleName.ts
1063
- /**
1064
- * Retrieves the display name(s) of locale code(s) using Intl.DisplayNames.
1065
- *
1066
- * @param {string} locale - A BCP-47 locale code.
1067
- * @param {string} [defaultLocale=libraryDefaultLocale] - The locale for display names.
1068
- * @returns {string} The display name(s) corresponding to the code(s), or empty string(s) if invalid.
1069
- * @internal
1070
- */
1071
- function _getLocaleName(locale, defaultLocale = "en", customMapping) {
1072
- const aliasedLocale = locale;
1073
- if (customMapping && shouldUseCanonicalLocale(locale, customMapping)) locale = customMapping[locale].code;
1074
- defaultLocale ||= "en";
1075
- try {
1076
- const standardizedLocale = _standardizeLocale(locale);
1077
- if (customMapping) for (const l of [
1078
- aliasedLocale,
1079
- locale,
1080
- standardizedLocale,
1081
- require_IntlCache.intlCache.get("Locale", standardizedLocale).language
1082
- ]) {
1083
- const customName = getCustomProperty(customMapping, l, "name");
1084
- if (customName) return customName;
1085
- }
1086
- return require_IntlCache.intlCache.get("DisplayNames", [
1087
- defaultLocale,
1088
- standardizedLocale,
1089
- "en"
1090
- ], { type: "language" }).of(standardizedLocale) || "";
1091
- } catch {
1092
- return "";
1093
- }
1094
- }
1095
- //#endregion
1096
- //#region src/locales/getLocaleDirection.ts
1097
- /**
1098
- * Get the text direction for a given locale code using the Intl.Locale API.
1099
- *
1100
- * @param {string} code - The locale code to check.
1101
- * @returns {string} 'rtl' if the language is right-to-left; otherwise 'ltr'.
1102
- * @internal
1103
- */
1104
- function _getLocaleDirection(code) {
1105
- try {
1106
- const textInfoDirection = extractDirectionWithTextInfo(require_IntlCache.intlCache.get("Locale", code));
1107
- if (textInfoDirection) return textInfoDirection;
1108
- } catch {}
1109
- const { scriptCode, languageCode } = _getLocaleProperties(code);
1110
- if (scriptCode) return isRtlScript(scriptCode) ? "rtl" : "ltr";
1111
- if (languageCode) return isRtlLanguage(languageCode) ? "rtl" : "ltr";
1112
- return "ltr";
1113
- }
1114
- const RTL_SCRIPTS = new Set([
1115
- "arab",
1116
- "adlm",
1117
- "hebr",
1118
- "nkoo",
1119
- "rohg",
1120
- "samr",
1121
- "syrc",
1122
- "thaa",
1123
- "yezi"
1124
- ]);
1125
- const RTL_LANGUAGES = new Set([
1126
- "ar",
1127
- "arc",
1128
- "ckb",
1129
- "dv",
1130
- "fa",
1131
- "he",
1132
- "iw",
1133
- "ku",
1134
- "lrc",
1135
- "nqo",
1136
- "ps",
1137
- "pnb",
1138
- "sd",
1139
- "syr",
1140
- "ug",
1141
- "ur",
1142
- "yi"
1143
- ]);
1144
- /**
1145
- * Handles extracting direction via textInfo property
1146
- * @param locale - Intl.Locale object.
1147
- * @returns {'ltr' | 'rtl'} - The direction of the locale
1148
- *
1149
- * Intl.Locale.prototype.getTextInfo() / textInfo property incorporated in ES2024 Specification.
1150
- * This is not supported by all browsers yet.
1151
- * See: {@link https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/Locale/getTextInfo#browser_compatibility}
1152
- */
1153
- function extractDirectionWithTextInfo(locale) {
1154
- 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;
1155
- }
1156
- function isRtlScript(script) {
1157
- return script ? RTL_SCRIPTS.has(script.toLowerCase()) : false;
1158
- }
1159
- function isRtlLanguage(language) {
1160
- return language ? RTL_LANGUAGES.has(language.toLowerCase()) : false;
1161
- }
1162
- //#endregion
1163
- //#region src/locales/isSupersetLocale.ts
1164
- /**
1165
- * @internal
1166
- */
1167
- function _isSupersetLocale(superLocale, subLocale) {
1168
- try {
1169
- const { language: languageSuper, region: regionSuper, script: scriptSuper } = require_IntlCache.intlCache.get("Locale", _standardizeLocale(superLocale));
1170
- const { language: languageSub, region: regionSub, script: scriptSub } = require_IntlCache.intlCache.get("Locale", _standardizeLocale(subLocale));
1171
- if (languageSuper !== languageSub) return false;
1172
- if (regionSuper && regionSuper !== regionSub) return false;
1173
- if (scriptSuper && scriptSuper !== scriptSub) return false;
1174
- return true;
1175
- } catch (error) {
1176
- console.error(error);
1177
- return false;
1178
- }
1179
- }
1180
- //#endregion
1181
- //#region src/locales/resolveAliasLocale.ts
1182
- /**
1183
- * Resolves the alias locale for a given locale.
1184
- * @param locale - The locale to resolve the alias locale for
1185
- * @param customMapping - The custom mapping to use for resolving the alias locale
1186
- * @returns The configured alias for a canonical locale, or the input locale when already an alias or no alias mapping exists.
1187
- */
1188
- function _resolveAliasLocale(locale, customMapping) {
1189
- let reverseCustomMapping;
1190
- if (customMapping) reverseCustomMapping = Object.fromEntries(Object.entries(customMapping).filter(([, value]) => value && typeof value === "object" && "code" in value).map(([key, value]) => [value.code, key]));
1191
- return reverseCustomMapping?.[locale] || locale;
1192
- }
1193
- //#endregion
1194
- //#region src/locales/resolveCanonicalLocale.ts
1195
- /**
1196
- * Resolves the canonical locale for a given locale.
1197
- * @param locale - The locale to resolve the canonical locale for
1198
- * @param customMapping - The custom mapping to use for resolving the canonical locale
1199
- * @returns The canonical locale, or the input locale when no canonical mapping exists.
1200
- */
1201
- function _resolveCanonicalLocale(locale, customMapping) {
1202
- if (customMapping && shouldUseCanonicalLocale(locale, customMapping)) return customMapping[locale].code;
1203
- return locale;
1204
- }
1205
- //#endregion
1206
- //#region src/LocaleConfig.ts
1207
- /**
1208
- * LocaleConfig contains the locale and formatting primitives exposed through
1209
- * the core entrypoint.
1210
- *
1211
- * It intentionally does not store project IDs, API keys, runtime URLs, or any
1212
- * translation credentials. It only stores locale metadata needed to resolve
1213
- * aliases, choose formatting fallbacks, and format values with Intl.
1214
- */
1215
- var LocaleConfig = class {
1216
- constructor({ defaultLocale = "en", locales = [], customMapping } = {}) {
1217
- this.defaultLocale = defaultLocale;
1218
- this.locales = locales;
1219
- this.customMapping = customMapping;
1220
- }
1221
- get translationLocales() {
1222
- return this.locales.length ? this.locales : void 0;
1223
- }
1224
- resolveCanonicalLocaleList(locales) {
1225
- return locales.map((locale) => this.resolveCanonicalLocale(locale));
1226
- }
1227
- resolveCanonicalLocaleArgs(locales) {
1228
- return locales.map((locale) => Array.isArray(locale) ? this.resolveCanonicalLocaleList(locale) : this.resolveCanonicalLocale(locale));
1229
- }
1230
- toLocaleList(locales) {
1231
- return Array.isArray(locales) ? locales : [locales];
1232
- }
1233
- getFormattingLocales(targetLocale, locales) {
1234
- return (locales !== void 0 ? this.toLocaleList(locales) : [
1235
- targetLocale,
1236
- this.defaultLocale,
1237
- "en"
1238
- ]).filter((locale) => !!locale).map((locale) => this.resolveCanonicalLocale(locale));
1239
- }
1240
- formatNum(value, targetLocale, options = {}) {
1241
- const { locales, ...intlOptions } = options;
1242
- return _formatNum({
1243
- value,
1244
- locales: this.getFormattingLocales(targetLocale, locales),
1245
- options: intlOptions
1246
- });
1247
- }
1248
- formatDateTime(value, targetLocale, options = {}) {
1249
- const { locales, ...intlOptions } = options;
1250
- return _formatDateTime({
1251
- value,
1252
- locales: this.getFormattingLocales(targetLocale, locales),
1253
- options: intlOptions
1254
- });
1255
- }
1256
- formatCurrency(value, currency, targetLocale, options = {}) {
1257
- const { locales, ...intlOptions } = options;
1258
- return _formatCurrency({
1259
- value,
1260
- currency,
1261
- locales: this.getFormattingLocales(targetLocale, locales),
1262
- options: intlOptions
1263
- });
1264
- }
1265
- formatRelativeTime(value, unit, targetLocale, options = {}) {
1266
- const { locales, ...intlOptions } = options;
1267
- return _formatRelativeTime({
1268
- value,
1269
- unit,
1270
- locales: this.getFormattingLocales(targetLocale, locales),
1271
- options: intlOptions
1272
- });
1273
- }
1274
- formatRelativeTimeFromDate(date, targetLocale, options = {}) {
1275
- const { locales, baseDate, ...intlOptions } = options;
1276
- return _formatRelativeTimeFromDate({
1277
- date,
1278
- baseDate: baseDate ?? /* @__PURE__ */ new Date(),
1279
- locales: this.getFormattingLocales(targetLocale, locales),
1280
- options: intlOptions
1281
- });
1282
- }
1283
- formatCutoff(value, targetLocale, options = {}) {
1284
- const { locales, ...formatOptions } = options;
1285
- return _formatCutoff({
1286
- value,
1287
- locales: this.getFormattingLocales(targetLocale, locales),
1288
- options: formatOptions
1289
- });
1290
- }
1291
- formatMessage(message, targetLocale, options = {}) {
1292
- const { locales, variables, dataFormat } = options;
1293
- if (dataFormat === "STRING") return _formatMessageString(message);
1294
- return _formatMessageICU(message, this.getFormattingLocales(targetLocale, locales), variables);
1295
- }
1296
- formatList(array, targetLocale, options = {}) {
1297
- const { locales, ...intlOptions } = options;
1298
- return _formatList({
1299
- value: array,
1300
- locales: this.getFormattingLocales(targetLocale, locales),
1301
- options: intlOptions
1302
- });
1303
- }
1304
- formatListToParts(array, targetLocale, options = {}) {
1305
- const { locales, ...intlOptions } = options;
1306
- return _formatListToParts({
1307
- value: array,
1308
- locales: this.getFormattingLocales(targetLocale, locales),
1309
- options: intlOptions
1310
- });
1311
- }
1312
- getLocaleName(locale) {
1313
- return _getLocaleName(locale, this.defaultLocale, this.customMapping);
1314
- }
1315
- getLocaleEmoji(locale) {
1316
- return _getLocaleEmoji(locale, this.customMapping);
1317
- }
1318
- getLocaleProperties(locale) {
1319
- return _getLocaleProperties(locale, this.defaultLocale, this.customMapping);
1320
- }
1321
- requiresTranslation(targetLocale, sourceLocale = this.defaultLocale, approvedLocales = this.translationLocales) {
1322
- return _requiresTranslation(this.resolveCanonicalLocale(sourceLocale), this.resolveCanonicalLocale(targetLocale), approvedLocales ? this.resolveCanonicalLocaleList(approvedLocales) : void 0, this.customMapping);
1323
- }
1324
- determineLocale(locales, approvedLocales = this.locales) {
1325
- const approvedLocalePairs = approvedLocales.map((locale) => ({
1326
- locale,
1327
- canonicalLocale: this.resolveCanonicalLocale(locale)
1328
- }));
1329
- const resolvedLocale = _determineLocale(Array.isArray(locales) ? this.resolveCanonicalLocaleList(locales) : this.resolveCanonicalLocale(locales), approvedLocalePairs.map(({ canonicalLocale }) => canonicalLocale), this.customMapping);
1330
- if (!resolvedLocale) return void 0;
1331
- return approvedLocalePairs.find(({ canonicalLocale }) => canonicalLocale === resolvedLocale)?.locale || this.resolveAliasLocale(resolvedLocale);
1332
- }
1333
- getLocaleDirection(locale) {
1334
- return _getLocaleDirection(this.resolveCanonicalLocale(locale));
1335
- }
1336
- isValidLocale(locale) {
1337
- return _isValidLocale(locale, this.customMapping);
1338
- }
1339
- resolveCanonicalLocale(locale) {
1340
- return _resolveCanonicalLocale(locale, this.customMapping);
1341
- }
1342
- resolveAliasLocale(locale) {
1343
- return _resolveAliasLocale(locale, this.customMapping);
1344
- }
1345
- standardizeLocale(locale) {
1346
- return _standardizeLocale(locale);
1347
- }
1348
- isSameDialect(...locales) {
1349
- return _isSameDialect(...this.resolveCanonicalLocaleArgs(locales));
1350
- }
1351
- isSameLanguage(...locales) {
1352
- return _isSameLanguage(...this.resolveCanonicalLocaleArgs(locales));
1353
- }
1354
- isSupersetLocale(superLocale, subLocale) {
1355
- return _isSupersetLocale(this.resolveCanonicalLocale(superLocale), this.resolveCanonicalLocale(subLocale));
1356
- }
1357
- };
1358
- //#endregion
1359
- //#region src/core.ts
1360
- /**
1361
- * Core formatting and locale helpers.
1362
- *
1363
- * This entry point exposes deterministic locale and formatting primitives. It
1364
- * does not export the GT service client, project credentials, network
1365
- * translation methods, file APIs, or other server/service concerns from the
1366
- * root `generaltranslation` facade.
1367
- *
1368
- * This entry point is intended for framework and shared packages that need
1369
- * locale metadata or formatting behavior without pulling in the full
1370
- * translation API surface.
1371
- */
1372
- /**
1373
- * Formats a string with cutoff behavior, applying a terminator when the string exceeds the maximum character limit.
1374
- *
1375
- * This standalone function provides cutoff formatting functionality without requiring a GT instance.
1376
- * The locales parameter is required for proper terminator selection based on the target language.
1377
- *
1378
- * @param {string} value - The string value to format with cutoff behavior.
1379
- * @param {Object} [options] - Configuration options for cutoff formatting.
1380
- * @param {string | string[]} [options.locales] - The locales to use for terminator selection.
1381
- * @param {number} [options.maxChars] - The maximum number of characters to display.
1382
- * - Undefined values are treated as no cutoff.
1383
- * - Negative values follow .slice() behavior and terminator will be added before the value.
1384
- * - 0 will result in an empty string.
1385
- * - If cutoff results in an empty string, no terminator is added.
1386
- * @param {CutoffFormatStyle} [options.style='ellipsis'] - The style of the terminator.
1387
- * @param {string} [options.terminator] - Optional override the terminator to use.
1388
- * @param {string} [options.separator] - Optional override the separator to use between the terminator and the value.
1389
- * - If no terminator is provided, then separator is ignored.
1390
- * @returns {string} The formatted string with terminator applied if cutoff occurs.
1391
- *
1392
- * @example
1393
- * formatCutoff('Hello, world!', { locales: 'en-US', maxChars: 8 });
1394
- * // Returns: 'Hello, …'
1395
- *
1396
- * @example
1397
- * formatCutoff('Hello, world!', { locales: 'en-US', maxChars: -3 });
1398
- * // Returns: '…d!'
1399
- *
1400
- * @example
1401
- * formatCutoff('Very long text that needs cutting', {
1402
- * locales: 'en-US',
1403
- * maxChars: 15,
1404
- * style: 'ellipsis',
1405
- * separator: ' '
1406
- * });
1407
- * // Returns: 'Very long tex …'
1408
- */
1409
- function formatCutoff(value, options) {
1410
- return _formatCutoff({
1411
- value,
1412
- locales: options?.locales,
1413
- options
1414
- });
1415
- }
1416
- /**
1417
- * Formats a message according to the specified locales and options.
1418
- *
1419
- * @param {string} message - The message to format.
1420
- * @param {Object} [options] - Configuration options for message formatting.
1421
- * @param {string | string[]} [options.locales] - The locales to use for formatting.
1422
- * @param {FormatVariables} [options.variables] - The variables to use for formatting.
1423
- * @param {StringFormat} [options.dataFormat='ICU'] - The format of the message. When STRING, the message is returned as is.
1424
- * @returns {string} The formatted message.
1425
- *
1426
- * @example
1427
- * formatMessage('Hello {name}', { variables: { name: 'John' } });
1428
- * // Returns: "Hello John"
1429
- *
1430
- * @example
1431
- * formatMessage('Hello {name}', {
1432
- * locales: ['fr'],
1433
- * variables: { name: 'John' }
1434
- * });
1435
- */
1436
- function formatMessage(message, options) {
1437
- switch (options?.dataFormat) {
1438
- case "STRING": return _formatMessageString(message);
1439
- default: return _formatMessageICU(message, options?.locales, options?.variables);
1440
- }
1441
- }
1442
- /**
1443
- * Checks if a given BCP 47 locale code is valid.
1444
- *
1445
- * @param {string} locale - The BCP 47 locale code to validate.
1446
- * @param {CustomMapping} [customMapping] - The custom mapping to use for validation.
1447
- * @returns {boolean} True if the BCP 47 code is valid, false otherwise.
1448
- *
1449
- * @example
1450
- * isValidLocale('en-US');
1451
- * // Returns: true
1452
- *
1453
- * @example
1454
- * isValidLocale('en_US');
1455
- * // Returns: false
1456
- */
1457
- function isValidLocale(locale, customMapping) {
1458
- return _isValidLocale(locale, customMapping);
1459
- }
1460
- /**
1461
- * Resolves the canonical locale for a given locale.
1462
- *
1463
- * @param {string} locale - The locale to resolve the canonical locale for.
1464
- * @param {CustomMapping} [customMapping] - The custom mapping to use for resolving the canonical locale.
1465
- * @returns {string} The canonical locale, or the input locale when no canonical mapping exists.
1466
- *
1467
- * @example
1468
- * resolveCanonicalLocale('en-US');
1469
- * // Returns: 'en-US'
1470
- *
1471
- * @example
1472
- * resolveCanonicalLocale('en', { en: 'en-US' });
1473
- * // Returns: 'en-US'
1474
- */
1475
- function resolveCanonicalLocale(locale, customMapping) {
1476
- return _resolveCanonicalLocale(locale, customMapping);
1477
- }
1478
- /**
1479
- * Standardizes a BCP 47 locale code to ensure correct formatting.
1480
- *
1481
- * @param {string} locale - The BCP 47 locale code to standardize.
1482
- * @returns {string} The standardized BCP 47 locale code, or the input string if it cannot be standardized.
1483
- *
1484
- * @example
1485
- * standardizeLocale('en-us');
1486
- * // Returns: 'en-US'
1487
- *
1488
- * @example
1489
- * standardizeLocale('not a locale');
1490
- * // Returns: 'not a locale'
1491
- */
1492
- function standardizeLocale(locale) {
1493
- return _standardizeLocale(locale);
1494
- }
1495
- //#endregion
1496
- Object.defineProperty(exports, "LocaleConfig", {
1497
- enumerable: true,
1498
- get: function() {
1499
- return LocaleConfig;
1500
- }
1501
- });
1502
- Object.defineProperty(exports, "_determineLocale", {
1503
- enumerable: true,
1504
- get: function() {
1505
- return _determineLocale;
1506
- }
1507
- });
1508
- Object.defineProperty(exports, "_formatCurrency", {
1509
- enumerable: true,
1510
- get: function() {
1511
- return _formatCurrency;
1512
- }
1513
- });
1514
- Object.defineProperty(exports, "_formatDateTime", {
1515
- enumerable: true,
1516
- get: function() {
1517
- return _formatDateTime;
1518
- }
1519
- });
1520
- Object.defineProperty(exports, "_formatList", {
1521
- enumerable: true,
1522
- get: function() {
1523
- return _formatList;
1524
- }
1525
- });
1526
- Object.defineProperty(exports, "_formatListToParts", {
1527
- enumerable: true,
1528
- get: function() {
1529
- return _formatListToParts;
1530
- }
1531
- });
1532
- Object.defineProperty(exports, "_formatNum", {
1533
- enumerable: true,
1534
- get: function() {
1535
- return _formatNum;
1536
- }
1537
- });
1538
- Object.defineProperty(exports, "_formatRelativeTime", {
1539
- enumerable: true,
1540
- get: function() {
1541
- return _formatRelativeTime;
1542
- }
1543
- });
1544
- Object.defineProperty(exports, "_formatRelativeTimeFromDate", {
1545
- enumerable: true,
1546
- get: function() {
1547
- return _formatRelativeTimeFromDate;
1548
- }
1549
- });
1550
- Object.defineProperty(exports, "_getLocaleDirection", {
1551
- enumerable: true,
1552
- get: function() {
1553
- return _getLocaleDirection;
1554
- }
1555
- });
1556
- Object.defineProperty(exports, "_getLocaleEmoji", {
1557
- enumerable: true,
1558
- get: function() {
1559
- return _getLocaleEmoji;
1560
- }
1561
- });
1562
- Object.defineProperty(exports, "_getLocaleName", {
1563
- enumerable: true,
1564
- get: function() {
1565
- return _getLocaleName;
1566
- }
1567
- });
1568
- Object.defineProperty(exports, "_getLocaleProperties", {
1569
- enumerable: true,
1570
- get: function() {
1571
- return _getLocaleProperties;
1572
- }
1573
- });
1574
- Object.defineProperty(exports, "_isSameDialect", {
1575
- enumerable: true,
1576
- get: function() {
1577
- return _isSameDialect;
1578
- }
1579
- });
1580
- Object.defineProperty(exports, "_isSameLanguage", {
1581
- enumerable: true,
1582
- get: function() {
1583
- return _isSameLanguage;
1584
- }
1585
- });
1586
- Object.defineProperty(exports, "_isSupersetLocale", {
1587
- enumerable: true,
1588
- get: function() {
1589
- return _isSupersetLocale;
1590
- }
1591
- });
1592
- Object.defineProperty(exports, "_isValidLocale", {
1593
- enumerable: true,
1594
- get: function() {
1595
- return _isValidLocale;
1596
- }
1597
- });
1598
- Object.defineProperty(exports, "_requiresTranslation", {
1599
- enumerable: true,
1600
- get: function() {
1601
- return _requiresTranslation;
1602
- }
1603
- });
1604
- Object.defineProperty(exports, "_resolveAliasLocale", {
1605
- enumerable: true,
1606
- get: function() {
1607
- return _resolveAliasLocale;
1608
- }
1609
- });
1610
- Object.defineProperty(exports, "_resolveCanonicalLocale", {
1611
- enumerable: true,
1612
- get: function() {
1613
- return _resolveCanonicalLocale;
1614
- }
1615
- });
1616
- Object.defineProperty(exports, "_standardizeLocale", {
1617
- enumerable: true,
1618
- get: function() {
1619
- return _standardizeLocale;
1620
- }
1621
- });
1622
- Object.defineProperty(exports, "defaultEmoji", {
1623
- enumerable: true,
1624
- get: function() {
1625
- return defaultEmoji;
1626
- }
1627
- });
1628
- Object.defineProperty(exports, "fetchLogger", {
1629
- enumerable: true,
1630
- get: function() {
1631
- return fetchLogger;
1632
- }
1633
- });
1634
- Object.defineProperty(exports, "formatCutoff", {
1635
- enumerable: true,
1636
- get: function() {
1637
- return formatCutoff;
1638
- }
1639
- });
1640
- Object.defineProperty(exports, "formatMessage", {
1641
- enumerable: true,
1642
- get: function() {
1643
- return formatMessage;
1644
- }
1645
- });
1646
- Object.defineProperty(exports, "getRegionEmoji", {
1647
- enumerable: true,
1648
- get: function() {
1649
- return getRegionEmoji;
1650
- }
1651
- });
1652
- Object.defineProperty(exports, "gtInstanceLogger", {
1653
- enumerable: true,
1654
- get: function() {
1655
- return gtInstanceLogger;
1656
- }
1657
- });
1658
- Object.defineProperty(exports, "isValidLocale", {
1659
- enumerable: true,
1660
- get: function() {
1661
- return isValidLocale;
1662
- }
1663
- });
1664
- Object.defineProperty(exports, "resolveCanonicalLocale", {
1665
- enumerable: true,
1666
- get: function() {
1667
- return resolveCanonicalLocale;
1668
- }
1669
- });
1670
- Object.defineProperty(exports, "standardizeLocale", {
1671
- enumerable: true,
1672
- get: function() {
1673
- return standardizeLocale;
1674
- }
1675
- });
1676
-
1677
- //# sourceMappingURL=core-7RP541eY.cjs.map