Sign inSign up

hominsu/dlx-svr

By hominsu

•Updated 3 months ago

Image
0

1.4K

hominsu/dlx-svr repository overview

Contributors Forks Stargazers Issues License Build


⁠dlx

A Rust package for unlimited DeepL translation

Features⁠ · Usage⁠ · Integration⁠ · Reference⁠ · License⁠

⁠Features

  • DeepL Chrome extension oneshot transport.
  • Typed library API with Client, TranslateRequest, Auth, and strong errors.
  • Workspace split with dlx for the typed library and dlx-svr for the HTTP server.
  • Proxy support on native targets.

⁠Usage

⁠Docker Deployment
  1. Clone the repository:
    git clone https://github.com/hominsu/deeplx-rs.git
    
  2. Start the container:
    cd deploy
    docker-compose up -d
    
⁠Install with Cargo
cargo install --path crates/dlx-svr --features mimalloc

⁠Integration

⁠Installation

Add dlx to your Cargo.toml:

[dependencies]
dlx = { version = "3", default-features = false }
⁠Configuration

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()?;
⁠Usage

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(())
}
⁠Server

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>.

⁠Reference

⁠License

Distributed under the MIT License. See LICENSE for more information.

Tag summary

Content type

Image

Digest

sha256:3ad796498…

Size

5.4 MB

Last updated

3 months ago

docker pull hominsu/dlx-svr