Sign inSign up

hominsu/deeplx

By hominsu

•Updated 3 months ago

A Rust package for unlimited DeepL translation

Image
Developer tools
Web servers
0

9.2K

hominsu/deeplx repository overview

Contributors Forks Stargazers Issues License Build


⁠deeplx-rs

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.
  • Optional server binary behind the server feature.
  • 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 deeplx --features server,mimalloc

⁠Integration

⁠Installation

Add deeplx to your Cargo.toml:

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

deeplx is configured through Client::builder():

use std::time::Duration;

use deeplx::{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 deeplx::{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 deeplx::{Auth, Client, SourceLang, TargetLang, TranslateRequest};

#[tokio::main]
async fn main() -> Result<(), deeplx::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 --features server,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:d3c45493a…

Size

5.4 MB

Last updated

3 months ago

docker pull hominsu/deeplx