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 starts SetLanguageRoutine(...) with that value.

Behavior

SetLanguageRoutine(Language lang):

  1. Waits for LocalizationSettings.InitializationOperation to complete.
  2. Sets the internal currentLanguage and stores PlayerPrefs("LANGUAGE").
  3. Applies both systems:
    • ENGLISHI2.Loc.LocalizationManager.CurrentLanguage = "English [en-US]"; and LocalizationSettings.SelectedLocale = GetLocale("en").
    • SPANISHI2... = "Spanish"; and GetLocale("es").
    • CATALANI2... = "Catalan"; and GetLocale("ca").
  4. Any unexpected value logs an error and falls back to English.

Integration Notes

  • Make sure Project Settings → Localization → Available Locales includes 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.systemLanguage and set PlayerPrefs("LANGUAGE") before the first scene loads.
  • Call PlayerPrefs.Save() if you need to guarantee persistence immediately after switching (e.g., before quitting).