forked from vitalets/google-translate-api
-
-
Notifications
You must be signed in to change notification settings - Fork 21
/
index.d.ts
435 lines (414 loc) · 10.5 KB
/
index.d.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
/**
* Google Translate API TypeScript Declaration File
* This file defines the types and interfaces for the Google Translate API wrapper.
*/
// Main export functions
export default translate;
export {
translate,
Translator,
speak,
singleTranslate,
batchTranslate,
languages,
isSupported,
getCode,
};
// Namespace containing all type definitions and interfaces
export declare namespace googleTranslateApi {
/**
* Options for translation requests
*/
interface TranslationOptions {
from?: string; // Source language
to?: string; // Target language
forceFrom?: boolean; // Force use of 'from' language
forceTo?: boolean; // Force use of 'to' language
autoCorrect?: boolean; // Enable auto-correction
}
/**
* Extended options for API requests
*/
export interface RequestOptions extends TranslationOptions {
tld?: string; // Top-level domain for the translate host
requestFunction?: Function; // Custom request function
forceBatch?: boolean; // Force batch translation
fallbackBatch?: boolean; // Allow batch as fallback
requestOptions?: object; // Additional request options
rejectOnPartialFail?: boolean; // Reject on partial failure
}
/**
* Represents a translated language
*/
interface TranslatedLanguage {
didYouMean: boolean; // Indicates if this was a suggested language
iso: string; // ISO code of the language
}
/**
* Represents translated text
*/
interface TranslatedText {
autoCorrected: boolean; // Indicates if text was auto-corrected
value: string; // The translated text
didYouMean: boolean; // Indicates if this was a suggested translation
}
/**
* Response structure for a translation request
*/
export interface TranslationResponse {
text: string; // Translated text
pronunciation?: string; // Pronunciation guide (if available)
from: {
language: TranslatedLanguage;
text: TranslatedText;
};
raw: string; // Raw response from the API
}
/**
* Query options for translation
*/
interface OptionQuery extends TranslationOptions {
text: string; // Text to translate
}
// Type aliases for various input formats
type Query = string | OptionQuery;
export type Input = string | Query[] | { [key: string]: Query };
// Type for translation response based on input type
export type TranslationResponseStructure<T> = T extends string
? Promise<TranslationResponse>
: T extends Query[]
? Promise<TranslationResponse[]>
: Promise<{ [key in keyof T]: TranslationResponse }>;
// Type for speak response based on input type
export type SpeakResponseStructure<T> = T extends string
? Promise<string>
: T extends Query[]
? Promise<string[]>
: Promise<{ [key in keyof T]: string }>;
/**
* Enum of supported languages
* Generated from https://translate.google.com
* See https://en.wikipedia.org/wiki/List_of_ISO_639-1_codes
*/
export enum languages {
"auto" = "Detect language",
"ab" = "Abkhaz",
"ace" = "Acehnese",
"ach" = "Acholi",
"aa" = "Afar",
"af" = "Afrikaans",
"sq" = "Albanian",
"alz" = "Alur",
"am" = "Amharic",
"ar" = "Arabic",
"hy" = "Armenian",
"as" = "Assamese",
"av" = "Avar",
"awa" = "Awadhi",
"ay" = "Aymara",
"az" = "Azerbaijani",
"ban" = "Balinese",
"bal" = "Baluchi",
"bm" = "Bambara",
"bci" = "Baoulé",
"ba" = "Bashkir",
"eu" = "Basque",
"btx" = "Batak Karo",
"bts" = "Batak Simalungun",
"bbc" = "Batak Toba",
"be" = "Belarusian",
"bem" = "Bemba",
"bn" = "Bengali",
"bew" = "Betawi",
"bho" = "Bhojpuri",
"bik" = "Bikol",
"bs" = "Bosnian",
"br" = "Breton",
"bg" = "Bulgarian",
"bua" = "Buryat",
"yue" = "Cantonese",
"ca" = "Catalan",
"ceb" = "Cebuano",
"ch" = "Chamorro",
"ce" = "Chechen",
"ny" = "Chichewa",
"zh-CN" = "Chinese (Simplified)",
"zh-TW" = "Chinese (Traditional)",
"chk" = "Chuukese",
"cv" = "Chuvash",
"co" = "Corsican",
"crh" = "Crimean Tatar",
"hr" = "Croatian",
"cs" = "Czech",
"da" = "Danish",
"fa-AF" = "Dari",
"dv" = "Dhivehi",
"din" = "Dinka",
"doi" = "Dogri",
"dov" = "Dombe",
"nl" = "Dutch",
"dyu" = "Dyula",
"dz" = "Dzongkha",
"en" = "English",
"eo" = "Esperanto",
"et" = "Estonian",
"ee" = "Ewe",
"fo" = "Faroese",
"fj" = "Fijian",
"tl" = "Filipino",
"fi" = "Finnish",
"fon" = "Fon",
"fr" = "French",
"fy" = "Frisian",
"fur" = "Friulian",
"ff" = "Fulani",
"gaa" = "Ga",
"gl" = "Galician",
"ka" = "Georgian",
"de" = "German",
"el" = "Greek",
"gn" = "Guarani",
"gu" = "Gujarati",
"ht" = "Haitian Creole",
"cnh" = "Hakha Chin",
"ha" = "Hausa",
"haw" = "Hawaiian",
"iw" = "Hebrew",
"hil" = "Hiligaynon",
"hi" = "Hindi",
"hmn" = "Hmong",
"hu" = "Hungarian",
"hrx" = "Hunsrik",
"iba" = "Iban",
"is" = "Icelandic",
"ig" = "Igbo",
"ilo" = "Ilocano",
"id" = "Indonesian",
"ga" = "Irish",
"it" = "Italian",
"jam" = "Jamaican Patois",
"ja" = "Japanese",
"jw" = "Javanese",
"kac" = "Jingpo",
"kl" = "Kalaallisut",
"kn" = "Kannada",
"kr" = "Kanuri",
"pam" = "Kapampangan",
"kk" = "Kazakh",
"kha" = "Khasi",
"km" = "Khmer",
"cgg" = "Kiga",
"kg" = "Kikongo",
"rw" = "Kinyarwanda",
"ktu" = "Kituba",
"trp" = "Kokborok",
"kv" = "Komi",
"gom" = "Konkani",
"ko" = "Korean",
"kri" = "Krio",
"ku" = "Kurdish (Kurmanji)",
"ckb" = "Kurdish (Sorani)",
"ky" = "Kyrgyz",
"lo" = "Lao",
"ltg" = "Latgalian",
"la" = "Latin",
"lv" = "Latvian",
"lij" = "Ligurian",
"li" = "Limburgish",
"ln" = "Lingala",
"lt" = "Lithuanian",
"lmo" = "Lombard",
"lg" = "Luganda",
"luo" = "Luo",
"lb" = "Luxembourgish",
"mk" = "Macedonian",
"mad" = "Madurese",
"mai" = "Maithili",
"mak" = "Makassar",
"mg" = "Malagasy",
"ms" = "Malay",
"ms-Arab" = "Malay (Jawi)",
"ml" = "Malayalam",
"mt" = "Maltese",
"mam" = "Mam",
"gv" = "Manx",
"mi" = "Maori",
"mr" = "Marathi",
"mh" = "Marshallese",
"mwr" = "Marwadi",
"mfe" = "Mauritian Creole",
"chm" = "Meadow Mari",
"mni-Mtei" = "Meiteilon (Manipuri)",
"min" = "Minang",
"lus" = "Mizo",
"mn" = "Mongolian",
"my" = "Myanmar (Burmese)",
"nhe" = "Nahuatl (Eastern Huasteca)",
"ndc-ZW" = "Ndau",
"nr" = "Ndebele (South)",
"new" = "Nepalbhasa (Newari)",
"ne" = "Nepali",
"bm-Nkoo" = "NKo",
"no" = "Norwegian",
"nus" = "Nuer",
"oc" = "Occitan",
"or" = "Odia (Oriya)",
"om" = "Oromo",
"os" = "Ossetian",
"pag" = "Pangasinan",
"pap" = "Papiamento",
"ps" = "Pashto",
"fa" = "Persian",
"pl" = "Polish",
"pt" = "Portuguese (Brazil)",
"pt-PT" = "Portuguese (Portugal)",
"pa" = "Punjabi (Gurmukhi)",
"pa-Arab" = "Punjabi (Shahmukhi)",
"qu" = "Quechua",
"kek" = "Qʼeqchiʼ",
"rom" = "Romani",
"ro" = "Romanian",
"rn" = "Rundi",
"ru" = "Russian",
"se" = "Sami (North)",
"sm" = "Samoan",
"sg" = "Sango",
"sa" = "Sanskrit",
"sat-Latn" = "Santali",
"gd" = "Scots Gaelic",
"nso" = "Sepedi",
"sr" = "Serbian",
"st" = "Sesotho",
"crs" = "Seychellois Creole",
"shn" = "Shan",
"sn" = "Shona",
"scn" = "Sicilian",
"szl" = "Silesian",
"sd" = "Sindhi",
"si" = "Sinhala",
"sk" = "Slovak",
"sl" = "Slovenian",
"so" = "Somali",
"es" = "Spanish",
"su" = "Sundanese",
"sus" = "Susu",
"sw" = "Swahili",
"ss" = "Swati",
"sv" = "Swedish",
"ty" = "Tahitian",
"tg" = "Tajik",
"ber-Latn" = "Tamazight",
"ber" = "Tamazight (Tifinagh)",
"ta" = "Tamil",
"tt" = "Tatar",
"te" = "Telugu",
"tet" = "Tetum",
"th" = "Thai",
"bo" = "Tibetan",
"ti" = "Tigrinya",
"tiv" = "Tiv",
"tpi" = "Tok Pisin",
"to" = "Tongan",
"ts" = "Tsonga",
"tn" = "Tswana",
"tcy" = "Tulu",
"tum" = "Tumbuka",
"tr" = "Turkish",
"tk" = "Turkmen",
"tyv" = "Tuvan",
"ak" = "Twi",
"udm" = "Udmurt",
"uk" = "Ukrainian",
"ur" = "Urdu",
"ug" = "Uyghur",
"uz" = "Uzbek",
"ve" = "Venda",
"vec" = "Venetian",
"vi" = "Vietnamese",
"war" = "Waray",
"cy" = "Welsh",
"wo" = "Wolof",
"xh" = "Xhosa",
"sah" = "Yakut",
"yi" = "Yiddish",
"yo" = "Yoruba",
"yua" = "Yucatec Maya",
"zap" = "Zapotec",
"zu" = "Zulu",
}
namespace languages {
/**
* Returns the ISO 639-1 code of the desired language
* @param desiredLang - The name or code (case sensitive) of the desired language
* @returns The ISO 639-1 code of the language or false if not supported
*/
function getCode(desiredLang: string): string | boolean;
/**
* Checks if the desired language is supported by Google Translate
* @param desiredLang - The ISO 639-1 code or name of the desired language
* @returns True if supported, false otherwise
*/
function isSupported(desiredLang: string): boolean;
}
}
/**
* Main translation function
* @param input - Text, array, or object of texts to translate
* @param opts - Translation options
* @returns Promise resolving to translation response(s)
*/
declare function translate<Input extends googleTranslateApi.Input>(
input: Input,
opts?: googleTranslateApi.RequestOptions,
): googleTranslateApi.TranslationResponseStructure<Input>;
/**
* Translator class for creating reusable translator instances
*/
declare class Translator {
constructor(options?: googleTranslateApi.RequestOptions);
translate<Input extends googleTranslateApi.Input>(
input: Input,
opts?: googleTranslateApi.RequestOptions,
): googleTranslateApi.TranslationResponseStructure<Input>;
options: googleTranslateApi.RequestOptions;
}
/**
* Function to get spoken audio of translated text
* @param input - Text, array, or object of texts to speak
* @param opts - Translation options
* @returns Promise resolving to Base64 string(s) encoding mp3 audio
*/
declare function speak<Input extends googleTranslateApi.Input>(
input: Input,
opts?: googleTranslateApi.RequestOptions,
): googleTranslateApi.SpeakResponseStructure<Input>;
/**
* Function to translate a single string
* @param input - Text to translate
* @param opts - Translation options
* @returns Promise resolving to translation response
*/
declare function singleTranslate(
input: string,
opts?: googleTranslateApi.RequestOptions,
): googleTranslateApi.TranslationResponseStructure<string>;
/**
* Bypass any single translate options and forces batch translation
*/
declare const batchTranslate: typeof translate;
/**
* Object containing supported languages
*/
declare const languages: typeof googleTranslateApi.languages;
/**
* Checks if a language is supported
* @param desiredLang - Language to check
* @returns True if supported, false otherwise
*/
declare function isSupported(desiredLang: string): boolean;
/**
* Gets the language code for a given language name
* @param desiredLang - Language name
* @returns Language code if found, null otherwise
*/
declare function getCode(desiredLang: string): string | null;