LanguageManager
Overview
Global language switcher that keeps Unity Localization and I2 Localization in sync. It persists the user’s choice in PlayerPrefs("LANGUAGE"), supports Next/Prev cycling, and applies the locale after LocalizationSettings has finished initializing.
Public API
public enum Language { ENGLISH, SPANISH, CATALAN }
[Button] // Odin inspector button
public void SetLanguage(Language lang);
public void SetNextLanguage(); // cycles forward with wrap-around
public void SetPrevLanguage(); // cycles backward with wrap-around
Lifecycle
- Start() → reads
PlayerPrefs("LANGUAGE", 0)and startsSetLanguageRoutine(...)with that value.
Behavior
SetLanguageRoutine(Language lang):
- Waits for
LocalizationSettings.InitializationOperationto complete. - Sets the internal
currentLanguageand storesPlayerPrefs("LANGUAGE"). - Applies both systems:
- ENGLISH →
I2.Loc.LocalizationManager.CurrentLanguage = "English [en-US]";andLocalizationSettings.SelectedLocale = GetLocale("en"). - SPANISH →
I2... = "Spanish";andGetLocale("es"). - CATALAN →
I2... = "Catalan";andGetLocale("ca").
- ENGLISH →
- Any unexpected value logs an error and falls back to English.
Integration Notes
- Make sure
Project Settings → Localization → Available Localesincludes en, es, and ca. - The language names in I2 (
"English [en-US]","Spanish","Catalan") must match the entries in your I2 Language Source. - If you want to preselect the OS language on first launch, you can check
Application.systemLanguageand setPlayerPrefs("LANGUAGE")before the first scene loads. - Call
PlayerPrefs.Save()if you need to guarantee persistence immediately after switching (e.g., before quitting).