Working version
parent
a7b609b93e
commit
087c1dc117
|
@ -5,8 +5,6 @@ edition = "2018"
|
||||||
license = "MIT OR Apache-2.0"
|
license = "MIT OR Apache-2.0"
|
||||||
authors = ["Mathias Rothenhäusler <safemind@posteo.net"]
|
authors = ["Mathias Rothenhäusler <safemind@posteo.net"]
|
||||||
|
|
||||||
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
|
|
||||||
|
|
||||||
[dependencies]
|
[dependencies]
|
||||||
hyper-tls = "^0.5.0"
|
hyper-tls = "^0.5.0"
|
||||||
hyper = { version = "0.14", features = ["full"] }
|
hyper = { version = "0.14", features = ["full"] }
|
||||||
|
|
|
@ -7,14 +7,14 @@ args:
|
||||||
short: s
|
short: s
|
||||||
long: source
|
long: source
|
||||||
value_name: source_lang
|
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
|
takes_value: true
|
||||||
required: false
|
required: false
|
||||||
- target:
|
- target:
|
||||||
short: d
|
short: t
|
||||||
long: target
|
long: target
|
||||||
value_name: target_lang
|
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
|
takes_value: true
|
||||||
required: false
|
required: false
|
||||||
- file:
|
- file:
|
||||||
|
|
10
src/lib.rs
10
src/lib.rs
|
@ -7,7 +7,7 @@ pub mod deepl_helper {
|
||||||
|
|
||||||
pub struct Params {
|
pub struct Params {
|
||||||
source_lang: String,
|
source_lang: String,
|
||||||
destination_lang: String,
|
target_lang: String,
|
||||||
file: String,
|
file: String,
|
||||||
key: String,
|
key: String,
|
||||||
uri: String,
|
uri: String,
|
||||||
|
@ -33,9 +33,9 @@ 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_lang").unwrap_or("EN").to_string(),
|
source_lang: matches.value_of("source").unwrap_or("EN").to_string(),
|
||||||
destination_lang: matches
|
target_lang: matches
|
||||||
.value_of("destination_lang")
|
.value_of("target")
|
||||||
.unwrap_or("DE")
|
.unwrap_or("DE")
|
||||||
.to_string(),
|
.to_string(),
|
||||||
file: matches.value_of("file").unwrap_or_default().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",
|
"auth_key=%s&text=%s&target_lang=%s&source_lang=%s",
|
||||||
self.key,
|
self.key,
|
||||||
self.text,
|
self.text,
|
||||||
self.destination_lang,
|
self.target_lang,
|
||||||
self.source_lang
|
self.source_lang
|
||||||
)
|
)
|
||||||
.unwrap()
|
.unwrap()
|
||||||
|
|
|
@ -24,8 +24,9 @@ async fn main() -> Result<(), Box<dyn std::error::Error>> {
|
||||||
let v: Value = serde_json::from_str(&body)?;
|
let v: Value = serde_json::from_str(&body)?;
|
||||||
let result = String::from_str(match v["translations"][0]["text"].as_str() {
|
let result = String::from_str(match v["translations"][0]["text"].as_str() {
|
||||||
Some(text) => text,
|
Some(text) => text,
|
||||||
None => "No results"
|
None => body.as_str()
|
||||||
}).unwrap();
|
}).unwrap();
|
||||||
|
|
||||||
println!("{}", result.replace("\"", ""));
|
println!("{}", result.replace("\"", ""));
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue