A Rust package for unlimited DeepL translation
Features
·
Usage
·
Integration
·
Reference
·
License
Client, TranslateRequest, Auth, and strong errors.dlx for the typed library and dlx-svr for the HTTP server.git clone https://github.com/hominsu/deeplx-rs.git
cd deploy
docker-compose up -d
cargo install --path crates/dlx-svr --features mimalloc
Add dlx to your Cargo.toml:
[dependencies]
dlx = { version = "3", default-features = false }
dlx is configured through Client::builder():
use std::time::Duration;
use dlx::{Auth, Client};
let client = Client::builder()
.auth(Auth::Anonymous)
.timeout(Duration::from_secs(20))
.proxy("http://127.0.0.1:7890".parse().unwrap())
.build()?;
For Pro requests, use a Bearer token:
use dlx::{Auth, Client};
use secrecy::SecretString;
let client = Client::builder()
.auth(Auth::Bearer(SecretString::from("token".to_string())))
.build()?;
Below is an example using tokio for async execution:
use dlx::{Auth, Client, SourceLang, TargetLang, TranslateRequest};
#[tokio::main]
async fn main() -> Result<(), dlx::Error> {
let client = Client::builder().auth(Auth::Anonymous).build()?;
let request = TranslateRequest::builder()
.text("Hello, world!")?
.source(SourceLang::Auto)
.target(TargetLang::parse("ZH-HANS")?)
.build()?;
let response = client.translate(&request).await?;
println!("{}", response.translations[0].text);
Ok(())
}
The HTTP server is optional:
cargo run -p dlx-svr --features mimalloc -- run --conf ./configs
/translate uses anonymous oneshot requests. /v1/translate accepts
Authorization: Bearer <token> for Pro requests, with temporary compatibility
for Cookie: dl_session=<token>.
Distributed under the MIT License. See LICENSE for more information.
Content type
Image
Digest
sha256:3ad796498…
Size
5.4 MB
Last updated
3 months ago
docker pull hominsu/dlx-svr