File size: 1,565 Bytes
921d377
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
"""
Multilingual variant generator.

``generate_language_variants`` takes a filled BranchGraph and a
list of target languages, and returns a list of dicts suitable
for persisting into ``ix_node_variants`` via the repo.

Phase 1 implementation: passthrough — same narration/subtitles in
every target language with an ``[untranslated:<lang>]`` prefix.
This keeps the pipeline testable without an LLM/translator in the
loop. Phase 2 swaps in a real translator behind the same
signature.
"""
from __future__ import annotations

from typing import Any, Dict, List

from ..branching.graph import BranchGraph


def generate_language_variants(
    graph: BranchGraph, *, target_languages: List[str],
) -> List[Dict[str, Any]]:
    """Produce variant rows (as dicts) for every (node, language)
    pair where language is NOT already the authoring language
    ('en' by convention). No side effects — the caller persists.
    """
    out: List[Dict[str, Any]] = []
    for lang in target_languages:
        lang = (lang or "").strip()
        if not lang or lang == "en":
            continue
        for node in graph.nodes:
            narration = (node.narration or "").strip()
            if not narration:
                continue
            out.append({
                "node_id": node.id,
                "language": lang,
                "narration": f"[untranslated:{lang}] {narration}",
                "subtitles": f"[untranslated:{lang}] {narration}",
                "audio_asset_id": "",
                "video_asset_id": "",
            })
    return out