markdown_translator/
lib.rs

1//! # Markdown Translator
2//!
3//! 一个高性能的Rust翻译库,专为Markdown文档设计,提供智能文本翻译功能。
4//!
5//! ## 主要特性
6//!
7//! - **智能代码块处理**: 自动识别并跳过代码块,保持代码完整性
8//! - **并行翻译**: 利用Rust异步特性,支持多任务并发翻译
9//! - **速率限制**: 内置智能速率限制器,防止API过载
10//! - **配置灵活**: 支持TOML配置文件和程序化配置
11//! - **错误恢复**: 完善的错误处理和重试机制
12//! - **文本分块**: 智能文本分割,处理长文档
13//!
14//! ## 快速开始
15//!
16//! ```rust
17//! use markdown_translator::{TranslationService, TranslationConfig};
18//!
19//! #[tokio::main]
20//! async fn main() -> Result<(), Box<dyn std::error::Error>> {
21//!     let config = TranslationConfig {
22//!         enabled: true,
23//!         source_lang: "en".to_string(),
24//!         target_lang: "zh".to_string(),
25//!         deeplx_api_url: "http://localhost:1188/translate".to_string(),
26//!         max_requests_per_second: 1.0,
27//!         max_text_length: 3000,
28//!         max_paragraphs_per_request: 10,
29//!     };
30//!     
31//!     let translator = TranslationService::new(config);
32//!     let result = translator.translate("Hello, world!").await?;
33//!     println!("Translation: {}", result);
34//!     
35//!     Ok(())
36//! }
37//! ```
38//!
39//! ## 配置文件支持
40//!
41//! ```toml
42//! [translation]
43//! enabled = true
44//! source_lang = "auto"
45//! target_lang = "zh"
46//! deeplx_api_url = "http://localhost:1188/translate"
47//! max_requests_per_second = 1.0
48//! max_text_length = 3000
49//! max_paragraphs_per_request = 10
50//! ```
51
52pub mod config;
53pub mod error;
54pub mod translator;
55pub mod types;
56
57pub use config::TranslationLibConfig;
58pub use error::{Result, TranslationError};
59pub use translator::{retry_with_backoff, RateLimiter, TranslationService};
60pub use types::{
61    DeepLXRequest, DeepLXResponse, DpTransRequest, RetryConfig, TextSegment, TranslationConfig,
62};