@@ -22,24 +22,29 @@ import {
2222 parseLanguageArray ,
2323 parseTextResultArray ,
2424 parseUsage ,
25+ standardizeLanguageCode ,
2526} from './parsing' ;
2627import {
2728 AppInfo ,
29+ DocumentHandle ,
30+ DocumentStatus ,
2831 DocumentTranslateOptions ,
2932 Formality ,
3033 GlossaryId ,
3134 GlossaryInfo ,
35+ GlossaryLanguagePair ,
36+ Language ,
3237 LanguageCode ,
3338 NonRegionalLanguageCode ,
3439 RequestParameters ,
3540 SentenceSplittingMode ,
36- SourceGlossaryLanguageCode ,
3741 SourceLanguageCode ,
3842 TagList ,
39- TargetGlossaryLanguageCode ,
4043 TargetLanguageCode ,
44+ TextResult ,
4145 TranslateTextOptions ,
4246 TranslatorOptions ,
47+ Usage ,
4348} from './types' ;
4449import { isString , logInfo , streamToBuffer , streamToString , timeout , toBoolString } from './utils' ;
4550
@@ -54,149 +59,6 @@ export * from './errors';
5459export * from './glossaryEntries' ;
5560export * from './types' ;
5661
57- /**
58- * Stores the count and limit for one usage type.
59- */
60- export interface UsageDetail {
61- /** The amount used of this usage type. */
62- readonly count : number ;
63- /** The maximum allowable amount for this usage type. */
64- readonly limit : number ;
65-
66- /**
67- * Returns true if the amount used has already reached or passed the allowable amount.
68- */
69- limitReached ( ) : boolean ;
70- }
71-
72- /**
73- * Information about the API usage: how much has been translated in this billing period, and the
74- * maximum allowable amount.
75- *
76- * Depending on the account type, different usage types are included: the character, document and
77- * teamDocument fields provide details about each corresponding usage type, allowing each usage type
78- * to be checked individually. The anyLimitReached() function checks if any usage type is exceeded.
79- */
80- export interface Usage {
81- /** Usage details for characters, for example due to the translateText() function. */
82- readonly character ?: UsageDetail ;
83- /** Usage details for documents. */
84- readonly document ?: UsageDetail ;
85- /** Usage details for documents shared among your team. */
86- readonly teamDocument ?: UsageDetail ;
87-
88- /** Returns true if any usage type limit has been reached or passed, otherwise false. */
89- anyLimitReached ( ) : boolean ;
90-
91- /** Converts the usage details to a human-readable string. */
92- toString ( ) : string ;
93- }
94-
95- /**
96- * Information about a language supported by DeepL translator.
97- */
98- export interface Language {
99- /** Name of the language in English. */
100- readonly name : string ;
101- /**
102- * Language code according to ISO 639-1, for example 'en'. Some target languages also include
103- * the regional variant according to ISO 3166-1, for example 'en-US'.
104- */
105- readonly code : LanguageCode ;
106- /**
107- * Only defined for target languages. If defined, specifies whether the formality option is
108- * available for this target language.
109- */
110- readonly supportsFormality ?: boolean ;
111- }
112-
113- /**
114- * Information about a pair of languages supported for DeepL glossaries.
115- */
116- export interface GlossaryLanguagePair {
117- /**
118- * The code of the source language.
119- */
120- readonly sourceLang : SourceGlossaryLanguageCode ;
121- /**
122- * The code of the target language.
123- */
124- readonly targetLang : TargetGlossaryLanguageCode ;
125- }
126-
127- /**
128- * Handle to an in-progress document translation.
129- */
130- export interface DocumentHandle {
131- /**
132- * ID of associated document request.
133- */
134- readonly documentId : string ;
135-
136- /**
137- * Key of associated document request.
138- */
139- readonly documentKey : string ;
140- }
141-
142- export type DocumentStatusCode = 'queued' | 'translating' | 'error' | 'done' ;
143-
144- /**
145- * Status of a document translation request.
146- */
147- export interface DocumentStatus {
148- /**
149- * One of the status values defined in DocumentStatusCode.
150- * @see DocumentStatusCode
151- */
152- readonly status : DocumentStatusCode ;
153-
154- /**
155- * Estimated time until document translation completes in seconds, otherwise undefined if
156- * unknown.
157- */
158- readonly secondsRemaining ?: number ;
159-
160- /**
161- * Number of characters billed for this document, or undefined if unknown or before translation
162- * is complete.
163- */
164- readonly billedCharacters ?: number ;
165-
166- /**
167- * A short description of the error, or undefined if no error has occurred.
168- */
169- readonly errorMessage ?: string ;
170-
171- /**
172- * True if no error has occurred, otherwise false. Note that while the document translation is
173- * in progress, this returns true.
174- */
175- ok ( ) : boolean ;
176-
177- /**
178- * True if the document translation completed successfully, otherwise false.
179- */
180- done ( ) : boolean ;
181- }
182-
183- /**
184- * Changes the upper- and lower-casing of the given language code to match ISO 639-1 with an
185- * optional regional code from ISO 3166-1.
186- * For example, input 'EN-US' returns 'en-US'.
187- * @param langCode String containing language code to standardize.
188- * @return Standardized language code.
189- */
190- export function standardizeLanguageCode ( langCode : string ) : LanguageCode {
191- if ( ! isString ( langCode ) || langCode . length === 0 ) {
192- throw new DeepLError ( 'langCode must be a non-empty string' ) ;
193- }
194- const [ lang , region ] = langCode . split ( '-' , 2 ) ;
195- return (
196- region === undefined ? lang . toLowerCase ( ) : `${ lang . toLowerCase ( ) } -${ region . toUpperCase ( ) } `
197- ) as LanguageCode ;
198- }
199-
20062/**
20163 * Removes the regional variant from a language, for example inputs 'en' and 'en-US' both return
20264 * 'en'.
@@ -210,21 +72,6 @@ export function nonRegionalLanguageCode(langCode: string): NonRegionalLanguageCo
21072 return langCode . split ( '-' , 2 ) [ 0 ] . toLowerCase ( ) as NonRegionalLanguageCode ;
21173}
21274
213- /**
214- * Holds the result of a text translation request.
215- */
216- export interface TextResult {
217- /**
218- * String containing the translated text.
219- */
220- readonly text : string ;
221-
222- /**
223- * Language code of the detected source language.
224- */
225- readonly detectedSourceLang : SourceLanguageCode ;
226- }
227-
22875/**
22976 * Returns true if the specified DeepL Authentication Key is associated with a free account,
23077 * otherwise false.
0 commit comments