Skip to content

hominsu/deeplx-rs

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

53 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Contributors Forks Stargazers Issues License Build


deeplx-rs

A Rust package for unlimited DeepL translation

Features · Usage · Integration · Reference · License

Features

  • Docker support for easy deployment.
  • Proxy support by default (can be disabled via features).
  • Optional impersonation using the impersonate feature to mimic browser settings.

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 --features="server"

If you want to mimic browser settings, use the impersonate feature:

cargo install --features="impersonate,server"

Note: The impersonate feature relies on the rquest crate, which may not be stable. Additionally, build artifacts may increase by ~50%.

Integration

Installation

Add deeplx to your Cargo.toml:

[dependencies]
deeplx = "1"

By default, deeplx includes proxy support. If you do not need proxy support, disable the default features:

[dependencies]
deeplx = { version = "1", default-features = false }

If you want to enable the impersonate feature to mimic browser headers, TLS settings, etc.:

[dependencies]
deeplx = { version = "1", features = ["impersonate"] }

Configuration

deeplx is configured via the Config struct. You can specify options such as proxy, timeout, and more. For example:

use deeplx::{Config, DeepLX};

let translator = DeepLX::new(Config {
    proxy: Some("http://pro.xy".to_string()),
    ..Default::default()
});

If you have disabled the proxy feature, you can simply omit the proxy field:

use deeplx::{Config, DeepLX};

let translator = DeepLX::new(Config::default ());

Usage

Below is an example using tokio for async execution:

use deeplx::{Config, DeepLX};

#[tokio::main]
async fn main() {
    let translator = DeepLX::new(Config {
        proxy: Some("http://pro.xy".to_string()),
        ..Default::default()
    });
    // Or without proxy:
    // let translator = DeepLX::new(Config::default());

    match translator.translate("auto", "zh", "Hello, world!", None, None).await {
        Ok(res) => println!("Translated: {}", res.data),
        Err(e) => eprintln!("Error: {}", e),
    }
}

Reference

License

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