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§
- Self-implementing type builder
Structs§
- The
DeepL
client struct - Document handle
- Options for
Document
translation - Document translation status
- The result of getting available glossaries
- Information that uniquely identifies a glossary
- A glossary language pair
- Defines the set of supported language pairs for a glossary
- Information about a supported language
- Options for
Text
translation - Translation result
- An individual translation
- API usage & account limits. Currently assumes an individual developer account.
Enums§
- Document state
- Crate error variants
- Sets whether the translation engine should lean towards formal or informal language
- Format in which glossary entries are provided
- Language variants.
- Language type. Note: this is currently only used when fetching language meta information.
- Sets whether the translation engine should first split the input into sentences
- Sets which kind of tags should be handled