diff --git a/Cargo.lock b/Cargo.lock index 98bb02b..32668a2 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -152,7 +152,7 @@ checksum = "ea221b5284a47e40033bf9b66f35f984ec0ea2931eb03505246cd27a963f981b" [[package]] name = "deepl" -version = "1.0.3" +version = "1.0.4" dependencies = [ "anyhow", "clap", diff --git a/Cargo.toml b/Cargo.toml index 3cd8742..556894b 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "deepl" -version = "1.0.3" +version = "1.0.4" edition = "2024" license = "MIT OR Apache-2.0" authors = ["Mathias Rothenhäusler Result { - let url = sprintf!("%s", self.uri) - .map_err(|e| anyhow!("could not create request body: {e:?}"))?; - - Ok(url) - } - pub fn body(&self) -> Result { let mut body = sprintf!( "text=%s&target_lang=%s", diff --git a/src/engine/response.rs b/src/engine/response.rs index da3426b..1c8b81a 100644 --- a/src/engine/response.rs +++ b/src/engine/response.rs @@ -1,7 +1,7 @@ use serde::{Deserialize, Serialize}; use crate::engine::params::Params; -use anyhow::Result; +use anyhow::{Result, anyhow}; #[derive(Serialize, Deserialize, Default)] struct Translations { @@ -16,7 +16,6 @@ pub struct DeeplResponse { impl DeeplResponse { pub fn get_text(&self, params: &Params) -> Result { - let max_src = self .translations .iter() @@ -27,6 +26,12 @@ impl DeeplResponse { let mut out = String::new(); for t in &self.translations { + if t.detected_source_language == params.target_lang { + return Err(anyhow!( + "Add target language, source and target identical ({})", + params.target_lang + )); + } out.push_str(&format!( "{src} >>> {:>> {}\n", params.input, diff --git a/src/main.rs b/src/main.rs index 34107f3..6dc4133 100644 --- a/src/main.rs +++ b/src/main.rs @@ -15,7 +15,7 @@ async fn main() -> Result<()> { let request = Request::builder() .method(Method::POST) - .uri(params.url()?) + .uri(¶ms.uri) .header("Authorization", format!("DeepL-Auth-Key {}", params.key)) .header("content-type", "application/x-www-form-urlencoded") .body(Body::from(params.body()?))?;