feat(translation): add Rust Translation Memory and config migration

This commit is contained in:
2026-09-06 22:48:51 +08:00
parent 93f4bc69b3
commit 7d6389806b
18 changed files with 4414 additions and 384 deletions
+2
View File
@@ -4,8 +4,10 @@
pub mod cas_repository;
pub mod resource_repository;
pub mod translation_memory_repository;
pub mod translation_repository;
pub use cas_repository::CasRepository;
pub use resource_repository::ResourceRepository;
pub use translation_memory_repository::TranslationMemoryRepository;
pub use translation_repository::TranslationRepository;
@@ -0,0 +1,47 @@
//! Translation Memory 仓储契约。
use crate::domain::{
TranslationMemoryContext, TranslationMemoryDraft, TranslationMemoryEntry,
TranslationMemoryMatch, TranslationMemorySummary,
};
use async_trait::async_trait;
/// 跨 official release 持久化的 Translation Memory 仓储。
///
/// 该契约只描述 V1 的精确查询和明确人工确认。仓储实现不得把
/// `TranslationTaskStatus::Completed` 或 provider 成功隐式解释为 trusted。
#[async_trait]
pub trait TranslationMemoryRepository: Send + Sync {
/// 保存一条 provider/manual/imported 译文候选。
///
/// 相同 source、上下文、译文、来源 release 和来源类型的重复写入必须幂等;
/// 已 trusted 的记录不得被普通候选静默覆盖。
async fn upsert_candidate(
&self,
draft: TranslationMemoryDraft,
) -> crate::Result<TranslationMemoryEntry>;
/// 按原始 source text 和上下文查询精确匹配。
///
/// 实现可以返回 source 归一化后但原文不同的辅助候选,但这类结果不能自动复用。
async fn find_matches(
&self,
source_text: &str,
source_context: &TranslationMemoryContext,
limit: usize,
) -> crate::Result<Vec<TranslationMemoryMatch>>;
/// 显式确认一条记录为 trusted。
async fn confirm(
&self,
record_id: &str,
reviewer: &str,
reason: Option<String>,
) -> crate::Result<TranslationMemoryEntry>;
/// 按稳定记录 ID 读取一条 TM 记录。
async fn find(&self, record_id: &str) -> crate::Result<TranslationMemoryEntry>;
/// 读取数据库和记录统计。
async fn summary(&self) -> crate::Result<TranslationMemorySummary>;
}