generaltranslation 6.3.2 → 7.0.0-alpha.1
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/id/{hashJsxChildren.d.ts → hashSource.d.ts} +2 -2
- package/dist/id/hashTemplate.d.ts +1 -1
- package/dist/id.cjs.min.cjs +1 -1
- package/dist/id.cjs.min.cjs.map +1 -1
- package/dist/id.d.ts +2 -2
- package/dist/id.esm.min.mjs +1 -1
- package/dist/id.esm.min.mjs.map +1 -1
- package/dist/index.cjs.min.cjs +1 -1
- package/dist/index.cjs.min.cjs.map +1 -1
- package/dist/index.d.ts +440 -266
- package/dist/index.esm.min.mjs +1 -1
- package/dist/index.esm.min.mjs.map +1 -1
- package/dist/settings/errors.d.ts +4 -0
- package/dist/types.d.ts +1 -0
- package/package.json +4 -2
- package/dist/formatting/string_content.d.ts +0 -1
- /package/dist/{api → deprecated}/batch/translateBatch.d.ts +0 -0
- /package/dist/{api → deprecated}/icu/translate.d.ts +0 -0
- /package/dist/{api → deprecated}/jsx/translateJsx.d.ts +0 -0
- /package/dist/{api → deprecated}/translate/translate.d.ts +0 -0
package/dist/index.d.ts
CHANGED
@@ -1,84 +1,420 @@
|
|
1
|
-
import {
|
1
|
+
import { CustomMapping, FormatVariables } from './types';
|
2
2
|
import { LocaleProperties } from './locales/getLocaleProperties';
|
3
|
-
import { FullCustomMapping } from './locales/customLocaleMapping';
|
4
3
|
/**
|
5
4
|
* Type representing the constructor parameters for the GT class.
|
5
|
+
* @typedef {Object} GTConstructorParams
|
6
|
+
* @property {string} [apiKey] - The API key for accessing the translation service
|
7
|
+
* @property {string} [devApiKey] - The development API key for accessing the translation service
|
8
|
+
* @property {string} [sourceLocale] - The default source locale for translations
|
9
|
+
* @property {string} [targetLocale] - The default target locale for translations
|
10
|
+
* @property {string[]} [locales] - Array of supported locales
|
11
|
+
* @property {string} [projectId] - The project ID for the translation service
|
12
|
+
* @property {string} [baseUrl] - The base URL for the translation service
|
13
|
+
* @property {CustomMapping} [customMapping] - Custom mapping of locale codes to their names
|
6
14
|
*/
|
7
15
|
type GTConstructorParams = {
|
8
16
|
apiKey?: string;
|
9
17
|
devApiKey?: string;
|
10
18
|
sourceLocale?: string;
|
19
|
+
targetLocale?: string;
|
20
|
+
locales?: string[];
|
11
21
|
projectId?: string;
|
12
22
|
baseUrl?: string;
|
13
23
|
customMapping?: CustomMapping;
|
14
24
|
};
|
15
25
|
/**
|
16
26
|
* GT is the core driver for the General Translation library.
|
27
|
+
* This class provides functionality for locale management, formatting, and translation operations.
|
28
|
+
*
|
29
|
+
* @class GT
|
30
|
+
* @description A comprehensive toolkit for handling internationalization and localization.
|
31
|
+
*
|
32
|
+
* @example
|
33
|
+
* const gt = new GT({
|
34
|
+
* sourceLocale: 'en-US',
|
35
|
+
* targetLocale: 'es-ES',
|
36
|
+
* locales: ['en-US', 'es-ES', 'fr-FR']
|
37
|
+
* });
|
17
38
|
*/
|
18
|
-
export
|
19
|
-
|
20
|
-
devApiKey: string;
|
21
|
-
sourceLocale: string;
|
22
|
-
projectId: string;
|
39
|
+
export default class GT {
|
40
|
+
/** Base URL for the translation service API */
|
23
41
|
baseUrl: string;
|
24
|
-
|
42
|
+
/** Project ID for the translation service */
|
43
|
+
projectId?: string;
|
44
|
+
/** API key for accessing the translation service */
|
45
|
+
apiKey?: string;
|
46
|
+
/** Development API key for accessing the translation service */
|
47
|
+
devApiKey?: string;
|
48
|
+
/** Source locale for translations */
|
49
|
+
sourceLocale?: string;
|
50
|
+
/** Target locale for translations */
|
51
|
+
targetLocale?: string;
|
52
|
+
/** Array of supported locales */
|
53
|
+
locales?: string[];
|
54
|
+
/** Array of locales used for rendering variables */
|
55
|
+
_renderingLocales: string[];
|
56
|
+
/** Custom mapping for locale codes to their names */
|
57
|
+
customMapping?: CustomMapping;
|
25
58
|
/**
|
26
59
|
* Constructs an instance of the GT class.
|
27
60
|
*
|
28
|
-
* @param {GTConstructorParams} [params] - The parameters for initializing the GT instance
|
29
|
-
* @
|
30
|
-
* @
|
31
|
-
*
|
32
|
-
* @
|
61
|
+
* @param {GTConstructorParams} [params] - The parameters for initializing the GT instance
|
62
|
+
* @throws {Error} If an invalid locale is provided
|
63
|
+
* @throws {Error} If any of the provided locales are invalid
|
64
|
+
*
|
65
|
+
* @example
|
66
|
+
* const gt = new GT({
|
67
|
+
* apiKey: 'your-api-key',
|
68
|
+
* sourceLocale: 'en-US',
|
69
|
+
* targetLocale: 'es-ES',
|
70
|
+
* locales: ['en-US', 'es-ES', 'fr-FR']
|
71
|
+
* });
|
33
72
|
*/
|
34
|
-
constructor({ apiKey, devApiKey, sourceLocale,
|
73
|
+
constructor({ apiKey, devApiKey, sourceLocale, targetLocale, locales, projectId, customMapping, baseUrl, }?: GTConstructorParams);
|
74
|
+
translatef(): void;
|
75
|
+
mtranslatef(): void;
|
35
76
|
/**
|
36
|
-
*
|
77
|
+
* Formats a message according to the specified locales and options.
|
78
|
+
*
|
79
|
+
* @param {string} message - The message to format.
|
80
|
+
* @param {string | string[]} [locales='en'] - The locales to use for formatting.
|
81
|
+
* @param {FormatVariables} [variables={}] - The variables to use for formatting.
|
82
|
+
* @returns {string} The formatted message.
|
37
83
|
*
|
38
|
-
* @
|
39
|
-
*
|
40
|
-
*
|
84
|
+
* @example
|
85
|
+
* gt.formatMessage('Hello {name}', { name: 'John' });
|
86
|
+
* // Returns: "Hello John"
|
41
87
|
*
|
42
|
-
*
|
88
|
+
* gt.formatMessage('Hello {name}', { name: 'John' }, { locales: ['fr'] });
|
89
|
+
* // Returns: "Bonjour John"
|
43
90
|
*/
|
44
|
-
|
91
|
+
formatMessage(message: string, options?: {
|
92
|
+
locales?: string[];
|
93
|
+
variables?: FormatVariables;
|
94
|
+
}): string;
|
45
95
|
/**
|
46
|
-
*
|
96
|
+
* Formats a number according to the specified locales and options.
|
47
97
|
*
|
48
|
-
* @param {
|
49
|
-
* @param {
|
50
|
-
* @param {string}
|
51
|
-
* @param {
|
98
|
+
* @param {number} number - The number to format
|
99
|
+
* @param {Object} [options] - Additional options for number formatting
|
100
|
+
* @param {string[]} [options.locales] - The locales to use for formatting
|
101
|
+
* @param {Intl.NumberFormatOptions} [options] - Additional Intl.NumberFormat options
|
102
|
+
* @returns {string} The formatted number
|
52
103
|
*
|
53
|
-
* @
|
104
|
+
* @example
|
105
|
+
* gt.formatNum(1234.56, { style: 'currency', currency: 'USD' });
|
106
|
+
* // Returns: "$1,234.56"
|
54
107
|
*/
|
55
|
-
|
108
|
+
formatNum(number: number, options?: {
|
109
|
+
locales?: string[];
|
110
|
+
} & Intl.NumberFormatOptions): string;
|
56
111
|
/**
|
57
|
-
*
|
112
|
+
* Formats a date according to the specified locales and options.
|
58
113
|
*
|
59
|
-
* @param {
|
60
|
-
* @param {
|
61
|
-
* @param {
|
62
|
-
* @param {
|
114
|
+
* @param {Date} date - The date to format
|
115
|
+
* @param {Object} [options] - Additional options for date formatting
|
116
|
+
* @param {string[]} [options.locales] - The locales to use for formatting
|
117
|
+
* @param {Intl.DateTimeFormatOptions} [options] - Additional Intl.DateTimeFormat options
|
118
|
+
* @returns {string} The formatted date
|
63
119
|
*
|
64
|
-
* @
|
120
|
+
* @example
|
121
|
+
* gt.formatDateTime(new Date(), { dateStyle: 'full', timeStyle: 'long' });
|
122
|
+
* // Returns: "Thursday, March 14, 2024 at 2:30:45 PM GMT-7"
|
65
123
|
*/
|
66
|
-
|
124
|
+
formatDateTime(date: Date, options?: {
|
125
|
+
locales?: string[];
|
126
|
+
} & Intl.DateTimeFormatOptions): string;
|
67
127
|
/**
|
68
|
-
*
|
128
|
+
* Formats a currency value according to the specified locales and options.
|
69
129
|
*
|
70
|
-
* @param {
|
71
|
-
* @
|
130
|
+
* @param {number} value - The currency value to format
|
131
|
+
* @param {string} currency - The currency code (e.g., 'USD', 'EUR')
|
132
|
+
* @param {Object} [options] - Additional options for currency formatting
|
133
|
+
* @param {string[]} [options.locales] - The locales to use for formatting
|
134
|
+
* @param {Intl.NumberFormatOptions} [options] - Additional Intl.NumberFormat options
|
135
|
+
* @returns {string} The formatted currency value
|
136
|
+
*
|
137
|
+
* @example
|
138
|
+
* gt.formatCurrency(1234.56, 'USD', { style: 'currency' });
|
139
|
+
* // Returns: "$1,234.56"
|
140
|
+
*/
|
141
|
+
formatCurrency(value: number, currency: string, options?: {
|
142
|
+
locales?: string[];
|
143
|
+
} & Intl.NumberFormatOptions): string;
|
144
|
+
/**
|
145
|
+
* Formats a list of items according to the specified locales and options.
|
146
|
+
*
|
147
|
+
* @param {Array<string | number>} array - The list of items to format
|
148
|
+
* @param {Object} [options] - Additional options for list formatting
|
149
|
+
* @param {string[]} [options.locales] - The locales to use for formatting
|
150
|
+
* @param {Intl.ListFormatOptions} [options] - Additional Intl.ListFormat options
|
151
|
+
* @returns {string} The formatted list
|
152
|
+
*
|
153
|
+
* @example
|
154
|
+
* gt.formatList(['apple', 'banana', 'orange'], { type: 'conjunction' });
|
155
|
+
* // Returns: "apple, banana, and orange"
|
156
|
+
*/
|
157
|
+
formatList(array: Array<string | number>, options?: {
|
158
|
+
locales?: string[];
|
159
|
+
} & Intl.ListFormatOptions): string;
|
160
|
+
/**
|
161
|
+
* Formats a relative time value according to the specified locales and options.
|
162
|
+
*
|
163
|
+
* @param {number} value - The relative time value to format
|
164
|
+
* @param {Intl.RelativeTimeFormatUnit} unit - The unit of time (e.g., 'second', 'minute', 'hour', 'day', 'week', 'month', 'year')
|
165
|
+
* @param {Object} options - Additional options for relative time formatting
|
166
|
+
* @param {string[]} [options.locales] - The locales to use for formatting
|
167
|
+
* @param {Intl.RelativeTimeFormatOptions} [options] - Additional Intl.RelativeTimeFormat options
|
168
|
+
* @returns {string} The formatted relative time string
|
169
|
+
*
|
170
|
+
* @example
|
171
|
+
* gt.formatRelativeTime(-1, 'day', { locales: ['en-US'], numeric: 'auto' });
|
172
|
+
* // Returns: "yesterday"
|
72
173
|
*/
|
73
|
-
|
174
|
+
formatRelativeTime(value: number, unit: Intl.RelativeTimeFormatUnit, options?: {
|
175
|
+
locales?: string[];
|
176
|
+
} & Omit<Intl.RelativeTimeFormatOptions, 'locales'>): string;
|
177
|
+
/**
|
178
|
+
* Retrieves the display name of a locale code using Intl.DisplayNames.
|
179
|
+
*
|
180
|
+
* @param {string} [locale=this.targetLocale] - A BCP-47 locale code
|
181
|
+
* @returns {string} The display name corresponding to the code
|
182
|
+
* @throws {Error} If no target locale is provided
|
183
|
+
*
|
184
|
+
* @example
|
185
|
+
* gt.getLocaleName('es-ES');
|
186
|
+
* // Returns: "Spanish (Spain)"
|
187
|
+
*/
|
188
|
+
getLocaleName(locale?: string | undefined): string;
|
189
|
+
/**
|
190
|
+
* Retrieves an emoji based on a given locale code.
|
191
|
+
* Uses the locale's region (if present) to select an emoji or falls back on default emojis.
|
192
|
+
*
|
193
|
+
* @param {string} [locale=this.targetLocale] - A BCP-47 locale code (e.g., 'en-US', 'fr-CA')
|
194
|
+
* @returns {string} The emoji representing the locale or its region
|
195
|
+
* @throws {Error} If no target locale is provided
|
196
|
+
*
|
197
|
+
* @example
|
198
|
+
* gt.getLocaleEmoji('es-ES');
|
199
|
+
* // Returns: "🇪🇸"
|
200
|
+
*/
|
201
|
+
getLocaleEmoji(locale?: string | undefined): string;
|
74
202
|
/**
|
75
203
|
* Retrieves an emoji based on a given locale code, taking into account region, language, and specific exceptions.
|
204
|
+
*
|
76
205
|
* This function uses the locale's region (if present) to select an emoji or falls back on default emojis for certain languages.
|
77
206
|
*
|
78
207
|
* @param locale - A string representing the locale code (e.g., 'en-US', 'fr-CA').
|
208
|
+
* @param {CustomMapping} [customMapping] - A custom mapping of locale codes to their names.
|
79
209
|
* @returns The emoji representing the locale or its region, or a default emoji if no specific match is found.
|
80
210
|
*/
|
81
|
-
getLocaleEmoji(locale: string): string;
|
211
|
+
static getLocaleEmoji(locale: string, customMapping?: CustomMapping): string;
|
212
|
+
/**
|
213
|
+
* Generates linguistic details for a given locale code.
|
214
|
+
*
|
215
|
+
* This function returns information about the locale,
|
216
|
+
* script, and region of a given language code both in a standard form and in a maximized form (with likely script and region).
|
217
|
+
* The function provides these names in both your default language and native forms, and an associated emoji.
|
218
|
+
*
|
219
|
+
* @param {string} [locale=this.targetLocale] - The locale code to get properties for (e.g., "de-AT").
|
220
|
+
* @returns {LocaleProperties} - An object containing detailed information about the locale.
|
221
|
+
*
|
222
|
+
* @property {string} code - The full locale code, e.g., "de-AT".
|
223
|
+
* @property {string} name - Language name in the default display language, e.g., "Austrian German".
|
224
|
+
* @property {string} nativeName - Language name in the locale's native language, e.g., "Österreichisches Deutsch".
|
225
|
+
* @property {string} languageCode - The base language code, e.g., "de".
|
226
|
+
* @property {string} languageName - The language name in the default display language, e.g., "German".
|
227
|
+
* @property {string} nativeLanguageName - The language name in the native language, e.g., "Deutsch".
|
228
|
+
* @property {string} nameWithRegionCode - Language name with region in the default language, e.g., "German (AT)".
|
229
|
+
* @property {string} nativeNameWithRegionCode - Language name with region in the native language, e.g., "Deutsch (AT)".
|
230
|
+
* @property {string} regionCode - The region code from maximization, e.g., "AT".
|
231
|
+
* @property {string} regionName - The region name in the default display language, e.g., "Austria".
|
232
|
+
* @property {string} nativeRegionName - The region name in the native language, e.g., "Österreich".
|
233
|
+
* @property {string} scriptCode - The script code from maximization, e.g., "Latn".
|
234
|
+
* @property {string} scriptName - The script name in the default display language, e.g., "Latin".
|
235
|
+
* @property {string} nativeScriptName - The script name in the native language, e.g., "Lateinisch".
|
236
|
+
* @property {string} maximizedCode - The maximized locale code, e.g., "de-Latn-AT".
|
237
|
+
* @property {string} maximizedName - Maximized locale name with likely script in the default language, e.g., "Austrian German (Latin)".
|
238
|
+
* @property {string} nativeMaximizedName - Maximized locale name in the native language, e.g., "Österreichisches Deutsch (Lateinisch)".
|
239
|
+
* @property {string} minimizedCode - Minimized locale code, e.g., "de-AT" (or "de" for "de-DE").
|
240
|
+
* @property {string} minimizedName - Minimized language name in the default language, e.g., "Austrian German".
|
241
|
+
* @property {string} nativeMinimizedName - Minimized language name in the native language, e.g., "Österreichisches Deutsch".
|
242
|
+
* @property {string} emoji - The emoji associated with the locale's region, if applicable.
|
243
|
+
*/
|
244
|
+
getLocaleProperties(locale?: string | undefined): LocaleProperties;
|
245
|
+
/**
|
246
|
+
* Determines whether a translation is required based on the source and target locales.
|
247
|
+
*
|
248
|
+
* @param {string} [sourceLocale=this.sourceLocale] - The locale code for the original content
|
249
|
+
* @param {string} [targetLocale=this.targetLocale] - The locale code to translate into
|
250
|
+
* @param {string[]} [approvedLocales=this.locales] - Optional array of approved target locales
|
251
|
+
* @returns {boolean} True if translation is required, false otherwise
|
252
|
+
* @throws {Error} If no source locale is provided
|
253
|
+
* @throws {Error} If no target locale is provided
|
254
|
+
*
|
255
|
+
* @example
|
256
|
+
* gt.requiresTranslation('en-US', 'es-ES');
|
257
|
+
* // Returns: true
|
258
|
+
*/
|
259
|
+
requiresTranslation(sourceLocale?: string | undefined, targetLocale?: string | undefined, approvedLocales?: string[] | undefined): boolean;
|
260
|
+
/**
|
261
|
+
* Determines the best matching locale from the provided approved locales list.
|
262
|
+
*
|
263
|
+
* @param {string | string[]} locales - A single locale or array of locales in preference order
|
264
|
+
* @param {string[]} [approvedLocales=this.locales] - Array of approved locales in preference order
|
265
|
+
* @returns {string | undefined} The best matching locale or undefined if no match is found
|
266
|
+
*
|
267
|
+
* @example
|
268
|
+
* gt.determineLocale(['fr-CA', 'fr-FR'], ['en-US', 'fr-FR', 'es-ES']);
|
269
|
+
* // Returns: "fr-FR"
|
270
|
+
*/
|
271
|
+
determineLocale(locales: string | string[], approvedLocales?: string[] | undefined): string | undefined;
|
272
|
+
/**
|
273
|
+
* Gets the text direction for a given locale code.
|
274
|
+
*
|
275
|
+
* @param {string} [locale=this.targetLocale] - A BCP-47 locale code
|
276
|
+
* @returns {'ltr' | 'rtl'} 'rtl' if the locale is right-to-left, otherwise 'ltr'
|
277
|
+
* @throws {Error} If no target locale is provided
|
278
|
+
*
|
279
|
+
* @example
|
280
|
+
* gt.getLocaleDirection('ar-SA');
|
281
|
+
* // Returns: "rtl"
|
282
|
+
*/
|
283
|
+
getLocaleDirection(locale?: string | undefined): 'ltr' | 'rtl';
|
284
|
+
/**
|
285
|
+
* Checks if a given BCP 47 locale code is valid.
|
286
|
+
*
|
287
|
+
* @param {string} [locale=this.targetLocale] - The BCP 47 locale code to validate
|
288
|
+
* @returns {boolean} True if the locale code is valid, false otherwise
|
289
|
+
* @throws {Error} If no target locale is provided
|
290
|
+
*
|
291
|
+
* @example
|
292
|
+
* gt.isValidLocale('en-US');
|
293
|
+
* // Returns: true
|
294
|
+
*/
|
295
|
+
isValidLocale(locale?: string | undefined): boolean;
|
296
|
+
/**
|
297
|
+
* Standardizes a BCP 47 locale code to ensure correct formatting.
|
298
|
+
*
|
299
|
+
* @param {string} [locale=this.targetLocale] - The BCP 47 locale code to standardize
|
300
|
+
* @returns {string} The standardized locale code or empty string if invalid
|
301
|
+
* @throws {Error} If no target locale is provided
|
302
|
+
*
|
303
|
+
* @example
|
304
|
+
* gt.standardizeLocale('en_us');
|
305
|
+
* // Returns: "en-US"
|
306
|
+
*/
|
307
|
+
standardizeLocale(locale?: string | undefined): string;
|
308
|
+
/**
|
309
|
+
* Checks if multiple BCP 47 locale codes represent the same dialect.
|
310
|
+
*
|
311
|
+
* @param {...(string | string[])} locales - The BCP 47 locale codes to compare
|
312
|
+
* @returns {boolean} True if all codes represent the same dialect, false otherwise
|
313
|
+
*
|
314
|
+
* @example
|
315
|
+
* gt.isSameDialect('en-US', 'en-GB');
|
316
|
+
* // Returns: false
|
317
|
+
*
|
318
|
+
* gt.isSameDialect('en', 'en-US');
|
319
|
+
* // Returns: true
|
320
|
+
*/
|
321
|
+
isSameDialect(...locales: (string | string[])[]): boolean;
|
322
|
+
/**
|
323
|
+
* Checks if multiple BCP 47 locale codes represent the same language.
|
324
|
+
*
|
325
|
+
* @param {...(string | string[])} locales - The BCP 47 locale codes to compare
|
326
|
+
* @returns {boolean} True if all codes represent the same language, false otherwise
|
327
|
+
*
|
328
|
+
* @example
|
329
|
+
* gt.isSameLanguage('en-US', 'en-GB');
|
330
|
+
* // Returns: true
|
331
|
+
*/
|
332
|
+
isSameLanguage(...locales: (string | string[])[]): boolean;
|
333
|
+
/**
|
334
|
+
* Checks if a locale is a superset of another locale.
|
335
|
+
*
|
336
|
+
* @param {string} superLocale - The locale to check if it is a superset
|
337
|
+
* @param {string} subLocale - The locale to check if it is a subset
|
338
|
+
* @returns {boolean} True if superLocale is a superset of subLocale, false otherwise
|
339
|
+
*
|
340
|
+
* @example
|
341
|
+
* gt.isSupersetLocale('en', 'en-US');
|
342
|
+
* // Returns: true
|
343
|
+
*
|
344
|
+
* gt.isSupersetLocale('en-US', 'en');
|
345
|
+
* // Returns: false
|
346
|
+
*/
|
347
|
+
isSupersetLocale(superLocale: string, subLocale: string): boolean;
|
348
|
+
static formatMessage(message: string, options?: {
|
349
|
+
locales?: string[];
|
350
|
+
variables?: FormatVariables;
|
351
|
+
}): string;
|
352
|
+
/**
|
353
|
+
* Formats a number according to the specified locales and options.
|
354
|
+
* @param {Object} params - The parameters for the number formatting.
|
355
|
+
* @param {number} params.value - The number to format.
|
356
|
+
* @param {Intl.NumberFormatOptions} [params.options] - Additional options for number formatting.
|
357
|
+
* @param {string[]} [params.options.locales] - The locales to use for formatting.
|
358
|
+
* @returns {string} The formatted number.
|
359
|
+
*/
|
360
|
+
static formatNum(number: number, options: {
|
361
|
+
locales: string[];
|
362
|
+
} & Intl.NumberFormatOptions): string;
|
363
|
+
/**
|
364
|
+
* Formats a date according to the specified languages and options.
|
365
|
+
* @param {Object} params - The parameters for the date formatting.
|
366
|
+
* @param {Date} params.value - The date to format.
|
367
|
+
* @param {Intl.DateTimeFormatOptions} [params.options] - Additional options for date formatting.
|
368
|
+
* @param {string[]} [params.options.locales] - The languages to use for formatting.
|
369
|
+
* @returns {string} The formatted date.
|
370
|
+
*/
|
371
|
+
static formatDateTime(date: Date, options?: {
|
372
|
+
locales?: string[];
|
373
|
+
} & Intl.DateTimeFormatOptions): string;
|
374
|
+
/**
|
375
|
+
* Formats a currency value according to the specified languages, currency, and options.
|
376
|
+
* @param {Object} params - The parameters for the currency formatting.
|
377
|
+
* @param {number} params.value - The currency value to format.
|
378
|
+
* @param {string} params.currency - The currency code (e.g., 'USD').
|
379
|
+
* @param {Intl.NumberFormatOptions} [params.options={}] - Additional options for currency formatting.
|
380
|
+
* @param {string[]} [params.options.locales] - The locale codes to use for formatting.
|
381
|
+
* @returns {string} The formatted currency value.
|
382
|
+
*/
|
383
|
+
static formatCurrency(value: number, currency: string, options: {
|
384
|
+
locales: string[];
|
385
|
+
} & Intl.NumberFormatOptions): string;
|
386
|
+
/**
|
387
|
+
* Formats a list of items according to the specified locales and options.
|
388
|
+
* @param {Object} params - The parameters for the list formatting.
|
389
|
+
* @param {Array<string | number>} params.value - The list of items to format.
|
390
|
+
* @param {Intl.ListFormatOptions} [params.options={}] - Additional options for list formatting.
|
391
|
+
* @param {string[]} [params.options.locales] - The locales to use for formatting.
|
392
|
+
* @returns {string} The formatted list.
|
393
|
+
*/
|
394
|
+
static formatList(array: Array<string | number>, options: {
|
395
|
+
locales: string[];
|
396
|
+
} & Intl.ListFormatOptions): string;
|
397
|
+
/**
|
398
|
+
* Formats a relative time value according to the specified locales and options.
|
399
|
+
* @param {Object} params - The parameters for the relative time formatting.
|
400
|
+
* @param {number} params.value - The relative time value to format.
|
401
|
+
* @param {Intl.RelativeTimeFormatUnit} params.unit - The unit of time (e.g., 'second', 'minute', 'hour', 'day', 'week', 'month', 'year').
|
402
|
+
* @param {Intl.RelativeTimeFormatOptions} [params.options={}] - Additional options for relative time formatting.
|
403
|
+
* @param {string[]} [params.options.locales] - The locales to use for formatting.
|
404
|
+
* @returns {string} The formatted relative time string.
|
405
|
+
*/
|
406
|
+
static formatRelativeTime(value: number, unit: Intl.RelativeTimeFormatUnit, options: {
|
407
|
+
locales: string[];
|
408
|
+
} & Omit<Intl.RelativeTimeFormatOptions, 'locales'>): string;
|
409
|
+
/**
|
410
|
+
* Retrieves the display name of locale code using Intl.DisplayNames.
|
411
|
+
*
|
412
|
+
* @param {string} locale - A BCP-47 locale code.
|
413
|
+
* @param {string} [defaultLocale] - The default locale to use for formatting.
|
414
|
+
* @param {CustomMapping} [customMapping] - A custom mapping of locale codes to their names.
|
415
|
+
* @returns {string} The display name corresponding to the code.
|
416
|
+
*/
|
417
|
+
static getLocaleName(locale: string, defaultLocale?: string, customMapping?: CustomMapping): string;
|
82
418
|
/**
|
83
419
|
* Generates linguistic details for a given locale code.
|
84
420
|
*
|
@@ -87,6 +423,8 @@ export declare class GT {
|
|
87
423
|
* The function provides these names in both your default language and native forms, and an associated emoji.
|
88
424
|
*
|
89
425
|
* @param {string} locale - The locale code to get properties for (e.g., "de-AT").
|
426
|
+
* @param {string} [defaultLocale] - The default locale to use for formatting.
|
427
|
+
* @param {CustomMapping} [customMapping] - A custom mapping of locale codes to their names.
|
90
428
|
* @returns {LocaleProperties} - An object containing detailed information about the locale.
|
91
429
|
*
|
92
430
|
* @property {string} code - The full locale code, e.g., "de-AT".
|
@@ -111,232 +449,68 @@ export declare class GT {
|
|
111
449
|
* @property {string} nativeMinimizedName - Minimized language name in the native language, e.g., "Österreichisches Deutsch".
|
112
450
|
* @property {string} emoji - The emoji associated with the locale's region, if applicable.
|
113
451
|
*/
|
114
|
-
getLocaleProperties(locale: string): LocaleProperties;
|
452
|
+
static getLocaleProperties(locale: string, defaultLocale?: string, customMapping?: CustomMapping): LocaleProperties;
|
453
|
+
/**
|
454
|
+
* Determines whether a translation is required based on the source and target locales.
|
455
|
+
*
|
456
|
+
* - If the target locale is not specified, the function returns `false`, as translation is not needed.
|
457
|
+
* - If the source and target locale are the same, returns `false`, indicating that no translation is necessary.
|
458
|
+
* - If the `approvedLocales` array is provided, and the target locale is not within that array, the function also returns `false`.
|
459
|
+
* - Otherwise, it returns `true`, meaning that a translation is required.
|
460
|
+
*
|
461
|
+
* @param {string} sourceLocale - The locale code for the original content (BCP 47 locale code).
|
462
|
+
* @param {string} targetLocale - The locale code of the language to translate the content into (BCP 47 locale code).
|
463
|
+
* @param {string[]} [approvedLocale] - An optional array of approved target locales.
|
464
|
+
*
|
465
|
+
* @returns {boolean} - Returns `true` if translation is required, otherwise `false`.
|
466
|
+
*/
|
467
|
+
static requiresTranslation(sourceLocale: string, targetLocale: string, approvedLocales?: string[]): boolean;
|
468
|
+
/**
|
469
|
+
* Determines the best matching locale from the provided approved locales list.
|
470
|
+
* @param {string | string[]} locales - A single locale or an array of locales sorted in preference order.
|
471
|
+
* @param {string[]} [approvedLocales=this.locales] - An array of approved locales, also sorted by preference.
|
472
|
+
* @returns {string | undefined} - The best matching locale from the approvedLocales list, or undefined if no match is found.
|
473
|
+
*/
|
474
|
+
static determineLocale(locales: string | string[], approvedLocales?: string[] | undefined): string | undefined;
|
475
|
+
/**
|
476
|
+
* Get the text direction for a given locale code using the Intl.Locale API.
|
477
|
+
*
|
478
|
+
* @param {string} locale - A BCP-47 locale code.
|
479
|
+
* @returns {string} - 'rtl' if the locale is right-to-left, otherwise 'ltr'.
|
480
|
+
*/
|
481
|
+
static getLocaleDirection(locale: string): 'ltr' | 'rtl';
|
482
|
+
/**
|
483
|
+
* Checks if a given BCP 47 locale code is valid.
|
484
|
+
* @param {string} locale - The BCP 47 locale code to validate.
|
485
|
+
* @returns {boolean} True if the BCP 47 code is valid, false otherwise.
|
486
|
+
*/
|
487
|
+
static isValidLocale(locale: string): boolean;
|
488
|
+
/**
|
489
|
+
* Standardizes a BCP 47 locale code to ensure correct formatting.
|
490
|
+
* @param {string} locale - The BCP 47 locale code to standardize.
|
491
|
+
* @returns {string} The standardized BCP 47 locale code or an empty string if it is an invalid code.
|
492
|
+
*/
|
493
|
+
static standardizeLocale(locale: string): string;
|
494
|
+
/**
|
495
|
+
* Checks if multiple BCP 47 locale codes represent the same dialect.
|
496
|
+
* @param {string[]} locales - The BCP 47 locale codes to compare.
|
497
|
+
* @returns {boolean} True if all BCP 47 codes represent the same dialect, false otherwise.
|
498
|
+
*/
|
499
|
+
static isSameDialect(...locales: (string | string[])[]): boolean;
|
500
|
+
/**
|
501
|
+
* Checks if multiple BCP 47 locale codes represent the same language.
|
502
|
+
* @param {string[]} locales - The BCP 47 locale codes to compare.
|
503
|
+
* @returns {boolean} True if all BCP 47 codes represent the same language, false otherwise.
|
504
|
+
*/
|
505
|
+
static isSameLanguage(...locales: (string | string[])[]): boolean;
|
506
|
+
/**
|
507
|
+
* Checks if a locale is a superset of another locale.
|
508
|
+
* A subLocale is a subset of superLocale if it is an extension of superLocale or are otherwise identical.
|
509
|
+
*
|
510
|
+
* @param {string} superLocale - The locale to check if it is a superset of the other locale.
|
511
|
+
* @param {string} subLocale - The locale to check if it is a subset of the other locale.
|
512
|
+
* @returns {boolean} True if the first locale is a superset of the second locale, false otherwise.
|
513
|
+
*/
|
514
|
+
static isSupersetLocale(superLocale: string, subLocale: string): boolean;
|
115
515
|
}
|
116
|
-
/**
|
117
|
-
* Get the text direction for a given locale code using the Intl.Locale API.
|
118
|
-
*
|
119
|
-
* @param locale - A BCP-47 locale code.
|
120
|
-
* @returns {string} - 'rtl' if the locale is right-to-left, otherwise 'ltr'.
|
121
|
-
*/
|
122
|
-
export declare function getLocaleDirection(locale: string): 'ltr' | 'rtl';
|
123
|
-
/**
|
124
|
-
* Retrieves the display name of locale code using Intl.DisplayNames.
|
125
|
-
*
|
126
|
-
* @param {string} locale - A BCP-47 locale code.
|
127
|
-
* @param {string} [defaultLocale = 'en'] - The locale for display names.
|
128
|
-
* @param {FullCustomMapping} [customMapping] - Optional custom mapping of locale codes to names.
|
129
|
-
* @returns {string} The display name corresponding to the code.
|
130
|
-
*/
|
131
|
-
export declare function getLocaleName(locale: string, defaultLocale?: string, customMapping?: FullCustomMapping): string;
|
132
|
-
/**
|
133
|
-
* Generates linguistic details for a given locale code.
|
134
|
-
*
|
135
|
-
* This function returns information about the locale,
|
136
|
-
* script, and region of a given language code both in a standard form and in a maximized form (with likely script and region).
|
137
|
-
* The function provides these names in both your default language and native forms, and an associated emoji.
|
138
|
-
*
|
139
|
-
* @param {string} locale - The locale code to get properties for (e.g., "de-AT").
|
140
|
-
* @param {string} [defaultLocale=libraryDefaultLocale] - The default locale code for display names.
|
141
|
-
* @param {FullCustomMapping} [customMapping] - Optional custom mapping of locale codes to properties.
|
142
|
-
* @returns {LocaleProperties} - An object containing detailed information about the locale.
|
143
|
-
*
|
144
|
-
* @property {string} code - The full locale code, e.g., "de-AT".
|
145
|
-
* @property {string} name - Language name in the default display language, e.g., "Austrian German".
|
146
|
-
* @property {string} nativeName - Language name in the locale's native language, e.g., "Österreichisches Deutsch".
|
147
|
-
* @property {string} languageCode - The base language code, e.g., "de".
|
148
|
-
* @property {string} languageName - The language name in the default display language, e.g., "German".
|
149
|
-
* @property {string} nativeLanguageName - The language name in the native language, e.g., "Deutsch".
|
150
|
-
* @property {string} nameWithRegionCode - Language name with region in the default language, e.g., "German (AT)".
|
151
|
-
* @property {string} nativeNameWithRegionCode - Language name with region in the native language, e.g., "Deutsch (AT)".
|
152
|
-
* @property {string} regionCode - The region code from maximization, e.g., "AT".
|
153
|
-
* @property {string} regionName - The region name in the default display language, e.g., "Austria".
|
154
|
-
* @property {string} nativeRegionName - The region name in the native language, e.g., "Österreich".
|
155
|
-
* @property {string} scriptCode - The script code from maximization, e.g., "Latn".
|
156
|
-
* @property {string} scriptName - The script name in the default display language, e.g., "Latin".
|
157
|
-
* @property {string} nativeScriptName - The script name in the native language, e.g., "Lateinisch".
|
158
|
-
* @property {string} maximizedCode - The maximized locale code, e.g., "de-Latn-AT".
|
159
|
-
* @property {string} maximizedName - Maximized locale name with likely script in the default language, e.g., "Austrian German (Latin)".
|
160
|
-
* @property {string} nativeMaximizedName - Maximized locale name in the native language, e.g., "Österreichisches Deutsch (Lateinisch)".
|
161
|
-
* @property {string} minimizedCode - Minimized locale code, e.g., "de-AT" (or "de" for "de-DE").
|
162
|
-
* @property {string} minimizedName - Minimized language name in the default language, e.g., "Austrian German".
|
163
|
-
* @property {string} nativeMinimizedName - Minimized language name in the native language, e.g., "Österreichisches Deutsch".
|
164
|
-
* @property {string} emoji - The emoji associated with the locale's region, if applicable.
|
165
|
-
*/
|
166
|
-
export declare function getLocaleProperties(locale: string, defaultLocale?: string, customMapping?: FullCustomMapping): {
|
167
|
-
code: string;
|
168
|
-
name: string;
|
169
|
-
nativeName: string;
|
170
|
-
languageCode: string;
|
171
|
-
languageName: string;
|
172
|
-
nativeLanguageName: string;
|
173
|
-
nameWithRegionCode: string;
|
174
|
-
nativeNameWithRegionCode: string;
|
175
|
-
regionCode: string;
|
176
|
-
regionName: string;
|
177
|
-
nativeRegionName: string;
|
178
|
-
scriptCode: string;
|
179
|
-
scriptName: string;
|
180
|
-
nativeScriptName: string;
|
181
|
-
maximizedCode: string;
|
182
|
-
maximizedName: string;
|
183
|
-
nativeMaximizedName: string;
|
184
|
-
minimizedCode: string;
|
185
|
-
minimizedName: string;
|
186
|
-
nativeMinimizedName: string;
|
187
|
-
emoji: string;
|
188
|
-
};
|
189
|
-
/**
|
190
|
-
* Retrieves an emoji based on a given locale code, taking into account region, language, and specific exceptions.
|
191
|
-
* This function uses the locale's region (if present) to select an emoji or falls back on default emojis for certain languages.
|
192
|
-
*
|
193
|
-
* @param locale - A string representing the locale code (e.g., 'en-US', 'fr-CA').
|
194
|
-
* @param customMapping - An optional custom mapping of locale codes to emojis.
|
195
|
-
* @returns The emoji representing the locale or its region, or a default emoji if no specific match is found.
|
196
|
-
*/
|
197
|
-
export declare function getLocaleEmoji(locale: string, customMapping?: FullCustomMapping): string;
|
198
|
-
/**
|
199
|
-
* Checks if a given BCP 47 locale code is valid.
|
200
|
-
* @param {string} locale - The BCP 47 locale code to validate.
|
201
|
-
* @returns {boolean} True if the BCP 47 code is valid, false otherwise.
|
202
|
-
*/
|
203
|
-
export declare function isValidLocale(locale: string): boolean;
|
204
|
-
/**
|
205
|
-
* Standardizes a BCP 47 locale code to ensure correct formatting.
|
206
|
-
* @param {string} locale - The BCP 47 locale code to standardize.
|
207
|
-
* @returns {string} The standardized BCP 47 locale code or an empty string if it is an invalid code.
|
208
|
-
*/
|
209
|
-
export declare function standardizeLocale(locale: string): string;
|
210
|
-
/**
|
211
|
-
* Checks if multiple BCP 47 locale codes represent the same dialect.
|
212
|
-
*
|
213
|
-
* For example, `"en-US"` and `"en-GB"` are the same language, but different dialects.
|
214
|
-
* `isSameDialect("en-US", "en-GB")` would return `false`.
|
215
|
-
*
|
216
|
-
* For checking if two locale codes represent the same language, see `isSameLanguage()`.
|
217
|
-
*
|
218
|
-
* Note that `isSameDialect("en", "en-US")` and `isSameDialect("en", "en-GB")` would both return true.
|
219
|
-
*
|
220
|
-
* @param {string[]} locales - The BCP 47 locale codes to compare.
|
221
|
-
* @returns {boolean} True if all BCP 47 codes represent the same dialect, false otherwise.
|
222
|
-
*/
|
223
|
-
export declare function isSameDialect(...locales: (string | string[])[]): boolean;
|
224
|
-
/**
|
225
|
-
* Checks if multiple BCP 47 locale codes represent the same language.
|
226
|
-
*
|
227
|
-
* For example, `"en-US"` and `"en-GB"` are the same language, English.
|
228
|
-
* `isSameDialect("en-US", "en-GB")` would return `true`.
|
229
|
-
*
|
230
|
-
* For checking if two codes represent the exact same dialect, see `isSameDialect()`.
|
231
|
-
*
|
232
|
-
* @param {string[]} locales - The BCP 47 locale codes to compare.
|
233
|
-
* @returns {boolean} True if all BCP 47 codes represent the same locale, false otherwise.
|
234
|
-
*/
|
235
|
-
export declare function isSameLanguage(...locales: (string | string[])[]): boolean;
|
236
|
-
/**
|
237
|
-
* Checks if a locale is a superset of another locale.
|
238
|
-
* A subLocale is a subset of superLocale if it is an extension of superLocale or are otherwise identical.
|
239
|
-
*
|
240
|
-
* `isSupersetLocale("en", "en-US")` would return `true`.
|
241
|
-
* `isSupersetLocale("en-US", "en")` would return `false`.
|
242
|
-
*
|
243
|
-
* @param {string} superLocale - The locale to check if it is a superset of the other locale.
|
244
|
-
* @param {string} subLocale - The locale to check if it is a subset of the other locale.
|
245
|
-
* @returns {boolean} True if the first locale is a superset of the second locale, false otherwise.
|
246
|
-
*/
|
247
|
-
export declare function isSupersetLocale(superLocale: string, subLocale: string): boolean;
|
248
|
-
/**
|
249
|
-
* Formats a number according to the specified locales and options.
|
250
|
-
* @param {Object} params - The parameters for the number formatting.
|
251
|
-
* @param {number} params.value - The number to format.
|
252
|
-
* @param {string | string[]} [params.locales=['en']] - The locales to use for formatting.
|
253
|
-
* @param {Intl.NumberFormatOptions} [params.options={}] - Additional options for number formatting.
|
254
|
-
* @returns {string} The formatted number.
|
255
|
-
*/
|
256
|
-
export declare function formatNum(number: number, options?: {
|
257
|
-
locales?: string | string[];
|
258
|
-
} & Intl.NumberFormatOptions): string;
|
259
|
-
/**
|
260
|
-
* Formats a date according to the specified languages and options.
|
261
|
-
* @param {Object} params - The parameters for the date formatting.
|
262
|
-
* @param {Date} params.value - The date to format.
|
263
|
-
* @param {string | string[]} [params.locales=['en']] - The languages to use for formatting.
|
264
|
-
* @param {Intl.DateTimeFormatOptions} [params.options={}] - Additional options for date formatting.
|
265
|
-
* @returns {string} The formatted date.
|
266
|
-
*/
|
267
|
-
export declare function formatDateTime(date: Date, options?: {
|
268
|
-
locales?: string | string[];
|
269
|
-
} & Intl.DateTimeFormatOptions): string;
|
270
|
-
/**
|
271
|
-
* Formats a currency value according to the specified languages, currency, and options.
|
272
|
-
* @param {Object} params - The parameters for the currency formatting.
|
273
|
-
* @param {number} params.value - The currency value to format.
|
274
|
-
* @param {string} params.currency - The currency code (e.g., 'USD').
|
275
|
-
* @param {string | string[]} [params.locales=['en']] - The locale codes to use for formatting.
|
276
|
-
* @param {Intl.NumberFormatOptions} [params.options={}] - Additional options for currency formatting.
|
277
|
-
* @returns {string} The formatted currency value.
|
278
|
-
*/
|
279
|
-
export declare function formatCurrency(value: number, currency: string, options?: {
|
280
|
-
locales?: string | string[];
|
281
|
-
} & Intl.NumberFormatOptions): string;
|
282
|
-
/**
|
283
|
-
* Formats a list of items according to the specified locales and options.
|
284
|
-
* @param {Object} params - The parameters for the list formatting.
|
285
|
-
* @param {Array<string | number>} params.value - The list of items to format.
|
286
|
-
* @param {string | string[]} [params.locales=['en']] - The locales to use for formatting.
|
287
|
-
* @param {Intl.ListFormatOptions} [params.options={}] - Additional options for list formatting.
|
288
|
-
* @returns {string} The formatted list.
|
289
|
-
*/
|
290
|
-
export declare function formatList(array: Array<string | number>, options: {
|
291
|
-
locales?: string | string[];
|
292
|
-
} & Intl.ListFormatOptions): string;
|
293
|
-
/**
|
294
|
-
* Formats a relative time value according to the specified locales and options.
|
295
|
-
* @param {Object} params - The parameters for the relative time formatting.
|
296
|
-
* @param {number} params.value - The relative time value to format.
|
297
|
-
* @param {Intl.RelativeTimeFormatUnit} params.unit - The unit of time (e.g., 'second', 'minute', 'hour', 'day', 'week', 'month', 'year').
|
298
|
-
* @param {string | string[]} [params.locales=['en']] - The locales to use for formatting.
|
299
|
-
* @param {Intl.RelativeTimeFormatOptions} [params.options={}] - Additional options for relative time formatting.
|
300
|
-
* @returns {string} The formatted relative time string.
|
301
|
-
*/
|
302
|
-
export declare function formatRelativeTime(value: number, unit: Intl.RelativeTimeFormatUnit, options: {
|
303
|
-
locales?: string | string[];
|
304
|
-
} & Intl.RelativeTimeFormatOptions): string;
|
305
|
-
/**
|
306
|
-
* Splits a string into an array of text and variable objects.
|
307
|
-
* @param {string} string - The input string to split.
|
308
|
-
* @returns {Content} - An array containing strings and variables.
|
309
|
-
*/
|
310
|
-
export declare function splitStringToContent(string: string): Content;
|
311
|
-
/**
|
312
|
-
* Renders content to a string by replacing variables with their formatted values.
|
313
|
-
* @param {Content} content - The content to render.
|
314
|
-
* @param {string | string[]} [locales='en'] - The locale(s) to use for formatting.
|
315
|
-
* @param {Record<string, any>} [variables={}] - An object containing variable values.
|
316
|
-
* @param {Record<string, any>} [variableOptions={}] - An object containing options for formatting variables.
|
317
|
-
* @returns {string} - The rendered string with variables replaced by their formatted values.
|
318
|
-
*/
|
319
|
-
export declare function renderContentToString(content: Content, locales?: string | string[], variables?: Record<string, any>, variableOptions?: Record<string, any>): string;
|
320
|
-
/**
|
321
|
-
* Determines the best matching locale from the provided approved locales list.
|
322
|
-
* @param {string | string[]} locales - A single locale or an array of locales sorted in preference order.
|
323
|
-
* @param {string[]} approvedLocales - An array of approved locales, also sorted by preference.
|
324
|
-
* @returns {string | undefined} - The best matching locale from the approvedLocales list, or undefined if no match is found.
|
325
|
-
*/
|
326
|
-
export declare function determineLocale(locales: string | string[], approvedLocales: string[]): string | undefined;
|
327
|
-
/**
|
328
|
-
* Determines whether a translation is required based on the source and target locales.
|
329
|
-
*
|
330
|
-
* - If the target locale is not specified, the function returns `false`, as translation is not needed.
|
331
|
-
* - If the source and target locale are the same, returns `false`, indicating that no translation is necessary.
|
332
|
-
* - If the `approvedLocales` array is provided, and the target locale is not within that array, the function also returns `false`.
|
333
|
-
* - Otherwise, it returns `true`, meaning that a translation is required.
|
334
|
-
*
|
335
|
-
* @param {string} sourceLocale - The locale code for the original content (BCP 47 locale code).
|
336
|
-
* @param {string} targetLocale - The locale code of the language to translate the content into (BCP 47 locale code).
|
337
|
-
* @param {string[]} [approvedLocale] - An optional array of approved target locales.
|
338
|
-
*
|
339
|
-
* @returns {boolean} - Returns `true` if translation is required, otherwise `false`.
|
340
|
-
*/
|
341
|
-
export declare function requiresTranslation(sourceLocale: string, targetLocale: string, approvedLocales?: string[]): boolean;
|
342
516
|
export {};
|