168 lines
5.6 KiB
Python
168 lines
5.6 KiB
Python
#!/usr/bin/env python3
|
|
"""
|
|
DeepL Translation Script
|
|
Translates Slovenian game text to 4 languages
|
|
"""
|
|
|
|
import json
|
|
import os
|
|
from pathlib import Path
|
|
|
|
try:
|
|
import deepl
|
|
DEEPL_AVAILABLE = True
|
|
except ImportError:
|
|
DEEPL_AVAILABLE = False
|
|
print("⚠️ DeepL not installed. Install with: pip3 install deepl")
|
|
print("Using fallback translations (manual review needed!)")
|
|
|
|
# Paths
|
|
LOCALIZATION_DIR = Path("assets/localization")
|
|
LOCALIZATION_DIR.mkdir(parents=True, exist_ok=True)
|
|
|
|
# Language mappings
|
|
LANGUAGES = {
|
|
'EN-US': 'en-US.json',
|
|
'DE': 'de-DE.json',
|
|
'IT': 'it-IT.json',
|
|
'ZH': 'zh-CN.json'
|
|
}
|
|
|
|
def translate_dict(data, translator, target_lang):
|
|
"""Recursively translate all strings in dictionary"""
|
|
if isinstance(data, dict):
|
|
return {k: translate_dict(v, translator, target_lang) for k, v in data.items()}
|
|
elif isinstance(data, list):
|
|
return [translate_dict(item, translator, target_lang) for item in data]
|
|
elif isinstance(data, str):
|
|
if DEEPL_AVAILABLE and translator:
|
|
try:
|
|
result = translator.translate_text(data, target_lang=target_lang)
|
|
return result.text
|
|
except Exception as e:
|
|
print(f" ⚠️ Translation error: {e}")
|
|
return data
|
|
else:
|
|
return data # Fallback: return original
|
|
else:
|
|
return data
|
|
|
|
def create_slovenian_json():
|
|
"""Extract Slovenian text from PrologueScene"""
|
|
slovenian_data = {
|
|
"ui": {
|
|
"skip": "Pritisni ESC za preskok",
|
|
"autoAdvance": "Pritisni PRESLEDNICA za samodejno nadaljevanje"
|
|
},
|
|
"prologue": {
|
|
"01": {
|
|
"speaker": "NARRATOR",
|
|
"text": "Leto 2084. Zombi virus je uničil svet."
|
|
},
|
|
"02": {
|
|
"speaker": "KAI",
|
|
"text": "Moje ime je Kai Marković. Star sem štirinajst let."
|
|
},
|
|
"03": {
|
|
"speaker": "KAI",
|
|
"text": "Moja dvojčica Ana in jaz, sva zelo povezana. Nezlomljiv vez."
|
|
},
|
|
"04": {
|
|
"speaker": "KAI",
|
|
"text": "Naša starša sta bila znanstvenika. Raziskovala sta virusne mutacije."
|
|
},
|
|
"05": {
|
|
"speaker": "NARRATOR",
|
|
"text": "Tretji dan izbruha. Horda zombijev napada družinsko hišo."
|
|
},
|
|
"06": {
|
|
"speaker": "NARRATOR",
|
|
"text": "Starša se žrtvujeta, da rešita dvojčka. Zadnji besede: 'Beži, Kai! Zaščiti Ano!'"
|
|
},
|
|
"07": {
|
|
"speaker": "NARRATOR",
|
|
"text": "Iz senc se pojavi Orjaški Troll Kralj. Poslal ga je zlobni doktor Krnić."
|
|
},
|
|
"08": {
|
|
"speaker": "ANA",
|
|
"text": "KAI! REŠI ME! KAIII!"
|
|
},
|
|
"09": {
|
|
"speaker": "KAI",
|
|
"text": "ANA! NE! VRNITE MI JO!"
|
|
},
|
|
"10": {
|
|
"speaker": "NARRATOR",
|
|
"text": "Kai se spremeni v Alfa Hibrida. Vijolične oči. Moč nadzora nad zombiji."
|
|
},
|
|
"11": {
|
|
"speaker": "NARRATOR",
|
|
"text": "Šest mesecev kasneje. Kai se zbudi na majhni kmetiji. Ana je izginila."
|
|
},
|
|
"12": {
|
|
"speaker": "KAI",
|
|
"text": "Moram jo najti. Ne glede na to, kaj bo potrebno. Ana, prihajam!"
|
|
}
|
|
}
|
|
}
|
|
|
|
output_file = LOCALIZATION_DIR / "sl-SI.json"
|
|
with open(output_file, 'w', encoding='utf-8') as f:
|
|
json.dump(slovenian_data, f, indent=2, ensure_ascii=False)
|
|
|
|
print(f"✅ Created {output_file}")
|
|
return slovenian_data
|
|
|
|
def main():
|
|
print("🌍 TRANSLATION SYSTEM")
|
|
print("=" * 50)
|
|
|
|
# Step 1: Create Slovenian JSON
|
|
print("\n📝 Step 1: Creating Slovenian source...")
|
|
sl_data = create_slovenian_json()
|
|
|
|
# Step 2: Initialize DeepL
|
|
translator = None
|
|
if DEEPL_AVAILABLE:
|
|
api_key = os.environ.get('DEEPL_API_KEY')
|
|
if api_key:
|
|
try:
|
|
translator = deepl.Translator(api_key)
|
|
print(f"✅ DeepL initialized")
|
|
except Exception as e:
|
|
print(f"⚠️ DeepL error: {e}")
|
|
else:
|
|
print("⚠️ DEEPL_API_KEY not set in environment")
|
|
|
|
# Step 3: Translate to each language
|
|
print("\n🔄 Step 2: Translating to 4 languages...\n")
|
|
|
|
for lang_code, filename in LANGUAGES.items():
|
|
print(f" Translating to {filename}...")
|
|
|
|
if translator:
|
|
translated_data = translate_dict(sl_data, translator, lang_code)
|
|
else:
|
|
# Fallback: Use Slovenian text (manual review needed)
|
|
print(f" ⚠️ Using fallback (Slovenian text)")
|
|
translated_data = sl_data.copy()
|
|
|
|
output_file = LOCALIZATION_DIR / filename
|
|
with open(output_file, 'w', encoding='utf-8') as f:
|
|
json.dump(translated_data, f, indent=2, ensure_ascii=False)
|
|
|
|
print(f" ✅ Created {filename}")
|
|
|
|
print("\n🎉 Translation complete!")
|
|
print(f"\n📁 Files created in {LOCALIZATION_DIR}:")
|
|
for file in LOCALIZATION_DIR.glob("*.json"):
|
|
size = file.stat().st_size
|
|
print(f" - {file.name} ({size:,} bytes)")
|
|
|
|
if not translator:
|
|
print("\n⚠️ NOTE: Files created with Slovenian text (DeepL unavailable)")
|
|
print("Manual translation or DeepL API key required for production!")
|
|
|
|
if __name__ == "__main__":
|
|
main()
|