/** * LOCALIZATION SYSTEM * Multi-language support with JSON translation files */ class LocalizationSystem { constructor() { this.currentLang = 'en'; // Default language this.translations = {}; this.supportedLanguages = ['slo', 'en', 'de', 'it', 'cn']; // Load from localStorage const savedLang = localStorage.getItem('novafarma_language'); if (savedLang && this.supportedLanguages.includes(savedLang)) { this.currentLang = savedLang; } this.loadTranslations(); } loadTranslations() { // Embedded translations (inline for simplicity) this.translations = { 'slo': { // UI 'ui.inventory': 'Inventar', 'ui.crafting': 'Izdelovanje', 'ui.health': 'Zdravje', 'ui.hunger': 'Lakota', 'ui.oxygen': 'Kisik', 'ui.day': 'Dan', 'ui.season': 'Letni čas', // Items 'item.wood': 'Les', 'item.stone': 'Kamen', 'item.seeds': 'Semena', 'item.wheat': 'Pšenica', 'item.corn': 'Koruza', // Actions 'action.plant': 'Posadi', 'action.harvest': 'Požanji', 'action.craft': 'Izdelaj', 'action.build': 'Zgradi', // Seasons 'season.spring': 'Pomlad', 'season.summer': 'Poletje', 'season.autumn': 'Jesen', 'season.winter': 'Zima', // Messages 'msg.demo_end': 'Demo končan! Hvala za igranje.', 'msg.freezing': '❄️ Zmrzuješ!', 'msg.overheating': '🔥 Pregrevanje!' }, 'en': { // UI 'ui.inventory': 'Inventory', 'ui.crafting': 'Crafting', 'ui.health': 'Health', 'ui.hunger': 'Hunger', 'ui.oxygen': 'Oxygen', 'ui.day': 'Day', 'ui.season': 'Season', // Items 'item.wood': 'Wood', 'item.stone': 'Stone', 'item.seeds': 'Seeds', 'item.wheat': 'Wheat', 'item.corn': 'Corn', // Actions 'action.plant': 'Plant', 'action.harvest': 'Harvest', 'action.craft': 'Craft', 'action.build': 'Build', // Seasons 'season.spring': 'Spring', 'season.summer': 'Summer', 'season.autumn': 'Autumn', 'season.winter': 'Winter', // Messages 'msg.demo_end': 'Demo Ended! Thanks for playing.', 'msg.freezing': '❄️ Freezing!', 'msg.overheating': '🔥 Overheating!' }, 'de': { 'ui.inventory': 'Inventar', 'ui.crafting': 'Handwerk', 'ui.health': 'Gesundheit', 'season.spring': 'Frühling', 'season.summer': 'Sommer', 'season.autumn': 'Herbst', 'season.winter': 'Winter' }, 'it': { 'ui.inventory': 'Inventario', 'ui.crafting': 'Artigianato', 'season.spring': 'Primavera', 'season.summer': 'Estate', 'season.autumn': 'Autunno', 'season.winter': 'Inverno' }, 'cn': { 'ui.inventory': '库存', 'ui.crafting': '制作', 'season.spring': '春天', 'season.summer': '夏天', 'season.autumn': '秋天', 'season.winter': '冬天' } }; } /** * Get translated string * @param {string} key - Translation key (e.g. 'ui.inventory') * @param {string} fallback - Fallback text if translation missing */ t(key, fallback = key) { const lang = this.translations[this.currentLang]; if (lang && lang[key]) { return lang[key]; } // Fallback to English const enLang = this.translations['en']; if (enLang && enLang[key]) { return enLang[key]; } return fallback; } /** * Set current language */ setLanguage(langCode) { if (this.supportedLanguages.includes(langCode)) { this.currentLang = langCode; localStorage.setItem('novafarma_language', langCode); console.log(`🌍 Language changed to: ${langCode}`); return true; } return false; } getCurrentLanguage() { return this.currentLang; } getSupportedLanguages() { return this.supportedLanguages.map(code => ({ code, name: this.getLanguageName(code) })); } getLanguageName(code) { const names = { 'slo': 'Slovenščina', 'en': 'English', 'de': 'Deutsch', 'it': 'Italiano', 'cn': '中文' }; return names[code] || code; } } // Global instance window.LocalizationSystem = LocalizationSystem;