deepl-dart
This is an inofficial library that accesses the DeepL API.
Install
Put deepl: <latest version>
into your pubspec.yaml
or call dart pub add deepl
or flutter pub add deepl
, respectively.
Usage
Create an instance with
var deeplApi = DeepLApi.fromAuthKey(<your API key>);
and access the API through the namespaces e.g.
var translation = (await deepl.translations.translateText(
options: TranslateTextRequestOptionsBuilder.simple(
text: 'Hello',
target: TargetLanguage.ES,
).build(),
))
.first;
print(
'Detected language: ${translation.detectedLanguage?.name}, translation: ${translation.text}');
Translating Documents
To translate a document, you must first upload it with
var document = await deepl.documents.uploadDocument(
options: TranslateDocumentRequestOptionsBuilder(
filename: '<your_filename>',
target: TargetLanguage.ES,
).build(),
));
If it is a large document, you could check its translation status with
var status = await deepl.document.status(document);
print('Status: ${status.key}'');
// works only if `status.key == TranslationStatus.translating`
print('Estd. seconds: ${(status.value as StatusTranslating).estimatedSeconds}');
and finally download it with
var file = await deepl.document.downloadDocument(document, '<your_translated_filename>');
Supported endpoints
x
Translating documentsx
Pploading filesx
Checking file statusx
Downloading document
x
Translating textx
Glossariesx
Tranlation quota