generaltranslation 8.2.13 → 8.2.15

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 (133) hide show
  1. package/CHANGELOG.md +22 -1
  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-YBGAXkqy.cjs} +74 -1
  9. package/dist/base64-YBGAXkqy.cjs.map +1 -0
  10. package/dist/{base64-DH0STixb.mjs → base64-r7YWJYWt.mjs} +51 -2
  11. package/dist/base64-r7YWJYWt.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 +431 -396
  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 +278 -363
  37. package/dist/index.mjs.map +1 -1
  38. package/dist/internal.cjs +8 -6
  39. package/dist/internal.cjs.map +1 -1
  40. package/dist/internal.d.cts +37 -6
  41. package/dist/internal.d.mts +37 -6
  42. package/dist/internal.d.ts +2 -0
  43. package/dist/internal.js +1 -0
  44. package/dist/internal.mjs +5 -5
  45. package/dist/internal.mjs.map +1 -1
  46. package/dist/{isVariable-B08mggBy.cjs → isVariable-Ba1gLXdB.cjs} +1 -1
  47. package/dist/{isVariable-B08mggBy.cjs.map → isVariable-Ba1gLXdB.cjs.map} +1 -1
  48. package/dist/{isVariable-CYsKFHvR.mjs → isVariable-fAKEB7gF.mjs} +1 -1
  49. package/dist/{isVariable-CYsKFHvR.mjs.map → isVariable-fAKEB7gF.mjs.map} +1 -1
  50. package/dist/locales/getPluralForm.js +2 -2
  51. package/dist/logging/diagnostics.d.ts +18 -0
  52. package/dist/logging/diagnostics.js +64 -0
  53. package/dist/logging/errors.d.ts +1 -1
  54. package/dist/logging/errors.js +64 -11
  55. package/dist/logging/logger.d.ts +0 -3
  56. package/dist/logging/logger.js +0 -3
  57. package/dist/{types-AHtYZIP-.d.mts → types-CdRgQtET.d.cts} +6 -106
  58. package/dist/{types-Bf8_Apq_.d.cts → types-Db2Dn3oN.d.mts} +6 -106
  59. package/dist/types-dir/api/enqueueEntries.d.ts +1 -1
  60. package/dist/types-dir/api/enqueueFiles.d.ts +1 -1
  61. package/dist/types-dir/api/fetchTranslations.d.ts +1 -1
  62. package/dist/types-dir/api/file.d.ts +1 -1
  63. package/dist/types-dir/api/translate.d.ts +1 -1
  64. package/dist/types-dir/api/uploadFiles.d.ts +1 -1
  65. package/dist/types.cjs +7 -16
  66. package/dist/types.d.cts +2 -2
  67. package/dist/types.d.mts +2 -2
  68. package/dist/types.d.ts +10 -13
  69. package/dist/types.js +1 -2
  70. package/dist/types.mjs +1 -15
  71. package/package.json +3 -2
  72. package/dist/IntlCache-CAW8tKhd.cjs +0 -212
  73. package/dist/IntlCache-CAW8tKhd.cjs.map +0 -1
  74. package/dist/IntlCache-WZk0rKvj.mjs +0 -195
  75. package/dist/IntlCache-WZk0rKvj.mjs.map +0 -1
  76. package/dist/base64-2fu94Klt.cjs.map +0 -1
  77. package/dist/base64-DH0STixb.mjs.map +0 -1
  78. package/dist/cache/IntlCache.d.ts +0 -26
  79. package/dist/cache/IntlCache.js +0 -84
  80. package/dist/cache/types.d.ts +0 -32
  81. package/dist/cache/types.js +0 -1
  82. package/dist/core-7RP541eY.cjs +0 -1677
  83. package/dist/core-7RP541eY.cjs.map +0 -1
  84. package/dist/core-I9pWGafA.d.mts +0 -209
  85. package/dist/core-TLJoDpJP.d.cts +0 -209
  86. package/dist/core-isLphYAZ.mjs +0 -1498
  87. package/dist/core-isLphYAZ.mjs.map +0 -1
  88. package/dist/errors/formattingErrors.d.ts +0 -1
  89. package/dist/errors/formattingErrors.js +0 -3
  90. package/dist/formatting/custom-formats/CutoffFormat/CutoffFormat.d.ts +0 -59
  91. package/dist/formatting/custom-formats/CutoffFormat/CutoffFormat.js +0 -147
  92. package/dist/formatting/custom-formats/CutoffFormat/constants.d.ts +0 -4
  93. package/dist/formatting/custom-formats/CutoffFormat/constants.js +0 -30
  94. package/dist/formatting/custom-formats/CutoffFormat/types.d.ts +0 -48
  95. package/dist/formatting/custom-formats/CutoffFormat/types.js +0 -2
  96. package/dist/formatting/format.d.ts +0 -1
  97. package/dist/formatting/format.js +0 -257
  98. package/dist/locales/customLocaleMapping.d.ts +0 -11
  99. package/dist/locales/customLocaleMapping.js +0 -23
  100. package/dist/locales/determineLocale.d.ts +0 -1
  101. package/dist/locales/determineLocale.js +0 -72
  102. package/dist/locales/getLocaleDirection.d.ts +0 -1
  103. package/dist/locales/getLocaleDirection.js +0 -89
  104. package/dist/locales/getLocaleEmoji.d.ts +0 -2
  105. package/dist/locales/getLocaleEmoji.js +0 -319
  106. package/dist/locales/getLocaleName.d.ts +0 -1
  107. package/dist/locales/getLocaleName.js +0 -45
  108. package/dist/locales/getLocaleProperties.d.ts +0 -32
  109. package/dist/locales/getLocaleProperties.js +0 -220
  110. package/dist/locales/getRegionProperties.d.ts +0 -7
  111. package/dist/locales/getRegionProperties.js +0 -61
  112. package/dist/locales/isSameDialect.d.ts +0 -1
  113. package/dist/locales/isSameDialect.js +0 -41
  114. package/dist/locales/isSameLanguage.d.ts +0 -1
  115. package/dist/locales/isSameLanguage.js +0 -20
  116. package/dist/locales/isSupersetLocale.d.ts +0 -1
  117. package/dist/locales/isSupersetLocale.js +0 -22
  118. package/dist/locales/isValidLocale.d.ts +0 -1
  119. package/dist/locales/isValidLocale.js +0 -75
  120. package/dist/locales/requiresTranslation.d.ts +0 -1
  121. package/dist/locales/requiresTranslation.js +0 -32
  122. package/dist/locales/resolveAliasLocale.d.ts +0 -8
  123. package/dist/locales/resolveAliasLocale.js +0 -21
  124. package/dist/locales/resolveCanonicalLocale.d.ts +0 -8
  125. package/dist/locales/resolveCanonicalLocale.js +0 -13
  126. package/dist/logging/warnings.d.ts +0 -2
  127. package/dist/logging/warnings.js +0 -2
  128. package/dist/types-dir/jsx/content.d.ts +0 -61
  129. package/dist/types-dir/jsx/content.js +0 -11
  130. package/dist/types-dir/jsx/variables.d.ts +0 -9
  131. package/dist/types-dir/jsx/variables.js +0 -1
  132. package/dist/types.cjs.map +0 -1
  133. package/dist/types.mjs.map +0 -1
package/dist/index.mjs CHANGED
@@ -1,20 +1,269 @@
1
- import { n as defaultTimeout, t as intlCache } from "./IntlCache-WZk0rKvj.mjs";
2
- import { A as _standardizeLocale, C as _getLocaleEmoji, D as _isSameLanguage, E as _requiresTranslation, O as _isSameDialect, S as _getLocaleProperties, T as getRegionEmoji, _ 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-isLphYAZ.mjs";
3
- import { n as encode, r as validateFileFormatTransforms, t as decode } from "./base64-DH0STixb.mjs";
4
- import { t as ApiError } from "./ApiError-IYfaOR30.mjs";
5
- import { n as hashSource } from "./id-DbD7K-HL.mjs";
1
+ import { c as createDiagnosticMessage, n as encode, r as validateFileFormatTransforms, t as decode, u as defaultTimeout } from "./base64-r7YWJYWt.mjs";
2
+ import { t as ApiError } from "./ApiError-0DxxIHLp.mjs";
3
+ import { n as hashSource } from "./id-DEaFhGqX.mjs";
4
+ import { LocaleConfig, LocaleConfig as LocaleConfig$1, determineLocale, determineLocale as determineLocale$1, formatCurrency, formatCutoff, formatDateTime, formatList, formatListToParts, formatMessage, formatNum, formatRelativeTime, formatRelativeTimeFromDate, getLocaleDirection, getLocaleEmoji, getLocaleName, getLocaleProperties, getRegionProperties, getRegionProperties as getRegionProperties$1, isSameDialect, isSameLanguage, isSupersetLocale, isValidLocale, isValidLocale as isValidLocale$1, requiresTranslation, requiresTranslation as requiresTranslation$1, resolveAliasLocale, resolveAliasLocale as resolveAliasLocale$1, resolveCanonicalLocale, resolveCanonicalLocale as resolveCanonicalLocale$1, standardizeLocale, standardizeLocale as standardizeLocale$1 } from "@generaltranslation/format";
6
5
  //#region src/logging/errors.ts
7
- const GT_ERROR_PREFIX = "GT Error:";
8
- const translationTimeoutError = (timeout) => `${GT_ERROR_PREFIX} Translation request timed out after ${timeout}ms.`;
9
- const translationRequestFailedError = (error) => `${GT_ERROR_PREFIX} Translation request failed. Error: ${error}`;
10
- const apiError = (status, statusText, error) => `${GT_ERROR_PREFIX} API returned error status. Status: ${status}, Status Text: ${statusText}, Error: ${error}`;
11
- `${GT_ERROR_PREFIX}`;
12
- const noTargetLocaleProvidedError = (functionName) => `${GT_ERROR_PREFIX} Cannot call \`${functionName}\` without a specified locale. Either pass a locale to the \`${functionName}\` function or specify a targetLocale in the GT constructor.`;
13
- const noSourceLocaleProvidedError = (functionName) => `${GT_ERROR_PREFIX} Cannot call \`${functionName}\` without a specified locale. Either pass a locale to the \`${functionName}\` function or specify a sourceLocale in the GT constructor.`;
14
- const noProjectIdProvidedError = (functionName) => `${GT_ERROR_PREFIX} Cannot call \`${functionName}\` without a specified project ID. Either pass a project ID to the \`${functionName}\` function or specify a projectId in the GT constructor.`;
15
- const noApiKeyProvidedError = (functionName) => `${GT_ERROR_PREFIX} Cannot call \`${functionName}\` without a specified API key. Either pass an API key to the \`${functionName}\` function or specify an apiKey in the GT constructor.`;
16
- const invalidLocaleError = (locale) => `${GT_ERROR_PREFIX} Invalid locale: ${locale}.`;
17
- const invalidLocalesError = (locales) => `${GT_ERROR_PREFIX} Invalid locales: ${locales.join(", ")}.`;
6
+ const GT_SOURCE = "GT";
7
+ const translationTimeoutError = (timeout) => createDiagnosticMessage({
8
+ source: GT_SOURCE,
9
+ severity: "Error",
10
+ whatHappened: `Translation request timed out after ${timeout}ms`,
11
+ fix: "Try again, or increase the request timeout if the source content is large"
12
+ });
13
+ const translationRequestFailedError = (error) => createDiagnosticMessage({
14
+ source: GT_SOURCE,
15
+ severity: "Error",
16
+ whatHappened: "Translation request could not be completed",
17
+ fix: "Check your network connection and translation credentials, then try again",
18
+ details: error
19
+ });
20
+ const apiError = (status, statusText, error) => createDiagnosticMessage({
21
+ source: GT_SOURCE,
22
+ severity: "Error",
23
+ whatHappened: `The translation API returned ${status} ${statusText}`,
24
+ fix: "Check the request configuration and try again",
25
+ details: error
26
+ });
27
+ createDiagnosticMessage({
28
+ source: GT_SOURCE,
29
+ severity: "Error",
30
+ whatHappened: "Authentication failed",
31
+ fix: "Check that your API key and project ID are correct"
32
+ });
33
+ const noTargetLocaleProvidedError = (functionName) => createDiagnosticMessage({
34
+ source: GT_SOURCE,
35
+ severity: "Error",
36
+ whatHappened: `Cannot call \`${functionName}\` without a specified locale`,
37
+ fix: `Pass a locale to \`${functionName}\` or specify targetLocale in the GT constructor`
38
+ });
39
+ const noSourceLocaleProvidedError = (functionName) => createDiagnosticMessage({
40
+ source: GT_SOURCE,
41
+ severity: "Error",
42
+ whatHappened: `Cannot call \`${functionName}\` without a specified locale`,
43
+ fix: `Pass a locale to \`${functionName}\` or specify sourceLocale in the GT constructor`
44
+ });
45
+ const noProjectIdProvidedError = (functionName) => createDiagnosticMessage({
46
+ source: GT_SOURCE,
47
+ severity: "Error",
48
+ whatHappened: `Cannot call \`${functionName}\` without a specified project ID`,
49
+ fix: `Pass a project ID to \`${functionName}\` or specify projectId in the GT constructor`
50
+ });
51
+ const noApiKeyProvidedError = (functionName) => createDiagnosticMessage({
52
+ source: GT_SOURCE,
53
+ severity: "Error",
54
+ whatHappened: `Cannot call \`${functionName}\` without a specified API key`,
55
+ fix: `Pass an API key to \`${functionName}\` or specify apiKey in the GT constructor`
56
+ });
57
+ const invalidLocaleError = (locale) => createDiagnosticMessage({
58
+ source: GT_SOURCE,
59
+ severity: "Error",
60
+ whatHappened: `Locale "${locale}" is not valid`,
61
+ fix: "Use a valid BCP 47 locale code or add a custom mapping"
62
+ });
63
+ const invalidLocalesError = (locales) => createDiagnosticMessage({
64
+ source: GT_SOURCE,
65
+ severity: "Error",
66
+ whatHappened: `These locales are not valid: ${locales.join(", ")}`,
67
+ fix: "Use valid BCP 47 locale codes or add custom mappings"
68
+ });
69
+ //#endregion
70
+ //#region src/logging/logger.ts
71
+ const LOG_LEVELS = {
72
+ debug: 0,
73
+ info: 1,
74
+ warn: 2,
75
+ error: 3,
76
+ off: 4
77
+ };
78
+ const LOG_COLORS = {
79
+ debug: "\x1B[36m",
80
+ info: "\x1B[32m",
81
+ warn: "\x1B[33m",
82
+ error: "\x1B[31m",
83
+ off: ""
84
+ };
85
+ const RESET_COLOR = "\x1B[0m";
86
+ /**
87
+ * Get the configured log level from environment variable or default to 'warn'
88
+ */
89
+ function getConfiguredLogLevel() {
90
+ if (typeof process !== "undefined" && process.env?._GT_LOG_LEVEL) {
91
+ const envLevel = process.env._GT_LOG_LEVEL.toLowerCase();
92
+ if (envLevel in LOG_LEVELS) return envLevel;
93
+ }
94
+ return "warn";
95
+ }
96
+ /**
97
+ * Console log handler that outputs formatted messages to console
98
+ */
99
+ var ConsoleLogHandler = class {
100
+ constructor(config) {
101
+ this.config = config;
102
+ }
103
+ handle(entry) {
104
+ const parts = [];
105
+ if (this.config.includeTimestamp) parts.push(`[${entry.timestamp.toISOString()}]`);
106
+ const colorCode = LOG_COLORS[entry.level];
107
+ const levelText = `[${entry.level.toUpperCase()}]`;
108
+ parts.push(`${colorCode}${levelText}${RESET_COLOR}`);
109
+ if (this.config.prefix) parts.push(`[${this.config.prefix}]`);
110
+ if (this.config.includeContext && entry.context) parts.push(`[${entry.context}]`);
111
+ parts.push(entry.message);
112
+ if (entry.metadata && Object.keys(entry.metadata).length > 0) parts.push(`\n Metadata: ${JSON.stringify(entry.metadata, null, 2)}`);
113
+ const formattedMessage = parts.join(" ");
114
+ switch (entry.level) {
115
+ case "debug":
116
+ console.debug(formattedMessage);
117
+ break;
118
+ case "info":
119
+ console.info(formattedMessage);
120
+ break;
121
+ case "warn":
122
+ console.warn(formattedMessage);
123
+ break;
124
+ case "error":
125
+ console.error(formattedMessage);
126
+ break;
127
+ }
128
+ }
129
+ };
130
+ /**
131
+ * Main Logger class providing structured logging capabilities.
132
+ */
133
+ var Logger = class {
134
+ constructor(config = {}) {
135
+ this.config = {
136
+ level: getConfiguredLogLevel(),
137
+ includeTimestamp: true,
138
+ includeContext: true,
139
+ enableConsole: true,
140
+ handlers: [],
141
+ ...config
142
+ };
143
+ this.handlers = [...this.config.handlers || []];
144
+ if (this.config.enableConsole) this.handlers.push(new ConsoleLogHandler(this.config));
145
+ }
146
+ /**
147
+ * Add a custom log handler
148
+ */
149
+ addHandler(handler) {
150
+ this.handlers.push(handler);
151
+ }
152
+ /**
153
+ * Remove a log handler
154
+ */
155
+ removeHandler(handler) {
156
+ const index = this.handlers.indexOf(handler);
157
+ if (index > -1) this.handlers.splice(index, 1);
158
+ }
159
+ /**
160
+ * Update logger configuration
161
+ */
162
+ configure(config) {
163
+ this.config = {
164
+ ...this.config,
165
+ ...config
166
+ };
167
+ }
168
+ /**
169
+ * Check if a log level should be output based on current configuration
170
+ */
171
+ shouldLog(level) {
172
+ return LOG_LEVELS[level] >= LOG_LEVELS[this.config.level];
173
+ }
174
+ /**
175
+ * Internal logging method that creates log entries and passes them to handlers
176
+ */
177
+ log(level, message, context, metadata) {
178
+ if (!this.shouldLog(level)) return;
179
+ const entry = {
180
+ level,
181
+ message,
182
+ timestamp: /* @__PURE__ */ new Date(),
183
+ context,
184
+ metadata
185
+ };
186
+ this.handlers.forEach((handler) => {
187
+ try {
188
+ handler.handle(entry);
189
+ } catch (error) {
190
+ console.error("Error in log handler:", error);
191
+ }
192
+ });
193
+ }
194
+ /**
195
+ * Log a debug message
196
+ * Used for detailed diagnostic information, typically of interest only when diagnosing problems
197
+ */
198
+ debug(message, context, metadata) {
199
+ this.log("debug", message, context, metadata);
200
+ }
201
+ /**
202
+ * Log an info message
203
+ * Used for general information about application operation.
204
+ */
205
+ info(message, context, metadata) {
206
+ this.log("info", message, context, metadata);
207
+ }
208
+ /**
209
+ * Log a warning message
210
+ * Used for potentially problematic situations that don't prevent operation
211
+ */
212
+ warn(message, context, metadata) {
213
+ this.log("warn", message, context, metadata);
214
+ }
215
+ /**
216
+ * Log an error message
217
+ * Used for error events that might still allow the application to continue.
218
+ */
219
+ error(message, context, metadata) {
220
+ this.log("error", message, context, metadata);
221
+ }
222
+ /**
223
+ * Create a child logger with a specific context
224
+ */
225
+ child(context) {
226
+ return new ContextLogger(this, context);
227
+ }
228
+ /**
229
+ * Get current logger configuration
230
+ */
231
+ getConfig() {
232
+ return { ...this.config };
233
+ }
234
+ };
235
+ /**
236
+ * Context logger that automatically includes context information.
237
+ */
238
+ var ContextLogger = class ContextLogger {
239
+ constructor(logger, context) {
240
+ this.logger = logger;
241
+ this.context = context;
242
+ }
243
+ debug(message, metadata) {
244
+ this.logger.debug(message, this.context, metadata);
245
+ }
246
+ info(message, metadata) {
247
+ this.logger.info(message, this.context, metadata);
248
+ }
249
+ warn(message, metadata) {
250
+ this.logger.warn(message, this.context, metadata);
251
+ }
252
+ error(message, metadata) {
253
+ this.logger.error(message, this.context, metadata);
254
+ }
255
+ child(childContext) {
256
+ return new ContextLogger(this.logger, `${this.context}:${childContext}`);
257
+ }
258
+ };
259
+ const defaultLogger = new Logger({
260
+ level: getConfiguredLogLevel(),
261
+ includeTimestamp: true,
262
+ includeContext: true,
263
+ prefix: "GT"
264
+ });
265
+ const fetchLogger = defaultLogger.child("fetch");
266
+ const gtInstanceLogger = defaultLogger.child("GT instance");
18
267
  //#endregion
19
268
  //#region src/translate/utils/fetchWithTimeout.ts
20
269
  /**
@@ -360,61 +609,6 @@ async function _submitUserEditDiffs(payload, config, options = {}) {
360
609
  return { success: true };
361
610
  }
362
611
  //#endregion
363
- //#region src/locales/getRegionProperties.ts
364
- /**
365
- * Retrieves multiple properties for a given region code, including:
366
- * - `code`: the original region code
367
- * - `name`: the localized display name
368
- * - `emoji`: the associated flag or symbol
369
- *
370
- * Behavior:
371
- * - Accepts ISO 3166-1 alpha-2 or UN M.49 region codes (e.g., `"US"`, `"FR"`, `"419"`).
372
- * - If `customMapping` contains a `name` or `emoji` for the region, those override the default values.
373
- * - Otherwise, uses `Intl.DisplayNames` to get the localized region name in the given `defaultLocale`,
374
- * falling back to `libraryDefaultLocale`.
375
- * - Falls back to the region code as `name` if display name resolution fails.
376
- * - Falls back to `defaultEmoji` if no emoji can be computed or found in `customMapping`.
377
- *
378
- * @param {string} region - The region code to look up (e.g., `"US"`, `"GB"`, `"DE"`).
379
- * @param {string} [defaultLocale=libraryDefaultLocale] - The locale to use when localizing the region name.
380
- * @param {CustomRegionMapping} [customMapping] - Optional mapping of region codes to custom names and/or emojis.
381
- * @returns {{ code: string, name: string, emoji: string }} An object containing:
382
- * - `code`: the input region code
383
- * - `name`: the localized or custom region name
384
- * - `emoji`: the matching emoji flag or symbol
385
- * @internal
386
- *
387
- * @example
388
- * _getRegionProperties('US', 'en');
389
- * // => { code: 'US', name: 'United States', emoji: '🇺🇸' }
390
- *
391
- * @example
392
- * _getRegionProperties('US', 'fr');
393
- * // => { code: 'US', name: 'États-Unis', emoji: '🇺🇸' }
394
- *
395
- * @example
396
- * _getRegionProperties('US', 'en', { US: { name: 'USA', emoji: '🗽' } });
397
- * // => { code: 'US', name: 'USA', emoji: '🗽' }
398
- */
399
- function _getRegionProperties(region, defaultLocale = "en", customMapping) {
400
- defaultLocale ||= "en";
401
- try {
402
- return {
403
- code: region,
404
- name: intlCache.get("DisplayNames", [defaultLocale, "en"], { type: "region" }).of(region) || region,
405
- emoji: getRegionEmoji(region),
406
- ...customMapping?.[region]
407
- };
408
- } catch {
409
- return {
410
- code: region,
411
- name: region,
412
- emoji: defaultEmoji,
413
- ...customMapping?.[region]
414
- };
415
- }
416
- }
417
- //#endregion
418
612
  //#region src/translate/uploadSourceFiles.ts
419
613
  /**
420
614
  * @internal
@@ -790,19 +984,19 @@ var GT = class {
790
984
  if (devApiKey) this.devApiKey = devApiKey;
791
985
  if (projectId) this.projectId = projectId;
792
986
  if (sourceLocale) {
793
- this.sourceLocale = _standardizeLocale(sourceLocale);
794
- if (!_isValidLocale(this.sourceLocale, customMapping)) throw new Error(invalidLocaleError(this.sourceLocale));
987
+ this.sourceLocale = standardizeLocale$1(sourceLocale);
988
+ if (!isValidLocale$1(this.sourceLocale, customMapping)) throw new Error(invalidLocaleError(this.sourceLocale));
795
989
  }
796
990
  if (targetLocale) {
797
- this.targetLocale = _standardizeLocale(targetLocale);
798
- if (!_isValidLocale(this.targetLocale, customMapping)) throw new Error(invalidLocaleError(this.targetLocale));
991
+ this.targetLocale = standardizeLocale$1(targetLocale);
992
+ if (!isValidLocale$1(this.targetLocale, customMapping)) throw new Error(invalidLocaleError(this.targetLocale));
799
993
  }
800
994
  if (locales) {
801
995
  const result = [];
802
996
  const invalidLocales = [];
803
997
  locales.forEach((locale) => {
804
- const standardizedLocale = _standardizeLocale(locale);
805
- if (_isValidLocale(standardizedLocale)) result.push(standardizedLocale);
998
+ const standardizedLocale = standardizeLocale$1(locale);
999
+ if (isValidLocale$1(standardizedLocale)) result.push(standardizedLocale);
806
1000
  else invalidLocales.push(locale);
807
1001
  });
808
1002
  if (invalidLocales.length > 0) throw new Error(invalidLocalesError(invalidLocales));
@@ -813,7 +1007,7 @@ var GT = class {
813
1007
  this.customMapping = customMapping;
814
1008
  this.reverseCustomMapping = Object.fromEntries(Object.entries(customMapping).filter(([, value]) => value && typeof value === "object" && "code" in value).map(([key, value]) => [value.code, key]));
815
1009
  }
816
- this._localeConfig = new LocaleConfig({
1010
+ this._localeConfig = new LocaleConfig$1({
817
1011
  defaultLocale: this.sourceLocale,
818
1012
  locales: this.locales ?? [],
819
1013
  customMapping: this.customMapping
@@ -1567,7 +1761,7 @@ var GT = class {
1567
1761
  }
1568
1762
  customMapping = this.customRegionMapping;
1569
1763
  }
1570
- return _getRegionProperties(region, this.targetLocale, customMapping);
1764
+ return getRegionProperties$1(region, this.targetLocale, customMapping);
1571
1765
  }
1572
1766
  /**
1573
1767
  * Determines whether a translation is required based on the source and target locales.
@@ -1587,7 +1781,7 @@ var GT = class {
1587
1781
  if (!sourceLocale) throw new Error(noSourceLocaleProvidedError("requiresTranslation"));
1588
1782
  if (!targetLocale) throw new Error(noTargetLocaleProvidedError("requiresTranslation"));
1589
1783
  if (customMapping === this.customMapping) return this.localeConfig.requiresTranslation(targetLocale, sourceLocale, approvedLocales);
1590
- return _requiresTranslation(sourceLocale, targetLocale, approvedLocales, customMapping);
1784
+ return requiresTranslation$1(sourceLocale, targetLocale, approvedLocales, customMapping);
1591
1785
  }
1592
1786
  /**
1593
1787
  * Determines the best matching locale from the provided approved locales list.
@@ -1602,7 +1796,7 @@ var GT = class {
1602
1796
  */
1603
1797
  determineLocale(locales, approvedLocales = this.locales || [], customMapping = this.customMapping) {
1604
1798
  if (customMapping === this.customMapping) return this.localeConfig.determineLocale(locales, approvedLocales ?? []);
1605
- return _determineLocale(locales, approvedLocales, customMapping);
1799
+ return determineLocale$1(locales, approvedLocales, customMapping);
1606
1800
  }
1607
1801
  /**
1608
1802
  * Gets the text direction for a given locale code.
@@ -1634,7 +1828,7 @@ var GT = class {
1634
1828
  isValidLocale(locale = this.targetLocale, customMapping = this.customMapping) {
1635
1829
  if (!locale) throw new Error(noTargetLocaleProvidedError("isValidLocale"));
1636
1830
  if (customMapping === this.customMapping) return this.localeConfig.isValidLocale(locale);
1637
- return _isValidLocale(locale, customMapping);
1831
+ return isValidLocale$1(locale, customMapping);
1638
1832
  }
1639
1833
  /**
1640
1834
  * Resolves the canonical locale for a given locale.
@@ -1645,7 +1839,7 @@ var GT = class {
1645
1839
  resolveCanonicalLocale(locale = this.targetLocale, customMapping = this.customMapping) {
1646
1840
  if (!locale) throw new Error(noTargetLocaleProvidedError("resolveCanonicalLocale"));
1647
1841
  if (customMapping === this.customMapping) return this.localeConfig.resolveCanonicalLocale(locale);
1648
- return _resolveCanonicalLocale(locale, customMapping);
1842
+ return resolveCanonicalLocale$1(locale, customMapping);
1649
1843
  }
1650
1844
  /**
1651
1845
  * Resolves the alias locale for a given locale.
@@ -1656,7 +1850,7 @@ var GT = class {
1656
1850
  resolveAliasLocale(locale, customMapping = this.customMapping) {
1657
1851
  if (!locale) throw new Error(noTargetLocaleProvidedError("resolveAliasLocale"));
1658
1852
  if (customMapping === this.customMapping) return this.localeConfig.resolveAliasLocale(locale);
1659
- return _resolveAliasLocale(locale, customMapping);
1853
+ return resolveAliasLocale$1(locale, customMapping);
1660
1854
  }
1661
1855
  /**
1662
1856
  * Standardizes a BCP 47 locale code to ensure correct formatting.
@@ -1720,285 +1914,6 @@ var GT = class {
1720
1914
  return this.localeConfig.isSupersetLocale(superLocale, subLocale);
1721
1915
  }
1722
1916
  };
1723
- /**
1724
- * Formats a number according to the specified locales and options.
1725
- * @param {Object} params - The parameters for the number formatting.
1726
- * @param {number} params.value - The number to format.
1727
- * @param {Intl.NumberFormatOptions} [params.options] - Additional options for number formatting.
1728
- * @param {string | string[]} [params.options.locales] - The locales to use for formatting.
1729
- * @returns {string} The formatted number.
1730
- */
1731
- function formatNum(number, options) {
1732
- return _formatNum({
1733
- value: number,
1734
- locales: options.locales,
1735
- options
1736
- });
1737
- }
1738
- /**
1739
- * Formats a date according to the specified languages and options.
1740
- * @param {Object} params - The parameters for the date formatting.
1741
- * @param {Date} params.value - The date to format.
1742
- * @param {Intl.DateTimeFormatOptions} [params.options] - Additional options for date formatting.
1743
- * @param {string | string[]} [params.options.locales] - The languages to use for formatting.
1744
- * @returns {string} The formatted date.
1745
- */
1746
- function formatDateTime(date, options) {
1747
- return _formatDateTime({
1748
- value: date,
1749
- locales: options?.locales,
1750
- options
1751
- });
1752
- }
1753
- /**
1754
- * Formats a currency value according to the specified languages, currency, and options.
1755
- * @param {Object} params - The parameters for the currency formatting.
1756
- * @param {number} params.value - The currency value to format.
1757
- * @param {string} params.currency - The currency code (e.g., 'USD').
1758
- * @param {Intl.NumberFormatOptions} [params.options={}] - Additional options for currency formatting.
1759
- * @param {string | string[]} [params.options.locales] - The locale codes to use for formatting.
1760
- * @returns {string} The formatted currency value.
1761
- */
1762
- function formatCurrency(value, currency, options) {
1763
- return _formatCurrency({
1764
- value,
1765
- currency,
1766
- locales: options.locales,
1767
- options
1768
- });
1769
- }
1770
- /**
1771
- * Formats a list of items according to the specified locales and options.
1772
- * @param {Object} params - The parameters for the list formatting.
1773
- * @param {Array<string | number>} params.value - The list of items to format.
1774
- * @param {Intl.ListFormatOptions} [params.options={}] - Additional options for list formatting.
1775
- * @param {string | string[]} [params.options.locales] - The locales to use for formatting.
1776
- * @returns {string} The formatted list.
1777
- */
1778
- function formatList(array, options) {
1779
- return _formatList({
1780
- value: array,
1781
- locales: options.locales,
1782
- options
1783
- });
1784
- }
1785
- /**
1786
- * Formats a list of items according to the specified locales and options.
1787
- * @param {Array<T>} array - The list of items to format.
1788
- * @param {Object} [options] - Additional options for list formatting.
1789
- * @param {string | string[]} [options.locales] - The locales to use for formatting.
1790
- * @param {Intl.ListFormatOptions} [options] - Additional Intl.ListFormat options.
1791
- * @returns {Array<T | string>} The formatted list parts.
1792
- */
1793
- function formatListToParts(array, options) {
1794
- return _formatListToParts({
1795
- value: array,
1796
- locales: options?.locales,
1797
- options
1798
- });
1799
- }
1800
- /**
1801
- * Formats a relative time value according to the specified locales and options.
1802
- * @param {Object} params - The parameters for the relative time formatting.
1803
- * @param {number} params.value - The relative time value to format.
1804
- * @param {Intl.RelativeTimeFormatUnit} params.unit - The unit of time (e.g., 'second', 'minute', 'hour', 'day', 'week', 'month', 'year').
1805
- * @param {Intl.RelativeTimeFormatOptions} [params.options={}] - Additional options for relative time formatting.
1806
- * @param {string | string[]} [params.options.locales] - The locales to use for formatting.
1807
- * @returns {string} The formatted relative time string.
1808
- */
1809
- function formatRelativeTime(value, unit, options) {
1810
- return _formatRelativeTime({
1811
- value,
1812
- unit,
1813
- locales: options.locales,
1814
- options
1815
- });
1816
- }
1817
- /**
1818
- * Formats a relative time string from a Date, automatically selecting the best unit.
1819
- * @param {Date} date - The date to format relative to now.
1820
- * @param {Object} options - Formatting options.
1821
- * @param {string | string[]} options.locales - The locales to use for formatting.
1822
- * @param {Intl.RelativeTimeFormatOptions} [options] - Additional Intl.RelativeTimeFormat options.
1823
- * @returns {string} The formatted relative time string (e.g., "2 hours ago", "in 3 days").
1824
- */
1825
- function formatRelativeTimeFromDate(date, options) {
1826
- const { locales, baseDate, ...intlOptions } = options;
1827
- return _formatRelativeTimeFromDate({
1828
- date,
1829
- baseDate: baseDate ?? /* @__PURE__ */ new Date(),
1830
- locales,
1831
- options: intlOptions
1832
- });
1833
- }
1834
- /**
1835
- * Retrieves the display name of locale code using Intl.DisplayNames.
1836
- *
1837
- * @param {string} locale - A BCP-47 locale code.
1838
- * @param {string} [defaultLocale] - The default locale to use for formatting.
1839
- * @param {CustomMapping} [customMapping] - A custom mapping of locale codes to their names.
1840
- * @returns {string} The display name corresponding to the code.
1841
- */
1842
- function getLocaleName(locale, defaultLocale, customMapping) {
1843
- return _getLocaleName(locale, defaultLocale, customMapping);
1844
- }
1845
- /**
1846
- * Retrieves an emoji based on a given locale code, taking into account region, language, and specific exceptions.
1847
- *
1848
- * This function uses the locale's region (if present) to select an emoji or falls back on default emojis for certain languages.
1849
- *
1850
- * @param locale - A string representing the locale code (e.g., 'en-US', 'fr-CA').
1851
- * @param {CustomMapping} [customMapping] - A custom mapping of locale codes to their names.
1852
- * @returns The emoji representing the locale or its region, or a default emoji if no specific match is found.
1853
- */
1854
- function getLocaleEmoji(locale, customMapping) {
1855
- return _getLocaleEmoji(locale, customMapping);
1856
- }
1857
- /**
1858
- * Generates linguistic details for a given locale code.
1859
- *
1860
- * This function returns information about the locale,
1861
- * script, and region of a given language code both in a standard form and in a maximized form (with likely script and region).
1862
- * The function provides these names in both your default language and native forms, and an associated emoji.
1863
- *
1864
- * @param {string} locale - The locale code to get properties for (e.g., "de-AT").
1865
- * @param {string} [defaultLocale] - The default locale to use for formatting.
1866
- * @param {CustomMapping} [customMapping] - A custom mapping of locale codes to their names.
1867
- * @returns {LocaleProperties} - An object containing detailed information about the locale.
1868
- *
1869
- * @property {string} code - The full locale code, e.g., "de-AT".
1870
- * @property {string} name - Language name in the default display language, e.g., "Austrian German".
1871
- * @property {string} nativeName - Language name in the locale's native language, e.g., "Österreichisches Deutsch".
1872
- * @property {string} languageCode - The base language code, e.g., "de".
1873
- * @property {string} languageName - The language name in the default display language, e.g., "German".
1874
- * @property {string} nativeLanguageName - The language name in the native language, e.g., "Deutsch".
1875
- * @property {string} nameWithRegionCode - Language name with region in the default language, e.g., "German (AT)".
1876
- * @property {string} nativeNameWithRegionCode - Language name with region in the native language, e.g., "Deutsch (AT)".
1877
- * @property {string} regionCode - The region code from maximization, e.g., "AT".
1878
- * @property {string} regionName - The region name in the default display language, e.g., "Austria".
1879
- * @property {string} nativeRegionName - The region name in the native language, e.g., "Österreich".
1880
- * @property {string} scriptCode - The script code from maximization, e.g., "Latn".
1881
- * @property {string} scriptName - The script name in the default display language, e.g., "Latin".
1882
- * @property {string} nativeScriptName - The script name in the native language, e.g., "Lateinisch".
1883
- * @property {string} maximizedCode - The maximized locale code, e.g., "de-Latn-AT".
1884
- * @property {string} maximizedName - Maximized locale name with likely script in the default language, e.g., "Austrian German (Latin)".
1885
- * @property {string} nativeMaximizedName - Maximized locale name in the native language, e.g., "Österreichisches Deutsch (Lateinisch)".
1886
- * @property {string} minimizedCode - Minimized locale code, e.g., "de-AT" (or "de" for "de-DE").
1887
- * @property {string} minimizedName - Minimized language name in the default language, e.g., "Austrian German".
1888
- * @property {string} nativeMinimizedName - Minimized language name in the native language, e.g., "Österreichisches Deutsch".
1889
- * @property {string} emoji - The emoji associated with the locale's region, if applicable.
1890
- */
1891
- function getLocaleProperties(locale, defaultLocale, customMapping) {
1892
- return _getLocaleProperties(locale, defaultLocale, customMapping);
1893
- }
1894
- /**
1895
- * Retrieves multiple properties for a given region code, including:
1896
- * - `code`: the original region code
1897
- * - `name`: the localized display name
1898
- * - `emoji`: the associated flag or symbol
1899
- *
1900
- * Behavior:
1901
- * - Accepts ISO 3166-1 alpha-2 or UN M.49 region codes (e.g., `"US"`, `"FR"`, `"419"`).
1902
- * - If `customMapping` contains a `name` or `emoji` for the region, those override the default values.
1903
- * - Otherwise, uses `Intl.DisplayNames` to get the localized region name in the given `defaultLocale`,
1904
- * falling back to `libraryDefaultLocale`.
1905
- * - Falls back to the region code as `name` if display name resolution fails.
1906
- * - Falls back to `defaultEmoji` if no emoji mapping is found in `emojis` or `customMapping`.
1907
- *
1908
- * @param {string} region - The region code to look up (e.g., `"US"`, `"GB"`, `"DE"`).
1909
- * @param {string} [defaultLocale=libraryDefaultLocale] - The locale to use when localizing the region name.
1910
- * @param {CustomRegionMapping} [customMapping] - Optional mapping of region codes to custom names and/or emojis.
1911
- * @returns {{ code: string, name: string, emoji: string }} An object containing:
1912
- * - `code`: the input region code
1913
- * - `name`: the localized or custom region name
1914
- * - `emoji`: the matching emoji flag or symbol
1915
- *
1916
- * @example
1917
- * getRegionProperties('US', 'en');
1918
- * // => { code: 'US', name: 'United States', emoji: '🇺🇸' }
1919
- *
1920
- * @example
1921
- * getRegionProperties('US', 'fr');
1922
- * // => { code: 'US', name: 'États-Unis', emoji: '🇺🇸' }
1923
- *
1924
- * @example
1925
- * getRegionProperties('US', 'en', { US: { name: 'USA', emoji: '🗽' } });
1926
- * // => { code: 'US', name: 'USA', emoji: '🗽' }
1927
- */
1928
- function getRegionProperties(region, defaultLocale, customMapping) {
1929
- return _getRegionProperties(region, defaultLocale, customMapping);
1930
- }
1931
- /**
1932
- * Determines whether a translation is required based on the source and target locales.
1933
- *
1934
- * - If the target locale is not specified, the function returns `false`, as translation is not needed.
1935
- * - If the source and target locale are the same, returns `false`, indicating that no translation is necessary.
1936
- * - If the `approvedLocales` array is provided, and the target locale is not within that array, the function also returns `false`.
1937
- * - Otherwise, it returns `true`, meaning that a translation is required.
1938
- *
1939
- * @param {string} sourceLocale - The locale code for the original content (BCP 47 locale code).
1940
- * @param {string} targetLocale - The locale code of the language to translate the content into (BCP 47 locale code).
1941
- * @param {string[]} [approvedLocale] - An optional array of approved target locales.
1942
- *
1943
- * @returns {boolean} - Returns `true` if translation is required, otherwise `false`.
1944
- */
1945
- function requiresTranslation(sourceLocale, targetLocale, approvedLocales, customMapping) {
1946
- return _requiresTranslation(sourceLocale, targetLocale, approvedLocales, customMapping);
1947
- }
1948
- /**
1949
- * Determines the best matching locale from the provided approved locales list.
1950
- * @param {string | string[]} locales - A single locale or an array of locales sorted in preference order.
1951
- * @param {string[]} [approvedLocales=this.locales] - An array of approved locales, also sorted by preference.
1952
- * @returns {string | undefined} - The best matching locale from the approvedLocales list, or undefined if no match is found.
1953
- */
1954
- function determineLocale(locales, approvedLocales = [], customMapping = void 0) {
1955
- return _determineLocale(locales, approvedLocales, customMapping);
1956
- }
1957
- /**
1958
- * Get the text direction for a given locale code using the Intl.Locale API.
1959
- *
1960
- * @param {string} locale - A BCP-47 locale code.
1961
- * @returns {string} 'rtl' if the locale is right-to-left; otherwise 'ltr'.
1962
- */
1963
- function getLocaleDirection(locale) {
1964
- return _getLocaleDirection(locale);
1965
- }
1966
- /**
1967
- * Resolves the alias locale for a given locale.
1968
- * @param {string} locale - The locale to resolve the alias locale for
1969
- * @param {CustomMapping} [customMapping] - The custom mapping to use for resolving the alias locale
1970
- * @returns {string} The alias locale
1971
- */
1972
- function resolveAliasLocale(locale, customMapping) {
1973
- return _resolveAliasLocale(locale, customMapping);
1974
- }
1975
- /**
1976
- * Checks if multiple BCP 47 locale codes represent the same dialect.
1977
- * @param {string[]} locales - The BCP 47 locale codes to compare.
1978
- * @returns {boolean} True if all BCP 47 codes represent the same dialect, false otherwise.
1979
- */
1980
- function isSameDialect(...locales) {
1981
- return _isSameDialect(...locales);
1982
- }
1983
- /**
1984
- * Checks if multiple BCP 47 locale codes represent the same language.
1985
- * @param {string[]} locales - The BCP 47 locale codes to compare.
1986
- * @returns {boolean} True if all BCP 47 codes represent the same language, false otherwise.
1987
- */
1988
- function isSameLanguage(...locales) {
1989
- return _isSameLanguage(...locales);
1990
- }
1991
- /**
1992
- * Checks if a locale is a superset of another locale.
1993
- * A subLocale is a subset of superLocale if it is an extension of superLocale or are otherwise identical.
1994
- *
1995
- * @param {string} superLocale - The locale to check if it is a superset of the other locale.
1996
- * @param {string} subLocale - The locale to check if it is a subset of the other locale.
1997
- * @returns {boolean} True if the first locale is a superset of the second locale, false otherwise.
1998
- */
1999
- function isSupersetLocale(superLocale, subLocale) {
2000
- return _isSupersetLocale(superLocale, subLocale);
2001
- }
2002
1917
  const API_VERSION = API_VERSION$1;
2003
1918
  //#endregion
2004
1919
  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 };