pub struct TranslationEngine { /* private fields */ }Expand description
Orchestrates subtitle translation through an AIProvider.
The engine is deliberately thin: it is composed of an AI provider, a
FormatManager for parsing/serialization, and a configurable batch
size. Constructors are provided so crate::core::factory::ComponentFactory
can wire the engine from runtime configuration without leaking provider
details.
Implementations§
Source§impl TranslationEngine
impl TranslationEngine
Sourcepub fn new(ai_provider: Arc<dyn AIProvider>, batch_size: usize) -> Result<Self>
pub fn new(ai_provider: Arc<dyn AIProvider>, batch_size: usize) -> Result<Self>
Create an engine with a custom batch size.
§Errors
Returns SubXError::config when batch_size is zero.
Sourcepub fn batch_size(&self) -> usize
pub fn batch_size(&self) -> usize
Get the configured AI batch size.
Sourcepub fn format_manager(&self) -> &FormatManager
pub fn format_manager(&self) -> &FormatManager
Borrow the underlying FormatManager.
Sourcepub async fn translate_subtitle(
&self,
subtitle: Subtitle,
request: &TranslationRequest,
) -> Result<TranslationResult>
pub async fn translate_subtitle( &self, subtitle: Subtitle, request: &TranslationRequest, ) -> Result<TranslationResult>
Translate a subtitle that has already been parsed into the shared
Subtitle data model.
This is the primary entry point used by the translate command and integration tests. It does not perform any filesystem I/O.
The order of operations matches the OpenSpec design:
- Generate UUIDv7 cue IDs with strict 1ms spacing.
- Run a terminology extraction pass (single AI request) and merge the result with the user glossary.
- Translate cues in configurable batches, validating each response against the requested cue IDs before applying any text changes.
- Reapply translated text to the parsed subtitle while preserving timing, ordering, cue counts, and styling metadata.
Sourcepub async fn translate_content(
&self,
content: &str,
request: &TranslationRequest,
) -> Result<TranslationResult>
pub async fn translate_content( &self, content: &str, request: &TranslationRequest, ) -> Result<TranslationResult>
Parse subtitle text content and translate it.
Convenience wrapper that detects the format using
FormatManager::parse_auto before delegating to
Self::translate_subtitle.
Sourcepub async fn extract_terminology(
&self,
cue_texts: &[String],
request: &TranslationRequest,
) -> Result<TerminologyMap>
pub async fn extract_terminology( &self, cue_texts: &[String], request: &TranslationRequest, ) -> Result<TerminologyMap>
Run only the terminology extraction pass.
Exposed so callers can preview the terminology map before issuing translation requests.