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