generaltranslation 6.2.5 â 6.2.6
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/api/batch/translateBatch.d.ts +1 -0
- package/dist/api/icu/translate.d.ts +1 -0
- package/dist/api/jsx/translateJsx.d.ts +1 -0
- package/dist/api/translate/translate.d.ts +1 -0
- package/dist/cache/IntlCache.d.ts +8 -0
- package/dist/formatting/format.d.ts +1 -0
- package/dist/formatting/string_content.d.ts +1 -0
- package/dist/id/hashJsxChildren.d.ts +23 -0
- package/dist/id/hashTemplate.d.ts +4 -0
- package/dist/id.cjs.min.cjs +2 -0
- package/dist/id.cjs.min.cjs.map +1 -0
- package/dist/id.d.ts +3 -0
- package/dist/id.esm.min.mjs +2 -0
- package/dist/id.esm.min.mjs.map +1 -0
- package/dist/index.cjs.min.cjs +2 -0
- package/dist/index.cjs.min.cjs.map +1 -0
- package/dist/index.d.ts +288 -0
- package/dist/index.esm.min.mjs +2 -0
- package/dist/index.esm.min.mjs.map +1 -0
- package/dist/internal.cjs.min.cjs +2 -0
- package/dist/internal.cjs.min.cjs.map +1 -0
- package/dist/internal.d.ts +40 -0
- package/dist/internal.esm.min.mjs +2 -0
- package/dist/internal.esm.min.mjs.map +1 -0
- package/dist/locales/determineLocale.d.ts +1 -0
- package/dist/locales/getLocaleDirection.d.ts +1 -0
- package/dist/locales/getLocaleEmoji.d.ts +1 -0
- package/dist/locales/getLocaleName.d.ts +1 -0
- package/dist/locales/getLocaleProperties.d.ts +1 -0
- package/dist/locales/getPluralForm.d.ts +9 -0
- package/dist/locales/isSameDialect.d.ts +1 -0
- package/dist/locales/isSameLanguage.d.ts +1 -0
- package/dist/locales/isSupersetLocale.d.ts +1 -0
- package/dist/locales/isValidLocale.d.ts +1 -0
- package/dist/locales/requiresTranslation.d.ts +1 -0
- package/dist/projects/getProjectLocales.d.ts +1 -0
- package/dist/projects/updateProjectTranslations.d.ts +1 -0
- package/dist/settings/plurals.d.ts +3 -0
- package/dist/settings/settings.d.ts +2 -0
- package/dist/settings/settingsUrls.d.ts +9 -0
- package/dist/types.d.ts +86 -0
- package/package.json +1 -1
package/dist/index.d.ts
ADDED
@@ -0,0 +1,288 @@
|
|
1
|
+
import { Content, JsxChildren, JsxTranslationResult, ContentTranslationResult, TranslationError, IcuTranslationResult, Metadata } from './types';
|
2
|
+
/**
|
3
|
+
* Type representing the constructor parameters for the GT class.
|
4
|
+
*/
|
5
|
+
type GTConstructorParams = {
|
6
|
+
apiKey?: string;
|
7
|
+
devApiKey?: string;
|
8
|
+
sourceLocale?: string;
|
9
|
+
projectId?: string;
|
10
|
+
baseUrl?: string;
|
11
|
+
};
|
12
|
+
/**
|
13
|
+
* GT is the core driver for the General Translation library.
|
14
|
+
*/
|
15
|
+
declare class GT {
|
16
|
+
apiKey: string;
|
17
|
+
devApiKey: string;
|
18
|
+
sourceLocale: string;
|
19
|
+
projectId: string;
|
20
|
+
baseUrl: string;
|
21
|
+
/**
|
22
|
+
* Constructs an instance of the GT class.
|
23
|
+
*
|
24
|
+
* @param {GTConstructorParams} [params] - The parameters for initializing the GT instance.
|
25
|
+
* @param {string} [params.apiKey=''] - The API key for accessing the translation service.
|
26
|
+
* @param {string} [params.sourceLocale=''] - The default locale for translations.
|
27
|
+
* @param {string} [params.projectId=''] - The project ID for the translation service.
|
28
|
+
* @param {string} [params.baseUrl='https://api.gtx.dev'] - The base URL for the translation service.
|
29
|
+
*/
|
30
|
+
constructor({ apiKey, devApiKey, sourceLocale, projectId, baseUrl, }?: GTConstructorParams);
|
31
|
+
/**
|
32
|
+
* Translates a string or an array of strings/variables into a target locale.
|
33
|
+
*
|
34
|
+
* @param {Content} source - The string or array of strings/variables to be translated.
|
35
|
+
* @param {string} locale - The target locale code (e.g., 'en-US', 'fr') for the translation.
|
36
|
+
* @param {{ context?: string, [key: string]: any }} [metadata] - Additional metadata for the translation request.
|
37
|
+
*
|
38
|
+
* @returns {Promise<ContentTranslationResult | TranslationError>} A promise that resolves to the translated content, or an error if the translation fails.
|
39
|
+
*/
|
40
|
+
translate(source: Content, locale: string, metadata?: Metadata): Promise<ContentTranslationResult | TranslationError>;
|
41
|
+
/**
|
42
|
+
* Translates JSX elements into a given locale.
|
43
|
+
*
|
44
|
+
* @param {Object} params - The parameters for the translation.
|
45
|
+
* @param {JsxChildren} params.source - The JSX children content to be translated.
|
46
|
+
* @param {string} params.locale - The target locale for the translation.
|
47
|
+
* @param {Object} params.metadata - Additional metadata for the translation process.
|
48
|
+
*
|
49
|
+
* @returns {Promise<JsxTranslationResult | TranslationError>} - A promise that resolves to the translated content.
|
50
|
+
*/
|
51
|
+
translateJsx(source: JsxChildren, locale: string, metadata?: Metadata): Promise<JsxTranslationResult | TranslationError>;
|
52
|
+
/**
|
53
|
+
* Translates an ICU message into a given locale.
|
54
|
+
*
|
55
|
+
* @param {string} source - The ICU message to be translated.
|
56
|
+
* @param {string} locale - The target locale code (e.g., 'en-US', 'fr') for the translation.
|
57
|
+
* @param {{ context?: string, [key: string]: any }} [metadata] - Additional metadata for the translation request.
|
58
|
+
* @param {string} [metadata.context] - Contextual information to assist with the translation.
|
59
|
+
*
|
60
|
+
* @returns {Promise<ContentTranslationResult | TranslationError>} A promise that resolves to the translated content, or an error if the translation fails.
|
61
|
+
*/
|
62
|
+
translateIcu(source: string, locale: string, metadata?: Metadata): Promise<IcuTranslationResult | TranslationError>;
|
63
|
+
}
|
64
|
+
/**
|
65
|
+
* Get the text direction for a given locale code using the Intl.Locale API.
|
66
|
+
*
|
67
|
+
* @param {string} locale - The locale code to check.
|
68
|
+
* @returns {string} - 'rtl' if the locale is right-to-left, otherwise 'ltr'.
|
69
|
+
*/
|
70
|
+
export declare function getLocaleDirection(locale: string): 'ltr' | 'rtl';
|
71
|
+
/**
|
72
|
+
* Retrieves the display name of locale code using Intl.DisplayNames.
|
73
|
+
*
|
74
|
+
* @param {string} locale - A BCP-47 locale code.
|
75
|
+
* @param {string} [defaultLocale = 'en'] - The locale for display names.
|
76
|
+
* @returns {string} The display name corresponding to the code.
|
77
|
+
*/
|
78
|
+
export declare function getLocaleName(locale: string, defaultLocale?: string): string;
|
79
|
+
/**
|
80
|
+
* Generates linguistic details for a given locale code.
|
81
|
+
*
|
82
|
+
* This function returns information about the locale,
|
83
|
+
* script, and region of a given language code both in a standard form and in a maximized form (with likely script and region).
|
84
|
+
* The function provides these names in both your default language and native forms, and an associated emoji.
|
85
|
+
*
|
86
|
+
* @param {string} locale - The locale code to get properties for (e.g., "de-AT").
|
87
|
+
* @param {string} [defaultLocale=libraryDefaultLocale] - The default locale code for display names.
|
88
|
+
* @returns {LocaleProperties} - An object containing detailed information about the locale.
|
89
|
+
*
|
90
|
+
* @property {string} code - The full locale code, e.g., "de-AT".
|
91
|
+
* @property {string} name - Language name in the default display language, e.g., "Austrian German".
|
92
|
+
* @property {string} nativeName - Language name in the locale's native language, e.g., "Ăsterreichisches Deutsch".
|
93
|
+
* @property {string} languageCode - The base language code, e.g., "de".
|
94
|
+
* @property {string} languageName - The language name in the default display language, e.g., "German".
|
95
|
+
* @property {string} nativeLanguageName - The language name in the native language, e.g., "Deutsch".
|
96
|
+
* @property {string} nameWithRegionCode - Language name with region in the default language, e.g., "German (AT)".
|
97
|
+
* @property {string} nativeNameWithRegionCode - Language name with region in the native language, e.g., "Deutsch (AT)".
|
98
|
+
* @property {string} regionCode - The region code from maximization, e.g., "AT".
|
99
|
+
* @property {string} regionName - The region name in the default display language, e.g., "Austria".
|
100
|
+
* @property {string} nativeRegionName - The region name in the native language, e.g., "Ăsterreich".
|
101
|
+
* @property {string} scriptCode - The script code from maximization, e.g., "Latn".
|
102
|
+
* @property {string} scriptName - The script name in the default display language, e.g., "Latin".
|
103
|
+
* @property {string} nativeScriptName - The script name in the native language, e.g., "Lateinisch".
|
104
|
+
* @property {string} maximizedCode - The maximized locale code, e.g., "de-Latn-AT".
|
105
|
+
* @property {string} maximizedName - Maximized locale name with likely script in the default language, e.g., "Austrian German (Latin)".
|
106
|
+
* @property {string} nativeMaximizedName - Maximized locale name in the native language, e.g., "Ăsterreichisches Deutsch (Lateinisch)".
|
107
|
+
* @property {string} minimizedCode - Minimized locale code, e.g., "de-AT" (or "de" for "de-DE").
|
108
|
+
* @property {string} minimizedName - Minimized language name in the default language, e.g., "Austrian German".
|
109
|
+
* @property {string} nativeMinimizedName - Minimized language name in the native language, e.g., "Ăsterreichisches Deutsch".
|
110
|
+
* @property {string} emoji - The emoji associated with the locale's region, if applicable.
|
111
|
+
*/
|
112
|
+
export declare function getLocaleProperties(locale: string, defaultLocale?: string): {
|
113
|
+
code: string;
|
114
|
+
name: string;
|
115
|
+
nativeName: string;
|
116
|
+
languageCode: string;
|
117
|
+
languageName: string;
|
118
|
+
nativeLanguageName: string;
|
119
|
+
nameWithRegionCode: string;
|
120
|
+
nativeNameWithRegionCode: string;
|
121
|
+
regionCode: string;
|
122
|
+
regionName: string;
|
123
|
+
nativeRegionName: string;
|
124
|
+
scriptCode: string;
|
125
|
+
scriptName: string;
|
126
|
+
nativeScriptName: string;
|
127
|
+
maximizedCode: string;
|
128
|
+
maximizedName: string;
|
129
|
+
nativeMaximizedName: string;
|
130
|
+
minimizedCode: string;
|
131
|
+
minimizedName: string;
|
132
|
+
nativeMinimizedName: string;
|
133
|
+
emoji: string;
|
134
|
+
};
|
135
|
+
/**
|
136
|
+
* Retrieves an emoji based on a given locale code, taking into account region, language, and specific exceptions.
|
137
|
+
* This function uses the locale's region (if present) to select an emoji or falls back on default emojis for certain languages.
|
138
|
+
*
|
139
|
+
* @param code - A string representing the locale code (e.g., 'en-US', 'fr-CA').
|
140
|
+
* @param custom - An optional custom mapping of locale codes to emojis.
|
141
|
+
* @returns The emoji representing the locale or its region, or a default emoji if no specific match is found.
|
142
|
+
*/
|
143
|
+
export declare function getLocaleEmoji(locale: string, custom?: Record<string, string>): string;
|
144
|
+
/**
|
145
|
+
* Checks if a given BCP 47 locale code is valid.
|
146
|
+
* @param {string} locale - The BCP 47 locale code to validate.
|
147
|
+
* @returns {boolean} True if the BCP 47 code is valid, false otherwise.
|
148
|
+
*/
|
149
|
+
export declare function isValidLocale(locale: string): boolean;
|
150
|
+
/**
|
151
|
+
* Standardizes a BCP 47 locale code to ensure correct formatting.
|
152
|
+
* @param {string} locale - The BCP 47 locale code to standardize.
|
153
|
+
* @returns {string} The standardized BCP 47 locale code or an empty string if it is an invalid code.
|
154
|
+
*/
|
155
|
+
export declare function standardizeLocale(locale: string): string;
|
156
|
+
/**
|
157
|
+
* Checks if multiple BCP 47 locale codes represent the same dialect.
|
158
|
+
*
|
159
|
+
* For example, `"en-US"` and `"en-GB"` are the same language, but different dialects.
|
160
|
+
* `isSameDialect("en-US", "en-GB")` would return `false`.
|
161
|
+
*
|
162
|
+
* For checking if two locale codes represent the same language, see `isSameLanguage()`.
|
163
|
+
*
|
164
|
+
* Note that `isSameDialect("en", "en-US")` and `isSameDialect("en", "en-GB")` would both return true.
|
165
|
+
*
|
166
|
+
* @param {string[]} locales - The BCP 47 locale codes to compare.
|
167
|
+
* @returns {boolean} True if all BCP 47 codes represent the same dialect, false otherwise.
|
168
|
+
*/
|
169
|
+
export declare function isSameDialect(...locales: (string | string[])[]): boolean;
|
170
|
+
/**
|
171
|
+
* Checks if multiple BCP 47 locale codes represent the same language.
|
172
|
+
*
|
173
|
+
* For example, `"en-US"` and `"en-GB"` are the same language, English.
|
174
|
+
* `isSameDialect("en-US", "en-GB")` would return `true`.
|
175
|
+
*
|
176
|
+
* For checking if two codes represent the exact same dialect, see `isSameDialect()`.
|
177
|
+
*
|
178
|
+
* @param {string[]} locales - The BCP 47 locale codes to compare.
|
179
|
+
* @returns {boolean} True if all BCP 47 codes represent the same locale, false otherwise.
|
180
|
+
*/
|
181
|
+
export declare function isSameLanguage(...locales: (string | string[])[]): boolean;
|
182
|
+
/**
|
183
|
+
* Checks if a locale is a superset of another locale.
|
184
|
+
* A subLocale is a subset of superLocale if it is an extension of superLocale or are otherwise identical.
|
185
|
+
*
|
186
|
+
* `isSupersetLocale("en", "en-US")` would return `true`.
|
187
|
+
* `isSupersetLocale("en-US", "en")` would return `false`.
|
188
|
+
*
|
189
|
+
* @param {string} superLocale - The locale to check if it is a superset of the other locale.
|
190
|
+
* @param {string} subLocale - The locale to check if it is a subset of the other locale.
|
191
|
+
* @returns {boolean} True if the first locale is a superset of the second locale, false otherwise.
|
192
|
+
*/
|
193
|
+
export declare function isSupersetLocale(superLocale: string, subLocale: string): boolean;
|
194
|
+
/**
|
195
|
+
* Formats a number according to the specified locales and options.
|
196
|
+
* @param {Object} params - The parameters for the number formatting.
|
197
|
+
* @param {number} params.value - The number to format.
|
198
|
+
* @param {string | string[]} [params.locales=['en']] - The locales to use for formatting.
|
199
|
+
* @param {Intl.NumberFormatOptions} [params.options={}] - Additional options for number formatting.
|
200
|
+
* @returns {string} The formatted number.
|
201
|
+
*/
|
202
|
+
export declare function formatNum(number: number, options?: {
|
203
|
+
locales?: string | string[];
|
204
|
+
} & Intl.NumberFormatOptions): string;
|
205
|
+
/**
|
206
|
+
* Formats a date according to the specified languages and options.
|
207
|
+
* @param {Object} params - The parameters for the date formatting.
|
208
|
+
* @param {Date} params.value - The date to format.
|
209
|
+
* @param {string | string[]} [params.locales=['en']] - The languages to use for formatting.
|
210
|
+
* @param {Intl.DateTimeFormatOptions} [params.options={}] - Additional options for date formatting.
|
211
|
+
* @returns {string} The formatted date.
|
212
|
+
*/
|
213
|
+
export declare function formatDateTime(date: Date, options?: {
|
214
|
+
locales?: string | string[];
|
215
|
+
} & Intl.DateTimeFormatOptions): string;
|
216
|
+
/**
|
217
|
+
* Formats a currency value according to the specified languages, currency, and options.
|
218
|
+
* @param {Object} params - The parameters for the currency formatting.
|
219
|
+
* @param {number} params.value - The currency value to format.
|
220
|
+
* @param {string} params.currency - The currency code (e.g., 'USD').
|
221
|
+
* @param {string | string[]} [params.locales=['en']] - The locale codes to use for formatting.
|
222
|
+
* @param {Intl.NumberFormatOptions} [params.options={}] - Additional options for currency formatting.
|
223
|
+
* @returns {string} The formatted currency value.
|
224
|
+
*/
|
225
|
+
export declare function formatCurrency(value: number, currency: string, options?: {
|
226
|
+
locales?: string | string[];
|
227
|
+
} & Intl.NumberFormatOptions): string;
|
228
|
+
/**
|
229
|
+
* Formats a list of items according to the specified locales and options.
|
230
|
+
* @param {Object} params - The parameters for the list formatting.
|
231
|
+
* @param {Array<string | number>} params.value - The list of items to format.
|
232
|
+
* @param {string | string[]} [params.locales=['en']] - The locales to use for formatting.
|
233
|
+
* @param {Intl.ListFormatOptions} [params.options={}] - Additional options for list formatting.
|
234
|
+
* @returns {string} The formatted list.
|
235
|
+
*/
|
236
|
+
export declare function formatList(array: Array<string | number>, options: {
|
237
|
+
locales?: string | string[];
|
238
|
+
} & Intl.ListFormatOptions): string;
|
239
|
+
/**
|
240
|
+
* Formats a relative time value according to the specified locales and options.
|
241
|
+
* @param {Object} params - The parameters for the relative time formatting.
|
242
|
+
* @param {number} params.value - The relative time value to format.
|
243
|
+
* @param {Intl.RelativeTimeFormatUnit} params.unit - The unit of time (e.g., 'second', 'minute', 'hour', 'day', 'week', 'month', 'year').
|
244
|
+
* @param {string | string[]} [params.locales=['en']] - The locales to use for formatting.
|
245
|
+
* @param {Intl.RelativeTimeFormatOptions} [params.options={}] - Additional options for relative time formatting.
|
246
|
+
* @returns {string} The formatted relative time string.
|
247
|
+
*/
|
248
|
+
export declare function formatRelativeTime(value: number, unit: Intl.RelativeTimeFormatUnit, options: {
|
249
|
+
locales?: string | string[];
|
250
|
+
} & Intl.RelativeTimeFormatOptions): string;
|
251
|
+
/**
|
252
|
+
* Splits a string into an array of text and variable objects.
|
253
|
+
* @param {string} string - The input string to split.
|
254
|
+
* @returns {Content} - An array containing strings and variables.
|
255
|
+
*/
|
256
|
+
export declare function splitStringToContent(string: string): Content;
|
257
|
+
/**
|
258
|
+
* Renders content to a string by replacing variables with their formatted values.
|
259
|
+
* @param {Content} content - The content to render.
|
260
|
+
* @param {string | string[]} [locales='en'] - The locale(s) to use for formatting.
|
261
|
+
* @param {Record<string, any>} [variables={}] - An object containing variable values.
|
262
|
+
* @param {Record<string, any>} [variableOptions={}] - An object containing options for formatting variables.
|
263
|
+
* @returns {string} - The rendered string with variables replaced by their formatted values.
|
264
|
+
*/
|
265
|
+
export declare function renderContentToString(content: Content, locales?: string | string[], variables?: Record<string, any>, variableOptions?: Record<string, any>): string;
|
266
|
+
/**
|
267
|
+
* Determines the best matching locale from the provided approved locales list.
|
268
|
+
* @param {string | string[]} locales - A single locale or an array of locales sorted in preference order.
|
269
|
+
* @param {string[]} approvedLocales - An array of approved locales, also sorted by preference.
|
270
|
+
* @returns {string | undefined} - The best matching locale from the approvedLocales list, or undefined if no match is found.
|
271
|
+
*/
|
272
|
+
export declare function determineLocale(locales: string | string[], approvedLocales: string[]): string | undefined;
|
273
|
+
/**
|
274
|
+
* Determines whether a translation is required based on the source and target locales.
|
275
|
+
*
|
276
|
+
* - If the target locale is not specified, the function returns `false`, as translation is not needed.
|
277
|
+
* - If the source and target locale are the same, returns `false`, indicating that no translation is necessary.
|
278
|
+
* - If the `approvedLocales` array is provided, and the target locale is not within that array, the function also returns `false`.
|
279
|
+
* - Otherwise, it returns `true`, meaning that a translation is required.
|
280
|
+
*
|
281
|
+
* @param {string} sourceLocale - The locale code for the original content (BCP 47 locale code).
|
282
|
+
* @param {string} targetLocale - The locale code of the language to translate the content into (BCP 47 locale code).
|
283
|
+
* @param {string[]} [approvedLocale] - An optional array of approved target locales.
|
284
|
+
*
|
285
|
+
* @returns {boolean} - Returns `true` if translation is required, otherwise `false`.
|
286
|
+
*/
|
287
|
+
export declare function requiresTranslation(sourceLocale: string, targetLocale: string, approvedLocales?: string[]): boolean;
|
288
|
+
export default GT;
|
@@ -0,0 +1,2 @@
|
|
1
|
+
var e=function(){return e=Object.assign||function(e){for(var t,n=1,r=arguments.length;n<r;n++)for(var o in t=arguments[n])Object.prototype.hasOwnProperty.call(t,o)&&(e[o]=t[o]);return e},e.apply(this,arguments)};function t(e,t,n,r){return new(n||(n=Promise))((function(o,a){function i(e){try{u(r.next(e))}catch(e){a(e)}}function c(e){try{u(r.throw(e))}catch(e){a(e)}}function u(e){var t;e.done?o(e.value):(t=e.value,t instanceof n?t:new n((function(e){e(t)}))).then(i,c)}u((r=r.apply(e,t||[])).next())}))}function n(e,t){var n,r,o,a={label:0,sent:function(){if(1&o[0])throw o[1];return o[1]},trys:[],ops:[]},i=Object.create(("function"==typeof Iterator?Iterator:Object).prototype);return i.next=c(0),i.throw=c(1),i.return=c(2),"function"==typeof Symbol&&(i[Symbol.iterator]=function(){return this}),i;function c(c){return function(u){return function(c){if(n)throw new TypeError("Generator is already executing.");for(;i&&(i=0,c[0]&&(a=0)),a;)try{if(n=1,r&&(o=2&c[0]?r.return:c[0]?r.throw||((o=r.return)&&o.call(r),0):r.next)&&!(o=o.call(r,c[1])).done)return o;switch(r=0,o&&(c=[2&c[0],o.value]),c[0]){case 0:case 1:o=c;break;case 4:return a.label++,{value:c[1],done:!1};case 5:a.label++,r=c[1],c=[0];continue;case 7:c=a.ops.pop(),a.trys.pop();continue;default:if(!(o=a.trys,(o=o.length>0&&o[o.length-1])||6!==c[0]&&2!==c[0])){a=0;continue}if(3===c[0]&&(!o||c[1]>o[0]&&c[1]<o[3])){a.label=c[1];break}if(6===c[0]&&a.label<o[1]){a.label=o[1],o=c;break}if(o&&a.label<o[2]){a.label=o[2],a.ops.push(c);break}o[2]&&a.ops.pop(),a.trys.pop();continue}c=t.call(e,a)}catch(e){c=[6,e],r=0}finally{n=o=0}if(5&c[0])throw c[1];return{value:c[0]?c[1]:void 0,done:!0}}([c,u])}}}"function"==typeof SuppressedError&&SuppressedError;var r=new(function(){function e(){this.cache=new Map}return e.prototype._generateKey=function(e,t,n){void 0===n&&(n={});var r=Array.isArray(t)?t.join(","):t,o=n?JSON.stringify(n,Object.keys(n).sort()):"{}";return"".concat(e,":").concat(r,":").concat(o)},e.prototype.get=function(e,t,n){void 0===n&&(n={});var r=this._generateKey(e,t,n);if(!this.cache.has(r)){var o=new Intl[e](t,n);this.cache.set(r,o)}return this.cache.get(r)},e}()),o="en",a=6e4,i=["Cham","Jamo","Kawi","Lisu","Toto","Thai"],c=function(e){try{var t=r.get("Locale",e),n=t.language,a=t.region,c=t.script;if(e.split("-").length!==(u=1,a&&(u+=1),c&&(u+=1),u))return!1;if(r.get("DisplayNames",[o],{type:"language"}).of(n)===n&&!function(e){return e>="qaa"&&e<="qtz"}(n))return!1;if(a)if(r.get("DisplayNames",[o],{type:"region"}).of(a)===a)return!1;if(c)if(r.get("DisplayNames",[o],{type:"script"}).of(c)===c&&!i.includes(c))return!1;return!0}catch(e){return!1}var u},u=function(e){try{return Intl.getCanonicalLocales(e)[0]}catch(t){return e}};function l(){for(var e,t,n,o,a,i,c,l,s,f,v=[],p=0;p<arguments.length;p++)v[p]=arguments[p];try{for(var d=v.flat().map(u),g=0;g<d.length;g++)for(var y=g+1;y<d.length;y++)if(e=d[g],t=d[y],n=void 0,o=void 0,a=void 0,i=void 0,c=void 0,l=void 0,s=void 0,f=void 0,n=r.get("Locale",e),o=n.language,a=n.region,i=n.script,c=r.get("Locale",t),l=c.language,s=c.region,f=c.script,o!==l||a&&s&&a!==s||i&&f&&i!==f)return!1;return!0}catch(e){return console.error(e),!1}}function s(){for(var e=[],t=0;t<arguments.length;t++)e[t]=arguments[t];try{var n=e.flat().map((function(e){return r.get("Locale",e).language}));return n.every((function(e){return e===n[0]}))}catch(e){return console.error(e),!1}}function f(r,o,i,c){return t(this,void 0,void 0,(function(){var t,u,l,s,f,v,p,d;return n(this,(function(n){switch(n.label){case 0:t=new AbortController,u=t.signal,(l=Math.min((null==c?void 0:c.timeout)||a,a))&&setTimeout((function(){return t.abort()}),l),n.label=1;case 1:return n.trys.push([1,3,,4]),[4,fetch("".concat(r.baseUrl).concat("/v1/translate/content"),{method:"POST",headers:e(e({"Content-Type":"application/json"},r.apiKey&&{"x-gt-api-key":r.apiKey}),r.devApiKey&&{"x-gt-dev-api-key":r.devApiKey}),body:JSON.stringify({source:o,targetLocale:i,metadata:c}),signal:u})];case 2:return s=n.sent(),[3,4];case 3:if("AbortError"===(null==(f=n.sent())?void 0:f.name))throw new Error("Translation request timed out. This has either occured due to the translation of an unusually large request or a translation failure in the API.");throw f;case 4:return s.ok?[3,6]:(v=Error.bind,d=(p="".concat(s.status,": ")).concat,[4,s.text()]);case 5:throw new(v.apply(Error,[void 0,d.apply(p,[n.sent()])]));case 6:return[4,s.json()];case 7:return[2,n.sent()]}}))}))}function v(r,o,i,c){return t(this,void 0,void 0,(function(){var t,u,l,s,f,v,p,d;return n(this,(function(n){switch(n.label){case 0:t=new AbortController,u=t.signal,(l=Math.min((null==c?void 0:c.timeout)||a,a))&&setTimeout((function(){return t.abort()}),l),n.label=1;case 1:return n.trys.push([1,3,,4]),[4,fetch("".concat(r.baseUrl).concat("/v1/translate/react"),{method:"POST",headers:e(e({"Content-Type":"application/json"},r.apiKey&&{"x-gt-api-key":r.apiKey}),r.devApiKey&&{"x-gt-dev-api-key":r.devApiKey}),body:JSON.stringify({source:o,targetLocale:i,metadata:c}),signal:u})];case 2:return s=n.sent(),[3,4];case 3:if("AbortError"===(null==(f=n.sent())?void 0:f.name))throw new Error("Translation request timed out. This has either occured due to the translation of an unusually large request or a translation failure in the API.");throw f;case 4:return s.ok?[3,6]:(v=Error.bind,d=(p="".concat(s.status,": ")).concat,[4,s.text()]);case 5:throw new(v.apply(Error,[void 0,d.apply(p,[n.sent()])]));case 6:return[4,s.json()];case 7:return[2,n.sent()]}}))}))}function p(r,o,i,c){return t(this,void 0,void 0,(function(){var t,u,l,s,f,v,p,d;return n(this,(function(n){switch(n.label){case 0:t=new AbortController,u=t.signal,(l=Math.min((null==c?void 0:c.timeout)||a,a))&&setTimeout((function(){return t.abort()}),l),n.label=1;case 1:return n.trys.push([1,3,,4]),[4,fetch("".concat(r.baseUrl).concat("/v1/translate/icu"),{method:"POST",headers:e(e({"Content-Type":"application/json"},r.apiKey&&{"x-gt-api-key":r.apiKey}),r.devApiKey&&{"x-gt-dev-api-key":r.devApiKey}),body:JSON.stringify({source:o,targetLocale:i,metadata:c}),signal:u})];case 2:return s=n.sent(),[3,4];case 3:if("AbortError"===(null==(f=n.sent())?void 0:f.name))throw new Error("Translation request timed out. This has either occured due to the translation of an unusually large request or a translation failure in the API.");throw f;case 4:return s.ok?[3,6]:(v=Error.bind,d=(p="".concat(s.status,": ")).concat,[4,s.text()]);case 5:throw new(v.apply(Error,[void 0,d.apply(p,[n.sent()])]));case 6:return[4,s.json()];case 7:return[2,n.sent()]}}))}))}function d(e,t){if(void 0===t&&(t={}),!c(e))return y;if(t[e=u(e)])return t[e];var n=r.get("Locale",e),o=n.region;if(o&&m[o])return m[o];var a=n.maximize(),i=a.region||"";return h[a.language]||m[i]||y}var g="đ",y=g,h={ca:g,eu:g,ku:g,bo:"đ",ug:"đ",gd:"đ´ó §ó ˘ó łó Łó ´ó ż",cy:"đ´ó §ó ˘ó ˇó Źó łó ż",gv:"đŽđ˛",grc:"đş"},m={AF:"đŚđŤ",AX:"đŚđ˝",AL:"đŚđą",DZ:"đŠđż",AS:"đŚđ¸",AD:"đŚđŠ",AO:"đŚđ´",AI:"đŚđŽ",AQ:"đŚđś",AG:"đŚđŹ",AR:"đŚđˇ",AM:"đŚđ˛",AW:"đŚđź",AU:"đŚđş",AT:"đŚđš",AZ:"đŚđż",BS:"đ§đ¸",BH:"đ§đ",BD:"đ§đŠ",BB:"đ§đ§",BY:"đ§đž",BE:"đ§đŞ",BZ:"đ§đż",BJ:"đ§đŻ",BM:"đ§đ˛",BT:"đ§đš",BO:"đ§đ´",BQ:"đ§đś",BA:"đ§đŚ",BW:"đ§đź",BV:"đ§đť",BR:"đ§đˇ",IO:"đŽđ´",BN:"đ§đł",BG:"đ§đŹ",BF:"đ§đŤ",BI:"đ§đŽ",CV:"đ¨đť",KH:"đ°đ",CM:"đ¨đ˛",CA:"đ¨đŚ",KY:"đ°đž",CF:"đ¨đŤ",TD:"đšđŠ",CL:"đ¨đą",CN:"đ¨đł",CX:"đ¨đ˝",CC:"đ¨đ¨",CO:"đ¨đ´",KM:"đ°đ˛",CD:"đ¨đŠ",CG:"đ¨đŹ",CK:"đ¨đ°",CR:"đ¨đˇ",CI:"đ¨đŽ",HR:"đđˇ",CU:"đ¨đş",CW:"đ¨đź",CY:"đ¨đž",CZ:"đ¨đż",DK:"đŠđ°",DJ:"đŠđŻ",DM:"đŠđ˛",DO:"đŠđ´",EC:"đŞđ¨",EG:"đŞđŹ",SV:"đ¸đť",GQ:"đŹđś",ER:"đŞđˇ",EE:"đŞđŞ",SZ:"đ¸đż",ET:"đŞđš",FK:"đŤđ°",FO:"đŤđ´",FJ:"đŤđŻ",FI:"đŤđŽ",FR:"đŤđˇ",GF:"đŹđŤ",PF:"đľđŤ",TF:"đšđŤ",GA:"đŹđŚ",GM:"đŹđ˛",GE:"đŹđŞ",DE:"đŠđŞ",GH:"đŹđ",GI:"đŹđŽ",GR:"đŹđˇ",GL:"đŹđą",GD:"đŹđŠ",GP:"đŹđľ",GU:"đŹđş",GT:"đŹđš",GG:"đŹđŹ",GN:"đŹđł",GW:"đŹđź",GY:"đŹđž",HT:"đđš",HM:"đđ˛",VA:"đťđŚ",HN:"đđł",HK:"đđ°",HU:"đđş",IS:"đŽđ¸",IN:"đŽđł",ID:"đŽđŠ",IR:"đŽđˇ",IQ:"đŽđś",IE:"đŽđŞ",IM:"đŽđ˛",IL:"đŽđą",IT:"đŽđš",JM:"đŻđ˛",JP:"đŻđľ",JE:"đŻđŞ",JO:"đŻđ´",KZ:"đ°đż",KE:"đ°đŞ",KI:"đ°đŽ",KP:"đ°đľ",KR:"đ°đˇ",KW:"đ°đź",KG:"đ°đŹ",LA:"đąđŚ",LV:"đąđť",LB:"đąđ§",LS:"đąđ¸",LR:"đąđˇ",LY:"đąđž",LI:"đąđŽ",LT:"đąđš",LU:"đąđş",MO:"đ˛đ´",MG:"đ˛đŹ",MW:"đ˛đź",MY:"đ˛đž",MV:"đ˛đť",ML:"đ˛đą",MT:"đ˛đš",MH:"đ˛đ",MQ:"đ˛đś",MR:"đ˛đˇ",MU:"đ˛đş",YT:"đžđš",MX:"đ˛đ˝",FM:"đŤđ˛",MD:"đ˛đŠ",MC:"đ˛đ¨",MN:"đ˛đł",ME:"đ˛đŞ",MS:"đ˛đ¸",MA:"đ˛đŚ",MZ:"đ˛đż",MM:"đ˛đ˛",NA:"đłđŚ",NR:"đłđˇ",NP:"đłđľ",NL:"đłđą",NC:"đłđ¨",NZ:"đłđż",NI:"đłđŽ",NE:"đłđŞ",NG:"đłđŹ",NU:"đłđş",NF:"đłđŤ",MK:"đ˛đ°",MP:"đ˛đľ",NO:"đłđ´",OM:"đ´đ˛",PK:"đľđ°",PW:"đľđź",PS:"đľđ¸",PA:"đľđŚ",PG:"đľđŹ",PY:"đľđž",PE:"đľđŞ",PH:"đľđ",PN:"đľđł",PL:"đľđą",PT:"đľđš",PR:"đľđˇ",QA:"đśđŚ",RE:"đˇđŞ",RO:"đˇđ´",RU:"đˇđş",RW:"đˇđź",BL:"đ§đą",SH:"đ¸đ",KN:"đ°đł",LC:"đąđ¨",MF:"đ˛đŤ",PM:"đľđ˛",VC:"đťđ¨",WS:"đźđ¸",SM:"đ¸đ˛",ST:"đ¸đš",SA:"đ¸đŚ",SN:"đ¸đł",RS:"đˇđ¸",SC:"đ¸đ¨",SL:"đ¸đą",SG:"đ¸đŹ",SX:"đ¸đ˝",SK:"đ¸đ°",SI:"đ¸đŽ",SB:"đ¸đ§",SO:"đ¸đ´",ZA:"đżđŚ",GS:"đŹđ¸",SS:"đ¸đ¸",ES:"đŞđ¸",LK:"đąđ°",SD:"đ¸đŠ",SR:"đ¸đˇ",SJ:"đ¸đŻ",SE:"đ¸đŞ",CH:"đ¨đ",SY:"đ¸đž",TW:"đšđź",TJ:"đšđŻ",TZ:"đšđż",TH:"đšđ",TL:"đšđą",TG:"đšđŹ",TK:"đšđ°",TO:"đšđ´",TT:"đšđš",TN:"đšđł",TR:"đšđˇ",TM:"đšđ˛",TC:"đšđ¨",TV:"đšđť",UG:"đşđŹ",UA:"đşđŚ",AE:"đŚđŞ",GB:"đŹđ§",US:"đşđ¸",UM:"đşđ˛",UY:"đşđž",UZ:"đşđż",VU:"đťđş",VE:"đťđŞ",VN:"đťđł",VG:"đťđŹ",VI:"đťđŽ",WF:"đźđŤ",EH:"đŞđ",YE:"đžđŞ",ZM:"đżđ˛",ZW:"đżđź",EU:"đŞđş"};function b(e,t){void 0===t&&(t=o);try{e=u(e);var n=r.get("Locale",e),a=n.language,i=n.region,c=n.maximize(),l=c.toString(),s=c.region||"",f=c.script||"",v=n.minimize().toString(),p=r.get("DisplayNames",[t,e,o],{type:"language"}),g=r.get("DisplayNames",[e,t,o],{type:"language"}),y=p.of(e)||e,h=g.of(e)||e,m=p.of(l)||e,b=g.of(l)||e,N=p.of(v)||e,C=g.of(v)||e,S=p.of(a)||e,T=g.of(a)||e,A=i?"".concat(S," (").concat(i,")"):S,M=i?"".concat(T," (").concat(i,")"):T,w=r.get("DisplayNames",[t,e,o],{type:"region"}),L=r.get("DisplayNames",[e,t,o],{type:"region"}),E=w.of(s)||"",K=L.of(s)||"",G=r.get("DisplayNames",[t,e,o],{type:"script"}),O=r.get("DisplayNames",[e,t,o],{type:"script"});return{code:e,name:y,nativeName:h,maximizedCode:l,maximizedName:m,nativeMaximizedName:b,minimizedCode:v,minimizedName:N,nativeMinimizedName:C,languageCode:a,languageName:S,nativeLanguageName:T,nameWithRegionCode:A,nativeNameWithRegionCode:M,regionCode:s,regionName:E,nativeRegionName:K,scriptCode:f,scriptName:G.of(f)||"",nativeScriptName:O.of(f)||"",emoji:d(e)}}catch(t){var I=e||"",P=null==I?void 0:I.split("-");return{code:I,name:I,nativeName:I,maximizedCode:I,maximizedName:I,nativeMaximizedName:I,minimizedCode:I,minimizedName:I,nativeMinimizedName:I,languageCode:a=(null==P?void 0:P[0])||I||"",languageName:a,nativeLanguageName:a,regionCode:s=P.length>2?null==P?void 0:P[2]:(null==P?void 0:P[1])||"",regionName:s,nativeRegionName:s,scriptCode:f=(null==P?void 0:P[3])||"",scriptName:f,nativeScriptName:f,nameWithRegionCode:A=a?s?"".concat(a," (").concat(s,")"):a:"",nativeNameWithRegionCode:I,emoji:d(I)}}}function N(t,n){"string"==typeof t&&(t=[t]),t=t.filter(c).map(u),n=n.filter(c).map(u);for(var r=function(t){var r=n.filter((function(e){return s(t,e)})),o=function(e){for(var t=e.locale,n=e.languageCode,o=e.minimizedCode,a=e.regionCode,i=e.scriptCode,c=0,u=[t,"".concat(n,"-").concat(a),"".concat(n,"-").concat(i),o];c<u.length;c++){var l=u[c];if(r.includes(l))return l}return null},a=b(t),i=a.languageCode,c=function(e,t){var n={};for(var r in e)Object.prototype.hasOwnProperty.call(e,r)&&t.indexOf(r)<0&&(n[r]=e[r]);if(null!=e&&"function"==typeof Object.getOwnPropertySymbols){var o=0;for(r=Object.getOwnPropertySymbols(e);o<r.length;o++)t.indexOf(r[o])<0&&Object.prototype.propertyIsEnumerable.call(e,r[o])&&(n[r[o]]=e[r[o]])}return n}(a,["languageCode"]),u=o(e({locale:t,languageCode:i},c))||o(e({locale:i},b(i)));if(u)return{value:u}},o=0,a=t;o<a.length;o++){var i=r(a[o]);if("object"==typeof i)return i.value}}function C(t){var n=t.value,a=t.locales,i=void 0===a?[o]:a,c=t.options,u=void 0===c?{}:c;return r.get("NumberFormat",i,e({numberingSystem:"latn"},u)).format(n)}function S(t){var n=t.value,a=t.locales,i=void 0===a?[o]:a,c=t.options,u=void 0===c?{}:c;return r.get("DateTimeFormat",i,e({calendar:"gregory",numberingSystem:"latn"},u)).format(n)}function T(t){var n=t.value,a=t.locales,i=void 0===a?[o]:a,c=t.currency,u=void 0===c?"USD":c,l=t.options,s=void 0===l?{}:l;return r.get("NumberFormat",i,e({style:"currency",currency:u,numberingSystem:"latn"},s)).format(n)}function A(t){var n=t.value,a=t.locales,i=void 0===a?[o]:a,c=t.options,u=void 0===c?{}:c;return r.get("ListFormat",i,e({type:"conjunction",style:"long"},u)).format(n)}var M={var:"variable",num:"number",datetime:"datetime",currency:"currency"};function w(t){if("string"!=typeof t)throw new Error("splitStringToContent: ".concat(t," is not a string!"));for(var n,r=[],o=/{([^}]+)}/g,a=0;null!==(n=o.exec(t));){var i=n[0],c=n[1],u=n.index;if("^"!==t[u-1]){u>a&&r.push(t.slice(a,u));var l=c.split(",").map((function(e){return e.trim()})),s=l[0],f=l[1]?M[l[1]]:void 0,v=e({key:s},f&&{variable:f});r.push(v),a=u+i.length}else u-1>a&&r.push(t.slice(a,u-1)),r.push(i),a=u+i.length}return a<t.length&&r.push(t.slice(a)),r}var L=function(){function r(e){var t=void 0===e?{}:e,n=t.apiKey,r=void 0===n?"":n,o=t.devApiKey,a=void 0===o?"":o,i=t.sourceLocale,c=void 0===i?"":i,l=t.projectId,s=void 0===l?"":l,f=t.baseUrl,v=void 0===f?"https://api.gtx.dev":f;this.apiKey=r||process.env.GT_API_KEY||"",this.devApiKey=a||process.env.GT_DEV_API_KEY||"",this.projectId=s||process.env.GT_PROJECT_ID||"",this.sourceLocale=u(c)||"",this.baseUrl=v}return r.prototype.translate=function(r,o,a){return t(this,void 0,void 0,(function(){return n(this,(function(t){switch(t.label){case 0:return[4,f(this,r,o,e({sourceLocale:this.sourceLocale},a))];case 1:return[2,t.sent()]}}))}))},r.prototype.translateJsx=function(r,o,a){return t(this,void 0,void 0,(function(){return n(this,(function(t){switch(t.label){case 0:return[4,v(this,r,o,e({sourceLocale:this.sourceLocale},a))];case 1:return[2,t.sent()]}}))}))},r.prototype.translateIcu=function(r,o,a){return t(this,void 0,void 0,(function(){return n(this,(function(t){switch(t.label){case 0:return[4,p(this,r,o,e({sourceLocale:this.sourceLocale},a))];case 1:return[2,t.sent()]}}))}))},r}();function E(e){return function(e){var t;try{var n=r.get("Locale",e);return"rtl"===(null===(t=null==n?void 0:n.textInfo)||void 0===t?void 0:t.direction)?"rtl":"ltr"}catch(e){return"ltr"}}(e)}function K(e,t){return void 0===t&&(t=o),function(e,t){void 0===t&&(t=o);try{return r.get("DisplayNames",[t,o],{type:"language"}).of(e)||""}catch(e){return""}}(e,t)}function G(e,t){return b(e,t)}function O(e,t){return d(e,t)}function I(e){return c(e)}function P(e){return u(e)}function x(){for(var e=[],t=0;t<arguments.length;t++)e[t]=arguments[t];return l.apply(void 0,e)}function D(){for(var e=[],t=0;t<arguments.length;t++)e[t]=arguments[t];return s.apply(void 0,e)}function R(e,t){return function(e,t){try{var n=r.get("Locale",u(e)),o=n.language,a=n.region,i=n.script,c=r.get("Locale",u(t)),l=c.language,s=c.region,f=c.script;return!(o!==l||a&&a!==s||i&&i!==f)}catch(e){return console.error(e),!1}}(e,t)}function k(e,t){return C({value:e,locales:null==t?void 0:t.locales,options:t})}function B(e,t){return S({value:e,locales:null==t?void 0:t.locales,options:t})}function j(e,t,n){return T({value:e,currency:t,locales:null==n?void 0:n.locales,options:n})}function U(e,t){return A({value:e,locales:null==t?void 0:t.locales,options:t})}function F(t,n,a){return function(t){var n=t.value,a=t.unit,i=t.locales,c=void 0===i?[o]:i,u=t.options,l=void 0===u?{}:u;return r.get("RelativeTimeFormat",c,e({style:"long",numeric:"auto"},l)).format(n,a)}({value:t,unit:n,locales:null==a?void 0:a.locales,options:a})}function z(e){return w(e)}function J(t,n,r,a){return function(t,n,r,a){if(void 0===n&&(n=o),void 0===r&&(r={}),void 0===a&&(a={}),"string"==typeof t&&(t=w(t)),"string"==typeof t)return t;if(!Array.isArray(t))throw new Error("renderContentToString: content ".concat(t," is invalid"));return t.map((function(t){var o;if("string"==typeof t)return t;if("object"==typeof t){var i=r[t.key];return t.variable?"number"===t.variable?C({value:i,locales:n,options:a[t.key]}):"currency"===t.variable?T(e(e({value:i,locales:n},a[t.key]&&{options:a[t.key]}),(null===(o=a[t.key])||void 0===o?void 0:o.currency)&&{currency:a[t.key].currency})):"datetime"===t.variable?S(e({value:i,locales:n},a[t.key]&&{options:a[t.key]})):"list"===t.variable?A(e({value:i,locales:n},a[t.key]&&{options:a[t.key]})):i:i}})).join("")}(t,n,r,a)}function W(e,t){return N(e,t)}function H(e,t,n){return function(e,t,n){return!(!c(e)||!c(t)||n&&n.some((function(e){return!c(e)}))||l(e,t)||n&&!n.some((function(e){return s(t,e)})))}(e,t,n)}export{L as default,W as determineLocale,j as formatCurrency,B as formatDateTime,U as formatList,k as formatNum,F as formatRelativeTime,E as getLocaleDirection,O as getLocaleEmoji,K as getLocaleName,G as getLocaleProperties,x as isSameDialect,D as isSameLanguage,R as isSupersetLocale,I as isValidLocale,J as renderContentToString,H as requiresTranslation,z as splitStringToContent,P as standardizeLocale};
|
2
|
+
//# sourceMappingURL=index.esm.min.mjs.map
|