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 types;
55pub mod translator;
56pub mod functional;
57pub mod collector;
58pub mod simple_config;
59pub mod engine;
60
61pub use config::TranslationLibConfig;
62pub use error::{TranslationError, Result};
63pub use types::{
64    TranslationConfig, RetryConfig, DeepLXRequest, DeepLXResponse, 
65    DpTransRequest, TextSegment
66};
67pub use translator::{TranslationService, RateLimiter, retry_with_backoff};
68pub use functional::{
69    TextItem, TextType, TextPriority, Batch, TextAnalysis,
70    TextFilter, BatchManager, create_text_item, batch_analyze_texts, create_optimized_batches
71};
72pub use collector::{
73    DomNode, TextCollector, collect_translatable_texts, 
74    group_texts_by_type, group_texts_by_priority
75};
76pub use simple_config::{
77    SimpleTranslationConfig, ConfigBuilder, SimpleConfigManager,
78    quick_config, config_builder, load_config_from_env, validate_config,
79    presets
80};
81pub use engine::{
82    UnifiedTranslationEngine, EngineStats, EngineHealth, HealthStatus,
83    create_engine, create_dev_engine, create_prod_engine
84};