Expand description
§deeprl
Access the DeepL translation engine through a quick and reliable interface. We aim to provide the full suite of tools DeepL offers. See the official docs for detailed resources.
§Note
This crate uses a blocking http client, and as such is only suitable for use in synchronous (blocking) applications. If you intend to use the library functions in an async app, there is a crate for that.
§Examples
Create a new client with a valid API token to access the associated methods. For instance, you may wish to translate a simple text string to some target language.
use deeprl::{DeepL, Language, TextOptions};
let key = std::env::var("DEEPL_API_KEY").unwrap();
let dl = DeepL::new(&key);
// Translate 'good morning' to German
let text = vec![
"good morning".to_string(),
];
let opt = TextOptions::new(Language::De).text(text);
let result = dl.translate(opt).unwrap();
assert!(!result.translations.is_empty());
let translation = &result.translations[0];
assert_eq!(translation.text, "Guten Morgen");
As a helpful sanity check, make sure you’re able to return account usage statistics.
use deeprl::DeepL;
let dl = DeepL::new(
&std::env::var("DEEPL_API_KEY").unwrap()
);
let usage = dl.usage().unwrap();
assert!(usage.character_limit > 0);
let count = usage.character_count;
let limit = usage.character_limit;
println!("Used: {count}/{limit}");
// Used: 42/500000
DeepL
also allows translating documents and creating custom glossaries.
§License
This project is licenced under MIT license.
Macros§
- builder
- Self-implementing type builder
Structs§
- DeepL
- The
DeepL
client struct - Document
- Document handle
- Document
Options - Options for
Document
translation - Document
Status - Document translation status
- Glossaries
Result - The result of getting available glossaries
- Glossary
- Information that uniquely identifies a glossary
- Glossary
Language Pair - A glossary language pair
- Glossary
Language Pairs Result - Defines the set of supported language pairs for a glossary
- Language
Info - Information about a supported language
- Text
Options - Options for
Text
translation - Translate
Text Result - Translation result
- Translation
- An individual translation
- Usage
- API usage & account limits. Currently assumes an individual developer account.
Enums§
- DocState
- Document state
- Error
- Crate error variants
- Formality
- Sets whether the translation engine should lean towards formal or informal language
- Glossary
Entries Format - Format in which glossary entries are provided
- Language
- Language variants.
- Language
Type - Language type. Note: this is currently only used when fetching language meta information.
- Split
Sentences - Sets whether the translation engine should first split the input into sentences
- TagHandling
- Sets which kind of tags should be handled