55 lines
1.7 KiB
Python
55 lines
1.7 KiB
Python
#!/usr/bin/env python3
|
|
"""
|
|
sync_cutscene_translations.py - Sync a cutscene config's strings into a translation file.
|
|
|
|
Reads <cutscene_config.json>, collects every non-empty "speaker" and "text" string
|
|
from its lines, and appends any string not already present as a "key" in
|
|
<translations.json> as a new entry with an empty "en" slot ready for a translator
|
|
to fill in. New entries are always appended at the end of the list so missing
|
|
translations are easy to locate.
|
|
|
|
Cutscene translations are intentionally kept in their own file/database, separate
|
|
from dialogue translations - point <translations.json> at a dedicated file such as
|
|
resources/dialogue/cutscene_translations.json.
|
|
|
|
Usage:
|
|
python sync_cutscene_translations.py <cutscene_config.json> <translations.json>
|
|
"""
|
|
|
|
import json
|
|
import sys
|
|
|
|
from translation_sync_common import sync_translations
|
|
|
|
|
|
def collect_strings(cutscene_config: dict) -> list[str]:
|
|
seen = set()
|
|
ordered = []
|
|
|
|
def add(value):
|
|
if value and value not in seen:
|
|
seen.add(value)
|
|
ordered.append(value)
|
|
|
|
for cutscene in cutscene_config.get("cutscenes", []):
|
|
for line in cutscene.get("lines", []):
|
|
add(line.get("speaker", ""))
|
|
add(line.get("text", ""))
|
|
|
|
return ordered
|
|
|
|
|
|
def sync(cutscene_path: str, translations_path: str) -> None:
|
|
with open(cutscene_path, 'r', encoding='utf-8') as f:
|
|
cutscene_config = json.load(f)
|
|
|
|
sync_translations(collect_strings(cutscene_config), translations_path)
|
|
|
|
|
|
if __name__ == '__main__':
|
|
if len(sys.argv) != 3:
|
|
print(f"Usage: {sys.argv[0]} <cutscene_config.json> <translations.json>")
|
|
sys.exit(1)
|
|
|
|
sync(sys.argv[1], sys.argv[2])
|