This Rust library provides a simple and easy-to-use interface for translating text. It can be used to chain translations, translate with different translators, and use a special translator based on the detected language. The library currently supports translation methods that involve making API requests to sites like Bing Translate, Google Translate, and other online translators.
- whatlang-detector
- lingua-detector
- all-detectors
- retries
- deepl
- mymemory
- chatgpt
- libre
- api
- papago-scrape
- google-scrape
- youdao-scrape
- edge-gpt-scrape
- baidu-scrape
- bing-scrape
- scraper
- online
Heres an example how to translate text from unkown language to english. When the detec.ted language is chinese it uses the papago translator. When the language isnt defined it uses the default translator which is google in this case
fn main() {
dotenv().ok();
let mut hashmap = HashMap::new();
hashmap.insert(Language::Chinese, Translator::Papago);
let selector = TranslatorSelectorInfo::Selective(
hashmap,
TranslatorInfo {
translator: Translator::Google,
to: Language::English,
},
);
let v = Translators::new(
Some(Tokens::get_env().unwrap()),
selector,
None,
Some(3),
Detectors::Whatlang,
)
.await
.unwrap();
let chatgpt_context = Context::ChatGPT("This is a text about ...".to_string());
let translation = v.translate("Hello world".to_string(), None, &[chatgpt_context]).await.unwrap();
let translations = v.translate_vec(vec!["Hello world".to_string(), "This is a test".to_string()], None, &[]).await.unwrap();
println!("{:?}, {:?}", translation, translations);
}
The detector could be used seperatly like this: Online detectors will be implemented oin the future
let text = "Hallo Welt";
let lang = detector::detect_language(text, & Detectors::Whatlang).unwrap();
println!("{:?}", lang);
๐ด = Offline, ๐๏ธ = Online, โ๏ธ = Supported, โฑ๏ธ = not implemented yet, โ = does not exist, โ = WIP
Translator | Kind | Scraped | API | Note |
---|---|---|---|---|
Baidu Translate | ๐๏ธ | โ๏ธ | โ๏ธ | |
Bing Translate | ๐๏ธ | โ๏ธ | โฑ๏ธ | |
ChatGPT | ๐๏ธ | โ๏ธ | โ๏ธ | |
Google Translate | ๐๏ธ | โ๏ธ | โ | |
Papago | ๐๏ธ | โ๏ธ | โ | |
Youdao | ๐๏ธ | โ๏ธ | โ | |
Libretranslate | ๐๏ธ | โ | โ๏ธ | |
Mymemory | ๐๏ธ | โ | โ๏ธ | |
Deepl | ๐๏ธ | โฑ๏ธ | โ๏ธ | |
M2M100 | ๐ด๏ธ | โ๏ธ | ๏ธ โ | Converted 05/13/23 |
JParaCrawl | ๐ด๏ธ | ๏ธ โ | ๏ธโ | V3 |
Sugoi [online] | ๐ด๏ธ | โฑ๏ธ๏ธ | โ๏ธ | V4 / Support the creator |
Nllb | ๐ด๏ธ | ๏ธ โ | ๏ธโ | Converted 05/13/23 |
The supported languages can be found in languages.csv
. This file is used to generate languages.rs. missing
contains
the languages that are missing in languages.csv
(languages i didn't find a name for)
If you find a bug or have an idea for a new feature, feel free to open an issue or submit a pull request. We welcome contributions from the community!