#!/usr/bin/env python3 """ sync_dialogue_translations.py - Sync a dialogue config's strings into a translation file. Reads , collects every non-empty "speaker" and "text" string from its nodes (and "text" from any node's "choices"), and appends any string not already present as a "key" in 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. Usage: python sync_dialogue_translations.py """ import json import sys from translation_sync_common import sync_translations def collect_strings(dialogue_config: dict) -> list[str]: seen = set() ordered = [] def add(value): if value and value not in seen: seen.add(value) ordered.append(value) for dialogue in dialogue_config.get("dialogues", []): for node in dialogue.get("nodes", []): add(node.get("speaker", "")) add(node.get("text", "")) for choice in node.get("choices", []): add(choice.get("text", "")) return ordered def sync(dialogue_path: str, translations_path: str) -> None: with open(dialogue_path, 'r', encoding='utf-8') as f: dialogue_config = json.load(f) sync_translations(collect_strings(dialogue_config), translations_path) if __name__ == '__main__': if len(sys.argv) != 3: print(f"Usage: {sys.argv[0]} ") sys.exit(1) sync(sys.argv[1], sys.argv[2])