generaltranslation 9.4.2 → 9.5.0

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 (153) hide show
  1. package/CHANGELOG.md +34 -0
  2. package/README.md +2 -1
  3. package/dist/{ApiError-BcjcnTAr.cjs → ApiError-BCjEo_CM.cjs} +1 -1
  4. package/dist/{ApiError-BcjcnTAr.cjs.map → ApiError-BCjEo_CM.cjs.map} +1 -1
  5. package/dist/{ApiError-CUKcz3YS.mjs → ApiError-DxWKM0Xt.mjs} +1 -1
  6. package/dist/{ApiError-CUKcz3YS.mjs.map → ApiError-DxWKM0Xt.mjs.map} +1 -1
  7. package/dist/adapter/createGtApi.d.ts +196 -27
  8. package/dist/adapter/createGtApi.js +561 -117
  9. package/dist/adapter/modelProvider.d.ts +4 -0
  10. package/dist/adapter/modelProvider.js +6 -0
  11. package/dist/derive-Cv5_y8Tf.mjs +656 -0
  12. package/dist/derive-Cv5_y8Tf.mjs.map +1 -0
  13. package/dist/{derive-DBCCXTmL.d.cts → derive-J2NQLqZm.d.cts} +1 -1
  14. package/dist/derive-t_E3ftJN.cjs +733 -0
  15. package/dist/derive-t_E3ftJN.cjs.map +1 -0
  16. package/dist/diagnostics-CqAHg_Vc.d.cts +34 -0
  17. package/dist/diagnostics-DKA2SkZB.mjs +45 -0
  18. package/dist/diagnostics-DKA2SkZB.mjs.map +1 -0
  19. package/dist/{unwrapApiResult-BzGfPw75.mjs → diagnostics-DKtiPUvo.cjs} +12 -31
  20. package/dist/diagnostics-DKtiPUvo.cjs.map +1 -0
  21. package/dist/diagnostics-DYtVjOm5.d.mts +34 -0
  22. package/dist/diagnostics.cjs +4 -0
  23. package/dist/diagnostics.d.cts +2 -0
  24. package/dist/diagnostics.d.mts +2 -0
  25. package/dist/diagnostics.d.ts +1 -0
  26. package/dist/diagnostics.js +1 -0
  27. package/dist/diagnostics.mjs +2 -0
  28. package/dist/errors.cjs +1 -1
  29. package/dist/errors.mjs +1 -1
  30. package/dist/file-B37WkCqM.cjs.map +1 -1
  31. package/dist/file-Dga6cyM8.mjs.map +1 -1
  32. package/dist/{id-X2zyx5Jk.mjs → id-B2wA7-S-.mjs} +19 -3
  33. package/dist/id-B2wA7-S-.mjs.map +1 -0
  34. package/dist/{id-pdr3R1xs.cjs → id-DJ_59q21.cjs} +25 -3
  35. package/dist/id-DJ_59q21.cjs.map +1 -0
  36. package/dist/id.cjs +1 -1
  37. package/dist/id.d.cts +1 -1
  38. package/dist/id.d.mts +1 -1
  39. package/dist/id.mjs +1 -1
  40. package/dist/index.cjs +94 -753
  41. package/dist/index.cjs.map +1 -1
  42. package/dist/index.d.cts +14 -33
  43. package/dist/index.d.mts +13 -32
  44. package/dist/index.d.ts +20 -16
  45. package/dist/index.js +110 -98
  46. package/dist/index.mjs +88 -746
  47. package/dist/index.mjs.map +1 -1
  48. package/dist/internal.cjs +16 -186
  49. package/dist/internal.cjs.map +1 -1
  50. package/dist/internal.d.cts +200 -62
  51. package/dist/internal.d.mts +199 -61
  52. package/dist/internal.d.ts +3 -1
  53. package/dist/internal.js +2 -1
  54. package/dist/internal.mjs +6 -178
  55. package/dist/internal.mjs.map +1 -1
  56. package/dist/logging/errors.d.ts +0 -1
  57. package/dist/logging/errors.js +0 -6
  58. package/dist/logging/logger.js +6 -4
  59. package/dist/openapi.json +2344 -845
  60. package/dist/runtime.cjs +580 -2
  61. package/dist/runtime.cjs.map +1 -0
  62. package/dist/runtime.d.cts +12 -6
  63. package/dist/runtime.d.mts +12 -6
  64. package/dist/runtime.d.ts +10 -4
  65. package/dist/runtime.js +10 -65
  66. package/dist/runtime.mjs +579 -1
  67. package/dist/runtime.mjs.map +1 -0
  68. package/dist/runtimeTranslate-CVw143pQ.mjs +506 -0
  69. package/dist/runtimeTranslate-CVw143pQ.mjs.map +1 -0
  70. package/dist/runtimeTranslate-DJioRjb6.cjs +601 -0
  71. package/dist/runtimeTranslate-DJioRjb6.cjs.map +1 -0
  72. package/dist/translate/awaitJobs.d.ts +2 -2
  73. package/dist/translate/awaitJobs.js +1 -156
  74. package/dist/translate/checkJobStatus.d.ts +2 -1
  75. package/dist/translate/checkJobStatus.js +1 -55
  76. package/dist/translate/createBranch.d.ts +2 -6
  77. package/dist/translate/createBranch.js +1 -53
  78. package/dist/translate/enqueueFiles.js +1 -95
  79. package/dist/translate/getProjectInfo.d.ts +2 -6
  80. package/dist/translate/getProjectInfo.js +1 -54
  81. package/dist/translate/processFileMoves.d.ts +3 -13
  82. package/dist/translate/processFileMoves.js +1 -90
  83. package/dist/translate/publishFiles.d.ts +3 -15
  84. package/dist/translate/publishFiles.js +1 -56
  85. package/dist/translate/queryBranchData.js +1 -53
  86. package/dist/translate/queryFileData.d.ts +3 -41
  87. package/dist/translate/queryFileData.js +1 -71
  88. package/dist/translate/runtimeTranslate.d.ts +6 -0
  89. package/dist/translate/runtimeTranslate.js +297 -0
  90. package/dist/translate/setupProject.d.ts +2 -6
  91. package/dist/translate/setupProject.js +1 -63
  92. package/dist/translate/submitUserEditDiffs.js +1 -68
  93. package/dist/translate/utils/fetchWithTimeout.js +19 -12
  94. package/dist/{types-bCr8pV1Z.d.cts → types-Si4UstLL.d.mts} +41 -165
  95. package/dist/types-dir/__tests__/runtimeTranslate.type-test.js +18 -0
  96. package/dist/types-dir/api/branch.d.ts +3 -9
  97. package/dist/types-dir/api/checkFileTranslations.d.ts +2 -22
  98. package/dist/types-dir/api/downloadFileBatch.d.ts +2 -7
  99. package/dist/types-dir/api/entry.d.ts +3 -8
  100. package/dist/types-dir/api/file.d.ts +2 -1
  101. package/dist/types-dir/api/json.d.ts +1 -4
  102. package/dist/types-dir/api/project.d.ts +2 -7
  103. package/dist/types-dir/api/uploadAssets.d.ts +3 -10
  104. package/dist/types-dir/api/uploadAssets.js +0 -4
  105. package/dist/types-dir/config.d.ts +1 -0
  106. package/dist/{types-Dp1drjxq.d.mts → types-yByDbKnV.d.cts} +41 -165
  107. package/dist/types.d.cts +2 -2
  108. package/dist/types.d.mts +2 -2
  109. package/dist/types.d.ts +26 -7
  110. package/package.json +15 -2
  111. package/dist/derive-2CDqwrvS.cjs +0 -303
  112. package/dist/derive-2CDqwrvS.cjs.map +0 -1
  113. package/dist/derive-CTzR56T_.mjs +0 -233
  114. package/dist/derive-CTzR56T_.mjs.map +0 -1
  115. package/dist/id-X2zyx5Jk.mjs.map +0 -1
  116. package/dist/id-pdr3R1xs.cjs.map +0 -1
  117. package/dist/isVariable-8-Wy5FnX.mjs +0 -20
  118. package/dist/isVariable-8-Wy5FnX.mjs.map +0 -1
  119. package/dist/isVariable-I3nllgeI.cjs +0 -25
  120. package/dist/isVariable-I3nllgeI.cjs.map +0 -1
  121. package/dist/projects/getProjectData.js +0 -87
  122. package/dist/runtime-Bcp4F2ME.mjs +0 -974
  123. package/dist/runtime-Bcp4F2ME.mjs.map +0 -1
  124. package/dist/runtime-C25lwh9m.cjs +0 -1027
  125. package/dist/runtime-C25lwh9m.cjs.map +0 -1
  126. package/dist/translate/api.d.ts +0 -4
  127. package/dist/translate/api.js +0 -4
  128. package/dist/translate/createTag.d.ts +0 -19
  129. package/dist/translate/createTag.js +0 -67
  130. package/dist/translate/downloadFileBatch.d.ts +0 -1
  131. package/dist/translate/downloadFileBatch.js +0 -80
  132. package/dist/translate/getOrphanedFiles.d.ts +0 -8
  133. package/dist/translate/getOrphanedFiles.js +0 -97
  134. package/dist/translate/querySourceFile.d.ts +0 -1
  135. package/dist/translate/querySourceFile.js +0 -67
  136. package/dist/translate/translateMany.d.ts +0 -1
  137. package/dist/translate/translateMany.js +0 -124
  138. package/dist/translate/uploadFonts.d.ts +0 -1
  139. package/dist/translate/uploadFonts.js +0 -74
  140. package/dist/translate/uploadSourceFiles.d.ts +0 -1
  141. package/dist/translate/uploadSourceFiles.js +0 -90
  142. package/dist/translate/uploadTranslations.d.ts +0 -1
  143. package/dist/translate/uploadTranslations.js +0 -106
  144. package/dist/translate/utils/apiRequest.d.ts +0 -1
  145. package/dist/translate/utils/apiRequest.js +0 -167
  146. package/dist/translate/utils/generateRequestHeaders.d.ts +0 -2
  147. package/dist/translate/utils/generateRequestHeaders.js +0 -21
  148. package/dist/translate/utils/handleFetchError.d.ts +0 -1
  149. package/dist/translate/utils/handleFetchError.js +0 -12
  150. package/dist/unwrapApiResult-BzGfPw75.mjs.map +0 -1
  151. package/dist/unwrapApiResult-Dv6Mfw_K.cjs +0 -134
  152. package/dist/unwrapApiResult-Dv6Mfw_K.cjs.map +0 -1
  153. /package/dist/{projects/getProjectData.d.ts → types-dir/__tests__/runtimeTranslate.type-test.d.ts} +0 -0
package/dist/runtime.mjs CHANGED
@@ -1,2 +1,580 @@
1
- import { t as GTRuntime } from "./runtime-Bcp4F2ME.mjs";
1
+ import { d as noSourceLocaleProvidedError, f as noTargetLocaleProvidedError, l as invalidLocaleError, n as translateMany, t as translate, u as invalidLocalesError } from "./runtimeTranslate-CVw143pQ.mjs";
2
+ import { LocaleConfig, getRegionProperties, isValidLocale, requiresTranslation, resolveAliasLocale, resolveCanonicalLocale } from "@generaltranslation/format";
3
+ //#region src/runtime.ts
4
+ /**
5
+ * GTRuntime is the runtime core of the GT driver: locale management,
6
+ * formatting, and runtime translation requests.
7
+ *
8
+ * Browser-facing SDK code constructs this class (via `generaltranslation/runtime`)
9
+ * so production bundles do not ship the project/file management API client
10
+ * that lives on the GT class exported from the main entry.
11
+ *
12
+ * @example
13
+ * const gt = new GTRuntime({
14
+ * sourceLocale: 'en-US',
15
+ * targetLocale: 'es-ES',
16
+ * locales: ['en-US', 'es-ES', 'fr-FR']
17
+ * });
18
+ */
19
+ var GTRuntime = class {
20
+ /** Runtime-safe locale and formatting helpers */
21
+ get localeConfig() {
22
+ return this._localeConfig;
23
+ }
24
+ /**
25
+ * Constructs an instance of the GTRuntime class.
26
+ *
27
+ * @param {GTConstructorParams} [params] - The parameters for initializing the GTRuntime instance
28
+ * @throws {Error} If an invalid locale is provided
29
+ * @throws {Error} If any of the provided locales are invalid
30
+ *
31
+ * @example
32
+ * const gt = new GTRuntime({
33
+ * apiKey: 'your-api-key',
34
+ * sourceLocale: 'en-US',
35
+ * targetLocale: 'es-ES',
36
+ * locales: ['en-US', 'es-ES', 'fr-FR']
37
+ * });
38
+ */
39
+ constructor(params = {}) {
40
+ if (typeof process !== "undefined") {
41
+ this.apiKey ||= process.env?.GT_API_KEY;
42
+ this.devApiKey ||= process.env?.GT_DEV_API_KEY;
43
+ this.projectId ||= process.env?.GT_PROJECT_ID;
44
+ }
45
+ this.setConfig(params);
46
+ }
47
+ setConfig({ apiKey, devApiKey, sourceLocale, targetLocale, locales, projectId, customMapping, baseUrl, userTokenProvider }) {
48
+ const effectiveCustomMapping = customMapping ?? this.customMapping;
49
+ if (apiKey) this.apiKey = apiKey;
50
+ if (devApiKey) this.devApiKey = devApiKey;
51
+ if (projectId) this.projectId = projectId;
52
+ if (userTokenProvider) this.userTokenProvider = userTokenProvider;
53
+ if (sourceLocale) {
54
+ this.sourceLocale = sourceLocale;
55
+ if (!isValidLocale(this.sourceLocale, effectiveCustomMapping)) throw new Error(invalidLocaleError(this.sourceLocale));
56
+ }
57
+ if (targetLocale) {
58
+ this.targetLocale = targetLocale;
59
+ if (!isValidLocale(this.targetLocale, effectiveCustomMapping)) throw new Error(invalidLocaleError(this.targetLocale));
60
+ }
61
+ if (locales) {
62
+ const result = [];
63
+ const invalidLocales = [];
64
+ locales.forEach((locale) => {
65
+ if (isValidLocale(locale, effectiveCustomMapping)) result.push(locale);
66
+ else invalidLocales.push(locale);
67
+ });
68
+ if (invalidLocales.length > 0) throw new Error(invalidLocalesError(invalidLocales));
69
+ this.locales = result;
70
+ }
71
+ if (baseUrl) this.baseUrl = baseUrl;
72
+ if (customMapping) {
73
+ this.customMapping = customMapping;
74
+ this.reverseCustomMapping = Object.fromEntries(Object.entries(customMapping).filter(([, value]) => value && typeof value === "object" && "code" in value).map(([key, value]) => [value.code, key]));
75
+ }
76
+ this._localeConfig = new LocaleConfig({
77
+ defaultLocale: this.sourceLocale,
78
+ locales: this.locales ?? [],
79
+ customMapping: this.customMapping
80
+ });
81
+ }
82
+ /** Convert app identity only where a GT service expects a language code. */
83
+ resolveServiceLocale(locale) {
84
+ return this.standardizeLocale(this.resolveCanonicalLocale(locale));
85
+ }
86
+ /**
87
+ * Recover configured spelling without negotiating an unrelated dialect.
88
+ * When several identities use the same service code and there is no request
89
+ * context to disambiguate them, the first configured identity wins.
90
+ */
91
+ resolveServiceResponseLocale(locale) {
92
+ const canonical = this.standardizeLocale(locale);
93
+ return [
94
+ ...this.locales ?? [],
95
+ this.sourceLocale,
96
+ this.targetLocale,
97
+ ...Object.keys(this.customMapping ?? {})
98
+ ].find((candidate) => candidate && this.resolveServiceLocale(candidate) === canonical) ?? locale;
99
+ }
100
+ _getTranslationConfig() {
101
+ return {
102
+ baseUrl: this.baseUrl,
103
+ apiKey: this.apiKey || this.devApiKey,
104
+ projectId: this.projectId || "",
105
+ userTokenProvider: this.userTokenProvider
106
+ };
107
+ }
108
+ /**
109
+ * Translates a single source string to the target locale.
110
+ * Routes through {@link translateMany} under the hood.
111
+ *
112
+ * @param {string} source - The source string to translate.
113
+ * @param {object} options - Translation options including targetLocale and optional entry metadata.
114
+ * @param {number} [timeout] - Timeout in milliseconds; 0 or omitted selects the runtime default.
115
+ * @returns {Promise<TranslationResult | TranslationError>} The translated content.
116
+ *
117
+ * @example
118
+ * const result = await gt.translate('Hello, world!', { targetLocale: 'es' });
119
+ *
120
+ * @example
121
+ * const result = await gt.translate('Hello, world!', {
122
+ * targetLocale: 'es',
123
+ * dataFormat: 'ICU',
124
+ * context: 'A formal greeting',
125
+ * });
126
+ */
127
+ async translate(source, options, timeout) {
128
+ return translate(source, options, {
129
+ ...this._getTranslationConfig(),
130
+ customMapping: this.customMapping,
131
+ timeoutMs: timeout || void 0
132
+ }, this);
133
+ }
134
+ async translateMany(sources, options, timeout) {
135
+ return translateMany(sources, options, {
136
+ ...this._getTranslationConfig(),
137
+ customMapping: this.customMapping,
138
+ timeoutMs: timeout || void 0
139
+ }, this);
140
+ }
141
+ /**
142
+ * Formats a string with cutoff behavior, applying a terminator when the string exceeds the maximum character limit.
143
+ *
144
+ * This method uses the GT instance's rendering locales by default for locale-specific terminator selection,
145
+ * but can be overridden with custom locales in the options.
146
+ *
147
+ * @param {string} value - The string value to format with cutoff behavior.
148
+ * @param {Object} [options] - Configuration options for cutoff formatting.
149
+ * @param {string | string[]} [options.locales] - The locales to use for terminator selection. Defaults to instance's rendering locales.
150
+ * @param {number} [options.maxChars] - The maximum number of characters to display.
151
+ * - Undefined values are treated as no cutoff.
152
+ * - Negative values follow .slice() behavior and terminator will be added before the value.
153
+ * - 0 will result in an empty string.
154
+ * - If cutoff results in an empty string, no terminator is added.
155
+ * @param {CutoffFormatStyle} [options.style='ellipsis'] - The style of the terminator.
156
+ * @param {string} [options.terminator] - Optional override the terminator to use.
157
+ * @param {string} [options.separator] - Optional override the separator to use between the terminator and the value.
158
+ * - If no terminator is provided, then separator is ignored.
159
+ * @returns {string} The formatted string with terminator applied if cutoff occurs.
160
+ *
161
+ * @example
162
+ * const gt = new GTRuntime({ targetLocale: 'en-US' });
163
+ * gt.formatCutoff('Hello, world!', { maxChars: 8 });
164
+ * // Returns: 'Hello, w...'
165
+ *
166
+ * @example
167
+ * gt.formatCutoff('Hello, world!', { maxChars: -3 });
168
+ * // Returns: '...ld!'
169
+ */
170
+ formatCutoff(value, options) {
171
+ return this.localeConfig.formatCutoff(value, this.targetLocale, options);
172
+ }
173
+ /**
174
+ * Formats a message according to the specified locales and options.
175
+ *
176
+ * @param {string} message - The message to format.
177
+ * @param {string | string[]} [locales=libraryDefaultLocale] - The locales to use for formatting.
178
+ * @param {FormatVariables} [variables={}] - The variables to use for formatting.
179
+ * @param {StringFormat} [dataFormat='ICU'] - The format of the message.
180
+ * @returns {string} The formatted message.
181
+ *
182
+ * @example
183
+ * gt.formatMessage('Hello {name}', { name: 'John' });
184
+ * // Returns: "Hello John"
185
+ *
186
+ * gt.formatMessage('Hello {name}', { name: 'John' }, { locales: ['fr'] });
187
+ * // Returns: "Bonjour John"
188
+ */
189
+ formatMessage(message, options) {
190
+ return this.localeConfig.formatMessage(message, this.targetLocale, options);
191
+ }
192
+ /**
193
+ * Formats a number according to the specified locales and options.
194
+ *
195
+ * @param {number} number - The number to format.
196
+ * @param {Object} [options] - Additional options for number formatting.
197
+ * @param {string | string[]} [options.locales] - The locales to use for formatting.
198
+ * @param {Intl.NumberFormatOptions} [options] - Additional Intl.NumberFormat options.
199
+ * @returns {string} The formatted number.
200
+ *
201
+ * @example
202
+ * gt.formatNum(1234.56, { style: 'currency', currency: 'USD' });
203
+ * // Returns: "$1,234.56"
204
+ */
205
+ formatNum(number, options) {
206
+ return this.localeConfig.formatNum(number, this.targetLocale, options);
207
+ }
208
+ /**
209
+ * Formats a date according to the specified locales and options.
210
+ *
211
+ * @param {Date} date - The date to format.
212
+ * @param {Object} [options] - Additional options for date formatting.
213
+ * @param {string | string[]} [options.locales] - The locales to use for formatting.
214
+ * @param {Intl.DateTimeFormatOptions} [options] - Additional Intl.DateTimeFormat options.
215
+ * @returns {string} The formatted date.
216
+ *
217
+ * @example
218
+ * gt.formatDateTime(new Date(), { dateStyle: 'full', timeStyle: 'long' });
219
+ * // Returns: "Thursday, March 14, 2024 at 2:30:45 PM GMT-7"
220
+ */
221
+ formatDateTime(date, options) {
222
+ return this.localeConfig.formatDateTime(date, this.targetLocale, options);
223
+ }
224
+ /**
225
+ * Formats a currency value according to the specified locales and options.
226
+ *
227
+ * @param {number} value - The currency value to format.
228
+ * @param {string} currency - The currency code (e.g., 'USD', 'EUR')
229
+ * @param {Object} [options] - Additional options for currency formatting.
230
+ * @param {string | string[]} [options.locales] - The locales to use for formatting.
231
+ * @param {Intl.NumberFormatOptions} [options] - Additional Intl.NumberFormat options.
232
+ * @returns {string} The formatted currency value.
233
+ *
234
+ * @example
235
+ * gt.formatCurrency(1234.56, 'USD', { style: 'currency' });
236
+ * // Returns: "$1,234.56"
237
+ */
238
+ formatCurrency(value, currency, options) {
239
+ return this.localeConfig.formatCurrency(value, currency, this.targetLocale, options);
240
+ }
241
+ /**
242
+ * Formats a list of items according to the specified locales and options.
243
+ *
244
+ * @param {Array<string | number>} array - The list of items to format.
245
+ * @param {Object} [options] - Additional options for list formatting.
246
+ * @param {string | string[]} [options.locales] - The locales to use for formatting.
247
+ * @param {Intl.ListFormatOptions} [options] - Additional Intl.ListFormat options.
248
+ * @returns {string} The formatted list.
249
+ *
250
+ * @example
251
+ * gt.formatList(['apple', 'banana', 'orange'], { type: 'conjunction' });
252
+ * // Returns: "apple, banana, and orange"
253
+ */
254
+ formatList(array, options) {
255
+ return this.localeConfig.formatList(array, this.targetLocale, options);
256
+ }
257
+ /**
258
+ * Formats a list of items according to the specified locales and options.
259
+ * @param {Array<T>} array - The list of items to format.
260
+ * @param {Object} [options] - Additional options for list formatting.
261
+ * @param {string | string[]} [options.locales] - The locales to use for formatting.
262
+ * @param {Intl.ListFormatOptions} [options] - Additional Intl.ListFormat options.
263
+ * @returns {Array<T | string>} The formatted list parts.
264
+ *
265
+ * @example
266
+ * gt.formatListToParts(['apple', 42, { foo: 'bar' }], { type: 'conjunction', style: 'short', locales: ['en'] });
267
+ * // Returns: ['apple', ', ', 42, ' and ', '{ foo: "bar" }']
268
+ */
269
+ formatListToParts(array, options) {
270
+ return this.localeConfig.formatListToParts(array, this.targetLocale, options);
271
+ }
272
+ /**
273
+ * Formats a relative time value according to the specified locales and options.
274
+ *
275
+ * @param {number} value - The relative time value to format.
276
+ * @param {Intl.RelativeTimeFormatUnit} unit - The unit of time (e.g., 'second', 'minute', 'hour', 'day', 'week', 'month', 'year')
277
+ * @param {Object} options - Additional options for relative time formatting.
278
+ * @param {string | string[]} [options.locales] - The locales to use for formatting.
279
+ * @param {Intl.RelativeTimeFormatOptions} [options] - Additional Intl.RelativeTimeFormat options.
280
+ * @returns {string} The formatted relative time string.
281
+ *
282
+ * @example
283
+ * gt.formatRelativeTime(-1, 'day', { locales: ['en-US'], numeric: 'auto' });
284
+ * // Returns: "yesterday"
285
+ */
286
+ formatRelativeTime(value, unit, options) {
287
+ return this.localeConfig.formatRelativeTime(value, unit, this.targetLocale, options);
288
+ }
289
+ /**
290
+ * Formats a relative time string from a Date, automatically selecting the best unit.
291
+ *
292
+ * @param {Date} date - The date to format relative to now.
293
+ * @param {Object} [options] - Additional options for relative time formatting.
294
+ * @param {string | string[]} [options.locales] - The locales to use for formatting.
295
+ * @returns {string} The formatted relative time string (e.g., "2 hours ago", "in 3 days")
296
+ *
297
+ * @example
298
+ * gt.formatRelativeTimeFromDate(new Date(Date.now() - 3600000));
299
+ * // Returns: "1 hour ago"
300
+ */
301
+ formatRelativeTimeFromDate(date, options) {
302
+ return this.localeConfig.formatRelativeTimeFromDate(date, this.targetLocale, options);
303
+ }
304
+ /**
305
+ * Retrieves the display name of a locale code using Intl.DisplayNames, returning an empty string if no name is found.
306
+ *
307
+ * @param {string} [locale=this.targetLocale] - A BCP-47 locale code.
308
+ * @returns {string} The display name corresponding to the code.
309
+ * @throws {Error} If no target locale is provided.
310
+ *
311
+ * @example
312
+ * gt.getLocaleName('es-ES');
313
+ * // Returns: "Spanish (Spain)"
314
+ */
315
+ getLocaleName(locale = this.targetLocale) {
316
+ if (!locale) throw new Error(noTargetLocaleProvidedError("getLocaleName"));
317
+ return this.localeConfig.getLocaleName(locale);
318
+ }
319
+ /**
320
+ * Retrieves an emoji based on a given locale code.
321
+ * Uses the locale's region (if present) to select an emoji or falls back on default emojis.
322
+ *
323
+ * @param {string} [locale=this.targetLocale] - A BCP-47 locale code (e.g., 'en-US', 'fr-CA')
324
+ * @returns {string} The emoji representing the locale or its region.
325
+ * @throws {Error} If no target locale is provided.
326
+ *
327
+ * @example
328
+ * gt.getLocaleEmoji('es-ES');
329
+ * // Returns: "🇪🇸"
330
+ */
331
+ getLocaleEmoji(locale = this.targetLocale) {
332
+ if (!locale) throw new Error(noTargetLocaleProvidedError("getLocaleEmoji"));
333
+ return this.localeConfig.getLocaleEmoji(locale);
334
+ }
335
+ /**
336
+ * Generates linguistic details for a given locale code.
337
+ *
338
+ * This function returns information about the locale,
339
+ * script, and region of a given language code both in a standard form and in a maximized form (with likely script and region).
340
+ * The function provides these names in both your default language and native forms, and an associated emoji.
341
+ *
342
+ * @param {string} [locale=this.targetLocale] - The locale code to get properties for (e.g., "de-AT").
343
+ * @returns {LocaleProperties} - An object containing detailed information about the locale.
344
+ *
345
+ * @property {string} code - The full locale code, e.g., "de-AT".
346
+ * @property {string} name - Language name in the default display language, e.g., "Austrian German".
347
+ * @property {string} nativeName - Language name in the locale's native language, e.g., "Österreichisches Deutsch".
348
+ * @property {string} languageCode - The base language code, e.g., "de".
349
+ * @property {string} languageName - The language name in the default display language, e.g., "German".
350
+ * @property {string} nativeLanguageName - The language name in the native language, e.g., "Deutsch".
351
+ * @property {string} nameWithRegionCode - Language name with region in the default language, e.g., "German (AT)".
352
+ * @property {string} nativeNameWithRegionCode - Language name with region in the native language, e.g., "Deutsch (AT)".
353
+ * @property {string} regionCode - The region code from maximization, e.g., "AT".
354
+ * @property {string} regionName - The region name in the default display language, e.g., "Austria".
355
+ * @property {string} nativeRegionName - The region name in the native language, e.g., "Österreich".
356
+ * @property {string} scriptCode - The script code from maximization, e.g., "Latn".
357
+ * @property {string} scriptName - The script name in the default display language, e.g., "Latin".
358
+ * @property {string} nativeScriptName - The script name in the native language, e.g., "Lateinisch".
359
+ * @property {string} maximizedCode - The maximized locale code, e.g., "de-Latn-AT".
360
+ * @property {string} maximizedName - Maximized locale name with likely script in the default language, e.g., "Austrian German (Latin)".
361
+ * @property {string} nativeMaximizedName - Maximized locale name in the native language, e.g., "Österreichisches Deutsch (Lateinisch)".
362
+ * @property {string} minimizedCode - Minimized locale code, e.g., "de-AT" (or "de" for "de-DE").
363
+ * @property {string} minimizedName - Minimized language name in the default language, e.g., "Austrian German".
364
+ * @property {string} nativeMinimizedName - Minimized language name in the native language, e.g., "Österreichisches Deutsch".
365
+ * @property {string} emoji - The emoji associated with the locale's region, if applicable.
366
+ */
367
+ getLocaleProperties(locale = this.targetLocale) {
368
+ if (!locale) throw new Error(noTargetLocaleProvidedError("getLocaleProperties"));
369
+ return this.localeConfig.getLocaleProperties(locale);
370
+ }
371
+ /**
372
+ * Retrieves multiple properties for a given region code, including:
373
+ * - `code`: the original region code
374
+ * - `name`: the localized display name
375
+ * - `emoji`: the associated flag or symbol
376
+ *
377
+ * Behavior:
378
+ * - Accepts ISO 3166-1 alpha-2 or UN M.49 region codes (e.g., `"US"`, `"FR"`, `"419"`).
379
+ * - Uses the instance's `targetLocale` to localize the region name for the user.
380
+ * - If `customMapping` contains a `name` or `emoji` for the region, those override the default values.
381
+ * - Otherwise, uses `Intl.DisplayNames` to get the localized region name, falling back to `libraryDefaultLocale`.
382
+ * - Falls back to the region code as `name` if display name resolution fails.
383
+ * - Falls back to a default emoji if no emoji mapping is found in built-in data or `customMapping`.
384
+ *
385
+ * @param {string} [region=this.getLocaleProperties().regionCode] - The region code to look up (e.g., `"US"`, `"GB"`, `"DE"`).
386
+ * @param {CustomRegionMapping} [customMapping] - Optional mapping of region codes to custom names and/or emojis.
387
+ * @returns {{ code: string, name: string, emoji: string }} An object containing:
388
+ * - `code`: the input region code
389
+ * - `name`: the localized or custom region name
390
+ * - `emoji`: the matching emoji flag or symbol
391
+ *
392
+ * @throws {Error} If no target locale is available to determine region properties.
393
+ *
394
+ * @example
395
+ * const gt = new GTRuntime({ targetLocale: 'en-US' });
396
+ * gt.getRegionProperties('US');
397
+ * // => { code: 'US', name: 'United States', emoji: '🇺🇸' }
398
+ *
399
+ * @example
400
+ * const gt = new GTRuntime({ targetLocale: 'fr-FR' });
401
+ * gt.getRegionProperties('US');
402
+ * // => { code: 'US', name: 'États-Unis', emoji: '🇺🇸' }
403
+ *
404
+ * @example
405
+ * gt.getRegionProperties('US', { US: { name: 'USA', emoji: '🗽' } });
406
+ * // => { code: 'US', name: 'USA', emoji: '🗽' }
407
+ */
408
+ getRegionProperties(region = this.getLocaleProperties().regionCode, customMapping) {
409
+ if (!customMapping) {
410
+ if (this.customMapping && !this.customRegionMapping) {
411
+ const customRegionMapping = {};
412
+ for (const [locale, lp] of Object.entries(this.customMapping)) if (lp && typeof lp === "object" && lp.regionCode && !customRegionMapping[lp.regionCode]) {
413
+ const { regionName: name, emoji } = lp;
414
+ customRegionMapping[lp.regionCode] = {
415
+ locale,
416
+ ...name && { name },
417
+ ...emoji && { emoji }
418
+ };
419
+ }
420
+ this.customRegionMapping = customRegionMapping;
421
+ }
422
+ customMapping = this.customRegionMapping;
423
+ }
424
+ return getRegionProperties(region, this.targetLocale, customMapping);
425
+ }
426
+ /**
427
+ * Determines whether a translation is required based on the source and target locales.
428
+ *
429
+ * @param {string} [sourceLocale=this.sourceLocale] - The locale code for the original content.
430
+ * @param {string} [targetLocale=this.targetLocale] - The locale code to translate into.
431
+ * @param {string[]} [approvedLocales=this.locales] - Optional array of approved target locales.
432
+ * @returns {boolean} True if translation is required, false otherwise
433
+ * @throws {Error} If no source locale is provided.
434
+ * @throws {Error} If no target locale is provided.
435
+ *
436
+ * @example
437
+ * gt.requiresTranslation('en-US', 'es-ES');
438
+ * // Returns: true
439
+ */
440
+ requiresTranslation(sourceLocale = this.sourceLocale, targetLocale = this.targetLocale, approvedLocales = this.locales, customMapping = this.customMapping) {
441
+ if (!sourceLocale) throw new Error(noSourceLocaleProvidedError("requiresTranslation"));
442
+ if (!targetLocale) throw new Error(noTargetLocaleProvidedError("requiresTranslation"));
443
+ if (customMapping === this.customMapping) return this.localeConfig.requiresTranslation(targetLocale, sourceLocale, approvedLocales);
444
+ return requiresTranslation(sourceLocale, targetLocale, approvedLocales, customMapping);
445
+ }
446
+ /**
447
+ * Determines the best matching locale from the provided approved locales list.
448
+ *
449
+ * @param {string | string[]} locales - A single locale or array of locales in preference order.
450
+ * @param {string[]} [approvedLocales=this.locales] - Array of approved locales in preference order.
451
+ * @returns {string | undefined} The best matching locale, or undefined if no match is found.
452
+ *
453
+ * @example
454
+ * gt.determineLocale(['fr-CA', 'fr-FR'], ['en-US', 'fr-FR', 'es-ES']);
455
+ * // Returns: "fr-FR"
456
+ */
457
+ determineLocale(locales, approvedLocales = this.locales || [], customMapping = this.customMapping) {
458
+ if (customMapping === this.customMapping) return this.localeConfig.determineLocale(locales, approvedLocales ?? []);
459
+ return new LocaleConfig({ customMapping }).determineLocale(locales, approvedLocales ?? []);
460
+ }
461
+ /**
462
+ * Gets the text direction for a given locale code.
463
+ *
464
+ * @param {string} [locale=this.targetLocale] - A BCP-47 locale code.
465
+ * @returns {'ltr' | 'rtl'} 'rtl' if the locale is right-to-left; otherwise 'ltr'.
466
+ * @throws {Error} If no target locale is provided.
467
+ *
468
+ * @example
469
+ * gt.getLocaleDirection('ar-SA');
470
+ * // Returns: "rtl"
471
+ */
472
+ getLocaleDirection(locale = this.targetLocale) {
473
+ if (!locale) throw new Error(noTargetLocaleProvidedError("getLocaleDirection"));
474
+ return this.localeConfig.getLocaleDirection(locale);
475
+ }
476
+ /**
477
+ * Checks if a given BCP 47 locale code is valid.
478
+ *
479
+ * @param {string} [locale=this.targetLocale] - The BCP 47 locale code to validate.
480
+ * @param {CustomMapping} [customMapping=this.customMapping] - The custom mapping to use for validation.
481
+ * @returns {boolean} True if the locale code is valid, false otherwise
482
+ * @throws {Error} If no target locale is provided.
483
+ *
484
+ * @example
485
+ * gt.isValidLocale('en-US');
486
+ * // Returns: true
487
+ */
488
+ isValidLocale(locale = this.targetLocale, customMapping = this.customMapping) {
489
+ if (!locale) throw new Error(noTargetLocaleProvidedError("isValidLocale"));
490
+ if (customMapping === this.customMapping) return this.localeConfig.isValidLocale(locale);
491
+ return isValidLocale(locale, customMapping);
492
+ }
493
+ /**
494
+ * Resolves the canonical locale for a given locale.
495
+ * @param locale - The locale to resolve the canonical locale for
496
+ * @param customMapping - The custom mapping to use for resolving the canonical locale
497
+ * @returns The canonical locale, or the input locale when no canonical mapping exists.
498
+ */
499
+ resolveCanonicalLocale(locale = this.targetLocale, customMapping = this.customMapping) {
500
+ if (!locale) throw new Error(noTargetLocaleProvidedError("resolveCanonicalLocale"));
501
+ if (customMapping === this.customMapping) return this.localeConfig.resolveCanonicalLocale(locale);
502
+ return resolveCanonicalLocale(locale, customMapping);
503
+ }
504
+ /**
505
+ * Resolves the alias locale for a given locale.
506
+ * @param locale - The locale to resolve the alias locale for
507
+ * @param customMapping - The custom mapping to use for resolving the alias locale
508
+ * @returns The configured alias for a canonical locale, or the input locale when already an alias or no alias mapping exists.
509
+ */
510
+ resolveAliasLocale(locale, customMapping = this.customMapping) {
511
+ if (!locale) throw new Error(noTargetLocaleProvidedError("resolveAliasLocale"));
512
+ if (customMapping === this.customMapping) return this.localeConfig.resolveAliasLocale(locale);
513
+ return resolveAliasLocale(locale, customMapping);
514
+ }
515
+ /**
516
+ * Standardizes a BCP 47 locale code to ensure correct formatting.
517
+ *
518
+ * @param {string} [locale=this.targetLocale] - The BCP 47 locale code to standardize.
519
+ * @returns {string} The standardized locale code, or the input string if it cannot be standardized.
520
+ * @throws {Error} If no target locale is provided.
521
+ *
522
+ * @example
523
+ * gt.standardizeLocale('en_us');
524
+ * // Returns: "en-US"
525
+ */
526
+ standardizeLocale(locale = this.targetLocale) {
527
+ if (!locale) throw new Error(noTargetLocaleProvidedError("standardizeLocale"));
528
+ return this.localeConfig.standardizeLocale(locale);
529
+ }
530
+ /**
531
+ * Checks if multiple BCP 47 locale codes represent the same dialect.
532
+ *
533
+ * @param {...(string | string[])} locales - The BCP 47 locale codes to compare.
534
+ * @returns {boolean} True if all codes represent the same dialect, false otherwise
535
+ *
536
+ * @example
537
+ * gt.isSameDialect('en-US', 'en-GB');
538
+ * // Returns: false
539
+ *
540
+ * gt.isSameDialect('en', 'en-US');
541
+ * // Returns: true
542
+ */
543
+ isSameDialect(...locales) {
544
+ return this.localeConfig.isSameDialect(...locales);
545
+ }
546
+ /**
547
+ * Checks if multiple BCP 47 locale codes represent the same language.
548
+ *
549
+ * @param {...(string | string[])} locales - The BCP 47 locale codes to compare.
550
+ * @returns {boolean} True if all codes represent the same language, false otherwise
551
+ *
552
+ * @example
553
+ * gt.isSameLanguage('en-US', 'en-GB');
554
+ * // Returns: true
555
+ */
556
+ isSameLanguage(...locales) {
557
+ return this.localeConfig.isSameLanguage(...locales);
558
+ }
559
+ /**
560
+ * Checks if a locale is a superset of another locale.
561
+ *
562
+ * @param {string} superLocale - The locale to check if it is a superset
563
+ * @param {string} subLocale - The locale to check if it is a subset
564
+ * @returns {boolean} True if superLocale is a superset of subLocale, false otherwise
565
+ *
566
+ * @example
567
+ * gt.isSupersetLocale('en', 'en-US');
568
+ * // Returns: true
569
+ *
570
+ * gt.isSupersetLocale('en-US', 'en');
571
+ * // Returns: false
572
+ */
573
+ isSupersetLocale(superLocale, subLocale) {
574
+ return this.localeConfig.isSupersetLocale(superLocale, subLocale);
575
+ }
576
+ };
577
+ //#endregion
2
578
  export { GTRuntime };
579
+
580
+ //# sourceMappingURL=runtime.mjs.map