-
Notifications
You must be signed in to change notification settings - Fork 35
Expand file tree
/
Copy pathtypes.ts
More file actions
269 lines (234 loc) · 8.49 KB
/
types.ts
File metadata and controls
269 lines (234 loc) · 8.49 KB
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
// Copyright 2022 DeepL SE (https://www.deepl.com)
// Use of this source code is governed by an MIT
// license that can be found in the LICENSE file.
/**
* Optional proxy configuration, may be specified as proxy in TranslatorOptions.
* @see TranslatorOptions.proxy
*/
export interface ProxyConfig {
host: string;
port: number;
auth?: {
username: string;
password: string;
};
protocol?: string;
}
/**
* Optional identifier for the app that is using this library, may be specified
* as appInfo in TranslatorOptions.
* @see TranslatorOptions.appInfo
*/
export interface AppInfo {
appName: string;
appVersion: string;
}
/**
* Options that can be specified when constructing a Translator.
*/
export interface TranslatorOptions {
/**
* Base URL of DeepL API, can be overridden for example for testing purposes. By default, the
* correct DeepL API URL is selected based on the user account type (free or paid).
*/
serverUrl?: string;
/**
* HTTP headers attached to every HTTP request. By default, no extra headers are used. Note that
* during Translator initialization headers for Authorization and User-Agent are added, unless
* they are overridden in this option.
*/
headers?: Record<string, string>;
/**
* The maximum number of failed attempts that Translator will retry, per request. By default, 5
* retries are made. Note: only errors due to transient conditions are retried.
*/
maxRetries?: number;
/**
* Connection timeout used for each HTTP request retry, in milliseconds. The default timeout
* if this value is unspecified is 10 seconds (10000).
*/
minTimeout?: number;
/**
* Define the host, port and protocol of the proxy server.
*/
proxy?: ProxyConfig;
/**
* Define if the library is allowed to send more detailed information about which platform
* it is running on with each API call. Defaults to true if undefined. Overriden by
* the `customUserAgent` option.
*/
sendPlatformInfo?: boolean;
/**
* Identifies the application using this client library, will be sent in the `User-Agent` header
*/
appInfo?: AppInfo;
}
export type Formality = 'less' | 'more' | 'default' | 'prefer_less' | 'prefer_more';
export type SentenceSplittingMode = 'off' | 'on' | 'nonewlines' | 'default';
export type TagHandlingMode = 'html' | 'xml';
export type ModelType = 'quality_optimized' | 'latency_optimized' | 'prefer_quality_optimized';
export type GlossaryId = string;
export type TagList = string | string[];
/**
* Information about a glossary, excluding the entry list.
*/
export interface GlossaryInfo {
/** Unique ID assigned to the glossary. */
readonly glossaryId: GlossaryId;
/** User-defined name assigned to the glossary. */
readonly name: string;
/** Indicates whether the glossary may be used for translations. */
readonly ready: boolean;
/** Language code of the glossary source terms. */
readonly sourceLang: SourceGlossaryLanguageCode;
/** Language code of the glossary target terms. */
readonly targetLang: TargetGlossaryLanguageCode;
/** Time when the glossary was created. */
readonly creationTime: Date;
/** The number of entries contained in the glossary. */
readonly entryCount: number;
}
/**
* Options that can be specified when translating text.
*/
export interface TranslateTextOptions {
/**
* Specifies how input translation text should be split into sentences.
* - 'on': Input translation text will be split into sentences using both newlines and
* punctuation, this is the default behaviour.
* - 'off': Input translation text will not be split into sentences. This is advisable for
* applications where each input translation text is only one sentence.
* - 'nonewlines': Input translation text will be split into sentences using only punctuation
* but not newlines.
*/
splitSentences?: SentenceSplittingMode;
/** Set to true to prevent the translation engine from correcting some formatting aspects, and
* instead leave the formatting unchanged, default is false. */
preserveFormatting?: boolean;
/** Controls whether translations should lean toward formal or informal language. */
formality?: Formality;
/** Specifies the ID of a glossary to use with translation. */
glossary?: GlossaryId | GlossaryInfo;
/** Type of tags to parse before translation, options are 'html' and 'xml'. */
tagHandling?: TagHandlingMode;
/** Set to false to disable automatic tag detection, default is true. */
outlineDetection?: boolean;
/** Specifies additional context to influence translations, that is not
* translated itself. Characters in the `context` parameter are not counted
* toward billing.
* See the API documentation for more information and example usage. */
context?: string;
/** Type of translation model to use. */
modelType?: ModelType;
/** List of XML tags that should be used to split text into sentences. */
splittingTags?: TagList;
/** List of XML tags that should not be used to split text into sentences. */
nonSplittingTags?: TagList;
/** List of XML tags containing content that should not be translated. */
ignoreTags?: TagList;
/** Extra parameters to be added to a text translation request. */
extraRequestParameters?: RequestParameters;
}
/**
* Options that can be specified when translating documents.
*/
export interface DocumentTranslateOptions {
/** Controls whether translations should lean toward formal or informal language. */
formality?: Formality;
/** Specifies the ID of a glossary to use with translation. */
glossary?: GlossaryId | GlossaryInfo;
/** Filename including extension, only required when translating documents as streams. */
filename?: string;
/** Extra parameters to be added to a text translation request. */
extraRequestParameters?: RequestParameters;
}
/**
* Language codes that may be used as a source or target language.
* Note: although the language code type definitions are case-sensitive, this package and the DeepL
* API accept case-insensitive language codes.
*/
type CommonLanguageCode =
| 'ar'
| 'bg'
| 'cs'
| 'da'
| 'de'
| 'el'
| 'es'
| 'et'
| 'fi'
| 'fr'
| 'hu'
| 'id'
| 'it'
| 'ja'
| 'ko'
| 'lt'
| 'lv'
| 'nb'
| 'nl'
| 'pl'
| 'ro'
| 'ru'
| 'sk'
| 'sl'
| 'sv'
| 'tr'
| 'uk'
| 'zh';
/**
* Language codes that may be used as a source language.
* Note: although the language code type definitions are case-sensitive, this package and the DeepL
* API accept case-insensitive language codes.
*/
export type SourceLanguageCode = CommonLanguageCode | 'en' | 'pt';
/**
* Language codes that may be used as a target language.
* Note: although the language code type definitions are case-sensitive, this package and the DeepL
* API accept case-insensitive language codes.
*/
export type TargetLanguageCode = CommonLanguageCode | 'en-GB' | 'en-US' | 'pt-BR' | 'pt-PT';
/**
* All language codes, including source-only and target-only language codes.
* Note: although the language code type definitions are case-sensitive, this package and the DeepL
* API accept case-insensitive language codes.
*/
export type LanguageCode = SourceLanguageCode | TargetLanguageCode;
/**
* Language codes that do not include a regional variant, for example 'en' is included, but 'en-US'
* is not.
*/
export type NonRegionalLanguageCode = CommonLanguageCode | 'en' | 'pt';
/**
* Language codes that may be used as a source language for glossaries.
* Note: although the language code type definitions are case-sensitive, this package and the DeepL
* API accept case-insensitive language codes.
*/
export type SourceGlossaryLanguageCode =
| 'da'
| 'de'
| 'en'
| 'es'
| 'fr'
| 'it'
| 'ja'
| 'ko'
| 'nb'
| 'nl'
| 'pl'
| 'pt'
| 'ro'
| 'ru'
| 'sv'
| 'zh';
/**
* Language codes that may be used as a target language for glossaries.
* Note: although the language code type definitions are case-sensitive, this package and the DeepL
* API accept case-insensitive language codes.
*/
export type TargetGlossaryLanguageCode = SourceGlossaryLanguageCode;
/**
* Extra request parameters to be passed with translation requests.
* They are stored as an object where each field represents a request parameter.
*/
export type RequestParameters = Record<string, string>;