generaltranslation 3.3.2 â 4.0.0
Sign up to get free protection for your applications and to get access to all the features.
- package/dist/id.cjs.min.cjs +2 -0
- package/dist/id.cjs.min.cjs.map +1 -0
- package/dist/id.d.ts +7 -0
- package/dist/id.esm.min.mjs +2 -0
- package/dist/id.esm.min.mjs.map +1 -0
- package/dist/index.cjs.min.cjs +1 -1
- package/dist/index.cjs.min.cjs.map +1 -1
- package/dist/index.d.ts +101 -80
- package/dist/index.esm.min.mjs +1 -1
- package/dist/index.esm.min.mjs.map +1 -1
- package/dist/internal.cjs.min.cjs +1 -1
- package/dist/internal.cjs.min.cjs.map +1 -1
- package/dist/internal.d.ts +7 -8
- package/dist/internal.esm.min.mjs +1 -1
- package/dist/internal.esm.min.mjs.map +1 -1
- 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/_isSameLanguage.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/settings/defaultAPIRoutes.d.ts +1 -1
- package/dist/settings/libraryDefaultLanguage.d.ts +1 -1
- package/dist/settings/libraryDefaultLocale.d.ts +2 -0
- package/dist/types/types.d.ts +5 -5
- package/package.json +13 -1
package/dist/index.d.ts
CHANGED
@@ -4,7 +4,7 @@ import { Content, Update, Request, ReactChildrenAsObject, ReactTranslationResult
|
|
4
4
|
*/
|
5
5
|
type GTConstructorParams = {
|
6
6
|
apiKey?: string;
|
7
|
-
|
7
|
+
defaultLocale?: string;
|
8
8
|
projectID?: string;
|
9
9
|
baseURL?: string;
|
10
10
|
};
|
@@ -13,7 +13,7 @@ type GTConstructorParams = {
|
|
13
13
|
*/
|
14
14
|
declare class GT {
|
15
15
|
apiKey: string;
|
16
|
-
|
16
|
+
defaultLocale: string;
|
17
17
|
projectID: string;
|
18
18
|
baseURL: string;
|
19
19
|
/**
|
@@ -21,44 +21,43 @@ declare class GT {
|
|
21
21
|
*
|
22
22
|
* @param {GTConstructorParams} [params] - The parameters for initializing the GT instance.
|
23
23
|
* @param {string} [params.apiKey=''] - The API key for accessing the translation service.
|
24
|
-
* @param {string} [params.
|
24
|
+
* @param {string} [params.defaultLocale='en-US'] - The default locale for translations.
|
25
25
|
* @param {string} [params.projectID=''] - The project ID for the translation service.
|
26
26
|
* @param {string} [params.baseURL='https://prod.gtx.dev'] - The base URL for the translation service.
|
27
27
|
*/
|
28
|
-
constructor({ apiKey,
|
28
|
+
constructor({ apiKey, defaultLocale, projectID, baseURL }?: GTConstructorParams);
|
29
29
|
/**
|
30
|
-
* Translates a string or an array of strings/variables into a target
|
30
|
+
* Translates a string or an array of strings/variables into a target locale.
|
31
31
|
* If `metadata.save` is provided, the translation is cached for use in a public project.
|
32
32
|
*
|
33
33
|
* @param {Content} content - The string or array of strings/variables to be translated.
|
34
|
-
* @param {string}
|
34
|
+
* @param {string} locale - The target locale code (e.g., 'en-US', 'fr') for the translation.
|
35
35
|
* @param {{ context?: string, save?: boolean, [key: string]: any }} [metadata] - Additional metadata for the translation request.
|
36
36
|
* @param {string} [metadata.context] - Contextual information to assist with the translation.
|
37
37
|
* @param {boolean} [metadata.save] - Whether to cache the translation for use in a public project.
|
38
38
|
*
|
39
39
|
* @returns {Promise<ContentTranslationResult>} A promise that resolves to the translated content, or an error if the translation fails.
|
40
40
|
*/
|
41
|
-
translate(content: Content,
|
41
|
+
translate(content: Content, locale: string, metadata?: {
|
42
42
|
context?: string;
|
43
43
|
save?: boolean;
|
44
44
|
[key: string]: any;
|
45
45
|
}): Promise<{
|
46
46
|
translation: Content;
|
47
|
-
|
47
|
+
locale: string;
|
48
48
|
}>;
|
49
49
|
/**
|
50
50
|
* Translates the content of React children elements.
|
51
51
|
*
|
52
52
|
* @param {Object} params - The parameters for the translation.
|
53
53
|
* @param {ReactChildrenAsObject} params.children - The React children content to be translated.
|
54
|
-
* @param {string} params.
|
54
|
+
* @param {string} params.locale - The target locale for the translation.
|
55
55
|
* @param {Object} params.metadata - Additional metadata for the translation process.
|
56
56
|
*
|
57
57
|
* @returns {Promise<ReactTranslationResult>} - A promise that resolves to the translated content.
|
58
58
|
*/
|
59
|
-
translateReact(children: ReactChildrenAsObject,
|
59
|
+
translateReact(children: ReactChildrenAsObject, locale: string, metadata?: {
|
60
60
|
context?: string;
|
61
|
-
save?: boolean;
|
62
61
|
[key: string]: any;
|
63
62
|
}): Promise<ReactTranslationResult>;
|
64
63
|
/**
|
@@ -70,49 +69,51 @@ declare class GT {
|
|
70
69
|
/**
|
71
70
|
* Pushes updates to a remotely cached translation dictionary.
|
72
71
|
* @param {Update[]} updates - Array of updates.
|
73
|
-
* @param {string[]} [
|
72
|
+
* @param {string[]} [locales] - Array of locales to create translations into.
|
74
73
|
* @param {string} [projectID=this.projectID] - The ID of the project. Defaults to the instance's projectID.
|
75
74
|
* @param {Record<string, any>} [object] - Options, such as whether to replace the existing dictionary. Defaults to false.
|
76
|
-
* @returns {Promise<string[]>} A promise that resolves to an array of strings indicating the
|
75
|
+
* @returns {Promise<string[]>} A promise that resolves to an array of strings indicating the locales which have been updated.
|
77
76
|
*/
|
78
|
-
updateProjectDictionary(updates: Update[],
|
77
|
+
updateProjectDictionary(updates: Update[], locales?: string[], options?: {
|
79
78
|
replace?: boolean;
|
80
79
|
retranslate?: boolean;
|
81
80
|
projectID?: string;
|
82
81
|
[key: string]: any;
|
83
82
|
}): Promise<string[]>;
|
84
83
|
/**
|
85
|
-
* Retrieves the
|
86
|
-
* @param projectID - The project ID to retrieve
|
87
|
-
* @returns A promise that resolves with an array of
|
84
|
+
* Retrieves the locales for a GT project as BCP 47 locale tags.
|
85
|
+
* @param projectID - The project ID to retrieve locales for. If not provided, `this.projectID` should be set.
|
86
|
+
* @returns A promise that resolves with an object containing an array of locale codes.
|
88
87
|
*/
|
89
|
-
|
88
|
+
getProjectLocales(projectID?: string): Promise<{
|
89
|
+
locales: string[];
|
90
|
+
}>;
|
90
91
|
}
|
91
92
|
/**
|
92
|
-
* Get the text direction for a given
|
93
|
+
* Get the text direction for a given locale code using the Intl.Locale API.
|
93
94
|
*
|
94
|
-
* @param {string}
|
95
|
-
* @returns {string} - 'rtl' if the
|
95
|
+
* @param {string} locale - The locale code to check.
|
96
|
+
* @returns {string} - 'rtl' if the locale is right-to-left, otherwise 'ltr'.
|
96
97
|
*/
|
97
|
-
export declare function
|
98
|
+
export declare function getLocaleDirection(locale: string): string;
|
98
99
|
/**
|
99
|
-
* Retrieves the display name
|
100
|
+
* Retrieves the display name of locale code using Intl.DisplayNames.
|
100
101
|
*
|
101
|
-
* @param {string
|
102
|
-
* @param {string} [
|
103
|
-
* @returns {string
|
102
|
+
* @param {string} locale - A BCP-47 locale code.
|
103
|
+
* @param {string} [defaultLocale = 'en-US'] - The locale for display names.
|
104
|
+
* @returns {string} The display name corresponding to the code.
|
104
105
|
*/
|
105
|
-
export declare function
|
106
|
+
export declare function getLocaleName(locale: string, defaultLocale?: string): string;
|
106
107
|
/**
|
107
|
-
* Generates
|
108
|
+
* Generates linguistic details for a given locale code.
|
108
109
|
*
|
109
|
-
* This function returns information about the
|
110
|
+
* This function returns information about the locale,
|
110
111
|
* script, and region of a given language code both in a standard form and in a maximized form (with likely script and region).
|
111
112
|
* The function provides these names in both your default language and native forms, and an associated emoji.
|
112
113
|
*
|
113
|
-
* @param {string}
|
114
|
-
* @param {string} [
|
115
|
-
* @returns {
|
114
|
+
* @param {string} locale - The locale code to get properties for (e.g., "de-AT").
|
115
|
+
* @param {string} [defaultLocale=libraryDefaultLocale] - The default locale code for display names.
|
116
|
+
* @returns {LocaleProperties} - An object containing detailed information about the locale.
|
116
117
|
*
|
117
118
|
* @property {string} code - The full locale code, e.g., "de-AT".
|
118
119
|
* @property {string} name - Language name in the default display language, e.g., "Austrian German".
|
@@ -129,14 +130,14 @@ export declare function getLanguageName(code: string | string[], language?: stri
|
|
129
130
|
* @property {string} scriptName - The script name in the default display language, e.g., "Latin".
|
130
131
|
* @property {string} nativeScriptName - The script name in the native language, e.g., "Lateinisch".
|
131
132
|
* @property {string} maximizedCode - The maximized locale code, e.g., "de-Latn-AT".
|
132
|
-
* @property {string} maximizedName - Maximized
|
133
|
-
* @property {string} nativeMaximizedName - Maximized
|
133
|
+
* @property {string} maximizedName - Maximized locale name with likely script in the default language, e.g., "Austrian German (Latin)".
|
134
|
+
* @property {string} nativeMaximizedName - Maximized locale name in the native language, e.g., "Ăsterreichisches Deutsch (Lateinisch)".
|
134
135
|
* @property {string} minimizedCode - Minimized locale code, e.g., "de-AT" (or "de" for "de-DE").
|
135
136
|
* @property {string} minimizedName - Minimized language name in the default language, e.g., "Austrian German".
|
136
137
|
* @property {string} nativeMinimizedName - Minimized language name in the native language, e.g., "Ăsterreichisches Deutsch".
|
137
138
|
* @property {string} emoji - The emoji associated with the locale's region, if applicable.
|
138
139
|
*/
|
139
|
-
export declare function
|
140
|
+
export declare function getLocaleProperties(locale: string, defaultLocale?: string): {
|
140
141
|
code: string;
|
141
142
|
name: string;
|
142
143
|
nativeName: string;
|
@@ -160,56 +161,76 @@ export declare function getLanguageNames(code: string, language?: string): {
|
|
160
161
|
emoji: string;
|
161
162
|
};
|
162
163
|
/**
|
163
|
-
* Retrieves an emoji based on a given
|
164
|
-
* This function uses the
|
164
|
+
* Retrieves an emoji based on a given locale code, taking into account region, language, and specific exceptions.
|
165
|
+
* This function uses the locale's region (if present) to select an emoji or falls back on default emojis for certain languages.
|
165
166
|
*
|
166
|
-
* @param code - A string representing the
|
167
|
-
* @param custom - An optional custom mapping of
|
168
|
-
* @returns The emoji representing the
|
167
|
+
* @param code - A string representing the locale code (e.g., 'en-US', 'fr-CA').
|
168
|
+
* @param custom - An optional custom mapping of locale codes to emojis.
|
169
|
+
* @returns The emoji representing the locale or its region, or a default emoji if no specific match is found.
|
169
170
|
*/
|
170
|
-
export declare function
|
171
|
+
export declare function getLocaleEmoji(locale: string, custom?: Record<string, string>): string;
|
171
172
|
/**
|
172
|
-
* Checks if a given BCP 47
|
173
|
-
* @param {string}
|
173
|
+
* Checks if a given BCP 47 locale code is valid.
|
174
|
+
* @param {string} locale - The BCP 47 locale code to validate.
|
174
175
|
* @returns {boolean} True if the BCP 47 code is valid, false otherwise.
|
175
176
|
*/
|
176
|
-
export declare function
|
177
|
+
export declare function isValidLocale(locale: string): boolean;
|
177
178
|
/**
|
178
|
-
* Standardizes a BCP 47
|
179
|
-
* @param {string}
|
180
|
-
* @returns {string} The standardized BCP 47
|
179
|
+
* Standardizes a BCP 47 locale code to ensure correct formatting.
|
180
|
+
* @param {string} locale - The BCP 47 locale code to standardize.
|
181
|
+
* @returns {string} The standardized BCP 47 locale code or an empty string if it is an invalid code.
|
181
182
|
*/
|
182
|
-
export declare function
|
183
|
+
export declare function standardizeLocale(locale: string): string;
|
183
184
|
/**
|
184
|
-
* Checks if multiple BCP 47
|
185
|
-
*
|
186
|
-
*
|
185
|
+
* Checks if multiple BCP 47 locale codes represent the same dialect.
|
186
|
+
*
|
187
|
+
* For example, `"en-US"` and `"en-GB"` are the same language, but different dialects.
|
188
|
+
* `isSameDialect("en-US", "en-GB")` would return `false`.
|
189
|
+
*
|
190
|
+
* For checking if two locale codes represent the same language, see `isSameLanguage()`.
|
191
|
+
*
|
192
|
+
* Note that `isSameDialect("en", "en-US")` and `isSameDialect("en", "en-GB")` would both return true.
|
193
|
+
*
|
194
|
+
* @param {string[]} locales - The BCP 47 locale codes to compare.
|
195
|
+
* @returns {boolean} True if all BCP 47 codes represent the same dialect, false otherwise.
|
187
196
|
*/
|
188
|
-
export declare function
|
197
|
+
export declare function isSameDialect(...locales: (string | string[])[]): boolean;
|
198
|
+
/**
|
199
|
+
* Checks if multiple BCP 47 locale codes represent the same language.
|
200
|
+
*
|
201
|
+
* For example, `"en-US"` and `"en-GB"` are the same language, English.
|
202
|
+
* `isSameDialect("en-US", "en-GB")` would return `true`.
|
203
|
+
*
|
204
|
+
* For checking if two codes represent the exact same dialect, see `isSameDialect()`.
|
205
|
+
*
|
206
|
+
* @param {string[]} locales - The BCP 47 locale codes to compare.
|
207
|
+
* @returns {boolean} True if all BCP 47 codes represent the same locale, false otherwise.
|
208
|
+
*/
|
209
|
+
export declare function isSameLanguage(...locales: (string | string[])[]): boolean;
|
189
210
|
/**
|
190
|
-
* Formats a number according to the specified
|
211
|
+
* Formats a number according to the specified locales and options.
|
191
212
|
* @param {Object} params - The parameters for the number formatting.
|
192
213
|
* @param {number} params.value - The number to format.
|
193
|
-
* @param {string | string[]} [params.
|
214
|
+
* @param {string | string[]} [params.locales=['en-US']] - The locales to use for formatting.
|
194
215
|
* @param {Intl.NumberFormatOptions} [params.options={}] - Additional options for number formatting.
|
195
216
|
* @returns {string} The formatted number.
|
196
217
|
*/
|
197
218
|
export declare function formatNum(params: {
|
198
219
|
value: number;
|
199
|
-
|
220
|
+
locales?: string | string[];
|
200
221
|
options?: Intl.NumberFormatOptions;
|
201
222
|
}): string;
|
202
223
|
/**
|
203
224
|
* Formats a date according to the specified languages and options.
|
204
225
|
* @param {Object} params - The parameters for the date formatting.
|
205
226
|
* @param {Date} params.value - The date to format.
|
206
|
-
* @param {string | string[]} [params.
|
227
|
+
* @param {string | string[]} [params.locales=['en-US']] - The languages to use for formatting.
|
207
228
|
* @param {Intl.DateTimeFormatOptions} [params.options={}] - Additional options for date formatting.
|
208
229
|
* @returns {string} The formatted date.
|
209
230
|
*/
|
210
231
|
export declare function formatDateTime(params: {
|
211
232
|
value: Date;
|
212
|
-
|
233
|
+
locales?: string | string[];
|
213
234
|
options?: Intl.DateTimeFormatOptions;
|
214
235
|
}): string;
|
215
236
|
/**
|
@@ -217,42 +238,42 @@ export declare function formatDateTime(params: {
|
|
217
238
|
* @param {Object} params - The parameters for the currency formatting.
|
218
239
|
* @param {number} params.value - The currency value to format.
|
219
240
|
* @param {string} params.currency - The currency code (e.g., 'USD').
|
220
|
-
* @param {string | string[]} [params.
|
241
|
+
* @param {string | string[]} [params.locales=['en-US']] - The locale codes to use for formatting.
|
221
242
|
* @param {Intl.NumberFormatOptions} [params.options={}] - Additional options for currency formatting.
|
222
243
|
* @returns {string} The formatted currency value.
|
223
244
|
*/
|
224
245
|
export declare function formatCurrency(params: {
|
225
246
|
value: number;
|
226
247
|
currency: string;
|
227
|
-
|
248
|
+
locales?: string | string[];
|
228
249
|
options?: Intl.NumberFormatOptions;
|
229
250
|
}): string;
|
230
251
|
/**
|
231
|
-
* Formats a list of items according to the specified
|
252
|
+
* Formats a list of items according to the specified locales and options.
|
232
253
|
* @param {Object} params - The parameters for the list formatting.
|
233
254
|
* @param {Array<string | number>} params.value - The list of items to format.
|
234
|
-
* @param {string | string[]} [params.
|
255
|
+
* @param {string | string[]} [params.locales=['en-US']] - The locales to use for formatting.
|
235
256
|
* @param {Intl.ListFormatOptions} [params.options={}] - Additional options for list formatting.
|
236
257
|
* @returns {string} The formatted list.
|
237
258
|
*/
|
238
259
|
export declare function formatList(params: {
|
239
260
|
value: Array<string | number>;
|
240
|
-
|
261
|
+
locales?: string | string[];
|
241
262
|
options?: Intl.ListFormatOptions;
|
242
263
|
}): string;
|
243
264
|
/**
|
244
|
-
* Formats a relative time value according to the specified
|
265
|
+
* Formats a relative time value according to the specified locales and options.
|
245
266
|
* @param {Object} params - The parameters for the relative time formatting.
|
246
267
|
* @param {number} params.value - The relative time value to format.
|
247
268
|
* @param {Intl.RelativeTimeFormatUnit} params.unit - The unit of time (e.g., 'second', 'minute', 'hour', 'day', 'week', 'month', 'year').
|
248
|
-
* @param {string | string[]} [params.
|
269
|
+
* @param {string | string[]} [params.locales=['en-US']] - The locales to use for formatting.
|
249
270
|
* @param {Intl.RelativeTimeFormatOptions} [params.options={}] - Additional options for relative time formatting.
|
250
271
|
* @returns {string} The formatted relative time string.
|
251
272
|
*/
|
252
273
|
export declare function formatRelativeTime(params: {
|
253
274
|
value: number;
|
254
275
|
unit: Intl.RelativeTimeFormatUnit;
|
255
|
-
|
276
|
+
locales?: string | string[];
|
256
277
|
options?: Intl.RelativeTimeFormatOptions;
|
257
278
|
}): string;
|
258
279
|
/**
|
@@ -264,32 +285,32 @@ export declare function splitStringToContent(string: string): Content;
|
|
264
285
|
/**
|
265
286
|
* Renders content to a string by replacing variables with their formatted values.
|
266
287
|
* @param {Content} content - The content to render.
|
267
|
-
* @param {string | string[]} [
|
288
|
+
* @param {string | string[]} [locales='en-US'] - The locale(s) to use for formatting.
|
268
289
|
* @param {Record<string, any>} [variables={}] - An object containing variable values.
|
269
290
|
* @param {Record<string, any>} [variableOptions={}] - An object containing options for formatting variables.
|
270
291
|
* @returns {string} - The rendered string with variables replaced by their formatted values.
|
271
292
|
*/
|
272
|
-
export declare function renderContentToString(content: Content,
|
293
|
+
export declare function renderContentToString(content: Content, locales?: string | string[], variables?: Record<string, any>, variableOptions?: Record<string, any>): string;
|
273
294
|
/**
|
274
|
-
* Determines the best matching
|
275
|
-
* @param {string | string[]}
|
276
|
-
* @param {string[]}
|
277
|
-
* @returns {string | undefined} - The best matching
|
295
|
+
* Determines the best matching locale from the provided approved locales list.
|
296
|
+
* @param {string | string[]} locales - A single locale or an array of locales sorted in preference order.
|
297
|
+
* @param {string[]} approvedLocales - An array of approved locales, also sorted by preference.
|
298
|
+
* @returns {string | undefined} - The best matching locale from the approvedLocales list, or undefined if no match is found.
|
278
299
|
*/
|
279
|
-
export declare function
|
300
|
+
export declare function determineLocale(locales: string | string[], approvedLocales: string[]): string | undefined;
|
280
301
|
/**
|
281
|
-
* Determines whether a translation is required based on the source and target
|
302
|
+
* Determines whether a translation is required based on the source and target locales.
|
282
303
|
*
|
283
|
-
* - If the target
|
284
|
-
* - If the source and target
|
285
|
-
* - If the `
|
304
|
+
* - If the target locale is not specified, the function returns `false`, as translation is not needed.
|
305
|
+
* - If the source and target locale are the same, returns `false`, indicating that no translation is necessary.
|
306
|
+
* - If the `approvedLocales` array is provided, and the target locale is not within that array, the function also returns `false`.
|
286
307
|
* - Otherwise, it returns `true`, meaning that a translation is required.
|
287
308
|
*
|
288
|
-
* @param {string}
|
289
|
-
* @param {string}
|
290
|
-
* @param {string[]} [
|
309
|
+
* @param {string} sourceLocale - The locale code for the original content (BCP 47 locale code).
|
310
|
+
* @param {string} targetLocale - The locale code of the language to translate the content into (BCP 47 locale code).
|
311
|
+
* @param {string[]} [approvedLocale] - An optional array of approved target locales.
|
291
312
|
*
|
292
313
|
* @returns {boolean} - Returns `true` if translation is required, otherwise `false`.
|
293
314
|
*/
|
294
|
-
export declare function requiresTranslation(
|
315
|
+
export declare function requiresTranslation(sourceLocale: string, targetLocale: string, approvedLocales?: string[]): boolean;
|
295
316
|
export default GT;
|
package/dist/index.esm.min.mjs
CHANGED
@@ -1,2 +1,2 @@
|
|
1
|
-
var t=function(){return t=Object.assign||function(t){for(var n,e=1,r=arguments.length;e<r;e++)for(var a in n=arguments[e])Object.prototype.hasOwnProperty.call(n,a)&&(t[a]=n[a]);return t},t.apply(this,arguments)};function n(t,n,e,r){return new(e||(e=Promise))((function(a,o){function i(t){try{c(r.next(t))}catch(t){o(t)}}function u(t){try{c(r.throw(t))}catch(t){o(t)}}function c(t){var n;t.done?a(t.value):(n=t.value,n instanceof e?n:new e((function(t){t(n)}))).then(i,u)}c((r=r.apply(t,n||[])).next())}))}function e(t,n){var e,r,a,o={label:0,sent:function(){if(1&a[0])throw a[1];return a[1]},trys:[],ops:[]},i=Object.create(("function"==typeof Iterator?Iterator:Object).prototype);return i.next=u(0),i.throw=u(1),i.return=u(2),"function"==typeof Symbol&&(i[Symbol.iterator]=function(){return this}),i;function u(u){return function(c){return function(u){if(e)throw new TypeError("Generator is already executing.");for(;i&&(i=0,u[0]&&(o=0)),o;)try{if(e=1,r&&(a=2&u[0]?r.return:u[0]?r.throw||((a=r.return)&&a.call(r),0):r.next)&&!(a=a.call(r,u[1])).done)return a;switch(r=0,a&&(u=[2&u[0],a.value]),u[0]){case 0:case 1:a=u;break;case 4:return o.label++,{value:u[1],done:!1};case 5:o.label++,r=u[1],u=[0];continue;case 7:u=o.ops.pop(),o.trys.pop();continue;default:if(!(a=o.trys,(a=a.length>0&&a[a.length-1])||6!==u[0]&&2!==u[0])){o=0;continue}if(3===u[0]&&(!a||u[1]>a[0]&&u[1]<a[3])){o.label=u[1];break}if(6===u[0]&&o.label<a[1]){o.label=a[1],a=u;break}if(a&&o.label<a[2]){o.label=a[2],o.ops.push(u);break}a[2]&&o.ops.pop(),o.trys.pop();continue}u=n.call(t,o)}catch(t){u=[6,t],r=0}finally{e=a=0}if(5&u[0])throw u[1];return{value:u[0]?u[1]:void 0,done:!0}}([u,c])}}}"function"==typeof SuppressedError&&SuppressedError;var r="/v1/translate/batch",a="/v1/translate/react",o="/v1/translate/content",i="/v1/project/dictionary/update",u="/v1/project/languages";function c(t,a){return n(this,void 0,void 0,(function(){var n,o,i,u,c,s,l,f,p;return e(this,(function(e){switch(e.label){case 0:return n=new AbortController,o=n.signal,(null===(p=null===(f=null===(l=a[0])||void 0===l?void 0:l.data)||void 0===f?void 0:f.metadata)||void 0===p?void 0:p.timeout)&&setTimeout((function(){return n.abort()}),a[0].data.metadata.timeout),[4,fetch("".concat(t.baseURL).concat(r),{method:"POST",headers:{"Content-Type":"application/json","gtx-api-key":t.apiKey},body:JSON.stringify(a),signal:o})];case 1:return(i=e.sent()).ok?[3,3]:(u=Error.bind,s=(c="".concat(i.status,": ")).concat,[4,i.text()]);case 2:throw new(u.apply(Error,[void 0,s.apply(c,[e.sent()])]));case 3:return[4,i.json()];case 4:return[2,e.sent()]}}))}))}var s="en",l=["Cham","Jamo","Kawi","Lisu","Toto","Thai"],f=function(t){try{var n=new Intl.Locale(t),e=n.language,r=n.region,a=n.script;if(new Intl.DisplayNames([s],{type:"language"}).of(e)===e)return!1;if(r)if(new Intl.DisplayNames([s],{type:"region"}).of(r)===r)return!1;if(a)if(new Intl.DisplayNames([s],{type:"script"}).of(a)===a&&!l.includes(a))return!1;return!0}catch(t){return!1}},p=function(t){try{return Intl.getCanonicalLocales(t)[0]}catch(t){return""}};function v(){for(var t=[],n=0;n<arguments.length;n++)t[n]=arguments[n];try{var e=t.flat().map((function(t){return new Intl.Locale(t).language}));return e.every((function(t){return t===e[0]}))}catch(t){return console.error(t),!1}}function d(t,r,a,i){return n(this,void 0,void 0,(function(){var n,u,c,s,l,f;return e(this,(function(e){switch(e.label){case 0:return n=new AbortController,u=n.signal,i.timeout&&setTimeout((function(){return n.abort()}),i.timeout),[4,fetch("".concat(t.baseURL).concat(o),{method:"POST",headers:{"Content-Type":"application/json","gtx-api-key":t.apiKey},body:JSON.stringify({content:r,targetLanguage:a,metadata:i}),signal:u})];case 1:return(c=e.sent()).ok?[3,3]:(s=Error.bind,f=(l="".concat(c.status,": ")).concat,[4,c.text()]);case 2:throw new(s.apply(Error,[void 0,f.apply(l,[e.sent()])]));case 3:return[4,c.json()];case 4:return[2,e.sent()]}}))}))}function g(t,r,o,i){return n(this,void 0,void 0,(function(){var n,u,c,s,l,f;return e(this,(function(e){switch(e.label){case 0:return n=new AbortController,u=n.signal,i.timeout&&setTimeout((function(){return n.abort()}),i.timeout),[4,fetch("".concat(t.baseURL).concat(a),{method:"POST",headers:{"Content-Type":"application/json","gtx-api-key":t.apiKey},body:JSON.stringify({children:r,targetLanguage:o,metadata:i}),signal:u})];case 1:return(c=e.sent()).ok?[3,3]:(s=Error.bind,f=(l="".concat(c.status,": ")).concat,[4,c.text()]);case 2:throw new(s.apply(Error,[void 0,f.apply(l,[e.sent()])]));case 3:return[4,c.json()];case 4:return[2,e.sent()]}}))}))}function y(t,r,a,o){return n(this,void 0,void 0,(function(){var n,u,c,s,l;return e(this,(function(e){switch(e.label){case 0:return[4,fetch("".concat(t.baseURL).concat(i),{method:"POST",headers:{"Content-Type":"application/json","gtx-api-key":t.apiKey},body:JSON.stringify({updates:r,languages:a,options:o})})];case 1:return(n=e.sent()).ok?[3,3]:(u=Error.bind,s=(c="".concat(n.status,": ")).concat,[4,n.text()]);case 2:throw new(u.apply(Error,[void 0,s.apply(c,[e.sent()])]));case 3:return[4,n.json()];case 4:return[2,null==(l=e.sent())?void 0:l.languages]}}))}))}function m(t,r){return n(this,void 0,void 0,(function(){var n,a,o,i,c;return e(this,(function(e){switch(e.label){case 0:return[4,fetch("".concat(t.baseURL).concat(u,"?projectID=").concat(r),{method:"GET",headers:{"Content-Type":"application/json","gtx-api-key":t.apiKey}})];case 1:return(n=e.sent()).ok?[3,3]:(a=Error.bind,i=(o="".concat(n.status,": ")).concat,[4,n.text()]);case 2:throw new(a.apply(Error,[void 0,i.apply(o,[e.sent()])]));case 3:return[4,n.json()];case 4:return[2,null==(c=e.sent())?void 0:c.languages]}}))}))}function h(n){var e=n.value,r=n.languages,a=void 0===r?[s]:r,o=n.options,i=void 0===o?{}:o;return new Intl.NumberFormat(a,t({numberingSystem:"latn"},i)).format(e)}function b(n){var e=n.value,r=n.languages,a=void 0===r?[s]:r,o=n.options,i=void 0===o?{}:o;return new Intl.DateTimeFormat(a,t({calendar:"gregory",numberingSystem:"latn"},i)).format(e)}function N(n){var e=n.value,r=n.languages,a=void 0===r?[s]:r,o=n.currency,i=void 0===o?"USD":o,u=n.options,c=void 0===u?{}:u;return new Intl.NumberFormat(a,t({style:"currency",currency:i,numberingSystem:"latn"},c)).format(e)}function w(n){var e=n.value,r=n.languages,a=void 0===r?[s]:r,o=n.options,i=void 0===o?{}:o;return new Intl.ListFormat(a,t({type:"conjunction",style:"long"},i)).format(e)}var S={var:"variable",num:"number",datetime:"datetime",currency:"currency"};function C(n){if("string"!=typeof n)throw new Error("splitStringToContent: ".concat(n," is not a string!"));for(var e,r=[],a=/{([^}]+)}/g,o=0;null!==(e=a.exec(n));){var i=e[0],u=e[1],c=e.index;if("^"!==n[c-1]){c>o&&r.push(n.slice(o,c));var s=u.split(",").map((function(t){return t.trim()})),l=s[0],f=s[1]?S[s[1]]:void 0,p=t({key:l},f&&{variable:f});r.push(p),o=c+i.length}else c-1>o&&r.push(n.slice(o,c-1)),r.push(i),o=c+i.length}return o<n.length&&r.push(n.slice(o)),r}function I(t,n){if(void 0===n&&(n={}),!f(t))return T;var e=new Intl.Locale(t);if(n[t=e.toString()])return n[t];var r=e.region;if(r&&E[r])return E[r];var a=e.maximize(),o=a.region||"";return M[a.language]||E[o]||T}var L="đ",T=L,M={ca:L,eu:L,ku:L,bo:"đ",ug:"đ",gd:"đ´ó §ó ˘ó łó Łó ´ó ż",cy:"đ´ó §ó ˘ó ˇó Źó łó ż",gv:"đŽđ˛",grc:"đş"},E={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:"đŞđş"};var A=function(t){return"undefined"!=typeof process&&process.env&&process.env[t]||""},G=function(){function r(t){var n=void 0===t?{}:t,e=n.apiKey,r=void 0===e?"":e,a=n.defaultLanguage,o=void 0===a?s:a,i=n.projectID,u=void 0===i?"":i,c=n.baseURL,l=void 0===c?"https://prod.gtx.dev":c;this.apiKey=r||A("GT_API_KEY"),this.projectID=u||A("GT_PROJECT_ID"),this.defaultLanguage=o.toLowerCase(),this.baseURL=l}return r.prototype.translate=function(r,a,o){return n(this,void 0,void 0,(function(){return e(this,(function(n){switch(n.label){case 0:return[4,d(this,r,a,t({defaultLanguage:this.defaultLanguage},o))];case 1:return[2,n.sent()]}}))}))},r.prototype.translateReact=function(r,a,o){return n(this,void 0,void 0,(function(){return e(this,(function(n){switch(n.label){case 0:return[4,g(this,r,a,t({defaultLanguage:this.defaultLanguage},o))];case 1:return[2,n.sent()]}}))}))},r.prototype.translateBatch=function(t){return n(this,void 0,void 0,(function(){return e(this,(function(n){return[2,c(this,t)]}))}))},r.prototype.updateProjectDictionary=function(t){return n(this,arguments,void 0,(function(t,n,r){return void 0===n&&(n=[]),void 0===r&&(r={}),e(this,(function(e){return[2,y(this,t,n,r)]}))}))},r.prototype.getProjectLanguages=function(t){return n(this,void 0,void 0,(function(){return e(this,(function(n){return[2,m(this,t||this.projectID)]}))}))},r}();function R(t){return function(t){var n;try{var e=new Intl.Locale(t);return"rtl"===(null===(n=null==e?void 0:e.textInfo)||void 0===n?void 0:n.direction)?"rtl":"ltr"}catch(t){return"ltr"}}(t)}function D(t,n){return function(t,n){void 0===n&&(n=s);try{var e=new Intl.DisplayNames([n,s],{type:"language"});return"string"==typeof t?e.of(t)||"":Array.isArray(t)?t.map((function(t){return e.of(t)||""})):""}catch(n){return"string"==typeof t?"":Array.isArray(t)?t.map((function(){return""})):""}}(t,n)}function K(t,n){return function(t,n){void 0===n&&(n=s);try{var e=new Intl.Locale(t);t=e.toString();var r=e.language,a=e.region,o=new Intl.Locale(t).maximize(),i=o.toString(),u=o.region||"",c=o.script||"",l=new Intl.Locale(t).minimize().toString(),f=new Intl.DisplayNames([n,t,s],{type:"language"}),p=new Intl.DisplayNames([t,n,s],{type:"language"}),v=f.of(t)||t,d=p.of(t)||t,g=f.of(i)||t,y=p.of(i)||t,m=f.of(l)||t,h=p.of(l)||t,b=f.of(r)||t,N=p.of(r)||t,w=a?"".concat(b," (").concat(a,")"):b,S=a?"".concat(N," (").concat(a,")"):N,C=new Intl.DisplayNames([n,t,s],{type:"region"}),L=new Intl.DisplayNames([t,n,s],{type:"region"}),T=C.of(u)||"",M=L.of(u)||"",E=new Intl.DisplayNames([n,t,s],{type:"script"}),A=new Intl.DisplayNames([t,n,s],{type:"script"});return{code:t,name:v,nativeName:d,maximizedCode:i,maximizedName:g,nativeMaximizedName:y,minimizedCode:l,minimizedName:m,nativeMinimizedName:h,languageCode:r,languageName:b,nativeLanguageName:N,nameWithRegionCode:w,nativeNameWithRegionCode:S,regionCode:u,regionName:T,nativeRegionName:M,scriptCode:c,scriptName:E.of(c)||"",nativeScriptName:A.of(c)||"",emoji:I(t)}}catch(n){t||(t="");var G=null==t?void 0:t.split("-");return{code:t,name:t,nativeName:t,maximizedCode:t,maximizedName:t,nativeMaximizedName:t,minimizedCode:t,minimizedName:t,nativeMinimizedName:t,languageCode:r=(null==G?void 0:G[0])||t||"",languageName:r,nativeLanguageName:r,regionCode:u=G.length>2?null==G?void 0:G[2]:(null==G?void 0:G[1])||"",regionName:u,nativeRegionName:u,scriptCode:c=(null==G?void 0:G[3])||"",scriptName:c,nativeScriptName:c,nameWithRegionCode:w=r?u?"".concat(r," (").concat(u,")"):r:"",nativeNameWithRegionCode:t,emoji:I(t)}}}(t,n)}function P(t,n){return I(t,n)}function j(t){return f(t)}function x(t){return p(t)}function O(){for(var t=[],n=0;n<arguments.length;n++)t[n]=arguments[n];return v.apply(void 0,t)}function k(t){return h(t)}function B(t){return b(t)}function U(t){return N(t)}function F(t){return w(t)}function W(n){return r=(e=n).value,a=e.unit,o=e.languages,i=void 0===o?[s]:o,u=e.options,c=void 0===u?{}:u,new Intl.RelativeTimeFormat(i,t({style:"long",numeric:"auto"},c)).format(r,a);var e,r,a,o,i,u,c}function z(t){return C(t)}function H(n,e,r,a){return function(n,e,r,a){if(void 0===e&&(e=s),void 0===r&&(r={}),void 0===a&&(a={}),"string"==typeof n&&(n=C(n)),"string"==typeof n)return n;if(!Array.isArray(n))throw new Error("renderContentToString: content ".concat(n," is invalid"));return n.map((function(n){var o;if("string"==typeof n)return n;if("object"==typeof n){var i=r[n.key];return n.variable?"number"===n.variable?h({value:i,languages:e,options:a[n.key]}):"currency"===n.variable?N(t(t({value:i,languages:e},a[n.key]&&{options:a[n.key]}),(null===(o=a[n.key])||void 0===o?void 0:o.currency)&&{currency:a[n.key].currency})):"datetime"===n.variable?b(t({value:i,languages:e},a[n.key]&&{options:a[n.key]})):"list"===n.variable?w(t({value:i,languages:e},a[n.key]&&{options:a[n.key]})):i:i}})).join("")}(n,e,r,a)}function J(t,n){return function(t,n){if("string"==typeof t&&(t=[t]),!n)return t[0];for(var e=function(t){var e=n.find((function(n){return n===t}));if(e)return{value:e};var r=n.find((function(n){return v(n,t)}));return r?{value:r}:void 0},r=0,a=t;r<a.length;r++){var o=e(a[r]);if("object"==typeof o)return o.value}}(t,n)}function V(t,n,e){return function(t,n,e){if(!n)return!1;if(p(n)===p(t))return!1;var r=new Intl.Locale(t),a=r.language,o=r.region,i=new Intl.Locale(n),u=i.language,c=i.region;return!(!(o&&c||!v(a,u))||e&&!e.some((function(t){return v(n,t)})))}(t,n,e)}export{G as default,J as determineLanguage,U as formatCurrency,B as formatDateTime,F as formatList,k as formatNum,W as formatRelativeTime,R as getLanguageDirection,P as getLanguageEmoji,D as getLanguageName,K as getLanguageNames,O as isSameLanguage,j as isValidLanguageCode,H as renderContentToString,V as requiresTranslation,z as splitStringToContent,x as standardizeLanguageCode};
|
1
|
+
var t=function(){return t=Object.assign||function(t){for(var e,n=1,r=arguments.length;n<r;n++)for(var o in e=arguments[n])Object.prototype.hasOwnProperty.call(e,o)&&(t[o]=e[o]);return t},t.apply(this,arguments)};function e(t,e,n,r){return new(n||(n=Promise))((function(o,i){function a(t){try{u(r.next(t))}catch(t){i(t)}}function c(t){try{u(r.throw(t))}catch(t){i(t)}}function u(t){var e;t.done?o(t.value):(e=t.value,e instanceof n?e:new n((function(t){t(e)}))).then(a,c)}u((r=r.apply(t,e||[])).next())}))}function n(t,e){var n,r,o,i={label:0,sent:function(){if(1&o[0])throw o[1];return o[1]},trys:[],ops:[]},a=Object.create(("function"==typeof Iterator?Iterator:Object).prototype);return a.next=c(0),a.throw=c(1),a.return=c(2),"function"==typeof Symbol&&(a[Symbol.iterator]=function(){return this}),a;function c(c){return function(u){return function(c){if(n)throw new TypeError("Generator is already executing.");for(;a&&(a=0,c[0]&&(i=0)),i;)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 i.label++,{value:c[1],done:!1};case 5:i.label++,r=c[1],c=[0];continue;case 7:c=i.ops.pop(),i.trys.pop();continue;default:if(!(o=i.trys,(o=o.length>0&&o[o.length-1])||6!==c[0]&&2!==c[0])){i=0;continue}if(3===c[0]&&(!o||c[1]>o[0]&&c[1]<o[3])){i.label=c[1];break}if(6===c[0]&&i.label<o[1]){i.label=o[1],o=c;break}if(o&&i.label<o[2]){i.label=o[2],i.ops.push(c);break}o[2]&&i.ops.pop(),i.trys.pop();continue}c=e.call(t,i)}catch(t){c=[6,t],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="/v1/translate/batch",o="/v1/translate/react",i="/v1/translate/content",a="/v1/project/dictionary/update",c="/v1/project/locales";function u(t,o){return e(this,void 0,void 0,(function(){var e,i,a,c,u,l,s,f,v;return n(this,(function(n){switch(n.label){case 0:return e=new AbortController,i=e.signal,(null===(v=null===(f=null===(s=o[0])||void 0===s?void 0:s.data)||void 0===f?void 0:f.metadata)||void 0===v?void 0:v.timeout)&&setTimeout((function(){return e.abort()}),o[0].data.metadata.timeout),[4,fetch("".concat(t.baseURL).concat(r),{method:"POST",headers:{"Content-Type":"application/json","gtx-api-key":t.apiKey},body:JSON.stringify(o),signal:i})];case 1:return(a=n.sent()).ok?[3,3]:(c=Error.bind,l=(u="".concat(a.status,": ")).concat,[4,a.text()]);case 2:throw new(c.apply(Error,[void 0,l.apply(u,[n.sent()])]));case 3:return[4,a.json()];case 4:return[2,n.sent()]}}))}))}function l(){for(var t=[],e=0;e<arguments.length;e++)t[e]=arguments[e];try{var n=t.flat().map((function(t){return new Intl.Locale(t).language}));return n.every((function(t){return t===n[0]}))}catch(t){return console.error(t),!1}}var s="en-US",f=["Cham","Jamo","Kawi","Lisu","Toto","Thai"],v=function(t){try{var e=new Intl.Locale(t),n=e.language,r=e.region,o=e.script;if(new Intl.DisplayNames([s],{type:"language"}).of(n)===n)return!1;if(r)if(new Intl.DisplayNames([s],{type:"region"}).of(r)===r)return!1;if(o)if(new Intl.DisplayNames([s],{type:"script"}).of(o)===o&&!f.includes(o))return!1;return!0}catch(t){return!1}},p=function(t){return Intl.getCanonicalLocales(t)[0]};function d(){for(var t,e,n,r,o,i,a,c,u,l,s=[],f=0;f<arguments.length;f++)s[f]=arguments[f];try{for(var v=s.flat().map(p),d=0;d<v.length;d++)for(var y=d+1;y<v.length;y++)if(t=v[d],e=v[y],n=void 0,r=void 0,o=void 0,i=void 0,a=void 0,c=void 0,u=void 0,l=void 0,n=new Intl.Locale(t),r=n.language,o=n.region,i=n.script,a=new Intl.Locale(e),c=a.language,u=a.region,l=a.script,r!==c||o&&u&&o!==u||i&&l&&i!==l)return!1;return!0}catch(t){return console.error(t),!1}}function y(t,r,o,a){return e(this,void 0,void 0,(function(){var e,c,u,l,s,f;return n(this,(function(n){switch(n.label){case 0:return e=new AbortController,c=e.signal,a.timeout&&setTimeout((function(){return e.abort()}),a.timeout),[4,fetch("".concat(t.baseURL).concat(i),{method:"POST",headers:{"Content-Type":"application/json","gtx-api-key":t.apiKey},body:JSON.stringify({content:r,targetLocale:o,metadata:a}),signal:c})];case 1:return(u=n.sent()).ok?[3,3]:(l=Error.bind,f=(s="".concat(u.status,": ")).concat,[4,u.text()]);case 2:throw new(l.apply(Error,[void 0,f.apply(s,[n.sent()])]));case 3:return[4,u.json()];case 4:return[2,n.sent()]}}))}))}function m(t,r,i,a){return e(this,void 0,void 0,(function(){var e,c,u,l,s,f;return n(this,(function(n){switch(n.label){case 0:return e=new AbortController,c=e.signal,a.timeout&&setTimeout((function(){return e.abort()}),a.timeout),[4,fetch("".concat(t.baseURL).concat(o),{method:"POST",headers:{"Content-Type":"application/json","gtx-api-key":t.apiKey},body:JSON.stringify({children:r,targetLocale:i,metadata:a}),signal:c})];case 1:return(u=n.sent()).ok?[3,3]:(l=Error.bind,f=(s="".concat(u.status,": ")).concat,[4,u.text()]);case 2:throw new(l.apply(Error,[void 0,f.apply(s,[n.sent()])]));case 3:return[4,u.json()];case 4:return[2,n.sent()]}}))}))}function h(t,r,o,i){return e(this,void 0,void 0,(function(){var e,c,u,l,s;return n(this,(function(n){switch(n.label){case 0:return[4,fetch("".concat(t.baseURL).concat(a),{method:"POST",headers:{"Content-Type":"application/json","gtx-api-key":t.apiKey},body:JSON.stringify({updates:r,locales:o,options:i})})];case 1:return(e=n.sent()).ok?[3,3]:(c=Error.bind,l=(u="".concat(e.status,": ")).concat,[4,e.text()]);case 2:throw new(c.apply(Error,[void 0,l.apply(u,[n.sent()])]));case 3:return[4,e.json()];case 4:return[2,null==(s=n.sent())?void 0:s.locales]}}))}))}function g(t,r){return e(this,void 0,void 0,(function(){var e,o,i,a;return n(this,(function(n){switch(n.label){case 0:return[4,fetch("".concat(t.baseURL).concat(c,"?projectID=").concat(r),{method:"GET",headers:{"Content-Type":"application/json","gtx-api-key":t.apiKey}})];case 1:return(e=n.sent()).ok?[3,3]:(o=Error.bind,a=(i="".concat(e.status,": ")).concat,[4,e.text()]);case 2:throw new(o.apply(Error,[void 0,a.apply(i,[n.sent()])]));case 3:return[4,e.json()];case 4:return[2,n.sent()]}}))}))}function b(e){var n=e.value,r=e.locales,o=void 0===r?[s]:r,i=e.options,a=void 0===i?{}:i;return new Intl.NumberFormat(o,t({numberingSystem:"latn"},a)).format(n)}function N(e){var n=e.value,r=e.locales,o=void 0===r?[s]:r,i=e.options,a=void 0===i?{}:i;return new Intl.DateTimeFormat(o,t({calendar:"gregory",numberingSystem:"latn"},a)).format(n)}function w(e){var n=e.value,r=e.locales,o=void 0===r?[s]:r,i=e.currency,a=void 0===i?"USD":i,c=e.options,u=void 0===c?{}:c;return new Intl.NumberFormat(o,t({style:"currency",currency:a,numberingSystem:"latn"},u)).format(n)}function S(e){var n=e.value,r=e.locales,o=void 0===r?[s]:r,i=e.options,a=void 0===i?{}:i;return new Intl.ListFormat(o,t({type:"conjunction",style:"long"},a)).format(n)}var C={var:"variable",num:"number",datetime:"datetime",currency:"currency"};function I(e){if("string"!=typeof e)throw new Error("splitStringToContent: ".concat(e," is not a string!"));for(var n,r=[],o=/{([^}]+)}/g,i=0;null!==(n=o.exec(e));){var a=n[0],c=n[1],u=n.index;if("^"!==e[u-1]){u>i&&r.push(e.slice(i,u));var l=c.split(",").map((function(t){return t.trim()})),s=l[0],f=l[1]?C[l[1]]:void 0,v=t({key:s},f&&{variable:f});r.push(v),i=u+a.length}else u-1>i&&r.push(e.slice(i,u-1)),r.push(a),i=u+a.length}return i<e.length&&r.push(e.slice(i)),r}function L(t,e){if(void 0===e&&(e={}),!v(t))return M;if(e[t=p(t)])return e[t];var n=new Intl.Locale(t),r=n.region;if(r&&G[r])return G[r];var o=n.maximize(),i=o.region||"";return E[o.language]||G[i]||M}var T="đ",M=T,E={ca:T,eu:T,ku:T,bo:"đ",ug:"đ",gd:"đ´ó §ó ˘ó łó Łó ´ó ż",cy:"đ´ó §ó ˘ó ˇó Źó łó ż",gv:"đŽđ˛",grc:"đş"},G={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:"đŞđş"};var R=function(t){return"undefined"!=typeof process&&process.env&&process.env[t]||""},A=function(){function r(t){var e=void 0===t?{}:t,n=e.apiKey,r=void 0===n?"":n,o=e.defaultLocale,i=void 0===o?s:o,a=e.projectID,c=void 0===a?"":a,u=e.baseURL,l=void 0===u?"https://prod.gtx.dev":u;this.apiKey=r||R("GT_API_KEY"),this.projectID=c||R("GT_PROJECT_ID"),this.defaultLocale=p(i)||s,this.baseURL=l}return r.prototype.translate=function(r,o,i){return e(this,void 0,void 0,(function(){return n(this,(function(e){switch(e.label){case 0:return[4,y(this,r,o,t({defaultLocale:this.defaultLocale},i))];case 1:return[2,e.sent()]}}))}))},r.prototype.translateReact=function(r,o,i){return e(this,void 0,void 0,(function(){return n(this,(function(e){switch(e.label){case 0:return[4,m(this,r,o,t({defaultLocale:this.defaultLocale},i))];case 1:return[2,e.sent()]}}))}))},r.prototype.translateBatch=function(t){return e(this,void 0,void 0,(function(){return n(this,(function(e){return[2,u(this,t)]}))}))},r.prototype.updateProjectDictionary=function(t){return e(this,arguments,void 0,(function(t,e,r){return void 0===e&&(e=[]),void 0===r&&(r={}),n(this,(function(n){return[2,h(this,t,e,r)]}))}))},r.prototype.getProjectLocales=function(t){return e(this,void 0,void 0,(function(){return n(this,(function(e){return[2,g(this,t||this.projectID)]}))}))},r}();function D(t){return function(t){var e;try{var n=new Intl.Locale(t);return"rtl"===(null===(e=null==n?void 0:n.textInfo)||void 0===e?void 0:e.direction)?"rtl":"ltr"}catch(t){return"ltr"}}(t)}function K(t,e){return void 0===e&&(e=s),function(t,e){void 0===e&&(e=s);try{return new Intl.DisplayNames([e,s],{type:"language"}).of(t)||""}catch(t){return""}}(t,e)}function P(t,e){return function(t,e){void 0===e&&(e=s);try{t=O(t);var n=new Intl.Locale(t),r=n.language,o=n.region,i=new Intl.Locale(t).maximize(),a=i.toString(),c=i.region||"",u=i.script||"",l=new Intl.Locale(t).minimize().toString(),f=new Intl.DisplayNames([e,t,s],{type:"language"}),v=new Intl.DisplayNames([t,e,s],{type:"language"}),p=f.of(t)||t,d=v.of(t)||t,y=f.of(a)||t,m=v.of(a)||t,h=f.of(l)||t,g=v.of(l)||t,b=f.of(r)||t,N=v.of(r)||t,w=o?"".concat(b," (").concat(o,")"):b,S=o?"".concat(N," (").concat(o,")"):N,C=new Intl.DisplayNames([e,t,s],{type:"region"}),I=new Intl.DisplayNames([t,e,s],{type:"region"}),T=C.of(c)||"",M=I.of(c)||"",E=new Intl.DisplayNames([e,t,s],{type:"script"}),G=new Intl.DisplayNames([t,e,s],{type:"script"});return{code:t,name:p,nativeName:d,maximizedCode:a,maximizedName:y,nativeMaximizedName:m,minimizedCode:l,minimizedName:h,nativeMinimizedName:g,languageCode:r,languageName:b,nativeLanguageName:N,nameWithRegionCode:w,nativeNameWithRegionCode:S,regionCode:c,regionName:T,nativeRegionName:M,scriptCode:u,scriptName:E.of(u)||"",nativeScriptName:G.of(u)||"",emoji:L(t)}}catch(e){var R=t||"",A=null==R?void 0:R.split("-");return{code:R,name:R,nativeName:R,maximizedCode:R,maximizedName:R,nativeMaximizedName:R,minimizedCode:R,minimizedName:R,nativeMinimizedName:R,languageCode:r=(null==A?void 0:A[0])||R||"",languageName:r,nativeLanguageName:r,regionCode:c=A.length>2?null==A?void 0:A[2]:(null==A?void 0:A[1])||"",regionName:c,nativeRegionName:c,scriptCode:u=(null==A?void 0:A[3])||"",scriptName:u,nativeScriptName:u,nameWithRegionCode:w=r?c?"".concat(r," (").concat(c,")"):r:"",nativeNameWithRegionCode:R,emoji:L(R)}}}(t,e)}function j(t,e){return L(t,e)}function x(t){return v(t)}function O(t){return p(t)}function k(){for(var t=[],e=0;e<arguments.length;e++)t[e]=arguments[e];return d.apply(void 0,t)}function B(){for(var t=[],e=0;e<arguments.length;e++)t[e]=arguments[e];return l.apply(void 0,t)}function U(t){return b(t)}function F(t){return N(t)}function W(t){return w(t)}function z(t){return S(t)}function H(e){return r=(n=e).value,o=n.unit,i=n.locales,a=void 0===i?[s]:i,c=n.options,u=void 0===c?{}:c,new Intl.RelativeTimeFormat(a,t({style:"long",numeric:"auto"},u)).format(r,o);var n,r,o,i,a,c,u}function J(t){return I(t)}function V(e,n,r,o){return function(e,n,r,o){if(void 0===n&&(n=s),void 0===r&&(r={}),void 0===o&&(o={}),"string"==typeof e&&(e=I(e)),"string"==typeof e)return e;if(!Array.isArray(e))throw new Error("renderContentToString: content ".concat(e," is invalid"));return e.map((function(e){var i;if("string"==typeof e)return e;if("object"==typeof e){var a=r[e.key];return e.variable?"number"===e.variable?b({value:a,locales:n,options:o[e.key]}):"currency"===e.variable?w(t(t({value:a,locales:n},o[e.key]&&{options:o[e.key]}),(null===(i=o[e.key])||void 0===i?void 0:i.currency)&&{currency:o[e.key].currency})):"datetime"===e.variable?N(t({value:a,locales:n},o[e.key]&&{options:o[e.key]})):"list"===e.variable?S(t({value:a,locales:n},o[e.key]&&{options:o[e.key]})):a:a}})).join("")}(e,n,r,o)}function Z(t,e){return function(t,e){if("string"==typeof t&&(t=[t]),!e)return t[0];for(var n=function(t){for(var n=p(t),r=[],o=0,i=e;o<i.length;o++){var a=i[o],c=p(a);if(n===c)return{value:c};l(n,c)&&r.push(c)}if(r.length)return{value:r.find((function(t){return d(n,t)}))||r[0]}},r=0,o=t;r<o.length;r++){var i=n(o[r]);if("object"==typeof i)return i.value}}(t,e)}function Y(t,e,n){return function(t,e,n){return!(!v(t)||!v(e)||n&&n.some((function(t){return!v(t)}))||d(t,e)||n&&!n.some((function(t){return l(e,t)})))}(t,e,n)}export{A as default,Z as determineLocale,W as formatCurrency,F as formatDateTime,z as formatList,U as formatNum,H as formatRelativeTime,D as getLocaleDirection,j as getLocaleEmoji,K as getLocaleName,P as getLocaleProperties,k as isSameDialect,B as isSameLanguage,x as isValidLocale,V as renderContentToString,Y as requiresTranslation,J as splitStringToContent,O as standardizeLocale};
|
2
2
|
//# sourceMappingURL=index.esm.min.mjs.map
|