113 lines
4.0 KiB
Python
113 lines
4.0 KiB
Python
#!/usr/bin/env python3
|
|
# -*- coding: utf-8 -*-
|
|
"""
|
|
start.py — главное меню утилиты перевода визуальной новеллы.
|
|
|
|
Запускать из папки translate_util:
|
|
python start.py
|
|
|
|
Показывает список доступных шагов и запускает выбранный скрипт.
|
|
"""
|
|
|
|
import subprocess
|
|
import sys
|
|
from pathlib import Path
|
|
|
|
BASE_DIR = Path(__file__).resolve().parent
|
|
|
|
MENU_ITEMS = [
|
|
{
|
|
"key": "1",
|
|
"title": "Extract — достать файлы из архива",
|
|
"desc": "Достаёт файлы из int архива и помещает их в одноимённую папку",
|
|
"script": "extract.py",
|
|
},
|
|
{
|
|
"key": "2",
|
|
"title": "Decompile — достать текст из .cst файлов",
|
|
"desc": "Берёт зашифрованные .cst файлы (например из update00) и превращает их в читаемые .txt файлы в папке txt.",
|
|
"script": "decompile.py",
|
|
},
|
|
{
|
|
"key": "3",
|
|
"title": "Txt to NSV — подготовить текст к переводу",
|
|
"desc": "Превращает .txt файлы из папки txt в .nsv файлы в папке json — компактный текстовый формат, удобный для перевода и для git-диффов.",
|
|
"script": "convert.py --txt2nsv",
|
|
},
|
|
{
|
|
"key": "4",
|
|
"title": "Names — скрап всех имён",
|
|
"desc": "Собирает все имена из .nsv файлов и помещает в CSV в формате original,translated",
|
|
"script": "names.py",
|
|
},
|
|
{
|
|
"key": "5",
|
|
"title": "Перевод",
|
|
"desc": "Перевод с помощью OpenAI-соместимой LLM (Gemini, Claude, ChatGPT и т.д.)",
|
|
"script": "translate.py",
|
|
},
|
|
{
|
|
"key": "6",
|
|
"title": "NSV to Txt — собрать текст после перевода",
|
|
"desc": "Берёт переведённые .nsv файлы и вставляет текст обратно в .txt (структура и команды не трогаются). Результат — в папке txt_translated.",
|
|
"script": "convert.py --nsv2txt",
|
|
},
|
|
{
|
|
"key": "7",
|
|
"title": "Compile — собрать .cst обратно для игры",
|
|
"desc": "Компилирует .txt файлы (по умолчанию из txt_translated) обратно в .cst и кладёт их в папку update01.",
|
|
"script": "compile.py",
|
|
},
|
|
]
|
|
|
|
|
|
def print_menu():
|
|
print("=" * 60)
|
|
print(" Утилита перевода визуальной новеллы — главное меню")
|
|
print("=" * 60)
|
|
print()
|
|
for item in MENU_ITEMS:
|
|
print(f" {item['key']}. {item['title']}")
|
|
print(f" {item['desc']}")
|
|
print()
|
|
print(" 0. Выход")
|
|
print()
|
|
print("=" * 60)
|
|
|
|
|
|
def run_script(command_str: str):
|
|
parts = command_str.split()
|
|
script_name = parts[0]
|
|
args = parts[1:]
|
|
|
|
script_path = BASE_DIR / script_name
|
|
if not script_path.exists():
|
|
print(f"Ошибка: не найден файл {script_path}")
|
|
return
|
|
|
|
print(f"\nЗапуск: {command_str}\n")
|
|
|
|
run_cmd = [sys.executable, str(script_path)] + args
|
|
subprocess.run(run_cmd)
|
|
|
|
|
|
def main():
|
|
while True:
|
|
print_menu()
|
|
choice = input("Выберите пункт (0-7): ").strip()
|
|
|
|
if choice == "0":
|
|
break
|
|
|
|
matched = next((item for item in MENU_ITEMS if item["key"] == choice), None)
|
|
if matched:
|
|
run_script(matched["script"])
|
|
input("\nНажмите Enter, чтобы вернуться в меню...")
|
|
else:
|
|
print("\nНеверный выбор, попробуйте ещё раз.")
|
|
input("Нажмите Enter, чтобы продолжить...")
|
|
|
|
|
|
if __name__ == "__main__":
|
|
main()
|