-
Notifications
You must be signed in to change notification settings - Fork 25
/
Copy pathtranslator.ts
716 lines (672 loc) · 27.5 KB
/
translator.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
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
// Copyright 2025 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.
import { HttpClient } from './client';
import {
AuthorizationError,
DeepLError,
DocumentNotReadyError,
DocumentTranslationError,
GlossaryNotFoundError,
QuotaExceededError,
TooManyRequestsError,
} from './errors';
import { GlossaryEntries } from './glossaryEntries';
import { Usage } from './index';
import {
parseDocumentHandle,
parseDocumentStatus,
parseGlossaryInfo,
parseGlossaryInfoList,
parseGlossaryLanguagePairArray,
parseLanguageArray,
parseTextResultArray,
parseUsage,
} from './parsing';
import {
AppInfo,
DocumentStatus,
DocumentHandle,
DocumentTranslateOptions,
GlossaryId,
GlossaryInfo,
GlossaryLanguagePair,
Language,
LanguageCode,
SourceLanguageCode,
TargetLanguageCode,
TranslateTextOptions,
TranslatorOptions,
TextResult,
} from './types';
import {
appendTextsAndReturnIsSingular,
validateAndAppendTextOptions,
nonRegionalLanguageCode,
buildURLSearchParams,
isFreeAccountAuthKey,
isString,
logInfo,
streamToBuffer,
streamToString,
timeout,
} from './utils';
import * as fs from 'fs';
import { IncomingMessage, STATUS_CODES } from 'http';
import path from 'path';
import * as os from 'os';
import { URLSearchParams } from 'url';
import * as util from 'util';
import { DocumentMinifier } from './documentMinifier';
/**
* Checks the HTTP status code, and in case of failure, throws an exception with diagnostic information.
* @private
*/
export async function checkStatusCode(
statusCode: number,
content: string | IncomingMessage,
usingGlossary = false,
inDocumentDownload = false,
): Promise<void> {
if (200 <= statusCode && statusCode < 400) return;
if (content instanceof IncomingMessage) {
try {
content = await streamToString(content);
} catch (e) {
content = `Error occurred while reading response: ${e}`;
}
}
let message = '';
try {
const jsonObj = JSON.parse(content);
if (jsonObj.message !== undefined) {
message += `, message: ${jsonObj.message}`;
}
if (jsonObj.detail !== undefined) {
message += `, detail: ${jsonObj.detail}`;
}
} catch (error) {
// JSON parsing errors are ignored, and we fall back to the raw content
message = ', ' + content;
}
switch (statusCode) {
case 403:
throw new AuthorizationError(`Authorization failure, check auth_key${message}`);
case 456:
throw new QuotaExceededError(
`Quota for this billing period has been exceeded${message}`,
);
case 404:
if (usingGlossary) throw new GlossaryNotFoundError(`Glossary not found${message}`);
throw new DeepLError(`Not found, check server_url${message}`);
case 400:
throw new DeepLError(`Bad request${message}`);
case 429:
throw new TooManyRequestsError(
`Too many requests, DeepL servers are currently experiencing high load${message}`,
);
case 503:
if (inDocumentDownload) {
throw new DocumentNotReadyError(`Document not ready${message}`);
} else {
throw new DeepLError(`Service unavailable${message}`);
}
default: {
const statusName = STATUS_CODES[statusCode] || 'Unknown';
throw new DeepLError(
`Unexpected status code: ${statusCode} ${statusName}${message}, content: ${content}`,
);
}
}
}
/**
* Wrapper for the DeepL API for language translation.
* Create an instance of Translator to use the DeepL API.
*/
export class Translator {
/**
* Construct a Translator object wrapping the DeepL API using your authentication key.
* This does not connect to the API, and returns immediately.
* @param authKey Authentication key as specified in your account.
* @param options Additional options controlling Translator behavior.
*/
constructor(authKey: string, options?: TranslatorOptions) {
if (!isString(authKey) || authKey.length === 0) {
throw new DeepLError('authKey must be a non-empty string');
}
let serverUrl;
if (options?.serverUrl !== undefined) {
serverUrl = options.serverUrl;
} else if (isFreeAccountAuthKey(authKey)) {
serverUrl = 'https://api-free.deepl.com';
} else {
serverUrl = 'https://api.deepl.com';
}
const headers = {
Authorization: `DeepL-Auth-Key ${authKey}`,
'User-Agent': this.constructUserAgentString(
options?.sendPlatformInfo === false ? false : true,
options?.appInfo,
),
...(options?.headers ?? {}),
};
const maxRetries = options?.maxRetries !== undefined ? options.maxRetries : 5;
const minTimeout = options?.minTimeout !== undefined ? options.minTimeout : 5000;
this.httpClient = new HttpClient(
serverUrl,
headers,
maxRetries,
minTimeout,
options?.proxy,
);
}
/**
* Queries character and document usage during the current billing period.
* @return Fulfills with Usage object on success.
*/
public async getUsage(): Promise<Usage> {
const { statusCode, content } = await this.httpClient.sendRequestWithBackoff<string>(
'GET',
'/v2/usage',
);
await checkStatusCode(statusCode, content);
return parseUsage(content);
}
/**
* Queries source languages supported by DeepL API.
* @return Fulfills with array of Language objects containing available source languages.
*/
async getSourceLanguages(): Promise<readonly Language[]> {
const { statusCode, content } = await this.httpClient.sendRequestWithBackoff<string>(
'GET',
'/v2/languages',
);
await checkStatusCode(statusCode, content);
return parseLanguageArray(content);
}
/**
* Queries target languages supported by DeepL API.
* @return Fulfills with array of Language objects containing available target languages.
*/
async getTargetLanguages(): Promise<readonly Language[]> {
const data = new URLSearchParams({ type: 'target' });
const { statusCode, content } = await this.httpClient.sendRequestWithBackoff<string>(
'GET',
'/v2/languages',
{
data,
},
);
await checkStatusCode(statusCode, content);
return parseLanguageArray(content);
}
/**
* Queries language pairs supported for glossaries by DeepL API.
* @return Fulfills with an array of GlossaryLanguagePair objects containing languages supported for glossaries.
*/
async getGlossaryLanguagePairs(): Promise<readonly GlossaryLanguagePair[]> {
const { statusCode, content } = await this.httpClient.sendRequestWithBackoff<string>(
'GET',
'/v2/glossary-language-pairs',
);
await checkStatusCode(statusCode, content);
return parseGlossaryLanguagePairArray(content);
}
/**
* Translates specified text string or array of text strings into the target language.
* @param texts Text string or array of strings containing input text(s) to translate.
* @param sourceLang Language code of input text language, or null to use auto-detection.
* @param targetLang Language code of language to translate into.
* @param options Optional TranslateTextOptions object containing additional options controlling translation.
* @return Fulfills with a TextResult object or an array of TextResult objects corresponding to input texts; use the `TextResult.text` property to access the translated text.
*/
async translateText<T extends string | string[]>(
texts: T,
sourceLang: SourceLanguageCode | null,
targetLang: TargetLanguageCode,
options?: TranslateTextOptions,
): Promise<T extends string ? TextResult : TextResult[]> {
const data = buildURLSearchParams(
sourceLang,
targetLang,
options?.formality,
options?.glossary,
options?.extraRequestParameters,
);
// Always send show_billed_characters=1, remove when the API default is changed to true
data.append('show_billed_characters', '1');
const singular = appendTextsAndReturnIsSingular(data, texts);
validateAndAppendTextOptions(data, options);
const translatePath = options?.__path ?? '/v2/translate';
const { statusCode, content } = await this.httpClient.sendRequestWithBackoff<string>(
'POST',
translatePath,
{ data },
);
await checkStatusCode(statusCode, content);
const textResults = parseTextResultArray(content);
return (singular ? textResults[0] : textResults) as T extends string
? TextResult
: TextResult[];
}
/**
* Uploads specified document to DeepL to translate into given target language, waits for
* translation to complete, then downloads translated document to specified output path.
* @param inputFile String containing file path of document to be translated, or a Stream,
* Buffer, or FileHandle containing file data. Note: unless file path is used, then
* `options.filename` must be specified.
* @param outputFile String containing file path to create translated document, or Stream or
* FileHandle to write translated document content.
* @param sourceLang Language code of input document, or null to use auto-detection.
* @param targetLang Language code of language to translate into.
* @param options Optional DocumentTranslateOptions object containing additional options controlling translation.
* @return Fulfills with a DocumentStatus object for the completed translation. You can use the
* billedCharacters property to check how many characters were billed for the document.
* @throws {Error} If no file exists at the input file path, or a file already exists at the output file path.
* @throws {DocumentTranslationError} If any error occurs during document upload, translation or
* download. The `documentHandle` property of the error may be used to recover the document.
*/
async translateDocument(
inputFile: string | Buffer | fs.ReadStream | fs.promises.FileHandle,
outputFile: string | fs.WriteStream | fs.promises.FileHandle,
sourceLang: SourceLanguageCode | null,
targetLang: TargetLanguageCode,
options?: DocumentTranslateOptions,
): Promise<DocumentStatus> {
// Helper function to open output file if provided as filepath and remove it on error
async function getOutputHandleAndOnError(): Promise<{
outputHandle: fs.WriteStream | fs.promises.FileHandle;
onError?: () => Promise<void>;
}> {
if (isString(outputFile)) {
// Open output file path, fail if file already exists
const outputHandle = await fs.promises.open(outputFile, 'wx');
// Set up error handler to remove created file
const onError = async () => {
try {
// remove created output file
await outputHandle.close();
await util.promisify(fs.unlink)(outputFile);
} catch {
// Ignore errors
}
};
return { outputHandle, onError };
}
return { outputHandle: outputFile };
}
const { outputHandle, onError } = await getOutputHandleAndOnError();
const documentMinifier = new DocumentMinifier();
const willMinify =
(options?.enableDocumentMinification ?? false) &&
isString(inputFile) &&
DocumentMinifier.canMinifyFile(inputFile) &&
isString(outputFile);
const fileToUpload = willMinify
? documentMinifier.minifyDocument(inputFile, true)
: inputFile;
let documentHandle = undefined;
try {
documentHandle = await this.uploadDocument(
fileToUpload,
sourceLang,
targetLang,
options,
);
const { status } = await this.isDocumentTranslationComplete(documentHandle);
await this.downloadDocument(documentHandle, outputHandle);
if (willMinify) {
documentMinifier.deminifyDocument(inputFile, outputFile, true);
}
return status;
} catch (errorUnknown: unknown) {
if (onError) await onError();
const error = errorUnknown instanceof Error ? errorUnknown : undefined;
const message =
'Error occurred while translating document: ' +
(error?.message ? error?.message : errorUnknown);
throw new DocumentTranslationError(message, documentHandle, error);
}
}
/**
* Uploads specified document to DeepL to translate into target language, and returns handle associated with the document.
* @param inputFile String containing file path, stream containing file data, or FileHandle.
* Note: if a Buffer, Stream, or FileHandle is used, then `options.filename` must be specified.
* @param sourceLang Language code of input document, or null to use auto-detection.
* @param targetLang Language code of language to translate into.
* @param options Optional DocumentTranslateOptions object containing additional options controlling translation.
* @return Fulfills with DocumentHandle associated with the in-progress translation.
*/
async uploadDocument(
inputFile: string | Buffer | fs.ReadStream | fs.promises.FileHandle,
sourceLang: SourceLanguageCode | null,
targetLang: TargetLanguageCode,
options?: DocumentTranslateOptions,
): Promise<DocumentHandle> {
if (isString(inputFile)) {
const buffer = await fs.promises.readFile(inputFile);
return this.internalUploadDocument(
buffer,
sourceLang,
targetLang,
path.basename(inputFile),
options,
);
} else {
if (options?.filename === undefined) {
throw new DeepLError(
'options.filename must be specified unless using input file path',
);
}
if (inputFile instanceof fs.ReadStream) {
const buffer = await streamToBuffer(inputFile);
return this.internalUploadDocument(
buffer,
sourceLang,
targetLang,
options.filename,
options,
);
} else if (inputFile instanceof Buffer) {
return this.internalUploadDocument(
inputFile,
sourceLang,
targetLang,
options.filename,
options,
);
} else {
// FileHandle
const buffer = await inputFile.readFile();
const handle = await this.internalUploadDocument(
buffer,
sourceLang,
targetLang,
options.filename,
options,
);
await inputFile.close();
return handle;
}
}
}
/**
* Retrieves the status of the document translation associated with the given document handle.
* @param handle Document handle associated with document.
* @return Fulfills with a DocumentStatus giving the document translation status.
*/
async getDocumentStatus(handle: DocumentHandle): Promise<DocumentStatus> {
const data = new URLSearchParams({ document_key: handle.documentKey });
const { statusCode, content } = await this.httpClient.sendRequestWithBackoff<string>(
'POST',
`/v2/document/${handle.documentId}`,
{ data },
);
await checkStatusCode(statusCode, content, false, true);
return parseDocumentStatus(content);
}
/**
* Downloads the translated document associated with the given document handle to the specified output file path or stream.handle.
* @param handle Document handle associated with document.
* @param outputFile String containing output file path, or Stream or FileHandle to store file data.
* @return Fulfills with undefined, or rejects if the document translation has not been completed.
*/
async downloadDocument(
handle: DocumentHandle,
outputFile: string | fs.WriteStream | fs.promises.FileHandle,
): Promise<void> {
if (isString(outputFile)) {
const fileStream = await fs.createWriteStream(outputFile, { flags: 'wx' });
try {
await this.internalDownloadDocument(handle, fileStream);
} catch (e) {
await new Promise((resolve) => fileStream.close(resolve));
await fs.promises.unlink(outputFile);
throw e;
}
} else if (outputFile instanceof fs.WriteStream) {
return this.internalDownloadDocument(handle, outputFile);
} else {
// FileHandle
const dummyFilePath = '';
const outputStream = fs.createWriteStream(dummyFilePath, { fd: outputFile.fd });
await this.internalDownloadDocument(handle, outputStream);
try {
await outputFile.close();
} catch {
// Ignore errors
}
}
}
/**
* Returns a promise that resolves when the given document translation completes, or rejects if
* there was an error communicating with the DeepL API or the document translation failed.
* @param handle {DocumentHandle} Handle to the document translation.
* @return Fulfills with input DocumentHandle and DocumentStatus when the document translation
* completes successfully, rejects if translation fails or a communication error occurs.
*/
async isDocumentTranslationComplete(
handle: DocumentHandle,
): Promise<{ handle: DocumentHandle; status: DocumentStatus }> {
let status = await this.getDocumentStatus(handle);
while (!status.done() && status.ok()) {
// status.secondsRemaining is currently unreliable, so just poll equidistantly
const secs = 5.0;
await timeout(secs * 1000);
logInfo(`Rechecking document translation status after sleeping for ${secs} seconds.`);
status = await this.getDocumentStatus(handle);
}
if (!status.ok()) {
const message = status.errorMessage || 'unknown error';
throw new DeepLError(message);
}
return { handle, status };
}
/**
* Creates a new glossary on the DeepL server with given name, languages, and entries.
* @param name User-defined name to assign to the glossary.
* @param sourceLang Language code of the glossary source terms.
* @param targetLang Language code of the glossary target terms.
* @param entries The source- & target-term pairs to add to the glossary.
* @return Fulfills with a GlossaryInfo containing details about the created glossary.
*/
async createGlossary(
name: string,
sourceLang: LanguageCode,
targetLang: LanguageCode,
entries: GlossaryEntries,
): Promise<GlossaryInfo> {
if (Object.keys(entries.entries()).length === 0) {
throw new DeepLError('glossary entries must not be empty');
}
const tsv = entries.toTsv();
return this.internalCreateGlossary(name, sourceLang, targetLang, 'tsv', tsv);
}
/**
* Creates a new glossary on DeepL server with given name, languages, and CSV data.
* @param name User-defined name to assign to the glossary.
* @param sourceLang Language code of the glossary source terms.
* @param targetLang Language code of the glossary target terms.
* @param csvFile String containing the path of the CSV file to be translated, or a Stream,
* Buffer, or a FileHandle containing CSV file content.
* @return Fulfills with a GlossaryInfo containing details about the created glossary.
*/
async createGlossaryWithCsv(
name: string,
sourceLang: LanguageCode,
targetLang: LanguageCode,
csvFile: string | Buffer | fs.ReadStream | fs.promises.FileHandle,
): Promise<GlossaryInfo> {
let csvContent;
if (isString(csvFile)) {
csvContent = (await fs.promises.readFile(csvFile)).toString();
} else if (csvFile instanceof fs.ReadStream) {
csvContent = (await streamToBuffer(csvFile)).toString();
} else if (csvFile instanceof Buffer) {
csvContent = csvFile.toString();
} else {
// FileHandle
csvContent = (await csvFile.readFile()).toString();
await csvFile.close();
}
return this.internalCreateGlossary(name, sourceLang, targetLang, 'csv', csvContent);
}
/**
* Gets information about an existing glossary.
* @param glossaryId Glossary ID of the glossary.
* @return Fulfills with a GlossaryInfo containing details about the glossary.
*/
async getGlossary(glossaryId: GlossaryId): Promise<GlossaryInfo> {
const { statusCode, content } = await this.httpClient.sendRequestWithBackoff<string>(
'GET',
`/v2/glossaries/${glossaryId}`,
);
await checkStatusCode(statusCode, content, true);
return parseGlossaryInfo(content);
}
/**
* Gets information about all existing glossaries.
* @return Fulfills with an array of GlossaryInfos containing details about all existing glossaries.
*/
async listGlossaries(): Promise<GlossaryInfo[]> {
const { statusCode, content } = await this.httpClient.sendRequestWithBackoff<string>(
'GET',
'/v2/glossaries',
);
await checkStatusCode(statusCode, content, true);
return parseGlossaryInfoList(content);
}
/**
* Retrieves the entries stored with the glossary with the given glossary ID or GlossaryInfo.
* @param glossary Glossary ID or GlossaryInfo of glossary to retrieve entries of.
* @return Fulfills with GlossaryEntries holding the glossary entries.
*/
async getGlossaryEntries(glossary: GlossaryId | GlossaryInfo): Promise<GlossaryEntries> {
glossary = isString(glossary) ? glossary : glossary.glossaryId;
const { statusCode, content } = await this.httpClient.sendRequestWithBackoff<string>(
'GET',
`/v2/glossaries/${glossary}/entries`,
);
await checkStatusCode(statusCode, content, true);
return new GlossaryEntries({ tsv: content });
}
/**
* Deletes the glossary with the given glossary ID or GlossaryInfo.
* @param glossary Glossary ID or GlossaryInfo of glossary to be deleted.
* @return Fulfills with undefined when the glossary is deleted.
*/
async deleteGlossary(glossary: GlossaryId | GlossaryInfo): Promise<void> {
glossary = isString(glossary) ? glossary : glossary.glossaryId;
const { statusCode, content } = await this.httpClient.sendRequestWithBackoff<string>(
'DELETE',
`/v2/glossaries/${glossary}`,
);
await checkStatusCode(statusCode, content, true);
}
/**
* Upload given stream for document translation and returns document handle.
* @private
*/
private async internalUploadDocument(
fileBuffer: Buffer,
sourceLang: SourceLanguageCode | null,
targetLang: TargetLanguageCode,
filename: string,
options?: DocumentTranslateOptions,
): Promise<DocumentHandle> {
const data = buildURLSearchParams(
sourceLang,
targetLang,
options?.formality,
options?.glossary,
options?.extraRequestParameters,
);
const { statusCode, content } = await this.httpClient.sendRequestWithBackoff<string>(
'POST',
'/v2/document',
{
data,
fileBuffer,
filename,
},
);
await checkStatusCode(statusCode, content);
return parseDocumentHandle(content);
}
/**
* Download translated document associated with specified handle to given stream.
* @private
*/
private async internalDownloadDocument(
handle: DocumentHandle,
outputStream: fs.WriteStream,
): Promise<void> {
const data = new URLSearchParams({ document_key: handle.documentKey });
const { statusCode, content } =
await this.httpClient.sendRequestWithBackoff<IncomingMessage>(
'POST',
`/v2/document/${handle.documentId}/result`,
{ data },
true,
);
await checkStatusCode(statusCode, content, false, true);
content.pipe(outputStream);
return new Promise((resolve, reject) => {
outputStream.on('finish', resolve);
outputStream.on('error', reject);
});
}
/**
* Create glossary with given details.
* @private
*/
private async internalCreateGlossary(
name: string,
sourceLang: LanguageCode,
targetLang: LanguageCode,
entriesFormat: string,
entries: string,
): Promise<GlossaryInfo> {
// Glossaries are only supported for base language types
sourceLang = nonRegionalLanguageCode(sourceLang);
targetLang = nonRegionalLanguageCode(targetLang);
if (!isString(name) || name.length === 0) {
throw new DeepLError('glossary name must be a non-empty string');
}
const data = new URLSearchParams({
name: name,
source_lang: sourceLang,
target_lang: targetLang,
entries_format: entriesFormat,
entries: entries,
});
const { statusCode, content } = await this.httpClient.sendRequestWithBackoff<string>(
'POST',
'/v2/glossaries',
{ data },
);
await checkStatusCode(statusCode, content, true);
return parseGlossaryInfo(content);
}
private constructUserAgentString(
sendPlatformInfo: boolean,
appInfo: AppInfo | undefined,
): string {
let libraryInfoString = 'deepl-node/1.17.3';
if (sendPlatformInfo) {
const systemType = os.type();
const systemVersion = os.version();
const nodeVersion = process.version.substring(1); // Drop the v in the version number
libraryInfoString += ` (${systemType} ${systemVersion}) node/${nodeVersion}`;
}
if (appInfo) {
libraryInfoString += ` ${appInfo.appName}/${appInfo.appVersion}`;
}
return libraryInfoString;
}
/**
* HttpClient implements all HTTP requests and retries.
* @protected
*/
protected readonly httpClient: HttpClient;
}