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,66 @@
|
||||
#!/usr/bin/env python3
|
||||
"""
|
||||
dialogue_translations_to_xlsx.py - Export dialogue_translations.json to an XLSX
|
||||
spreadsheet for translators.
|
||||
|
||||
Reads a translation file shaped as {"dialogue_translations": [{"key":..., "ru":...,
|
||||
"en":...}, ...]}, and writes one row per entry with a "key" column followed by one
|
||||
column per language found in the file (order: ru, en, then any others found,
|
||||
alphabetically). Missing values are written as empty cells.
|
||||
|
||||
Usage:
|
||||
python dialogue_translations_to_xlsx.py <translations.json> <output.xlsx>
|
||||
"""
|
||||
|
||||
import json
|
||||
import sys
|
||||
|
||||
try:
|
||||
from openpyxl import Workbook
|
||||
from openpyxl.utils import get_column_letter
|
||||
except ImportError:
|
||||
raise SystemExit("openpyxl is required: pip install openpyxl")
|
||||
|
||||
PREFERRED_LANGUAGE_ORDER = ("ru", "en")
|
||||
|
||||
|
||||
def collect_languages(entries: list[dict]) -> list[str]:
|
||||
found = set()
|
||||
for entry in entries:
|
||||
found.update(k for k in entry.keys() if k != "key")
|
||||
|
||||
ordered = [lang for lang in PREFERRED_LANGUAGE_ORDER if lang in found]
|
||||
ordered += sorted(found - set(ordered))
|
||||
return ordered
|
||||
|
||||
|
||||
def export_to_xlsx(json_path: str, xlsx_path: str) -> None:
|
||||
with open(json_path, 'r', encoding='utf-8') as f:
|
||||
data = json.load(f)
|
||||
|
||||
entries = data.get("dialogue_translations", [])
|
||||
languages = collect_languages(entries)
|
||||
|
||||
wb = Workbook()
|
||||
ws = wb.active
|
||||
ws.title = "dialogue_translations"
|
||||
|
||||
ws.append(["key"] + languages)
|
||||
for entry in entries:
|
||||
ws.append([entry.get("key", "")] + [entry.get(lang, "") for lang in languages])
|
||||
|
||||
ws.freeze_panes = "A2"
|
||||
ws.column_dimensions["A"].width = 50
|
||||
for col_index in range(len(languages)):
|
||||
ws.column_dimensions[get_column_letter(col_index + 2)].width = 50
|
||||
|
||||
wb.save(xlsx_path)
|
||||
print(f"Saved: {xlsx_path} ({len(entries)} row(s), languages: {', '.join(languages)})")
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
if len(sys.argv) != 3:
|
||||
print(f"Usage: {sys.argv[0]} <translations.json> <output.xlsx>")
|
||||
sys.exit(1)
|
||||
|
||||
export_to_xlsx(sys.argv[1], sys.argv[2])
|
||||
Reference in new issue
Block a user