generaltranslation 8.2.7 → 8.2.9
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +12 -0
- package/dist/{ApiError-4zIP-twr.cjs → ApiError-CZ45tkW6.cjs} +1 -1
- package/dist/{ApiError-4zIP-twr.cjs.map → ApiError-CZ45tkW6.cjs.map} +1 -1
- package/dist/{ApiError-Bv7vlzyQ.mjs → ApiError-IYfaOR30.mjs} +1 -1
- package/dist/{ApiError-Bv7vlzyQ.mjs.map → ApiError-IYfaOR30.mjs.map} +1 -1
- package/dist/IntlCache-Ccg_cQPR.mjs +195 -0
- package/dist/IntlCache-Ccg_cQPR.mjs.map +1 -0
- package/dist/IntlCache-k2qfrDqB.cjs +212 -0
- package/dist/IntlCache-k2qfrDqB.cjs.map +1 -0
- package/dist/base64-C1sogiix.mjs +70 -0
- package/dist/base64-C1sogiix.mjs.map +1 -0
- package/dist/base64-CUcEPEC5.cjs +111 -0
- package/dist/base64-CUcEPEC5.cjs.map +1 -0
- package/dist/core-CJMv4fMa.d.cts +209 -0
- package/dist/core-DOrYXXpO.mjs +1487 -0
- package/dist/core-DOrYXXpO.mjs.map +1 -0
- package/dist/core-DtPj_ruw.d.mts +209 -0
- package/dist/core-LS3Pia40.cjs +1666 -0
- package/dist/core-LS3Pia40.cjs.map +1 -0
- package/dist/core.cjs +8 -0
- package/dist/core.d.cts +2 -0
- package/dist/core.d.mts +2 -0
- package/dist/core.mjs +2 -0
- package/dist/errors.cjs +1 -1
- package/dist/errors.mjs +1 -1
- package/dist/{id-CPbVYREY.mjs → id-BmOyfaug.mjs} +2 -2
- package/dist/{id-CPbVYREY.mjs.map → id-BmOyfaug.mjs.map} +1 -1
- package/dist/{id-VXBgyXu2.cjs → id-COlX5v3V.cjs} +6 -6
- package/dist/{id-VXBgyXu2.cjs.map → id-COlX5v3V.cjs.map} +1 -1
- package/dist/id.cjs +1 -1
- package/dist/id.d.cts +1 -1
- package/dist/id.d.mts +1 -1
- package/dist/id.mjs +1 -1
- package/dist/index.cjs +91 -1413
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +7 -103
- package/dist/index.d.mts +7 -103
- package/dist/index.mjs +43 -1342
- package/dist/index.mjs.map +1 -1
- package/dist/internal.cjs +602 -42
- package/dist/internal.cjs.map +1 -0
- package/dist/internal.d.cts +23 -2
- package/dist/internal.d.mts +23 -2
- package/dist/internal.mjs +563 -3
- package/dist/internal.mjs.map +1 -0
- package/dist/{sha2-DKowBr6H.cjs → isVariable-B08mggBy.cjs} +18 -18
- package/dist/isVariable-B08mggBy.cjs.map +1 -0
- package/dist/{stableStringify-DgDlE_pD.mjs → isVariable-CYsKFHvR.mjs} +19 -19
- package/dist/isVariable-CYsKFHvR.mjs.map +1 -0
- package/dist/{types-fUW4_Ole.d.mts → types-Dfy_sRLD.d.mts} +6 -2
- package/dist/{types-D2fTTTvZ.d.cts → types-mZeu4HS3.d.cts} +6 -2
- package/dist/types.d.cts +1 -1
- package/dist/types.d.mts +1 -1
- package/package.json +17 -1
- package/dist/internal-CTeI8uLd.mjs +0 -774
- package/dist/internal-CTeI8uLd.mjs.map +0 -1
- package/dist/internal-PCKq4YMW.cjs +0 -1012
- package/dist/internal-PCKq4YMW.cjs.map +0 -1
- package/dist/sha2-DKowBr6H.cjs.map +0 -1
- package/dist/stableStringify-DgDlE_pD.mjs.map +0 -1
package/dist/index.mjs
CHANGED
|
@@ -1,1174 +1,8 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import { t as
|
|
3
|
-
import { n as
|
|
4
|
-
import
|
|
5
|
-
|
|
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.`;
|
|
@@ -1445,6 +279,7 @@ async function processBatches(items, processor, options = {}) {
|
|
|
1445
279
|
* @returns The result of the API call
|
|
1446
280
|
*/
|
|
1447
281
|
async function _enqueueFiles(files, options, config) {
|
|
282
|
+
validateFileFormatTransforms(files);
|
|
1448
283
|
const result = await processBatches(files, async (batch) => {
|
|
1449
284
|
const apiResult = await apiRequest(config, "/v2/project/translations/enqueue", {
|
|
1450
285
|
body: {
|
|
@@ -1452,7 +287,8 @@ async function _enqueueFiles(files, options, config) {
|
|
|
1452
287
|
branchId: f.branchId,
|
|
1453
288
|
fileId: f.fileId,
|
|
1454
289
|
versionId: f.versionId,
|
|
1455
|
-
fileName: f.fileName
|
|
290
|
+
fileName: f.fileName,
|
|
291
|
+
transformFormat: f.transformFormat
|
|
1456
292
|
})),
|
|
1457
293
|
targetLocales: options.targetLocales,
|
|
1458
294
|
sourceLocale: options.sourceLocale,
|
|
@@ -1579,31 +415,6 @@ function _getRegionProperties(region, defaultLocale = "en", customMapping) {
|
|
|
1579
415
|
}
|
|
1580
416
|
}
|
|
1581
417
|
//#endregion
|
|
1582
|
-
//#region src/locales/resolveAliasLocale.ts
|
|
1583
|
-
/**
|
|
1584
|
-
* Resolves the alias locale for a given locale.
|
|
1585
|
-
* @param locale - The locale to resolve the alias locale for
|
|
1586
|
-
* @param customMapping - The custom mapping to use for resolving the alias locale
|
|
1587
|
-
* @returns The alias locale
|
|
1588
|
-
*/
|
|
1589
|
-
function _resolveAliasLocale(locale, customMapping) {
|
|
1590
|
-
let reverseCustomMapping;
|
|
1591
|
-
if (customMapping) reverseCustomMapping = Object.fromEntries(Object.entries(customMapping).filter(([, value]) => value && typeof value === "object" && "code" in value).map(([key, value]) => [value.code, key]));
|
|
1592
|
-
return reverseCustomMapping?.[locale] || locale;
|
|
1593
|
-
}
|
|
1594
|
-
//#endregion
|
|
1595
|
-
//#region src/locales/resolveCanonicalLocale.ts
|
|
1596
|
-
/**
|
|
1597
|
-
* Resolves the canonical locale for a given locale.
|
|
1598
|
-
* @param locale - The locale to resolve the canonical locale for
|
|
1599
|
-
* @param customMapping - The custom mapping to use for resolving the canonical locale
|
|
1600
|
-
* @returns The canonical locale
|
|
1601
|
-
*/
|
|
1602
|
-
function _resolveCanonicalLocale(locale, customMapping) {
|
|
1603
|
-
if (customMapping && shouldUseCanonicalLocale(locale, customMapping)) return customMapping[locale].code;
|
|
1604
|
-
return locale;
|
|
1605
|
-
}
|
|
1606
|
-
//#endregion
|
|
1607
418
|
//#region src/translate/uploadSourceFiles.ts
|
|
1608
419
|
/**
|
|
1609
420
|
* @internal
|
|
@@ -1647,6 +458,7 @@ async function _uploadSourceFiles(files, options, config) {
|
|
|
1647
458
|
* @returns Promise resolving to a BatchList with all uploaded files
|
|
1648
459
|
*/
|
|
1649
460
|
async function _uploadTranslations(files, options, config) {
|
|
461
|
+
validateFileFormatTransforms(files.map(({ source }) => source));
|
|
1650
462
|
return processBatches(files, async (batch) => {
|
|
1651
463
|
return (await apiRequest(config, "/v2/project/files/upload-translations", {
|
|
1652
464
|
body: {
|
|
@@ -1655,6 +467,7 @@ async function _uploadTranslations(files, options, config) {
|
|
|
1655
467
|
content: encode(source.content),
|
|
1656
468
|
fileName: source.fileName,
|
|
1657
469
|
fileFormat: source.fileFormat,
|
|
470
|
+
transformFormat: source.transformFormat,
|
|
1658
471
|
locale: source.locale,
|
|
1659
472
|
dataFormat: source.dataFormat,
|
|
1660
473
|
formatMetadata: source.formatMetadata,
|
|
@@ -1945,6 +758,10 @@ async function _publishFiles(files, config) {
|
|
|
1945
758
|
* });
|
|
1946
759
|
*/
|
|
1947
760
|
var GT = class {
|
|
761
|
+
/** Runtime-safe locale and formatting helpers */
|
|
762
|
+
get localeConfig() {
|
|
763
|
+
return this._localeConfig;
|
|
764
|
+
}
|
|
1948
765
|
/**
|
|
1949
766
|
* Constructs an instance of the GT class.
|
|
1950
767
|
*
|
|
@@ -1961,7 +778,6 @@ var GT = class {
|
|
|
1961
778
|
* });
|
|
1962
779
|
*/
|
|
1963
780
|
constructor(params = {}) {
|
|
1964
|
-
this._renderingLocales = [];
|
|
1965
781
|
if (typeof process !== "undefined") {
|
|
1966
782
|
this.apiKey ||= process.env?.GT_API_KEY;
|
|
1967
783
|
this.devApiKey ||= process.env?.GT_DEV_API_KEY;
|
|
@@ -1981,10 +797,6 @@ var GT = class {
|
|
|
1981
797
|
this.targetLocale = _standardizeLocale(targetLocale);
|
|
1982
798
|
if (!_isValidLocale(this.targetLocale, customMapping)) throw new Error(invalidLocaleError(this.targetLocale));
|
|
1983
799
|
}
|
|
1984
|
-
this._renderingLocales = [];
|
|
1985
|
-
if (this.sourceLocale) this._renderingLocales.push(this.sourceLocale);
|
|
1986
|
-
if (this.targetLocale) this._renderingLocales.push(this.targetLocale);
|
|
1987
|
-
this._renderingLocales.push("en");
|
|
1988
800
|
if (locales) {
|
|
1989
801
|
const result = [];
|
|
1990
802
|
const invalidLocales = [];
|
|
@@ -2001,6 +813,11 @@ var GT = class {
|
|
|
2001
813
|
this.customMapping = customMapping;
|
|
2002
814
|
this.reverseCustomMapping = Object.fromEntries(Object.entries(customMapping).filter(([, value]) => value && typeof value === "object" && "code" in value).map(([key, value]) => [value.code, key]));
|
|
2003
815
|
}
|
|
816
|
+
this._localeConfig = new LocaleConfig({
|
|
817
|
+
defaultLocale: this.sourceLocale,
|
|
818
|
+
locales: this.locales ?? [],
|
|
819
|
+
customMapping: this.customMapping
|
|
820
|
+
});
|
|
2004
821
|
}
|
|
2005
822
|
_getTranslationConfig() {
|
|
2006
823
|
return {
|
|
@@ -2497,10 +1314,7 @@ var GT = class {
|
|
|
2497
1314
|
* // Returns: '...ld!'
|
|
2498
1315
|
*/
|
|
2499
1316
|
formatCutoff(value, options) {
|
|
2500
|
-
return formatCutoff(value,
|
|
2501
|
-
locales: this._renderingLocales,
|
|
2502
|
-
...options
|
|
2503
|
-
});
|
|
1317
|
+
return this.localeConfig.formatCutoff(value, this.targetLocale, options);
|
|
2504
1318
|
}
|
|
2505
1319
|
/**
|
|
2506
1320
|
* Formats a message according to the specified locales and options.
|
|
@@ -2519,10 +1333,7 @@ var GT = class {
|
|
|
2519
1333
|
* // Returns: "Bonjour John"
|
|
2520
1334
|
*/
|
|
2521
1335
|
formatMessage(message, options) {
|
|
2522
|
-
return formatMessage(message,
|
|
2523
|
-
locales: this._renderingLocales,
|
|
2524
|
-
...options
|
|
2525
|
-
});
|
|
1336
|
+
return this.localeConfig.formatMessage(message, this.targetLocale, options);
|
|
2526
1337
|
}
|
|
2527
1338
|
/**
|
|
2528
1339
|
* Formats a number according to the specified locales and options.
|
|
@@ -2538,10 +1349,7 @@ var GT = class {
|
|
|
2538
1349
|
* // Returns: "$1,234.56"
|
|
2539
1350
|
*/
|
|
2540
1351
|
formatNum(number, options) {
|
|
2541
|
-
return formatNum(number,
|
|
2542
|
-
locales: this._renderingLocales,
|
|
2543
|
-
...options
|
|
2544
|
-
});
|
|
1352
|
+
return this.localeConfig.formatNum(number, this.targetLocale, options);
|
|
2545
1353
|
}
|
|
2546
1354
|
/**
|
|
2547
1355
|
* Formats a date according to the specified locales and options.
|
|
@@ -2557,10 +1365,7 @@ var GT = class {
|
|
|
2557
1365
|
* // Returns: "Thursday, March 14, 2024 at 2:30:45 PM GMT-7"
|
|
2558
1366
|
*/
|
|
2559
1367
|
formatDateTime(date, options) {
|
|
2560
|
-
return formatDateTime(date,
|
|
2561
|
-
locales: this._renderingLocales,
|
|
2562
|
-
...options
|
|
2563
|
-
});
|
|
1368
|
+
return this.localeConfig.formatDateTime(date, this.targetLocale, options);
|
|
2564
1369
|
}
|
|
2565
1370
|
/**
|
|
2566
1371
|
* Formats a currency value according to the specified locales and options.
|
|
@@ -2577,10 +1382,7 @@ var GT = class {
|
|
|
2577
1382
|
* // Returns: "$1,234.56"
|
|
2578
1383
|
*/
|
|
2579
1384
|
formatCurrency(value, currency, options) {
|
|
2580
|
-
return formatCurrency(value, currency,
|
|
2581
|
-
locales: this._renderingLocales,
|
|
2582
|
-
...options
|
|
2583
|
-
});
|
|
1385
|
+
return this.localeConfig.formatCurrency(value, currency, this.targetLocale, options);
|
|
2584
1386
|
}
|
|
2585
1387
|
/**
|
|
2586
1388
|
* Formats a list of items according to the specified locales and options.
|
|
@@ -2596,11 +1398,7 @@ var GT = class {
|
|
|
2596
1398
|
* // Returns: "apple, banana, and orange"
|
|
2597
1399
|
*/
|
|
2598
1400
|
formatList(array, options) {
|
|
2599
|
-
return
|
|
2600
|
-
value: array,
|
|
2601
|
-
locales: options?.locales || this._renderingLocales,
|
|
2602
|
-
options
|
|
2603
|
-
});
|
|
1401
|
+
return this.localeConfig.formatList(array, this.targetLocale, options);
|
|
2604
1402
|
}
|
|
2605
1403
|
/**
|
|
2606
1404
|
* Formats a list of items according to the specified locales and options.
|
|
@@ -2615,11 +1413,7 @@ var GT = class {
|
|
|
2615
1413
|
* // Returns: ['apple', ', ', 42, ' and ', '{ foo: "bar" }']
|
|
2616
1414
|
*/
|
|
2617
1415
|
formatListToParts(array, options) {
|
|
2618
|
-
return
|
|
2619
|
-
value: array,
|
|
2620
|
-
locales: options?.locales || this._renderingLocales,
|
|
2621
|
-
options
|
|
2622
|
-
});
|
|
1416
|
+
return this.localeConfig.formatListToParts(array, this.targetLocale, options);
|
|
2623
1417
|
}
|
|
2624
1418
|
/**
|
|
2625
1419
|
* Formats a relative time value according to the specified locales and options.
|
|
@@ -2636,10 +1430,7 @@ var GT = class {
|
|
|
2636
1430
|
* // Returns: "yesterday"
|
|
2637
1431
|
*/
|
|
2638
1432
|
formatRelativeTime(value, unit, options) {
|
|
2639
|
-
return formatRelativeTime(value, unit,
|
|
2640
|
-
locales: this._renderingLocales,
|
|
2641
|
-
...options
|
|
2642
|
-
});
|
|
1433
|
+
return this.localeConfig.formatRelativeTime(value, unit, this.targetLocale, options);
|
|
2643
1434
|
}
|
|
2644
1435
|
/**
|
|
2645
1436
|
* Formats a relative time string from a Date, automatically selecting the best unit.
|
|
@@ -2654,10 +1445,7 @@ var GT = class {
|
|
|
2654
1445
|
* // Returns: "1 hour ago"
|
|
2655
1446
|
*/
|
|
2656
1447
|
formatRelativeTimeFromDate(date, options) {
|
|
2657
|
-
return formatRelativeTimeFromDate(date,
|
|
2658
|
-
locales: this._renderingLocales,
|
|
2659
|
-
...options
|
|
2660
|
-
});
|
|
1448
|
+
return this.localeConfig.formatRelativeTimeFromDate(date, this.targetLocale, options);
|
|
2661
1449
|
}
|
|
2662
1450
|
/**
|
|
2663
1451
|
* Retrieves the display name of a locale code using Intl.DisplayNames, returning an empty string if no name is found.
|
|
@@ -2672,7 +1460,7 @@ var GT = class {
|
|
|
2672
1460
|
*/
|
|
2673
1461
|
getLocaleName(locale = this.targetLocale) {
|
|
2674
1462
|
if (!locale) throw new Error(noTargetLocaleProvidedError("getLocaleName"));
|
|
2675
|
-
return
|
|
1463
|
+
return this.localeConfig.getLocaleName(locale);
|
|
2676
1464
|
}
|
|
2677
1465
|
/**
|
|
2678
1466
|
* Retrieves an emoji based on a given locale code.
|
|
@@ -2688,7 +1476,7 @@ var GT = class {
|
|
|
2688
1476
|
*/
|
|
2689
1477
|
getLocaleEmoji(locale = this.targetLocale) {
|
|
2690
1478
|
if (!locale) throw new Error(noTargetLocaleProvidedError("getLocaleEmoji"));
|
|
2691
|
-
return getLocaleEmoji(locale
|
|
1479
|
+
return this.localeConfig.getLocaleEmoji(locale);
|
|
2692
1480
|
}
|
|
2693
1481
|
/**
|
|
2694
1482
|
* Generates linguistic details for a given locale code.
|
|
@@ -2724,7 +1512,7 @@ var GT = class {
|
|
|
2724
1512
|
*/
|
|
2725
1513
|
getLocaleProperties(locale = this.targetLocale) {
|
|
2726
1514
|
if (!locale) throw new Error(noTargetLocaleProvidedError("getLocaleProperties"));
|
|
2727
|
-
return getLocaleProperties(locale
|
|
1515
|
+
return this.localeConfig.getLocaleProperties(locale);
|
|
2728
1516
|
}
|
|
2729
1517
|
/**
|
|
2730
1518
|
* Retrieves multiple properties for a given region code, including:
|
|
@@ -2798,6 +1586,7 @@ var GT = class {
|
|
|
2798
1586
|
requiresTranslation(sourceLocale = this.sourceLocale, targetLocale = this.targetLocale, approvedLocales = this.locales, customMapping = this.customMapping) {
|
|
2799
1587
|
if (!sourceLocale) throw new Error(noSourceLocaleProvidedError("requiresTranslation"));
|
|
2800
1588
|
if (!targetLocale) throw new Error(noTargetLocaleProvidedError("requiresTranslation"));
|
|
1589
|
+
if (customMapping === this.customMapping) return this.localeConfig.requiresTranslation(targetLocale, sourceLocale, approvedLocales);
|
|
2801
1590
|
return _requiresTranslation(sourceLocale, targetLocale, approvedLocales, customMapping);
|
|
2802
1591
|
}
|
|
2803
1592
|
/**
|
|
@@ -2812,6 +1601,7 @@ var GT = class {
|
|
|
2812
1601
|
* // Returns: "fr-FR"
|
|
2813
1602
|
*/
|
|
2814
1603
|
determineLocale(locales, approvedLocales = this.locales || [], customMapping = this.customMapping) {
|
|
1604
|
+
if (customMapping === this.customMapping) return this.localeConfig.determineLocale(locales, approvedLocales ?? []);
|
|
2815
1605
|
return _determineLocale(locales, approvedLocales, customMapping);
|
|
2816
1606
|
}
|
|
2817
1607
|
/**
|
|
@@ -2827,7 +1617,7 @@ var GT = class {
|
|
|
2827
1617
|
*/
|
|
2828
1618
|
getLocaleDirection(locale = this.targetLocale) {
|
|
2829
1619
|
if (!locale) throw new Error(noTargetLocaleProvidedError("getLocaleDirection"));
|
|
2830
|
-
return getLocaleDirection(locale);
|
|
1620
|
+
return this.localeConfig.getLocaleDirection(locale);
|
|
2831
1621
|
}
|
|
2832
1622
|
/**
|
|
2833
1623
|
* Checks if a given BCP 47 locale code is valid.
|
|
@@ -2843,7 +1633,8 @@ var GT = class {
|
|
|
2843
1633
|
*/
|
|
2844
1634
|
isValidLocale(locale = this.targetLocale, customMapping = this.customMapping) {
|
|
2845
1635
|
if (!locale) throw new Error(noTargetLocaleProvidedError("isValidLocale"));
|
|
2846
|
-
return isValidLocale(locale
|
|
1636
|
+
if (customMapping === this.customMapping) return this.localeConfig.isValidLocale(locale);
|
|
1637
|
+
return _isValidLocale(locale, customMapping);
|
|
2847
1638
|
}
|
|
2848
1639
|
/**
|
|
2849
1640
|
* Resolves the canonical locale for a given locale.
|
|
@@ -2853,6 +1644,7 @@ var GT = class {
|
|
|
2853
1644
|
*/
|
|
2854
1645
|
resolveCanonicalLocale(locale = this.targetLocale, customMapping = this.customMapping) {
|
|
2855
1646
|
if (!locale) throw new Error(noTargetLocaleProvidedError("resolveCanonicalLocale"));
|
|
1647
|
+
if (customMapping === this.customMapping) return this.localeConfig.resolveCanonicalLocale(locale);
|
|
2856
1648
|
return _resolveCanonicalLocale(locale, customMapping);
|
|
2857
1649
|
}
|
|
2858
1650
|
/**
|
|
@@ -2863,6 +1655,7 @@ var GT = class {
|
|
|
2863
1655
|
*/
|
|
2864
1656
|
resolveAliasLocale(locale, customMapping = this.customMapping) {
|
|
2865
1657
|
if (!locale) throw new Error(noTargetLocaleProvidedError("resolveAliasLocale"));
|
|
1658
|
+
if (customMapping === this.customMapping) return this.localeConfig.resolveAliasLocale(locale);
|
|
2866
1659
|
return _resolveAliasLocale(locale, customMapping);
|
|
2867
1660
|
}
|
|
2868
1661
|
/**
|
|
@@ -2878,7 +1671,7 @@ var GT = class {
|
|
|
2878
1671
|
*/
|
|
2879
1672
|
standardizeLocale(locale = this.targetLocale) {
|
|
2880
1673
|
if (!locale) throw new Error(noTargetLocaleProvidedError("standardizeLocale"));
|
|
2881
|
-
return
|
|
1674
|
+
return this.localeConfig.standardizeLocale(locale);
|
|
2882
1675
|
}
|
|
2883
1676
|
/**
|
|
2884
1677
|
* Checks if multiple BCP 47 locale codes represent the same dialect.
|
|
@@ -2894,7 +1687,7 @@ var GT = class {
|
|
|
2894
1687
|
* // Returns: true
|
|
2895
1688
|
*/
|
|
2896
1689
|
isSameDialect(...locales) {
|
|
2897
|
-
return isSameDialect(...locales);
|
|
1690
|
+
return this.localeConfig.isSameDialect(...locales);
|
|
2898
1691
|
}
|
|
2899
1692
|
/**
|
|
2900
1693
|
* Checks if multiple BCP 47 locale codes represent the same language.
|
|
@@ -2907,7 +1700,7 @@ var GT = class {
|
|
|
2907
1700
|
* // Returns: true
|
|
2908
1701
|
*/
|
|
2909
1702
|
isSameLanguage(...locales) {
|
|
2910
|
-
return
|
|
1703
|
+
return this.localeConfig.isSameLanguage(...locales);
|
|
2911
1704
|
}
|
|
2912
1705
|
/**
|
|
2913
1706
|
* Checks if a locale is a superset of another locale.
|
|
@@ -2924,76 +1717,10 @@ var GT = class {
|
|
|
2924
1717
|
* // Returns: false
|
|
2925
1718
|
*/
|
|
2926
1719
|
isSupersetLocale(superLocale, subLocale) {
|
|
2927
|
-
return isSupersetLocale(superLocale, subLocale);
|
|
1720
|
+
return this.localeConfig.isSupersetLocale(superLocale, subLocale);
|
|
2928
1721
|
}
|
|
2929
1722
|
};
|
|
2930
1723
|
/**
|
|
2931
|
-
* Formats a string with cutoff behavior, applying a terminator when the string exceeds the maximum character limit.
|
|
2932
|
-
*
|
|
2933
|
-
* This standalone function provides cutoff formatting functionality without requiring a GT instance.
|
|
2934
|
-
* The locales parameter is required for proper terminator selection based on the target language.
|
|
2935
|
-
*
|
|
2936
|
-
* @param {string} value - The string value to format with cutoff behavior.
|
|
2937
|
-
* @param {Object} [options] - Configuration options for cutoff formatting.
|
|
2938
|
-
* @param {string | string[]} [options.locales] - The locales to use for terminator selection.
|
|
2939
|
-
* @param {number} [options.maxChars] - The maximum number of characters to display.
|
|
2940
|
-
* - Undefined values are treated as no cutoff.
|
|
2941
|
-
* - Negative values follow .slice() behavior and terminator will be added before the value.
|
|
2942
|
-
* - 0 will result in an empty string.
|
|
2943
|
-
* - If cutoff results in an empty string, no terminator is added.
|
|
2944
|
-
* @param {CutoffFormatStyle} [options.style='ellipsis'] - The style of the terminator.
|
|
2945
|
-
* @param {string} [options.terminator] - Optional override the terminator to use.
|
|
2946
|
-
* @param {string} [options.separator] - Optional override the separator to use between the terminator and the value.
|
|
2947
|
-
* - If no terminator is provided, then separator is ignored.
|
|
2948
|
-
* @returns {string} The formatted string with terminator applied if cutoff occurs.
|
|
2949
|
-
*
|
|
2950
|
-
* @example
|
|
2951
|
-
* formatCutoff('Hello, world!', { locales: 'en-US', maxChars: 8 });
|
|
2952
|
-
* // Returns: 'Hello, w...'
|
|
2953
|
-
*
|
|
2954
|
-
* @example
|
|
2955
|
-
* formatCutoff('Hello, world!', { locales: 'en-US', maxChars: -3 });
|
|
2956
|
-
* // Returns: '...ld!'
|
|
2957
|
-
*
|
|
2958
|
-
* @example
|
|
2959
|
-
* formatCutoff('Very long text that needs cutting', {
|
|
2960
|
-
* locales: 'en-US',
|
|
2961
|
-
* maxChars: 15,
|
|
2962
|
-
* style: 'ellipsis',
|
|
2963
|
-
* separator: ' '
|
|
2964
|
-
* });
|
|
2965
|
-
* // Returns: 'Very long text ...'
|
|
2966
|
-
*/
|
|
2967
|
-
function formatCutoff(value, options) {
|
|
2968
|
-
return _formatCutoff({
|
|
2969
|
-
value,
|
|
2970
|
-
locales: options?.locales,
|
|
2971
|
-
options
|
|
2972
|
-
});
|
|
2973
|
-
}
|
|
2974
|
-
/**
|
|
2975
|
-
* Formats a message according to the specified locales and options.
|
|
2976
|
-
*
|
|
2977
|
-
* @param {string} message - The message to format.
|
|
2978
|
-
* @param {string | string[]} [locales='en'] - The locales to use for formatting.
|
|
2979
|
-
* @param {FormatVariables} [variables={}] - The variables to use for formatting.
|
|
2980
|
-
* @param {StringFormat} [dataFormat='ICU'] - The format of the message. (When STRING, the message is returned as is)
|
|
2981
|
-
* @returns {string} The formatted message.
|
|
2982
|
-
*
|
|
2983
|
-
* @example
|
|
2984
|
-
* formatMessage('Hello {name}', { name: 'John' });
|
|
2985
|
-
* // Returns: "Hello John"
|
|
2986
|
-
*
|
|
2987
|
-
* formatMessage('Hello {name}', { name: 'John' }, { locales: ['fr'] });
|
|
2988
|
-
* // Returns: "Bonjour John"
|
|
2989
|
-
*/
|
|
2990
|
-
function formatMessage(message, options) {
|
|
2991
|
-
switch (options?.dataFormat) {
|
|
2992
|
-
case "STRING": return _formatMessageString(message);
|
|
2993
|
-
default: return _formatMessageICU(message, options?.locales, options?.variables);
|
|
2994
|
-
}
|
|
2995
|
-
}
|
|
2996
|
-
/**
|
|
2997
1724
|
* Formats a number according to the specified locales and options.
|
|
2998
1725
|
* @param {Object} params - The parameters for the number formatting.
|
|
2999
1726
|
* @param {number} params.value - The number to format.
|
|
@@ -3237,15 +1964,6 @@ function getLocaleDirection(locale) {
|
|
|
3237
1964
|
return _getLocaleDirection(locale);
|
|
3238
1965
|
}
|
|
3239
1966
|
/**
|
|
3240
|
-
* Checks if a given BCP 47 locale code is valid.
|
|
3241
|
-
* @param {string} locale - The BCP 47 locale code to validate.
|
|
3242
|
-
* @param {CustomMapping} [customMapping] - The custom mapping to use for validation.
|
|
3243
|
-
* @returns {boolean} True if the BCP 47 code is valid, false otherwise.
|
|
3244
|
-
*/
|
|
3245
|
-
function isValidLocale(locale, customMapping) {
|
|
3246
|
-
return _isValidLocale(locale, customMapping);
|
|
3247
|
-
}
|
|
3248
|
-
/**
|
|
3249
1967
|
* Resolves the alias locale for a given locale.
|
|
3250
1968
|
* @param {string} locale - The locale to resolve the alias locale for
|
|
3251
1969
|
* @param {CustomMapping} [customMapping] - The custom mapping to use for resolving the alias locale
|
|
@@ -3255,23 +1973,6 @@ function resolveAliasLocale(locale, customMapping) {
|
|
|
3255
1973
|
return _resolveAliasLocale(locale, customMapping);
|
|
3256
1974
|
}
|
|
3257
1975
|
/**
|
|
3258
|
-
* Resolves the canonical locale for a given locale.
|
|
3259
|
-
* @param {string} locale - The locale to resolve the canonical locale for
|
|
3260
|
-
* @param {CustomMapping} [customMapping] - The custom mapping to use for resolving the canonical locale
|
|
3261
|
-
* @returns {string} The canonical locale
|
|
3262
|
-
*/
|
|
3263
|
-
function resolveCanonicalLocale(locale, customMapping) {
|
|
3264
|
-
return _resolveCanonicalLocale(locale, customMapping);
|
|
3265
|
-
}
|
|
3266
|
-
/**
|
|
3267
|
-
* Standardizes a BCP 47 locale code to ensure correct formatting.
|
|
3268
|
-
* @param {string} locale - The BCP 47 locale code to standardize.
|
|
3269
|
-
* @returns {string} The standardized BCP 47 locale code or an empty string if it is an invalid code.
|
|
3270
|
-
*/
|
|
3271
|
-
function standardizeLocale(locale) {
|
|
3272
|
-
return _standardizeLocale(locale);
|
|
3273
|
-
}
|
|
3274
|
-
/**
|
|
3275
1976
|
* Checks if multiple BCP 47 locale codes represent the same dialect.
|
|
3276
1977
|
* @param {string[]} locales - The BCP 47 locale codes to compare.
|
|
3277
1978
|
* @returns {boolean} True if all BCP 47 codes represent the same dialect, false otherwise.
|
|
@@ -3300,6 +2001,6 @@ function isSupersetLocale(superLocale, subLocale) {
|
|
|
3300
2001
|
}
|
|
3301
2002
|
const API_VERSION = API_VERSION$1;
|
|
3302
2003
|
//#endregion
|
|
3303
|
-
export { API_VERSION, GT, determineLocale, formatCurrency, formatCutoff, formatDateTime, formatList, formatListToParts, formatMessage, formatNum, formatRelativeTime, formatRelativeTimeFromDate, getLocaleDirection, getLocaleEmoji, getLocaleName, getLocaleProperties, getRegionProperties, isSameDialect, isSameLanguage, isSupersetLocale, isValidLocale, requiresTranslation, resolveAliasLocale, resolveCanonicalLocale, standardizeLocale };
|
|
2004
|
+
export { API_VERSION, GT, LocaleConfig, determineLocale, formatCurrency, formatCutoff, formatDateTime, formatList, formatListToParts, formatMessage, formatNum, formatRelativeTime, formatRelativeTimeFromDate, getLocaleDirection, getLocaleEmoji, getLocaleName, getLocaleProperties, getRegionProperties, isSameDialect, isSameLanguage, isSupersetLocale, isValidLocale, requiresTranslation, resolveAliasLocale, resolveCanonicalLocale, standardizeLocale };
|
|
3304
2005
|
|
|
3305
2006
|
//# sourceMappingURL=index.mjs.map
|