use auto detect source language

master
Mathias Rothenhaeusler 2022-01-07 09:59:32 +01:00
parent 60d011a5db
commit 3c92b26599
2 changed files with 13 additions and 6 deletions

1
.gitignore vendored
View File

@ -1,4 +1,5 @@
.vscode/ .vscode/
.idea
# Generated by Cargo # Generated by Cargo
# will have compiled files and executables # will have compiled files and executables
debug/ debug/

View File

@ -34,7 +34,7 @@ pub mod deepl_helper {
let matches = App::from_yaml(yaml).get_matches(); let matches = App::from_yaml(yaml).get_matches();
Self { Self {
source_lang: matches.value_of("source").unwrap_or("DE").to_string(), source_lang: matches.value_of("source").unwrap_or("0").to_string(),
target_lang: matches.value_of("target").unwrap_or("EN-US").to_string(), target_lang: matches.value_of("target").unwrap_or("EN-US").to_string(),
file: matches.value_of("file").unwrap_or_default().to_string(), file: matches.value_of("file").unwrap_or_default().to_string(),
key: env::var("key").unwrap(), key: env::var("key").unwrap(),
@ -48,14 +48,20 @@ pub mod deepl_helper {
} }
pub fn body(&self) -> String { pub fn body(&self) -> String {
sprintf!( let mut body = sprintf!(
"auth_key=%s&text=%s&target_lang=%s&source_lang=%s", "auth_key=%s&text=%s&target_lang=%s",
self.key, self.key,
self.text, self.text,
self.target_lang, self.target_lang
self.source_lang
) )
.unwrap() .unwrap();
if self.source_lang != "0" {
let add = sprintf!("&source_lang=%s", self.source_lang).unwrap();
body.push_str(&add);
}
body
} }
} }