diff --git a/.gitignore b/.gitignore index 4683d71..7937363 100644 --- a/.gitignore +++ b/.gitignore @@ -1,4 +1,5 @@ .vscode/ +.idea # Generated by Cargo # will have compiled files and executables debug/ diff --git a/src/lib.rs b/src/lib.rs index e43b570..5da6756 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -34,7 +34,7 @@ pub mod deepl_helper { let matches = App::from_yaml(yaml).get_matches(); 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(), file: matches.value_of("file").unwrap_or_default().to_string(), key: env::var("key").unwrap(), @@ -48,14 +48,20 @@ pub mod deepl_helper { } pub fn body(&self) -> String { - sprintf!( - "auth_key=%s&text=%s&target_lang=%s&source_lang=%s", + let mut body = sprintf!( + "auth_key=%s&text=%s&target_lang=%s", self.key, self.text, - self.target_lang, - self.source_lang + self.target_lang ) - .unwrap() + .unwrap(); + + if self.source_lang != "0" { + let add = sprintf!("&source_lang=%s", self.source_lang).unwrap(); + body.push_str(&add); + } + + body } }