pub struct HtmlTranslator {
config: TranslationConfig,
text_collector: TextCollector,
text_filter: TextFilter,
batch_manager: BatchManager,
cache_manager: Option<Arc<Mutex<CacheManager>>>,
http_client: Client,
stats: TranslationStats,
}Expand description
HTML翻译器
这是库的主要接口,提供完整的HTML翻译功能
Fields§
§config: TranslationConfig翻译配置
text_collector: TextCollector文本收集器
text_filter: TextFilter文本过滤器
batch_manager: BatchManager批次管理器
cache_manager: Option<Arc<Mutex<CacheManager>>>缓存管理器
http_client: ClientHTTP客户端
stats: TranslationStats翻译统计
Implementations§
Source§impl HtmlTranslator
impl HtmlTranslator
Sourcepub async fn new(config: TranslationConfig) -> TranslationResult<Self>
pub async fn new(config: TranslationConfig) -> TranslationResult<Self>
创建新的翻译器实例
Sourcepub async fn translate_html(&mut self, html: &str) -> TranslationResult<String>
pub async fn translate_html(&mut self, html: &str) -> TranslationResult<String>
翻译HTML字符串
Sourcepub async fn translate_file<P: AsRef<Path>>(
&mut self,
input_path: P,
output_path: P,
) -> TranslationResult<()>
pub async fn translate_file<P: AsRef<Path>>( &mut self, input_path: P, output_path: P, ) -> TranslationResult<()>
翻译HTML文件
Sourcepub async fn translate_dom(&mut self, dom: RcDom) -> TranslationResult<RcDom>
pub async fn translate_dom(&mut self, dom: RcDom) -> TranslationResult<RcDom>
翻译DOM树
Sourcefn parse_html(&self, html: &str) -> TranslationResult<RcDom>
fn parse_html(&self, html: &str) -> TranslationResult<RcDom>
解析HTML字符串为DOM
Sourcefn serialize_dom(&self, dom: RcDom) -> TranslationResult<String>
fn serialize_dom(&self, dom: RcDom) -> TranslationResult<String>
序列化DOM为HTML字符串
Sourceasync fn check_cache(
&self,
texts: &[TextItem],
) -> TranslationResult<(Vec<(TextItem, String)>, Vec<TextItem>)>
async fn check_cache( &self, texts: &[TextItem], ) -> TranslationResult<(Vec<(TextItem, String)>, Vec<TextItem>)>
检查缓存
Sourceasync fn update_cache(
&self,
translations: &[(TextItem, String)],
) -> TranslationResult<()>
async fn update_cache( &self, translations: &[(TextItem, String)], ) -> TranslationResult<()>
更新缓存
Sourceasync fn translate_batch(
&self,
batch: &[TextItem],
) -> TranslationResult<Vec<(TextItem, String)>>
async fn translate_batch( &self, batch: &[TextItem], ) -> TranslationResult<Vec<(TextItem, String)>>
翻译单个批次
Sourceasync fn call_translation_api(&self, text: &str) -> TranslationResult<String>
async fn call_translation_api(&self, text: &str) -> TranslationResult<String>
调用翻译API
Sourcefn parse_translation_response(
&self,
response: &str,
expected_count: usize,
) -> TranslationResult<Vec<String>>
fn parse_translation_response( &self, response: &str, expected_count: usize, ) -> TranslationResult<Vec<String>>
解析翻译响应
Sourcefn apply_translations_to_dom(
&self,
dom: RcDom,
translations: Vec<(TextItem, String)>,
) -> TranslationResult<RcDom>
fn apply_translations_to_dom( &self, dom: RcDom, translations: Vec<(TextItem, String)>, ) -> TranslationResult<RcDom>
应用翻译到DOM
Sourcepub fn get_stats(&self) -> &TranslationStats
pub fn get_stats(&self) -> &TranslationStats
获取翻译统计信息
Sourcepub fn reset_stats(&mut self)
pub fn reset_stats(&mut self)
重置统计信息
Auto Trait Implementations§
impl Freeze for HtmlTranslator
impl !RefUnwindSafe for HtmlTranslator
impl Send for HtmlTranslator
impl Sync for HtmlTranslator
impl Unpin for HtmlTranslator
impl !UnwindSafe for HtmlTranslator
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more