🌍🔥 LOCALIZATION SYSTEM - INTRO SYNC + VOICE SWITCHING
✅ LOCALIZATION.JSON CREATED (5 LANGUAGES): 📂 assets/localization.json (NEW!): - 🇸🇮 Slovenščina (slo) - 🇬🇧 English (en) - 🇩🇪 Deutsch (de) - 🇮🇹 Italiano (it) - 🇨🇳 中文 (cn) 📝 COMPLETE TRANSLATIONS: - All 20 Polaroid texts - Menu buttons (New Game, Load, Settings, Exit) - Game title + subtitle ✅ LOCALIZATIONSYSTEM.JS UPDATED: 🔧 NEW METHODS ADDED: 1. loadIntroTexts() - Load JSON - Fetches assets/localization.json - Merges intro_polaroids into translations - Merges menu texts - Adds title/subtitle - Console: '✅ Intro texts loaded from JSON' 2. getIntroText(polaroidKey) - Get text - Returns translated Polaroid text - Falls back to English if missing - Usage: i18n.getIntroText('kai_dad_longboard') 3. getVoicePath(character, index) - Voice switching! - 🇸🇮 Slovenian → assets/audio/voiceover/sl/ - 🇬🇧 English → assets/audio/voiceover/en/ - Auto-formats filename - Example SL: kai_01.mp3 - Example EN: kai_en_01.mp3 4. hasVoiceForLanguage(character, index) - Checks if voice exists for language - SL + EN have full voiceovers - DE/IT/CN fall back to EN 🎯 LANGUAGE TO VOICE PATH MAPPING: - slo → /voiceover/sl/kai_01.mp3 - en → /voiceover/en/kai_en_01.mp3 - de → /voiceover/en/kai_en_01.mp3 (fallback) - it → /voiceover/en/kai_en_01.mp3 (fallback) - cn → /voiceover/en/kai_en_01.mp3 (fallback) 📋 20 POLAROID KEYS: 1. kai_dad_longboard 2. barbershop 3. birthday_cake 4. family_portrait 5. twins_holding_hands 6. kai_bedroom 7. virus_microscope 8. chaos_streets 9. zombies 10. parents_ghosts 11. ana_taken 12. black_screen 13. kai_alone 14. ana_memory_1 15. ana_memory_2 16. ana_memory_3 17. ana_memory_4 18. ana_memory_5 19. gronk_arrival 20. determination 21. lifetime 🎮 USAGE EXAMPLE: // In IntroScene preload() await window.i18n.loadIntroTexts(); // Get text for current language const text = window.i18n.getIntroText('birthday_cake'); // SL: 'Tukaj smo bili še vedno srečni...' // EN: 'Here we were still happy...' // Get voice path const path = window.i18n.getVoicePath('kai', 1); // SL: 'assets/audio/voiceover/sl/kai_01.mp3' // EN: 'assets/audio/voiceover/en/kai_en_01.mp3' 🌍 LANGUAGE FLOW: 1. Player selects language on launcher 2. window.i18n.setLanguage('slo') 3. Saved to LocalStorage 4. IntroScene loads JSON texts 5. Displays translated Polaroid captions 6. Plays SL voice files from /sl/ folder 7. Full sync! NEXT: Hook up IntroScene to use these methods! Files: - assets/localization.json (NEW!) - src/systems/LocalizationSystem.js (UPDATED!) READY FOR INTRO TEXT SYNC! 🌍🔥
This commit is contained in:
@@ -278,6 +278,90 @@ class LocalizationSystem {
|
||||
return fallback;
|
||||
}
|
||||
|
||||
/**
|
||||
* LOAD INTRO TEXTS FROM JSON
|
||||
*/
|
||||
async loadIntroTexts() {
|
||||
try {
|
||||
const response = await fetch('assets/localization.json');
|
||||
const data = await response.json();
|
||||
|
||||
// Merge intro texts into translations
|
||||
for (const lang in data) {
|
||||
if (!this.translations[lang]) {
|
||||
this.translations[lang] = {};
|
||||
}
|
||||
|
||||
// Add intro polaroid texts
|
||||
if (data[lang].intro_polaroids) {
|
||||
this.translations[lang].intro_polaroids = data[lang].intro_polaroids;
|
||||
}
|
||||
|
||||
// Add menu texts
|
||||
if (data[lang].menu) {
|
||||
Object.assign(this.translations[lang], data[lang].menu);
|
||||
}
|
||||
|
||||
// Add title/subtitle
|
||||
if (data[lang].game_title) {
|
||||
this.translations[lang].game_title = data[lang].game_title;
|
||||
}
|
||||
if (data[lang].subtitle) {
|
||||
this.translations[lang].subtitle = data[lang].subtitle;
|
||||
}
|
||||
}
|
||||
|
||||
console.log('✅ Intro texts loaded from JSON');
|
||||
return true;
|
||||
} catch (error) {
|
||||
console.warn('⚠️ Could not load localization.json:', error);
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* GET INTRO POLAROID TEXT
|
||||
*/
|
||||
getIntroText(polaroidKey) {
|
||||
const lang = this.translations[this.currentLang];
|
||||
if (lang && lang.intro_polaroids && lang.intro_polaroids[polaroidKey]) {
|
||||
return lang.intro_polaroids[polaroidKey];
|
||||
}
|
||||
|
||||
// Fallback to English
|
||||
const enLang = this.translations['en'];
|
||||
if (enLang && enLang.intro_polaroids && enLang.intro_polaroids[polaroidKey]) {
|
||||
return enLang.intro_polaroids[polaroidKey];
|
||||
}
|
||||
|
||||
return polaroidKey; // Return key if not found
|
||||
}
|
||||
|
||||
/**
|
||||
* GET VOICE FILE PATH (switches language folder)
|
||||
*/
|
||||
getVoicePath(character, index, format = 'mp3') {
|
||||
const langSuffix = this.currentLang === 'en' ? 'en' : 'sl';
|
||||
|
||||
// Map language codes to voice folders
|
||||
if (this.currentLang === 'slo') {
|
||||
// Slovenian voices in /sl/ folder
|
||||
return `assets/audio/voiceover/sl/${character}_${String(index).padStart(2, '0')}.${format}`;
|
||||
} else {
|
||||
// English voices (default for DE, IT, CN too)
|
||||
return `assets/audio/voiceover/en/${character}_en_${String(index).padStart(2, '0')}.${format}`;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* CHECK IF VOICE FILE EXISTS FOR CURRENT LANGUAGE
|
||||
*/
|
||||
hasVoiceForLanguage(character, index) {
|
||||
// Slovenian and English have full voiceovers
|
||||
// Other languages fall back to English
|
||||
return this.currentLang === 'slo' || this.currentLang === 'en';
|
||||
}
|
||||
|
||||
/**
|
||||
* Set current language
|
||||
*/
|
||||
|
||||
Reference in New Issue
Block a user