generaltranslation 8.2.6 → 8.2.8

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (162) hide show
  1. package/CHANGELOG.md +14 -0
  2. package/dist/ApiError-4zIP-twr.cjs +24 -0
  3. package/dist/ApiError-4zIP-twr.cjs.map +1 -0
  4. package/dist/ApiError-Bv7vlzyQ.mjs +19 -0
  5. package/dist/ApiError-Bv7vlzyQ.mjs.map +1 -0
  6. package/dist/errors.cjs +3 -0
  7. package/dist/errors.d.cts +11 -0
  8. package/dist/errors.d.mts +11 -0
  9. package/dist/errors.mjs +2 -0
  10. package/dist/id-CPbVYREY.mjs +74 -0
  11. package/dist/id-CPbVYREY.mjs.map +1 -0
  12. package/dist/id-VXBgyXu2.cjs +89 -0
  13. package/dist/id-VXBgyXu2.cjs.map +1 -0
  14. package/dist/id.cjs +5 -0
  15. package/dist/{id/hashSource.d.ts → id.d.cts} +20 -5
  16. package/dist/id.d.mts +40 -0
  17. package/dist/id.mjs +2 -0
  18. package/dist/index.cjs +3491 -0
  19. package/dist/index.cjs.map +1 -0
  20. package/dist/index.d.cts +1219 -0
  21. package/dist/index.d.mts +1219 -0
  22. package/dist/index.mjs +3441 -0
  23. package/dist/index.mjs.map +1 -0
  24. package/dist/internal-B3QbyI_5.mjs +820 -0
  25. package/dist/internal-B3QbyI_5.mjs.map +1 -0
  26. package/dist/internal-DIHQF9gs.cjs +1070 -0
  27. package/dist/internal-DIHQF9gs.cjs.map +1 -0
  28. package/dist/internal.cjs +45 -0
  29. package/dist/{internal.d.ts → internal.d.cts} +82 -113
  30. package/dist/internal.d.mts +263 -0
  31. package/dist/internal.mjs +3 -0
  32. package/dist/sha2-DKowBr6H.cjs +747 -0
  33. package/dist/sha2-DKowBr6H.cjs.map +1 -0
  34. package/dist/stableStringify-DgDlE_pD.mjs +53 -0
  35. package/dist/stableStringify-DgDlE_pD.mjs.map +1 -0
  36. package/dist/types-BJdoI1d1.d.cts +741 -0
  37. package/dist/types-DazaDJbs.d.mts +741 -0
  38. package/dist/types.cjs +17 -0
  39. package/dist/types.cjs.map +1 -0
  40. package/dist/types.d.cts +2 -0
  41. package/dist/types.d.mts +2 -0
  42. package/dist/types.mjs +16 -0
  43. package/dist/types.mjs.map +1 -0
  44. package/package.json +52 -32
  45. package/dist/backwards-compatability/dataConversion.d.ts +0 -23
  46. package/dist/backwards-compatability/oldHashJsxChildren.d.ts +0 -23
  47. package/dist/backwards-compatability/oldTypes.d.ts +0 -21
  48. package/dist/backwards-compatability/typeChecking.d.ts +0 -21
  49. package/dist/cache/IntlCache.d.ts +0 -26
  50. package/dist/cache/types.d.ts +0 -32
  51. package/dist/derive/condenseVars.d.ts +0 -7
  52. package/dist/derive/declareVar.d.ts +0 -26
  53. package/dist/derive/decodeVars.d.ts +0 -9
  54. package/dist/derive/derive.d.ts +0 -38
  55. package/dist/derive/extractVars.d.ts +0 -9
  56. package/dist/derive/index.d.ts +0 -7
  57. package/dist/derive/indexVars.d.ts +0 -6
  58. package/dist/derive/utils/constants.d.ts +0 -2
  59. package/dist/derive/utils/regex.d.ts +0 -2
  60. package/dist/derive/utils/sanitizeVar.d.ts +0 -12
  61. package/dist/derive/utils/traverseHelpers.d.ts +0 -4
  62. package/dist/derive/utils/traverseIcu.d.ts +0 -20
  63. package/dist/derive/utils/types.d.ts +0 -23
  64. package/dist/errors/ApiError.d.ts +0 -7
  65. package/dist/errors/formattingErrors.d.ts +0 -1
  66. package/dist/errors.cjs.min.cjs +0 -2
  67. package/dist/errors.cjs.min.cjs.map +0 -1
  68. package/dist/errors.d.ts +0 -9
  69. package/dist/errors.esm.min.mjs +0 -2
  70. package/dist/errors.esm.min.mjs.map +0 -1
  71. package/dist/formatting/custom-formats/CutoffFormat/CutoffFormat.d.ts +0 -59
  72. package/dist/formatting/custom-formats/CutoffFormat/constants.d.ts +0 -4
  73. package/dist/formatting/custom-formats/CutoffFormat/types.d.ts +0 -48
  74. package/dist/formatting/format.d.ts +0 -1
  75. package/dist/id/hashTemplate.d.ts +0 -4
  76. package/dist/id/types.d.ts +0 -7
  77. package/dist/id.cjs.min.cjs +0 -2
  78. package/dist/id.cjs.min.cjs.map +0 -1
  79. package/dist/id.d.ts +0 -86
  80. package/dist/id.esm.min.mjs +0 -2
  81. package/dist/id.esm.min.mjs.map +0 -1
  82. package/dist/index.cjs.min.cjs +0 -2
  83. package/dist/index.cjs.min.cjs.map +0 -1
  84. package/dist/index.d.ts +0 -1627
  85. package/dist/index.esm.min.mjs +0 -2
  86. package/dist/index.esm.min.mjs.map +0 -1
  87. package/dist/internal.cjs.min.cjs +0 -2
  88. package/dist/internal.cjs.min.cjs.map +0 -1
  89. package/dist/internal.esm.min.mjs +0 -2
  90. package/dist/internal.esm.min.mjs.map +0 -1
  91. package/dist/locales/customLocaleMapping.d.ts +0 -11
  92. package/dist/locales/determineLocale.d.ts +0 -1
  93. package/dist/locales/getLocaleDirection.d.ts +0 -1
  94. package/dist/locales/getLocaleEmoji.d.ts +0 -2
  95. package/dist/locales/getLocaleName.d.ts +0 -1
  96. package/dist/locales/getLocaleProperties.d.ts +0 -32
  97. package/dist/locales/getPluralForm.d.ts +0 -9
  98. package/dist/locales/getRegionProperties.d.ts +0 -7
  99. package/dist/locales/isSameDialect.d.ts +0 -1
  100. package/dist/locales/isSameLanguage.d.ts +0 -1
  101. package/dist/locales/isSupersetLocale.d.ts +0 -1
  102. package/dist/locales/isValidLocale.d.ts +0 -1
  103. package/dist/locales/requiresTranslation.d.ts +0 -1
  104. package/dist/locales/resolveAliasLocale.d.ts +0 -8
  105. package/dist/locales/resolveCanonicalLocale.d.ts +0 -8
  106. package/dist/logging/errors.d.ts +0 -10
  107. package/dist/logging/logger.d.ts +0 -117
  108. package/dist/logging/warnings.d.ts +0 -2
  109. package/dist/projects/getProjectData.d.ts +0 -1
  110. package/dist/settings/plurals.d.ts +0 -3
  111. package/dist/settings/settings.d.ts +0 -2
  112. package/dist/settings/settingsUrls.d.ts +0 -3
  113. package/dist/translate/api.d.ts +0 -1
  114. package/dist/translate/awaitJobs.d.ts +0 -19
  115. package/dist/translate/checkJobStatus.d.ts +0 -8
  116. package/dist/translate/createBranch.d.ts +0 -10
  117. package/dist/translate/createTag.d.ts +0 -19
  118. package/dist/translate/downloadFileBatch.d.ts +0 -1
  119. package/dist/translate/enqueueFiles.d.ts +0 -8
  120. package/dist/translate/getOrphanedFiles.d.ts +0 -8
  121. package/dist/translate/processFileMoves.d.ts +0 -25
  122. package/dist/translate/publishFiles.d.ts +0 -17
  123. package/dist/translate/queryBranchData.d.ts +0 -3
  124. package/dist/translate/queryFileData.d.ts +0 -42
  125. package/dist/translate/querySourceFile.d.ts +0 -1
  126. package/dist/translate/setupProject.d.ts +0 -11
  127. package/dist/translate/submitUserEditDiffs.d.ts +0 -12
  128. package/dist/translate/translateMany.d.ts +0 -1
  129. package/dist/translate/uploadSourceFiles.d.ts +0 -1
  130. package/dist/translate/uploadTranslations.d.ts +0 -1
  131. package/dist/translate/utils/apiRequest.d.ts +0 -1
  132. package/dist/translate/utils/batch.d.ts +0 -52
  133. package/dist/translate/utils/fetchWithTimeout.d.ts +0 -1
  134. package/dist/translate/utils/generateRequestHeaders.d.ts +0 -2
  135. package/dist/translate/utils/handleFetchError.d.ts +0 -1
  136. package/dist/translate/utils/validateResponse.d.ts +0 -1
  137. package/dist/types-dir/api/branch.d.ts +0 -10
  138. package/dist/types-dir/api/checkFileTranslations.d.ts +0 -37
  139. package/dist/types-dir/api/downloadFile.d.ts +0 -3
  140. package/dist/types-dir/api/downloadFileBatch.d.ts +0 -34
  141. package/dist/types-dir/api/enqueueEntries.d.ts +0 -21
  142. package/dist/types-dir/api/enqueueFiles.d.ts +0 -56
  143. package/dist/types-dir/api/entry.d.ts +0 -36
  144. package/dist/types-dir/api/fetchTranslations.d.ts +0 -11
  145. package/dist/types-dir/api/file.d.ts +0 -54
  146. package/dist/types-dir/api/project.d.ts +0 -7
  147. package/dist/types-dir/api/translate.d.ts +0 -34
  148. package/dist/types-dir/api/translateMany.d.ts +0 -5
  149. package/dist/types-dir/api/translationStatus.d.ts +0 -9
  150. package/dist/types-dir/api/uploadFiles.d.ts +0 -43
  151. package/dist/types-dir/jsx/content.d.ts +0 -61
  152. package/dist/types-dir/jsx/variables.d.ts +0 -9
  153. package/dist/types-dir/transformations.d.ts +0 -8
  154. package/dist/types.cjs.min.cjs +0 -2
  155. package/dist/types.cjs.min.cjs.map +0 -1
  156. package/dist/types.d.ts +0 -652
  157. package/dist/types.esm.min.mjs +0 -2
  158. package/dist/types.esm.min.mjs.map +0 -1
  159. package/dist/utils/base64.d.ts +0 -2
  160. package/dist/utils/isVariable.d.ts +0 -2
  161. package/dist/utils/minify.d.ts +0 -2
  162. package/dist/utils/stableStringify.d.ts +0 -1
package/dist/index.d.ts DELETED
@@ -1,1627 +0,0 @@
1
- type CustomMapping = Record<string, string | Partial<LocaleProperties>>;
2
-
3
- type LocaleProperties = {
4
- code: string;
5
- name: string;
6
- nativeName: string;
7
- languageCode: string;
8
- languageName: string;
9
- nativeLanguageName: string;
10
- nameWithRegionCode: string;
11
- nativeNameWithRegionCode: string;
12
- regionCode: string;
13
- regionName: string;
14
- nativeRegionName: string;
15
- scriptCode: string;
16
- scriptName: string;
17
- nativeScriptName: string;
18
- maximizedCode: string;
19
- maximizedName: string;
20
- nativeMaximizedName: string;
21
- minimizedCode: string;
22
- minimizedName: string;
23
- nativeMinimizedName: string;
24
- emoji: string;
25
- };
26
-
27
- type VariableType = 'v' | 'n' | 'd' | 'c' | 'rt';
28
- /**
29
- * Variables are used to store the variable name and type.
30
- */
31
- type Variable = {
32
- k: string;
33
- i?: number;
34
- v?: VariableType;
35
- };
36
-
37
- /**
38
- * Map of data-_gt properties to their corresponding React props
39
- */
40
- declare const HTML_CONTENT_PROPS: {
41
- readonly pl: "placeholder";
42
- readonly ti: "title";
43
- readonly alt: "alt";
44
- readonly arl: "aria-label";
45
- readonly arb: "aria-labelledby";
46
- readonly ard: "aria-describedby";
47
- };
48
- type HtmlContentPropKeysRecord = Partial<Record<keyof typeof HTML_CONTENT_PROPS, string>>;
49
- /**
50
- * GTProp is an internal property used to contain data for translating and rendering elements.
51
- * note, transformations are only read on the server side if they are 'plural' or 'branch'
52
- */
53
- type GTProp = {
54
- b?: Record<string, JsxChildren>;
55
- t?: 'p' | 'b';
56
- } & HtmlContentPropKeysRecord;
57
- type JsxElement = {
58
- t?: string;
59
- i?: number;
60
- d?: GTProp;
61
- c?: JsxChildren;
62
- };
63
- type JsxChild = string | JsxElement | Variable;
64
- /**
65
- * The format of the string content
66
- */
67
- type StringFormat = 'ICU' | 'I18NEXT' | 'STRING';
68
- /**
69
- * The format of the content
70
- */
71
- type DataFormat = 'JSX' | StringFormat;
72
- /**
73
- * String format content
74
- */
75
- type StringContent = IcuMessage | StringMessage | I18nextMessage;
76
- /**
77
- * A content type representing JSX, ICU, and I18next messages
78
- */
79
- type Content = JsxChildren | StringContent;
80
- /**
81
- * A content type representing JSX elements
82
- */
83
- type JsxChildren = JsxChild | JsxChild[];
84
- /**
85
- * A content type representing ICU messages
86
- */
87
- type IcuMessage = string;
88
- /**
89
- * A content type representing I18next messages
90
- */
91
- type I18nextMessage = string;
92
- /**
93
- * A content type representing plain strings
94
- */
95
- type StringMessage = string;
96
-
97
- /**
98
- * ActionType is the type of action to perform on the request.
99
- *
100
- * @param fast - The fast action type (mini model).
101
- */
102
- type ActionType = 'fast';
103
- /**
104
- * EntryMetadata is the metadata for a GTRequest.
105
- *
106
- * @param context - The context of the request.
107
- * @param id - The id of the request.
108
- * @param maxChars - The maxChars of the request.
109
- * @param hash - The hash of the request.
110
- */
111
- type EntryMetadata = {
112
- id?: string;
113
- hash?: string;
114
- context?: string;
115
- maxChars?: number;
116
- dataFormat?: DataFormat;
117
- actionType?: ActionType;
118
- };
119
- type TranslateOptions = {
120
- targetLocale: string;
121
- sourceLocale?: string;
122
- modelProvider?: string;
123
- };
124
- /**
125
- * TranslateManyEntry is the input type for translateMany.
126
- * Can be a plain string or an object with source and entry metadata fields.
127
- */
128
- type TranslateManyEntry = string | {
129
- source: Content;
130
- metadata?: EntryMetadata;
131
- };
132
-
133
- type CheckFileTranslationsOptions = {
134
- timeout?: number;
135
- };
136
- type FileQuery = {
137
- fileId: string;
138
- branchId?: string;
139
- versionId?: string;
140
- };
141
- type FileQueryResult = {
142
- sourceFile: {
143
- id: string;
144
- fileId: string;
145
- versionId: string;
146
- sourceLocale: string;
147
- fileName: string;
148
- fileFormat: string;
149
- dataFormat: string | null;
150
- createdAt: string;
151
- updatedAt: string;
152
- approvalRequiredAt: string | null;
153
- locales: string[];
154
- };
155
- translations: {
156
- locale: string;
157
- completedAt: string | null;
158
- approvedAt: string | null;
159
- publishedAt: string | null;
160
- createdAt: string | null;
161
- updatedAt: string | null;
162
- }[];
163
- };
164
-
165
- type EnqueueFilesResult = {
166
- jobData: {
167
- [jobId: string]: {
168
- sourceFileId: string;
169
- fileId: string;
170
- versionId: string;
171
- branchId: string;
172
- targetLocale: string;
173
- projectId: string;
174
- force: boolean;
175
- modelProvider?: string;
176
- };
177
- };
178
- locales: string[];
179
- message: string;
180
- };
181
-
182
- type FileFormat = 'GTJSON' | 'JSON' | 'YAML' | 'MDX' | 'MD' | 'TS' | 'JS' | 'HTML' | 'TXT' | 'TWILIO_CONTENT_JSON';
183
- /**
184
- * File object structure for referencing files
185
- * @property {string} fileId - The ID of the file
186
- * @property {string} versionId - The ID of the version of the file
187
- * @property {string} branchId - The ID of the branch of the file
188
- * @property {string} locale - The locale of the file (e.g. 'en', 'de', 'es', etc.)
189
- * @property {string} fileName - The name of the file
190
- * @property {FileFormat} fileFormat - The format of the file (JSON, MDX, MD, etc.)
191
- * @property {DataFormat} [dataFormat] - Optional format of the data within the file
192
- */
193
- type FileReference = {
194
- fileId: string;
195
- versionId: string;
196
- branchId: string;
197
- fileName: string;
198
- fileFormat: FileFormat;
199
- dataFormat?: DataFormat;
200
- };
201
- /**
202
- * File reference object structure for referencing files
203
- * @see {@link FileReference}
204
- * @property {string} [branchId] - The ID of the branch of the file
205
- */
206
- type FileReferenceIds = Omit<FileReference, 'branchId' | 'fileName' | 'fileFormat' | 'dataFormat'> & {
207
- branchId?: string;
208
- fileName?: string;
209
- fileFormat?: FileFormat;
210
- dataFormat?: DataFormat;
211
- };
212
-
213
- type DownloadFileBatchRequest = {
214
- fileId: string;
215
- branchId?: string;
216
- versionId?: string;
217
- locale?: string;
218
- useLatestAvailableVersion?: boolean;
219
- }[];
220
- type DownloadFileBatchOptions = {
221
- timeout?: number;
222
- };
223
- type DownloadedFile = {
224
- id: string;
225
- branchId: string;
226
- fileId: string;
227
- versionId: string;
228
- locale?: string;
229
- fileName?: string;
230
- data: string;
231
- metadata: Record<string, any>;
232
- fileFormat: FileFormat;
233
- };
234
- type DownloadFileBatchResult = {
235
- files: DownloadedFile[];
236
- count: number;
237
- };
238
-
239
- type CreateTagFileReference = {
240
- fileId: string;
241
- versionId: string;
242
- branchId: string;
243
- };
244
- type CreateTagOptions = {
245
- tagId: string;
246
- files: CreateTagFileReference[];
247
- message?: string;
248
- };
249
- type CreateTagResult = {
250
- tag: {
251
- id: string;
252
- tagId: string;
253
- message: string | null;
254
- createdAt: string;
255
- updatedAt: string;
256
- };
257
- };
258
-
259
- /**
260
- * Metadata stored alongside GTJSON file entries.
261
- * Keys correspond to the entry id/hash in the GTJSON body.
262
- */
263
- type GTJsonFormatMetadata = Record<string, {
264
- context?: string;
265
- id?: string;
266
- domain?: string;
267
- maxChars?: number;
268
- dataFormat?: 'JSX' | 'ICU' | 'I18NEXT';
269
- requestVersion?: number;
270
- approved_at?: string | null;
271
- approved_by?: string | null;
272
- hash?: string;
273
- staticId?: string;
274
- filePaths?: string[];
275
- }>;
276
- type FileUpload = {
277
- branchId?: string;
278
- incomingBranchId?: string;
279
- checkedOutBranchId?: string;
280
- content: string;
281
- fileName: string;
282
- fileFormat: FileFormat;
283
- dataFormat?: DataFormat;
284
- locale: string;
285
- formatMetadata?: GTJsonFormatMetadata;
286
- versionId?: string;
287
- fileId?: string;
288
- };
289
- type UploadFilesOptions = {
290
- sourceLocale: string;
291
- modelProvider?: string;
292
- timeout?: number;
293
- };
294
- type UploadFilesResponse = {
295
- uploadedFiles: FileReference[];
296
- count: number;
297
- message: string;
298
- };
299
-
300
- type PublishFileEntry = {
301
- fileId: string;
302
- versionId: string;
303
- branchId?: string;
304
- publish: boolean;
305
- fileName?: string;
306
- };
307
- type PublishFilesResult = {
308
- results: {
309
- fileId: string;
310
- versionId: string;
311
- locale?: string;
312
- branchId: string;
313
- success: boolean;
314
- error?: string;
315
- }[];
316
- };
317
-
318
- type DownloadFileOptions = {
319
- timeout?: number;
320
- };
321
-
322
- /**
323
- * TypedResult is a union type that represents the different types of translations that can be returned.
324
- */
325
- type TypedResult = {
326
- translation: JsxChildren;
327
- dataFormat: 'JSX';
328
- } | {
329
- translation: I18nextMessage | IcuMessage | StringMessage;
330
- dataFormat: 'ICU' | 'I18NEXT' | 'STRING';
331
- };
332
- /**
333
- * RequestError is a type that represents an error that occurred during a translation request.
334
- */
335
- type TranslationError = {
336
- success: false;
337
- error: string;
338
- code: number;
339
- };
340
- /**
341
- * RequestSuccess is a type that represents a successful translation request.
342
- */
343
- type RequestSuccess = TypedResult & {
344
- success: true;
345
- locale: string;
346
- };
347
- type TranslationResult = RequestSuccess | TranslationError;
348
-
349
- /**
350
- * BatchTranslationResult is the result of a batch translation request.
351
- */
352
- type TranslateManyResult = TranslationResult[];
353
-
354
- type BranchDataResult = {
355
- branches: {
356
- id: string;
357
- name: string;
358
- }[];
359
- defaultBranch: {
360
- id: string;
361
- name: string;
362
- } | null;
363
- };
364
-
365
- type BranchQuery = {
366
- branchNames: string[];
367
- };
368
-
369
- type FileDataQuery = {
370
- sourceFiles?: {
371
- fileId: string;
372
- versionId: string;
373
- branchId: string;
374
- }[];
375
- translatedFiles?: {
376
- fileId: string;
377
- versionId: string;
378
- branchId: string;
379
- locale: string;
380
- }[];
381
- };
382
- type FileDataResult = {
383
- sourceFiles?: {
384
- branchId: string;
385
- fileId: string;
386
- versionId: string;
387
- fileName: string;
388
- fileFormat: string;
389
- dataFormat: string | null;
390
- createdAt: string;
391
- updatedAt: string;
392
- approvalRequiredAt: string | null;
393
- publishedAt: string | null;
394
- locales: string[];
395
- sourceLocale: string;
396
- }[];
397
- translatedFiles?: {
398
- branchId: string;
399
- fileId: string;
400
- versionId: string;
401
- fileFormat: string;
402
- dataFormat: string | null;
403
- createdAt: string;
404
- updatedAt: string;
405
- approvedAt: string | null;
406
- publishedAt: string | null;
407
- completedAt: string | null;
408
- locale: string;
409
- }[];
410
- };
411
-
412
- type OrphanedFile = {
413
- fileId: string;
414
- versionId: string;
415
- fileName: string;
416
- };
417
- type GetOrphanedFilesResult = {
418
- orphanedFiles: OrphanedFile[];
419
- };
420
-
421
- type MoveMapping = {
422
- oldFileId: string;
423
- newFileId: string;
424
- newFileName: string;
425
- };
426
- type MoveResult = {
427
- oldFileId: string;
428
- newFileId: string;
429
- success: boolean;
430
- newSourceFileId?: string;
431
- clonedTranslationsCount?: number;
432
- error?: string;
433
- };
434
- type ProcessMovesResponse = {
435
- results: MoveResult[];
436
- summary: {
437
- total: number;
438
- succeeded: number;
439
- failed: number;
440
- };
441
- };
442
- type ProcessMovesOptions = {
443
- timeout?: number;
444
- branchId?: string;
445
- };
446
-
447
- type JobStatus = 'queued' | 'processing' | 'completed' | 'failed' | 'unknown';
448
- type CheckJobStatusResult = {
449
- jobId: string;
450
- status: JobStatus;
451
- error?: {
452
- message: string;
453
- };
454
- }[];
455
-
456
- type AwaitJobsOptions = {
457
- /** Polling interval in seconds. Defaults to 5. */
458
- pollingIntervalSeconds?: number;
459
- /** Timeout in seconds. Defaults to 600 (10 minutes). If reached, resolves with whatever status is current. */
460
- timeoutSeconds?: number;
461
- };
462
- type JobResult = {
463
- jobId: string;
464
- status: JobStatus;
465
- error?: {
466
- message: string;
467
- };
468
- };
469
- type AwaitJobsResult = {
470
- /** Whether all jobs completed (none still in progress). */
471
- complete: boolean;
472
- jobs: JobResult[];
473
- };
474
-
475
- type SubmitUserEditDiff = {
476
- fileName: string;
477
- locale: string;
478
- diff: string;
479
- branchId: string;
480
- versionId: string;
481
- fileId: string;
482
- localContent: string;
483
- };
484
- type SubmitUserEditDiffsPayload = {
485
- diffs: SubmitUserEditDiff[];
486
- };
487
-
488
- type FormatVariables = Record<string, string | number | boolean | null | undefined | Date>;
489
-
490
- type SetupProjectResult = {
491
- setupJobId: string;
492
- status: 'queued';
493
- } | {
494
- status: 'completed';
495
- };
496
- type SetupProjectOptions = {
497
- force?: boolean;
498
- locales?: string[];
499
- timeoutMs?: number;
500
- };
501
-
502
- type EnqueueOptions = {
503
- sourceLocale?: string;
504
- targetLocales: string[];
505
- requireApproval?: boolean;
506
- modelProvider?: string;
507
- force?: boolean;
508
- timeout?: number;
509
- };
510
-
511
- type CustomRegionMapping = {
512
- [region: string]: {
513
- name?: string;
514
- emoji?: string;
515
- locale?: string;
516
- };
517
- };
518
-
519
- type ProjectData = {
520
- id: string;
521
- name: string;
522
- orgId: string;
523
- defaultLocale: string;
524
- currentLocales: string[];
525
- };
526
-
527
- type CreateBranchQuery = {
528
- branchName: string;
529
- defaultBranch: boolean;
530
- };
531
- type CreateBranchResult = {
532
- branch: {
533
- id: string;
534
- name: string;
535
- };
536
- };
537
-
538
- /** Type of terminator */
539
- type CutoffFormatStyle = 'none' | 'ellipsis';
540
- /** Terminator options */
541
- interface TerminatorOptions {
542
- /** The terminator to use */
543
- terminator?: string;
544
- /** An optional separator between the terminator and the value */
545
- separator?: string;
546
- }
547
- /** Input formatting options (for constructor) */
548
- interface CutoffFormatOptions extends TerminatorOptions {
549
- /** Cutoff length */
550
- maxChars?: number;
551
- /** Type of terminator */
552
- style?: CutoffFormatStyle;
553
- }
554
-
555
- /**
556
- * Type representing the constructor parameters for the GT class.
557
- * @typedef {Object} GTConstructorParams
558
- * @property {string} [apiKey] - The API key for accessing the translation service
559
- * @property {string} [devApiKey] - The development API key for accessing the translation service
560
- * @property {string} [sourceLocale] - The default source locale for translations
561
- * @property {string} [targetLocale] - The default target locale for translations
562
- * @property {string[]} [locales] - Array of supported locales
563
- * @property {string} [projectId] - The project ID for the translation service
564
- * @property {string} [baseUrl] - The base URL for the translation service
565
- * @property {CustomMapping} [customMapping] - Custom mapping of locale codes to their names
566
- */
567
- type GTConstructorParams = {
568
- apiKey?: string;
569
- devApiKey?: string;
570
- sourceLocale?: string;
571
- targetLocale?: string;
572
- locales?: string[];
573
- projectId?: string;
574
- baseUrl?: string;
575
- customMapping?: CustomMapping;
576
- };
577
- /**
578
- * GT is the core driver for the General Translation library.
579
- * This class provides functionality for locale management, formatting, and translation operations.
580
- *
581
- * @class GT
582
- * @description A comprehensive toolkit for handling internationalization and localization.
583
- *
584
- * @example
585
- * const gt = new GT({
586
- * sourceLocale: 'en-US',
587
- * targetLocale: 'es-ES',
588
- * locales: ['en-US', 'es-ES', 'fr-FR']
589
- * });
590
- */
591
- declare class GT {
592
- /** Base URL for the translation service API */
593
- baseUrl?: string;
594
- /** Project ID for the translation service */
595
- projectId?: string;
596
- /** API key for accessing the translation service */
597
- apiKey?: string;
598
- /** Development API key for accessing the translation service */
599
- devApiKey?: string;
600
- /** Source locale for translations */
601
- sourceLocale?: string;
602
- /** Target locale for translations */
603
- targetLocale?: string;
604
- /** Array of supported locales */
605
- locales?: string[];
606
- /** Array of locales used for rendering variables */
607
- _renderingLocales: string[];
608
- /** Custom mapping for locale codes to their names */
609
- customMapping?: CustomMapping;
610
- /** Lazily derived reverse custom mapping for alias locales */
611
- reverseCustomMapping?: Record<string, string>;
612
- /** Lazily derived custom mapping for regions */
613
- customRegionMapping?: CustomRegionMapping;
614
- /**
615
- * Constructs an instance of the GT class.
616
- *
617
- * @param {GTConstructorParams} [params] - The parameters for initializing the GT instance
618
- * @throws {Error} If an invalid locale is provided
619
- * @throws {Error} If any of the provided locales are invalid
620
- *
621
- * @example
622
- * const gt = new GT({
623
- * apiKey: 'your-api-key',
624
- * sourceLocale: 'en-US',
625
- * targetLocale: 'es-ES',
626
- * locales: ['en-US', 'es-ES', 'fr-FR']
627
- * });
628
- */
629
- constructor(params?: GTConstructorParams);
630
- setConfig({ apiKey, devApiKey, sourceLocale, targetLocale, locales, projectId, customMapping, baseUrl, }: GTConstructorParams): void;
631
- private _getTranslationConfig;
632
- private _validateAuth;
633
- /**
634
- * Queries branch information from the API.
635
- *
636
- * @param {BranchQuery} query - Object mapping the current branch and incoming branches
637
- * @returns {Promise<BranchDataResult>} The branch information
638
- */
639
- queryBranchData(query: BranchQuery): Promise<BranchDataResult>;
640
- /**
641
- * Creates a new branch in the API. If the branch already exists, it will be returned.
642
- *
643
- * @param {CreateBranchQuery} query - Object mapping the branch name and default branch flag
644
- * @returns {Promise<CreateBranchResult>} The created branch information
645
- */
646
- createBranch(query: CreateBranchQuery): Promise<CreateBranchResult>;
647
- /**
648
- * Processes file moves by cloning source files and translations with new fileIds.
649
- * This is called when files have been moved/renamed and we want to preserve translations.
650
- *
651
- * @param {MoveMapping[]} moves - Array of move mappings (old fileId to new fileId)
652
- * @param {ProcessMovesOptions} options - Options including branchId and timeout
653
- * @returns {Promise<ProcessMovesResponse>} The move processing results
654
- *
655
- * @example
656
- * const result = await gt.processFileMoves([
657
- * { oldFileId: 'abc123', newFileId: 'def456', newFileName: 'locales/en.json' }
658
- * ], { branchId: 'main' });
659
- */
660
- processFileMoves(moves: MoveMapping[], options?: ProcessMovesOptions): Promise<ProcessMovesResponse>;
661
- /**
662
- * Gets orphaned files for a branch - files that exist on the branch
663
- * but whose fileIds are not in the provided list.
664
- * Used for move detection.
665
- *
666
- * @param {string} branchId - The branch to check for orphaned files
667
- * @param {string[]} fileIds - List of current file IDs (files that are NOT orphaned)
668
- * @param {Object} options - Options including timeout
669
- * @returns {Promise<GetOrphanedFilesResult>} The orphaned files
670
- *
671
- * @example
672
- * const result = await gt.getOrphanedFiles('branch-id', ['file-1', 'file-2']);
673
- */
674
- getOrphanedFiles(branchId: string, fileIds: string[], options?: {
675
- timeout?: number;
676
- }): Promise<GetOrphanedFilesResult>;
677
- /**
678
- * Enqueues project setup job using the specified file references
679
- *
680
- * This method creates setup jobs that will process source file references
681
- * and generate a project setup. The files parameter contains references (IDs) to source
682
- * files that have already been uploaded via uploadSourceFiles. The setup jobs are queued
683
- * for processing and will generate a project setup based on the source files.
684
- *
685
- * @param {FileReference[]} files - Array of file references containing IDs of previously uploaded source files
686
- * @param {SetupProjectOptions} [options] - Optional settings for target locales and timeout
687
- * @returns {Promise<SetupProjectResult>} Object containing the jobId and status
688
- */
689
- setupProject(files: FileReference[], options?: SetupProjectOptions): Promise<SetupProjectResult>;
690
- /**
691
- * Checks the current status of one or more project jobs by their unique identifiers.
692
- *
693
- * This method polls the API to determine whether one or more jobs are still running,
694
- * have completed successfully, or have failed. Jobs are created after calling either enqueueFiles or setupProject.
695
- *
696
- * @param {string[]} jobIds - The unique identifiers of the jobs to check
697
- * @param {number} [timeoutMs] - Optional timeout in milliseconds for the API request
698
- * @returns {Promise<CheckJobStatusResult>} Object containing the job status
699
- *
700
- * @example
701
- * const result = await gt.checkJobStatus([
702
- * 'job-123',
703
- * 'job-456',
704
- * ], {
705
- * timeout: 10000,
706
- * });
707
- */
708
- checkJobStatus(jobIds: string[], timeoutMs?: number): Promise<CheckJobStatusResult>;
709
- /**
710
- * Polls job statuses until all jobs from enqueueFiles are finished or the timeout is reached.
711
- *
712
- * @param {EnqueueFilesResult} enqueueResult - The result returned from enqueueFiles
713
- * @param {AwaitJobsOptions} [options] - Polling configuration (interval, timeout)
714
- * @returns {Promise<AwaitJobsResult>} The final status of all jobs and whether they all completed
715
- */
716
- awaitJobs(enqueueResult: EnqueueFilesResult, options?: AwaitJobsOptions): Promise<AwaitJobsResult>;
717
- /**
718
- * Enqueues translation jobs for previously uploaded source files.
719
- *
720
- * This method creates translation jobs that will process existing source files
721
- * and generate translations in the specified target languages. The files parameter
722
- * contains references (IDs) to source files that have already been uploaded via
723
- * uploadSourceFiles. The translation jobs are queued for processing and will
724
- * generate translated content based on the source files and target locales provided.
725
- *
726
- * @param {FileReferenceIds[]} files - Array of file references containing IDs of previously uploaded source files
727
- * @param {EnqueueOptions} options - Configuration options including source locale, target locales, and job settings
728
- * @returns {Promise<EnqueueFilesResult>} Result containing job IDs, queue status, and processing information
729
- */
730
- enqueueFiles(files: FileReferenceIds[], options: EnqueueOptions): Promise<EnqueueFilesResult>;
731
- /**
732
- * Creates or upserts a file tag, associating a set of source files
733
- * with a user-defined tag ID and optional message.
734
- *
735
- * @param {CreateTagOptions} options - Tag creation options including tagId, sourceFileIds, and optional message
736
- * @returns {Promise<CreateTagResult>} The created or updated tag
737
- */
738
- createTag(options: CreateTagOptions): Promise<CreateTagResult>;
739
- /**
740
- * Publishes or unpublishes files on the CDN.
741
- *
742
- * @param {PublishFileEntry[]} files - Array of file entries with publish flags
743
- * @returns {Promise<PublishFilesResult>} Result containing per-file success/failure
744
- */
745
- publishFiles(files: PublishFileEntry[]): Promise<PublishFilesResult>;
746
- /**
747
- * Submits user edit diffs for existing translations so future generations preserve user intent.
748
- *
749
- * @param {SubmitUserEditDiffsPayload} payload - Project-scoped diff payload.
750
- * @returns {Promise<void>} Resolves when submission succeeds.
751
- */
752
- submitUserEditDiffs(payload: SubmitUserEditDiffsPayload): Promise<void>;
753
- /**
754
- * Queries data about one or more source or translation files.
755
- *
756
- * @param {FileDataQuery} data - Object mapping source and translation file information.
757
- * @param {CheckFileTranslationsOptions} options - Options for the API call.
758
- * @returns {Promise<FileDataResult>} The source and translation file data information.
759
- *
760
- * @example
761
- * const result = await gt.queryFileData({
762
- * sourceFiles: [
763
- * { fileId: '1234567890', versionId: '1234567890', branchId: '1234567890' },
764
- * ],
765
- * translatedFiles: [
766
- * { fileId: '1234567890', versionId: '1234567890', branchId: '1234567890', locale: 'es-ES' },
767
- * ],
768
- * }, {
769
- * timeout: 10000,
770
- * });
771
- *
772
- */
773
- queryFileData(data: FileDataQuery, options?: CheckFileTranslationsOptions): Promise<FileDataResult>;
774
- /**
775
- * Gets source and translation information for a given file ID and version ID.
776
- *
777
- * @param {FileQuery} data - File query containing file ID and version ID.
778
- * @param {CheckFileTranslationsOptions} options - Options for getting source and translation information.
779
- * @returns {Promise<FileQueryResult>} The source file and translation information.
780
- *
781
- * @example
782
- * const result = await gt.querySourceFile(
783
- * { fileId: '1234567890', versionId: '1234567890' },
784
- * { timeout: 10000 }
785
- * );
786
- *
787
- */
788
- querySourceFile(data: FileQuery, options?: CheckFileTranslationsOptions): Promise<FileQueryResult>;
789
- /**
790
- * Get project data for a given project ID.
791
- *
792
- * @param {string} projectId - The ID of the project to get the data for.
793
- * @returns {Promise<ProjectData>} The project data.
794
- *
795
- * @example
796
- * const result = await gt.getProjectData(
797
- * '1234567890'
798
- * );
799
- *
800
- */
801
- getProjectData(projectId: string, options?: {
802
- timeout?: number;
803
- }): Promise<ProjectData>;
804
- /**
805
- * Downloads a single file.
806
- *
807
- * @param file - The file query object.
808
- * @param {string} file.fileId - The ID of the file to download.
809
- * @param {string} [file.branchId] - The ID of the branch to download the file from. If not provided, the default branch will be used.
810
- * @param {string} [file.locale] - The locale to download the file for. If not provided, the source file will be downloaded.
811
- * @param {string} [file.versionId] - The version ID to download the file from. If not provided, the latest version will be used.
812
- * @param {DownloadFileOptions} options - Options for downloading the file.
813
- * @returns {Promise<string>} The downloaded file content.
814
- *
815
- * @example
816
- * const result = await gt.downloadFile({
817
- * fileId: '1234567890',
818
- * branchId: '1234567890',
819
- * locale: 'es-ES',
820
- * versionId: '1234567890',
821
- * }, {
822
- * timeout: 10000,
823
- * });
824
- */
825
- downloadFile(file: {
826
- fileId: string;
827
- branchId?: string;
828
- locale?: string;
829
- versionId?: string;
830
- useLatestAvailableVersion?: boolean;
831
- }, options?: DownloadFileOptions): Promise<string>;
832
- /**
833
- * Downloads multiple files in a batch.
834
- *
835
- * @param {DownloadFileBatchRequest} requests - Array of file query objects to download.
836
- * @param {DownloadFileBatchOptions} options - Options for the batch download.
837
- * @returns {Promise<DownloadFileBatchResult>} The batch download results.
838
- *
839
- * @example
840
- * const result = await gt.downloadFileBatch([{
841
- * fileId: '1234567890',
842
- * locale: 'es-ES',
843
- * versionId: '1234567890',
844
- * }], {
845
- * timeout: 10000,
846
- * });
847
- */
848
- downloadFileBatch(requests: DownloadFileBatchRequest, options?: DownloadFileBatchOptions): Promise<DownloadFileBatchResult>;
849
- /**
850
- * Translates a single source string to the target locale.
851
- * Routes through {@link translateMany} under the hood.
852
- *
853
- * @param {string} source - The source string to translate.
854
- * @param {object} options - Translation options including targetLocale and optional entry metadata.
855
- * @returns {Promise<TranslationResult | TranslationError>} The translated content.
856
- *
857
- * @example
858
- * const result = await gt.translate('Hello, world!', { targetLocale: 'es' });
859
- *
860
- * @example
861
- * const result = await gt.translate('Hello, world!', {
862
- * targetLocale: 'es',
863
- * dataFormat: 'ICU',
864
- * context: 'A formal greeting',
865
- * });
866
- */
867
- translate(source: TranslateManyEntry, options: string | TranslateOptions, timeout?: number): Promise<TranslationResult | TranslationError>;
868
- /**
869
- * Translates multiple source strings to the target locale.
870
- * Each entry can be a plain string or an object with source and metadata fields.
871
- *
872
- * @param {TranslateManyEntry[] | Record<string, TranslateManyEntry>} sources - The source entries to translate. Can be an array or a record keyed by hash.
873
- * @param {object} options - Translation options including targetLocale.
874
- * @returns {Promise<TranslateManyResult | Record<string, TranslationResult>>} The translated contents. An array if sources was an array, a record if sources was a record.
875
- *
876
- * @example
877
- * const result = await gt.translateMany(
878
- * ['Hello, world!', 'Goodbye, world!'],
879
- * { targetLocale: 'es' }
880
- * );
881
- *
882
- * @example
883
- * const result = await gt.translateMany(
884
- * [{ source: 'Hello, world!', dataFormat: 'ICU' }],
885
- * { targetLocale: 'es' }
886
- * );
887
- *
888
- * @example
889
- * const result = await gt.translateMany(
890
- * { 'my-hash': 'Hello, world!' },
891
- * { targetLocale: 'es' }
892
- * );
893
- */
894
- translateMany(sources: TranslateManyEntry[], options: string | TranslateOptions, timeout?: number): Promise<TranslateManyResult>;
895
- translateMany(sources: Record<string, TranslateManyEntry>, options: string | TranslateOptions, timeout?: number): Promise<Record<string, TranslationResult>>;
896
- /**
897
- * Uploads source files to the translation service without any translation content.
898
- *
899
- * This method creates or replaces source file entries in your project. Each uploaded
900
- * file becomes a source that can later be translated into target languages. The files
901
- * are processed and stored as base entries that serve as the foundation for generating
902
- * translations through the translation workflow.
903
- *
904
- * @param {Array<{source: FileUpload}>} files - Array of objects containing source file data to upload
905
- * @param {UploadFilesOptions} options - Configuration options including source locale and other upload settings
906
- * @returns {Promise<UploadFilesResponse>} Upload result containing file IDs, version information, and upload status
907
- */
908
- uploadSourceFiles(files: {
909
- source: FileUpload;
910
- }[], options: UploadFilesOptions): Promise<UploadFilesResponse>;
911
- /**
912
- * Uploads translation files that correspond to previously uploaded source files.
913
- *
914
- * This method allows you to provide translated content for existing source files in your project.
915
- * Each translation must reference an existing source file and include the translated content
916
- * along with the target locale information. This is used when you have pre-existing translations
917
- * that you want to upload directly rather than generating them through the translation service.
918
- *
919
- * @param {Array<{source: FileUpload, translations: FileUpload[]}>} files - Array of file objects where:
920
- * - `source`: Reference to the existing source file (contains IDs but no content)
921
- * - `translations`: Array of translated files, each containing content, locale, and reference IDs
922
- * @param {UploadFilesOptions} options - Configuration options including source locale and upload settings
923
- * @returns {Promise<UploadFilesResponse>} Upload result containing translation IDs, status, and processing information
924
- */
925
- uploadTranslations(files: {
926
- source: FileUpload;
927
- translations: FileUpload[];
928
- }[], options: UploadFilesOptions): Promise<UploadFilesResponse>;
929
- /**
930
- * Formats a string with cutoff behavior, applying a terminator when the string exceeds the maximum character limit.
931
- *
932
- * This method uses the GT instance's rendering locales by default for locale-specific terminator selection,
933
- * but can be overridden with custom locales in the options.
934
- *
935
- * @param {string} value - The string value to format with cutoff behavior.
936
- * @param {Object} [options] - Configuration options for cutoff formatting.
937
- * @param {string | string[]} [options.locales] - The locales to use for terminator selection. Defaults to instance's rendering locales.
938
- * @param {number} [options.maxChars] - The maximum number of characters to display.
939
- * - Undefined values are treated as no cutoff.
940
- * - Negative values follow .slice() behavior and terminator will be added before the value.
941
- * - 0 will result in an empty string.
942
- * - If cutoff results in an empty string, no terminator is added.
943
- * @param {CutoffFormatStyle} [options.style='ellipsis'] - The style of the terminator.
944
- * @param {string} [options.terminator] - Optional override the terminator to use.
945
- * @param {string} [options.separator] - Optional override the separator to use between the terminator and the value.
946
- * - If no terminator is provided, then separator is ignored.
947
- * @returns {string} The formatted string with terminator applied if cutoff occurs.
948
- *
949
- * @example
950
- * const gt = new GT({ targetLocale: 'en-US' });
951
- * gt.formatCutoff('Hello, world!', { maxChars: 8 });
952
- * // Returns: 'Hello, w...'
953
- *
954
- * @example
955
- * gt.formatCutoff('Hello, world!', { maxChars: -3 });
956
- * // Returns: '...ld!'
957
- */
958
- formatCutoff(value: string, options?: {
959
- locales?: string | string[];
960
- } & CutoffFormatOptions): string;
961
- /**
962
- * Formats a message according to the specified locales and options.
963
- *
964
- * @param {string} message - The message to format.
965
- * @param {string | string[]} [locales='en'] - The locales to use for formatting.
966
- * @param {FormatVariables} [variables={}] - The variables to use for formatting.
967
- * @param {StringFormat} [dataFormat='ICU'] - The format of the message.
968
- * @returns {string} The formatted message.
969
- *
970
- * @example
971
- * gt.formatMessage('Hello {name}', { name: 'John' });
972
- * // Returns: "Hello John"
973
- *
974
- * gt.formatMessage('Hello {name}', { name: 'John' }, { locales: ['fr'] });
975
- * // Returns: "Bonjour John"
976
- */
977
- formatMessage(message: string, options?: {
978
- locales?: string | string[];
979
- variables?: FormatVariables;
980
- dataFormat?: StringFormat;
981
- }): string;
982
- /**
983
- * Formats a number according to the specified locales and options.
984
- *
985
- * @param {number} number - The number to format
986
- * @param {Object} [options] - Additional options for number formatting
987
- * @param {string | string[]} [options.locales] - The locales to use for formatting
988
- * @param {Intl.NumberFormatOptions} [options] - Additional Intl.NumberFormat options
989
- * @returns {string} The formatted number
990
- *
991
- * @example
992
- * gt.formatNum(1234.56, { style: 'currency', currency: 'USD' });
993
- * // Returns: "$1,234.56"
994
- */
995
- formatNum(number: number, options?: {
996
- locales?: string | string[];
997
- } & Intl.NumberFormatOptions): string;
998
- /**
999
- * Formats a date according to the specified locales and options.
1000
- *
1001
- * @param {Date} date - The date to format
1002
- * @param {Object} [options] - Additional options for date formatting
1003
- * @param {string | string[]} [options.locales] - The locales to use for formatting
1004
- * @param {Intl.DateTimeFormatOptions} [options] - Additional Intl.DateTimeFormat options
1005
- * @returns {string} The formatted date
1006
- *
1007
- * @example
1008
- * gt.formatDateTime(new Date(), { dateStyle: 'full', timeStyle: 'long' });
1009
- * // Returns: "Thursday, March 14, 2024 at 2:30:45 PM GMT-7"
1010
- */
1011
- formatDateTime(date: Date, options?: {
1012
- locales?: string | string[];
1013
- } & Intl.DateTimeFormatOptions): string;
1014
- /**
1015
- * Formats a currency value according to the specified locales and options.
1016
- *
1017
- * @param {number} value - The currency value to format
1018
- * @param {string} currency - The currency code (e.g., 'USD', 'EUR')
1019
- * @param {Object} [options] - Additional options for currency formatting
1020
- * @param {string | string[]} [options.locales] - The locales to use for formatting
1021
- * @param {Intl.NumberFormatOptions} [options] - Additional Intl.NumberFormat options
1022
- * @returns {string} The formatted currency value
1023
- *
1024
- * @example
1025
- * gt.formatCurrency(1234.56, 'USD', { style: 'currency' });
1026
- * // Returns: "$1,234.56"
1027
- */
1028
- formatCurrency(value: number, currency: string, options?: {
1029
- locales?: string | string[];
1030
- } & Intl.NumberFormatOptions): string;
1031
- /**
1032
- * Formats a list of items according to the specified locales and options.
1033
- *
1034
- * @param {Array<string | number>} array - The list of items to format
1035
- * @param {Object} [options] - Additional options for list formatting
1036
- * @param {string | string[]} [options.locales] - The locales to use for formatting
1037
- * @param {Intl.ListFormatOptions} [options] - Additional Intl.ListFormat options
1038
- * @returns {string} The formatted list
1039
- *
1040
- * @example
1041
- * gt.formatList(['apple', 'banana', 'orange'], { type: 'conjunction' });
1042
- * // Returns: "apple, banana, and orange"
1043
- */
1044
- formatList(array: Array<string | number>, options?: {
1045
- locales?: string | string[];
1046
- } & Intl.ListFormatOptions): string;
1047
- /**
1048
- * Formats a list of items according to the specified locales and options.
1049
- * @param {Array<T>} array - The list of items to format
1050
- * @param {Object} [options] - Additional options for list formatting
1051
- * @param {string | string[]} [options.locales] - The locales to use for formatting
1052
- * @param {Intl.ListFormatOptions} [options] - Additional Intl.ListFormat options
1053
- * @returns {Array<T | string>} The formatted list parts
1054
- *
1055
- * @example
1056
- * gt.formatListToParts(['apple', 42, { foo: 'bar' }], { type: 'conjunction', style: 'short', locales: ['en'] });
1057
- * // Returns: ['apple', ', ', 42, ' and ', '{ foo: "bar" }']
1058
- */
1059
- formatListToParts<T>(array: Array<T>, options?: {
1060
- locales?: string | string[];
1061
- } & Intl.ListFormatOptions): Array<T | string>;
1062
- /**
1063
- * Formats a relative time value according to the specified locales and options.
1064
- *
1065
- * @param {number} value - The relative time value to format
1066
- * @param {Intl.RelativeTimeFormatUnit} unit - The unit of time (e.g., 'second', 'minute', 'hour', 'day', 'week', 'month', 'year')
1067
- * @param {Object} options - Additional options for relative time formatting
1068
- * @param {string | string[]} [options.locales] - The locales to use for formatting
1069
- * @param {Intl.RelativeTimeFormatOptions} [options] - Additional Intl.RelativeTimeFormat options
1070
- * @returns {string} The formatted relative time string
1071
- *
1072
- * @example
1073
- * gt.formatRelativeTime(-1, 'day', { locales: ['en-US'], numeric: 'auto' });
1074
- * // Returns: "yesterday"
1075
- */
1076
- formatRelativeTime(value: number, unit: Intl.RelativeTimeFormatUnit, options?: {
1077
- locales?: string | string[];
1078
- } & Omit<Intl.RelativeTimeFormatOptions, 'locales'>): string;
1079
- /**
1080
- * Formats a relative time string from a Date, automatically selecting the best unit.
1081
- *
1082
- * @param {Date} date - The date to format relative to now
1083
- * @param {Object} [options] - Additional options for relative time formatting
1084
- * @param {string | string[]} [options.locales] - The locales to use for formatting
1085
- * @returns {string} The formatted relative time string (e.g., "2 hours ago", "in 3 days")
1086
- *
1087
- * @example
1088
- * gt.formatRelativeTimeFromDate(new Date(Date.now() - 3600000));
1089
- * // Returns: "1 hour ago"
1090
- */
1091
- formatRelativeTimeFromDate(date: Date, options?: {
1092
- locales?: string | string[];
1093
- baseDate?: Date;
1094
- } & Omit<Intl.RelativeTimeFormatOptions, 'locales'>): string;
1095
- /**
1096
- * Retrieves the display name of a locale code using Intl.DisplayNames, returning an empty string if no name is found.
1097
- *
1098
- * @param {string} [locale=this.targetLocale] - A BCP-47 locale code
1099
- * @returns {string} The display name corresponding to the code
1100
- * @throws {Error} If no target locale is provided
1101
- *
1102
- * @example
1103
- * gt.getLocaleName('es-ES');
1104
- * // Returns: "Spanish (Spain)"
1105
- */
1106
- getLocaleName(locale?: string | undefined): string;
1107
- /**
1108
- * Retrieves an emoji based on a given locale code.
1109
- * Uses the locale's region (if present) to select an emoji or falls back on default emojis.
1110
- *
1111
- * @param {string} [locale=this.targetLocale] - A BCP-47 locale code (e.g., 'en-US', 'fr-CA')
1112
- * @returns {string} The emoji representing the locale or its region
1113
- * @throws {Error} If no target locale is provided
1114
- *
1115
- * @example
1116
- * gt.getLocaleEmoji('es-ES');
1117
- * // Returns: "🇪🇸"
1118
- */
1119
- getLocaleEmoji(locale?: string | undefined): string;
1120
- /**
1121
- * Generates linguistic details for a given locale code.
1122
- *
1123
- * This function returns information about the locale,
1124
- * script, and region of a given language code both in a standard form and in a maximized form (with likely script and region).
1125
- * The function provides these names in both your default language and native forms, and an associated emoji.
1126
- *
1127
- * @param {string} [locale=this.targetLocale] - The locale code to get properties for (e.g., "de-AT").
1128
- * @returns {LocaleProperties} - An object containing detailed information about the locale.
1129
- *
1130
- * @property {string} code - The full locale code, e.g., "de-AT".
1131
- * @property {string} name - Language name in the default display language, e.g., "Austrian German".
1132
- * @property {string} nativeName - Language name in the locale's native language, e.g., "Österreichisches Deutsch".
1133
- * @property {string} languageCode - The base language code, e.g., "de".
1134
- * @property {string} languageName - The language name in the default display language, e.g., "German".
1135
- * @property {string} nativeLanguageName - The language name in the native language, e.g., "Deutsch".
1136
- * @property {string} nameWithRegionCode - Language name with region in the default language, e.g., "German (AT)".
1137
- * @property {string} nativeNameWithRegionCode - Language name with region in the native language, e.g., "Deutsch (AT)".
1138
- * @property {string} regionCode - The region code from maximization, e.g., "AT".
1139
- * @property {string} regionName - The region name in the default display language, e.g., "Austria".
1140
- * @property {string} nativeRegionName - The region name in the native language, e.g., "Österreich".
1141
- * @property {string} scriptCode - The script code from maximization, e.g., "Latn".
1142
- * @property {string} scriptName - The script name in the default display language, e.g., "Latin".
1143
- * @property {string} nativeScriptName - The script name in the native language, e.g., "Lateinisch".
1144
- * @property {string} maximizedCode - The maximized locale code, e.g., "de-Latn-AT".
1145
- * @property {string} maximizedName - Maximized locale name with likely script in the default language, e.g., "Austrian German (Latin)".
1146
- * @property {string} nativeMaximizedName - Maximized locale name in the native language, e.g., "Österreichisches Deutsch (Lateinisch)".
1147
- * @property {string} minimizedCode - Minimized locale code, e.g., "de-AT" (or "de" for "de-DE").
1148
- * @property {string} minimizedName - Minimized language name in the default language, e.g., "Austrian German".
1149
- * @property {string} nativeMinimizedName - Minimized language name in the native language, e.g., "Österreichisches Deutsch".
1150
- * @property {string} emoji - The emoji associated with the locale's region, if applicable.
1151
- */
1152
- getLocaleProperties(locale?: string | undefined): LocaleProperties;
1153
- /**
1154
- * Retrieves multiple properties for a given region code, including:
1155
- * - `code`: the original region code
1156
- * - `name`: the localized display name
1157
- * - `emoji`: the associated flag or symbol
1158
- *
1159
- * Behavior:
1160
- * - Accepts ISO 3166-1 alpha-2 or UN M.49 region codes (e.g., `"US"`, `"FR"`, `"419"`).
1161
- * - Uses the instance's `targetLocale` to localize the region name for the user.
1162
- * - If `customMapping` contains a `name` or `emoji` for the region, those override the default values.
1163
- * - Otherwise, uses `Intl.DisplayNames` to get the localized region name, falling back to `libraryDefaultLocale`.
1164
- * - Falls back to the region code as `name` if display name resolution fails.
1165
- * - Falls back to a default emoji if no emoji mapping is found in built-in data or `customMapping`.
1166
- *
1167
- * @param {string} [region=this.getLocaleProperties().regionCode] - The region code to look up (e.g., `"US"`, `"GB"`, `"DE"`).
1168
- * @param {CustomRegionMapping} [customMapping] - Optional mapping of region codes to custom names and/or emojis.
1169
- * @returns {{ code: string, name: string, emoji: string }} An object containing:
1170
- * - `code`: the input region code
1171
- * - `name`: the localized or custom region name
1172
- * - `emoji`: the matching emoji flag or symbol
1173
- *
1174
- * @throws {Error} If no target locale is available to determine region properties.
1175
- *
1176
- * @example
1177
- * const gt = new GT({ targetLocale: 'en-US' });
1178
- * gt.getRegionProperties('US');
1179
- * // => { code: 'US', name: 'United States', emoji: '🇺🇸' }
1180
- *
1181
- * @example
1182
- * const gt = new GT({ targetLocale: 'fr-FR' });
1183
- * gt.getRegionProperties('US');
1184
- * // => { code: 'US', name: 'États-Unis', emoji: '🇺🇸' }
1185
- *
1186
- * @example
1187
- * gt.getRegionProperties('US', { US: { name: 'USA', emoji: '🗽' } });
1188
- * // => { code: 'US', name: 'USA', emoji: '🗽' }
1189
- */
1190
- getRegionProperties(region?: string, customMapping?: CustomRegionMapping): {
1191
- code: string;
1192
- name: string;
1193
- emoji: string;
1194
- };
1195
- /**
1196
- * Determines whether a translation is required based on the source and target locales.
1197
- *
1198
- * @param {string} [sourceLocale=this.sourceLocale] - The locale code for the original content
1199
- * @param {string} [targetLocale=this.targetLocale] - The locale code to translate into
1200
- * @param {string[]} [approvedLocales=this.locales] - Optional array of approved target locales
1201
- * @returns {boolean} True if translation is required, false otherwise
1202
- * @throws {Error} If no source locale is provided
1203
- * @throws {Error} If no target locale is provided
1204
- *
1205
- * @example
1206
- * gt.requiresTranslation('en-US', 'es-ES');
1207
- * // Returns: true
1208
- */
1209
- requiresTranslation(sourceLocale?: string | undefined, targetLocale?: string | undefined, approvedLocales?: string[] | undefined, customMapping?: CustomMapping | undefined): boolean;
1210
- /**
1211
- * Determines the best matching locale from the provided approved locales list.
1212
- *
1213
- * @param {string | string[]} locales - A single locale or array of locales in preference order
1214
- * @param {string[]} [approvedLocales=this.locales] - Array of approved locales in preference order
1215
- * @returns {string | undefined} The best matching locale or undefined if no match is found
1216
- *
1217
- * @example
1218
- * gt.determineLocale(['fr-CA', 'fr-FR'], ['en-US', 'fr-FR', 'es-ES']);
1219
- * // Returns: "fr-FR"
1220
- */
1221
- determineLocale(locales: string | string[], approvedLocales?: string[] | undefined, customMapping?: CustomMapping | undefined): string | undefined;
1222
- /**
1223
- * Gets the text direction for a given locale code.
1224
- *
1225
- * @param {string} [locale=this.targetLocale] - A BCP-47 locale code
1226
- * @returns {'ltr' | 'rtl'} 'rtl' if the locale is right-to-left, otherwise 'ltr'
1227
- * @throws {Error} If no target locale is provided
1228
- *
1229
- * @example
1230
- * gt.getLocaleDirection('ar-SA');
1231
- * // Returns: "rtl"
1232
- */
1233
- getLocaleDirection(locale?: string | undefined): 'ltr' | 'rtl';
1234
- /**
1235
- * Checks if a given BCP 47 locale code is valid.
1236
- *
1237
- * @param {string} [locale=this.targetLocale] - The BCP 47 locale code to validate
1238
- * @param {customMapping} [customMapping=this.customMapping] - The custom mapping to use for validation
1239
- * @returns {boolean} True if the locale code is valid, false otherwise
1240
- * @throws {Error} If no target locale is provided
1241
- *
1242
- * @example
1243
- * gt.isValidLocale('en-US');
1244
- * // Returns: true
1245
- */
1246
- isValidLocale(locale?: string | undefined, customMapping?: CustomMapping | undefined): boolean;
1247
- /**
1248
- * Resolves the canonical locale for a given locale.
1249
- * @param locale - The locale to resolve the canonical locale for
1250
- * @param customMapping - The custom mapping to use for resolving the canonical locale
1251
- * @returns The canonical locale
1252
- */
1253
- resolveCanonicalLocale(locale?: string | undefined, customMapping?: CustomMapping | undefined): string;
1254
- /**
1255
- * Resolves the alias locale for a given locale.
1256
- * @param locale - The locale to resolve the alias locale for
1257
- * @param customMapping - The custom mapping to use for resolving the alias locale
1258
- * @returns The alias locale
1259
- */
1260
- resolveAliasLocale(locale: string, customMapping?: CustomMapping | undefined): string;
1261
- /**
1262
- * Standardizes a BCP 47 locale code to ensure correct formatting.
1263
- *
1264
- * @param {string} [locale=this.targetLocale] - The BCP 47 locale code to standardize
1265
- * @returns {string} The standardized locale code or empty string if invalid
1266
- * @throws {Error} If no target locale is provided
1267
- *
1268
- * @example
1269
- * gt.standardizeLocale('en_us');
1270
- * // Returns: "en-US"
1271
- */
1272
- standardizeLocale(locale?: string | undefined): string;
1273
- /**
1274
- * Checks if multiple BCP 47 locale codes represent the same dialect.
1275
- *
1276
- * @param {...(string | string[])} locales - The BCP 47 locale codes to compare
1277
- * @returns {boolean} True if all codes represent the same dialect, false otherwise
1278
- *
1279
- * @example
1280
- * gt.isSameDialect('en-US', 'en-GB');
1281
- * // Returns: false
1282
- *
1283
- * gt.isSameDialect('en', 'en-US');
1284
- * // Returns: true
1285
- */
1286
- isSameDialect(...locales: (string | string[])[]): boolean;
1287
- /**
1288
- * Checks if multiple BCP 47 locale codes represent the same language.
1289
- *
1290
- * @param {...(string | string[])} locales - The BCP 47 locale codes to compare
1291
- * @returns {boolean} True if all codes represent the same language, false otherwise
1292
- *
1293
- * @example
1294
- * gt.isSameLanguage('en-US', 'en-GB');
1295
- * // Returns: true
1296
- */
1297
- isSameLanguage(...locales: (string | string[])[]): boolean;
1298
- /**
1299
- * Checks if a locale is a superset of another locale.
1300
- *
1301
- * @param {string} superLocale - The locale to check if it is a superset
1302
- * @param {string} subLocale - The locale to check if it is a subset
1303
- * @returns {boolean} True if superLocale is a superset of subLocale, false otherwise
1304
- *
1305
- * @example
1306
- * gt.isSupersetLocale('en', 'en-US');
1307
- * // Returns: true
1308
- *
1309
- * gt.isSupersetLocale('en-US', 'en');
1310
- * // Returns: false
1311
- */
1312
- isSupersetLocale(superLocale: string, subLocale: string): boolean;
1313
- }
1314
- /**
1315
- * Formats a string with cutoff behavior, applying a terminator when the string exceeds the maximum character limit.
1316
- *
1317
- * This standalone function provides cutoff formatting functionality without requiring a GT instance.
1318
- * The locales parameter is required for proper terminator selection based on the target language.
1319
- *
1320
- * @param {string} value - The string value to format with cutoff behavior.
1321
- * @param {Object} [options] - Configuration options for cutoff formatting.
1322
- * @param {string | string[]} [options.locales] - The locales to use for terminator selection.
1323
- * @param {number} [options.maxChars] - The maximum number of characters to display.
1324
- * - Undefined values are treated as no cutoff.
1325
- * - Negative values follow .slice() behavior and terminator will be added before the value.
1326
- * - 0 will result in an empty string.
1327
- * - If cutoff results in an empty string, no terminator is added.
1328
- * @param {CutoffFormatStyle} [options.style='ellipsis'] - The style of the terminator.
1329
- * @param {string} [options.terminator] - Optional override the terminator to use.
1330
- * @param {string} [options.separator] - Optional override the separator to use between the terminator and the value.
1331
- * - If no terminator is provided, then separator is ignored.
1332
- * @returns {string} The formatted string with terminator applied if cutoff occurs.
1333
- *
1334
- * @example
1335
- * formatCutoff('Hello, world!', { locales: 'en-US', maxChars: 8 });
1336
- * // Returns: 'Hello, w...'
1337
- *
1338
- * @example
1339
- * formatCutoff('Hello, world!', { locales: 'en-US', maxChars: -3 });
1340
- * // Returns: '...ld!'
1341
- *
1342
- * @example
1343
- * formatCutoff('Very long text that needs cutting', {
1344
- * locales: 'en-US',
1345
- * maxChars: 15,
1346
- * style: 'ellipsis',
1347
- * separator: ' '
1348
- * });
1349
- * // Returns: 'Very long text ...'
1350
- */
1351
- declare function formatCutoff(value: string, options?: {
1352
- locales?: string | string[];
1353
- } & CutoffFormatOptions): string;
1354
- /**
1355
- * Formats a message according to the specified locales and options.
1356
- *
1357
- * @param {string} message - The message to format.
1358
- * @param {string | string[]} [locales='en'] - The locales to use for formatting.
1359
- * @param {FormatVariables} [variables={}] - The variables to use for formatting.
1360
- * @param {StringFormat} [dataFormat='ICU'] - The format of the message. (When STRING, the message is returned as is)
1361
- * @returns {string} The formatted message.
1362
- *
1363
- * @example
1364
- * formatMessage('Hello {name}', { name: 'John' });
1365
- * // Returns: "Hello John"
1366
- *
1367
- * formatMessage('Hello {name}', { name: 'John' }, { locales: ['fr'] });
1368
- * // Returns: "Bonjour John"
1369
- */
1370
- declare function formatMessage(message: string, options?: {
1371
- locales?: string | string[];
1372
- variables?: FormatVariables;
1373
- dataFormat?: StringFormat;
1374
- }): string;
1375
- /**
1376
- * Formats a number according to the specified locales and options.
1377
- * @param {Object} params - The parameters for the number formatting.
1378
- * @param {number} params.value - The number to format.
1379
- * @param {Intl.NumberFormatOptions} [params.options] - Additional options for number formatting.
1380
- * @param {string | string[]} [params.options.locales] - The locales to use for formatting.
1381
- * @returns {string} The formatted number.
1382
- */
1383
- declare function formatNum(number: number, options: {
1384
- locales: string | string[];
1385
- } & Intl.NumberFormatOptions): string;
1386
- /**
1387
- * Formats a date according to the specified languages and options.
1388
- * @param {Object} params - The parameters for the date formatting.
1389
- * @param {Date} params.value - The date to format.
1390
- * @param {Intl.DateTimeFormatOptions} [params.options] - Additional options for date formatting.
1391
- * @param {string | string[]} [params.options.locales] - The languages to use for formatting.
1392
- * @returns {string} The formatted date.
1393
- */
1394
- declare function formatDateTime(date: Date, options?: {
1395
- locales?: string | string[];
1396
- } & Intl.DateTimeFormatOptions): string;
1397
- /**
1398
- * Formats a currency value according to the specified languages, currency, and options.
1399
- * @param {Object} params - The parameters for the currency formatting.
1400
- * @param {number} params.value - The currency value to format.
1401
- * @param {string} params.currency - The currency code (e.g., 'USD').
1402
- * @param {Intl.NumberFormatOptions} [params.options={}] - Additional options for currency formatting.
1403
- * @param {string | string[]} [params.options.locales] - The locale codes to use for formatting.
1404
- * @returns {string} The formatted currency value.
1405
- */
1406
- declare function formatCurrency(value: number, currency: string, options: {
1407
- locales: string | string[];
1408
- } & Intl.NumberFormatOptions): string;
1409
- /**
1410
- * Formats a list of items according to the specified locales and options.
1411
- * @param {Object} params - The parameters for the list formatting.
1412
- * @param {Array<string | number>} params.value - The list of items to format.
1413
- * @param {Intl.ListFormatOptions} [params.options={}] - Additional options for list formatting.
1414
- * @param {string | string[]} [params.options.locales] - The locales to use for formatting.
1415
- * @returns {string} The formatted list.
1416
- */
1417
- declare function formatList(array: Array<string | number>, options: {
1418
- locales: string | string[];
1419
- } & Intl.ListFormatOptions): string;
1420
- /**
1421
- * Formats a list of items according to the specified locales and options.
1422
- * @param {Array<T>} array - The list of items to format
1423
- * @param {Object} [options] - Additional options for list formatting
1424
- * @param {string | string[]} [options.locales] - The locales to use for formatting
1425
- * @param {Intl.ListFormatOptions} [options] - Additional Intl.ListFormat options
1426
- * @returns {Array<T | string>} The formatted list parts
1427
- */
1428
- declare function formatListToParts<T>(array: Array<T>, options?: {
1429
- locales?: string | string[];
1430
- } & Intl.ListFormatOptions): Array<T | string>;
1431
- /**
1432
- * Formats a relative time value according to the specified locales and options.
1433
- * @param {Object} params - The parameters for the relative time formatting.
1434
- * @param {number} params.value - The relative time value to format.
1435
- * @param {Intl.RelativeTimeFormatUnit} params.unit - The unit of time (e.g., 'second', 'minute', 'hour', 'day', 'week', 'month', 'year').
1436
- * @param {Intl.RelativeTimeFormatOptions} [params.options={}] - Additional options for relative time formatting.
1437
- * @param {string | string[]} [params.options.locales] - The locales to use for formatting.
1438
- * @returns {string} The formatted relative time string.
1439
- */
1440
- declare function formatRelativeTime(value: number, unit: Intl.RelativeTimeFormatUnit, options: {
1441
- locales: string | string[];
1442
- } & Omit<Intl.RelativeTimeFormatOptions, 'locales'>): string;
1443
- /**
1444
- * Formats a relative time string from a Date, automatically selecting the best unit.
1445
- * @param {Date} date - The date to format relative to now.
1446
- * @param {Object} options - Formatting options.
1447
- * @param {string | string[]} options.locales - The locales to use for formatting.
1448
- * @param {Intl.RelativeTimeFormatOptions} [options] - Additional Intl.RelativeTimeFormat options.
1449
- * @returns {string} The formatted relative time string (e.g., "2 hours ago", "in 3 days").
1450
- */
1451
- declare function formatRelativeTimeFromDate(date: Date, options: {
1452
- locales: string | string[];
1453
- baseDate?: Date;
1454
- } & Omit<Intl.RelativeTimeFormatOptions, 'locales'>): string;
1455
- /**
1456
- * Retrieves the display name of locale code using Intl.DisplayNames.
1457
- *
1458
- * @param {string} locale - A BCP-47 locale code.
1459
- * @param {string} [defaultLocale] - The default locale to use for formatting.
1460
- * @param {CustomMapping} [customMapping] - A custom mapping of locale codes to their names.
1461
- * @returns {string} The display name corresponding to the code.
1462
- */
1463
- declare function getLocaleName(locale: string, defaultLocale?: string, customMapping?: CustomMapping): string;
1464
- /**
1465
- * Retrieves an emoji based on a given locale code, taking into account region, language, and specific exceptions.
1466
- *
1467
- * This function uses the locale's region (if present) to select an emoji or falls back on default emojis for certain languages.
1468
- *
1469
- * @param locale - A string representing the locale code (e.g., 'en-US', 'fr-CA').
1470
- * @param {CustomMapping} [customMapping] - A custom mapping of locale codes to their names.
1471
- * @returns The emoji representing the locale or its region, or a default emoji if no specific match is found.
1472
- */
1473
- declare function getLocaleEmoji(locale: string, customMapping?: CustomMapping): string;
1474
- /**
1475
- * Generates linguistic details for a given locale code.
1476
- *
1477
- * This function returns information about the locale,
1478
- * script, and region of a given language code both in a standard form and in a maximized form (with likely script and region).
1479
- * The function provides these names in both your default language and native forms, and an associated emoji.
1480
- *
1481
- * @param {string} locale - The locale code to get properties for (e.g., "de-AT").
1482
- * @param {string} [defaultLocale] - The default locale to use for formatting.
1483
- * @param {CustomMapping} [customMapping] - A custom mapping of locale codes to their names.
1484
- * @returns {LocaleProperties} - An object containing detailed information about the locale.
1485
- *
1486
- * @property {string} code - The full locale code, e.g., "de-AT".
1487
- * @property {string} name - Language name in the default display language, e.g., "Austrian German".
1488
- * @property {string} nativeName - Language name in the locale's native language, e.g., "Österreichisches Deutsch".
1489
- * @property {string} languageCode - The base language code, e.g., "de".
1490
- * @property {string} languageName - The language name in the default display language, e.g., "German".
1491
- * @property {string} nativeLanguageName - The language name in the native language, e.g., "Deutsch".
1492
- * @property {string} nameWithRegionCode - Language name with region in the default language, e.g., "German (AT)".
1493
- * @property {string} nativeNameWithRegionCode - Language name with region in the native language, e.g., "Deutsch (AT)".
1494
- * @property {string} regionCode - The region code from maximization, e.g., "AT".
1495
- * @property {string} regionName - The region name in the default display language, e.g., "Austria".
1496
- * @property {string} nativeRegionName - The region name in the native language, e.g., "Österreich".
1497
- * @property {string} scriptCode - The script code from maximization, e.g., "Latn".
1498
- * @property {string} scriptName - The script name in the default display language, e.g., "Latin".
1499
- * @property {string} nativeScriptName - The script name in the native language, e.g., "Lateinisch".
1500
- * @property {string} maximizedCode - The maximized locale code, e.g., "de-Latn-AT".
1501
- * @property {string} maximizedName - Maximized locale name with likely script in the default language, e.g., "Austrian German (Latin)".
1502
- * @property {string} nativeMaximizedName - Maximized locale name in the native language, e.g., "Österreichisches Deutsch (Lateinisch)".
1503
- * @property {string} minimizedCode - Minimized locale code, e.g., "de-AT" (or "de" for "de-DE").
1504
- * @property {string} minimizedName - Minimized language name in the default language, e.g., "Austrian German".
1505
- * @property {string} nativeMinimizedName - Minimized language name in the native language, e.g., "Österreichisches Deutsch".
1506
- * @property {string} emoji - The emoji associated with the locale's region, if applicable.
1507
- */
1508
- declare function getLocaleProperties(locale: string, defaultLocale?: string, customMapping?: CustomMapping): LocaleProperties;
1509
- /**
1510
- * Retrieves multiple properties for a given region code, including:
1511
- * - `code`: the original region code
1512
- * - `name`: the localized display name
1513
- * - `emoji`: the associated flag or symbol
1514
- *
1515
- * Behavior:
1516
- * - Accepts ISO 3166-1 alpha-2 or UN M.49 region codes (e.g., `"US"`, `"FR"`, `"419"`).
1517
- * - If `customMapping` contains a `name` or `emoji` for the region, those override the default values.
1518
- * - Otherwise, uses `Intl.DisplayNames` to get the localized region name in the given `defaultLocale`,
1519
- * falling back to `libraryDefaultLocale`.
1520
- * - Falls back to the region code as `name` if display name resolution fails.
1521
- * - Falls back to `defaultEmoji` if no emoji mapping is found in `emojis` or `customMapping`.
1522
- *
1523
- * @param {string} region - The region code to look up (e.g., `"US"`, `"GB"`, `"DE"`).
1524
- * @param {string} [defaultLocale=libraryDefaultLocale] - The locale to use when localizing the region name.
1525
- * @param {CustomRegionMapping} [customMapping] - Optional mapping of region codes to custom names and/or emojis.
1526
- * @returns {{ code: string, name: string, emoji: string }} An object containing:
1527
- * - `code`: the input region code
1528
- * - `name`: the localized or custom region name
1529
- * - `emoji`: the matching emoji flag or symbol
1530
- *
1531
- * @example
1532
- * getRegionProperties('US', 'en');
1533
- * // => { code: 'US', name: 'United States', emoji: '🇺🇸' }
1534
- *
1535
- * @example
1536
- * getRegionProperties('US', 'fr');
1537
- * // => { code: 'US', name: 'États-Unis', emoji: '🇺🇸' }
1538
- *
1539
- * @example
1540
- * getRegionProperties('US', 'en', { US: { name: 'USA', emoji: '🗽' } });
1541
- * // => { code: 'US', name: 'USA', emoji: '🗽' }
1542
- */
1543
- declare function getRegionProperties(region: string, defaultLocale?: string, customMapping?: CustomRegionMapping): {
1544
- code: string;
1545
- name: string;
1546
- emoji: string;
1547
- };
1548
- /**
1549
- * Determines whether a translation is required based on the source and target locales.
1550
- *
1551
- * - If the target locale is not specified, the function returns `false`, as translation is not needed.
1552
- * - If the source and target locale are the same, returns `false`, indicating that no translation is necessary.
1553
- * - If the `approvedLocales` array is provided, and the target locale is not within that array, the function also returns `false`.
1554
- * - Otherwise, it returns `true`, meaning that a translation is required.
1555
- *
1556
- * @param {string} sourceLocale - The locale code for the original content (BCP 47 locale code).
1557
- * @param {string} targetLocale - The locale code of the language to translate the content into (BCP 47 locale code).
1558
- * @param {string[]} [approvedLocale] - An optional array of approved target locales.
1559
- *
1560
- * @returns {boolean} - Returns `true` if translation is required, otherwise `false`.
1561
- */
1562
- declare function requiresTranslation(sourceLocale: string, targetLocale: string, approvedLocales?: string[], customMapping?: CustomMapping): boolean;
1563
- /**
1564
- * Determines the best matching locale from the provided approved locales list.
1565
- * @param {string | string[]} locales - A single locale or an array of locales sorted in preference order.
1566
- * @param {string[]} [approvedLocales=this.locales] - An array of approved locales, also sorted by preference.
1567
- * @returns {string | undefined} - The best matching locale from the approvedLocales list, or undefined if no match is found.
1568
- */
1569
- declare function determineLocale(locales: string | string[], approvedLocales?: string[] | undefined, customMapping?: CustomMapping | undefined): string | undefined;
1570
- /**
1571
- * Get the text direction for a given locale code using the Intl.Locale API.
1572
- *
1573
- * @param {string} locale - A BCP-47 locale code.
1574
- * @returns {string} - 'rtl' if the locale is right-to-left, otherwise 'ltr'.
1575
- */
1576
- declare function getLocaleDirection(locale: string): 'ltr' | 'rtl';
1577
- /**
1578
- * Checks if a given BCP 47 locale code is valid.
1579
- * @param {string} locale - The BCP 47 locale code to validate.
1580
- * @param {CustomMapping} [customMapping] - The custom mapping to use for validation.
1581
- * @returns {boolean} True if the BCP 47 code is valid, false otherwise.
1582
- */
1583
- declare function isValidLocale(locale: string, customMapping?: CustomMapping): boolean;
1584
- /**
1585
- * Resolves the alias locale for a given locale.
1586
- * @param {string} locale - The locale to resolve the alias locale for
1587
- * @param {CustomMapping} [customMapping] - The custom mapping to use for resolving the alias locale
1588
- * @returns {string} The alias locale
1589
- */
1590
- declare function resolveAliasLocale(locale: string, customMapping?: CustomMapping): string;
1591
- /**
1592
- * Resolves the canonical locale for a given locale.
1593
- * @param {string} locale - The locale to resolve the canonical locale for
1594
- * @param {CustomMapping} [customMapping] - The custom mapping to use for resolving the canonical locale
1595
- * @returns {string} The canonical locale
1596
- */
1597
- declare function resolveCanonicalLocale(locale: string, customMapping?: CustomMapping): string;
1598
- /**
1599
- * Standardizes a BCP 47 locale code to ensure correct formatting.
1600
- * @param {string} locale - The BCP 47 locale code to standardize.
1601
- * @returns {string} The standardized BCP 47 locale code or an empty string if it is an invalid code.
1602
- */
1603
- declare function standardizeLocale(locale: string): string;
1604
- /**
1605
- * Checks if multiple BCP 47 locale codes represent the same dialect.
1606
- * @param {string[]} locales - The BCP 47 locale codes to compare.
1607
- * @returns {boolean} True if all BCP 47 codes represent the same dialect, false otherwise.
1608
- */
1609
- declare function isSameDialect(...locales: (string | string[])[]): boolean;
1610
- /**
1611
- * Checks if multiple BCP 47 locale codes represent the same language.
1612
- * @param {string[]} locales - The BCP 47 locale codes to compare.
1613
- * @returns {boolean} True if all BCP 47 codes represent the same language, false otherwise.
1614
- */
1615
- declare function isSameLanguage(...locales: (string | string[])[]): boolean;
1616
- /**
1617
- * Checks if a locale is a superset of another locale.
1618
- * A subLocale is a subset of superLocale if it is an extension of superLocale or are otherwise identical.
1619
- *
1620
- * @param {string} superLocale - The locale to check if it is a superset of the other locale.
1621
- * @param {string} subLocale - The locale to check if it is a subset of the other locale.
1622
- * @returns {boolean} True if the first locale is a superset of the second locale, false otherwise.
1623
- */
1624
- declare function isSupersetLocale(superLocale: string, subLocale: string): boolean;
1625
- declare const API_VERSION = "2026-03-06.v1";
1626
-
1627
- export { API_VERSION, GT, determineLocale, formatCurrency, formatCutoff, formatDateTime, formatList, formatListToParts, formatMessage, formatNum, formatRelativeTime, formatRelativeTimeFromDate, getLocaleDirection, getLocaleEmoji, getLocaleName, getLocaleProperties, getRegionProperties, isSameDialect, isSameLanguage, isSupersetLocale, isValidLocale, requiresTranslation, resolveAliasLocale, resolveCanonicalLocale, standardizeLocale };