Working version

master
Mathias Rothenhaeusler 2021-09-17 19:51:09 +02:00
parent a7b609b93e
commit 087c1dc117
4 changed files with 10 additions and 11 deletions

View File

@ -5,8 +5,6 @@ edition = "2018"
license = "MIT OR Apache-2.0"
authors = ["Mathias Rothenhäusler <safemind@posteo.net"]
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
[dependencies]
hyper-tls = "^0.5.0"
hyper = { version = "0.14", features = ["full"] }

View File

@ -7,14 +7,14 @@ args:
short: s
long: source
value_name: source_lang
help: The language you want to translate.
help: The language you want to translate. Default is EN_US
takes_value: true
required: false
- target:
short: d
short: t
long: target
value_name: target_lang
help: The language your text should be tranlated to.
help: The language your text should be tranlated to. Default is DE
takes_value: true
required: false
- file:

View File

@ -7,7 +7,7 @@ pub mod deepl_helper {
pub struct Params {
source_lang: String,
destination_lang: String,
target_lang: String,
file: String,
key: String,
uri: String,
@ -33,9 +33,9 @@ pub mod deepl_helper {
let matches = App::from_yaml(yaml).get_matches();
Self {
source_lang: matches.value_of("source_lang").unwrap_or("EN").to_string(),
destination_lang: matches
.value_of("destination_lang")
source_lang: matches.value_of("source").unwrap_or("EN").to_string(),
target_lang: matches
.value_of("target")
.unwrap_or("DE")
.to_string(),
file: matches.value_of("file").unwrap_or_default().to_string(),
@ -54,7 +54,7 @@ pub mod deepl_helper {
"auth_key=%s&text=%s&target_lang=%s&source_lang=%s",
self.key,
self.text,
self.destination_lang,
self.target_lang,
self.source_lang
)
.unwrap()

View File

@ -24,8 +24,9 @@ async fn main() -> Result<(), Box<dyn std::error::Error>> {
let v: Value = serde_json::from_str(&body)?;
let result = String::from_str(match v["translations"][0]["text"].as_str() {
Some(text) => text,
None => "No results"
None => body.as_str()
}).unwrap();
println!("{}", result.replace("\"", ""));
Ok(())
}