Working on translations for dialogs and cutscenes
This commit is contained in:
1 parent
a98f71676d
commit
794a820be9
25 files changed
+3015
-123
No files matched your search
@@ -0,0 +1,38 @@
|
||||
"""
|
||||
translation_sync_common.py - Shared merge/write logic for the *_translations sync
|
||||
scripts (sync_dialogue_translations.py, sync_cutscene_translations.py).
|
||||
|
||||
Each sync script collects strings from its own JSON shape (dialogue nodes/choices,
|
||||
cutscene lines, ...) and hands the ordered list of unique strings to
|
||||
sync_translations(), which merges them into a translations JSON file shaped as
|
||||
{"dialogue_translations": [{"key":..., "ru":..., "en":...}, ...]}. New entries are
|
||||
always appended at the end so missing translations are easy to locate.
|
||||
"""
|
||||
|
||||
import json
|
||||
import os
|
||||
|
||||
|
||||
def sync_translations(strings: list[str], translations_path: str) -> None:
|
||||
if os.path.isfile(translations_path):
|
||||
with open(translations_path, 'r', encoding='utf-8') as f:
|
||||
translations = json.load(f)
|
||||
else:
|
||||
translations = {}
|
||||
|
||||
entries = translations.setdefault("dialogue_translations", [])
|
||||
existing_keys = {entry.get("key") for entry in entries}
|
||||
|
||||
added = 0
|
||||
for text in strings:
|
||||
if text in existing_keys:
|
||||
continue
|
||||
entries.append({"key": text, "ru": text, "en": ""})
|
||||
existing_keys.add(text)
|
||||
added += 1
|
||||
|
||||
os.makedirs(os.path.dirname(os.path.abspath(translations_path)), exist_ok=True)
|
||||
with open(translations_path, 'w', encoding='utf-8') as f:
|
||||
json.dump(translations, f, indent=4, ensure_ascii=False)
|
||||
|
||||
print(f"Saved: {translations_path} ({added} new key(s) added, {len(entries)} total)")
|
||||
Reference in new issue
Block a user