Localization Manager
Runtime controller for handling languages and events
Overview
A singleton MonoBehavior responsible for handling the localization system at runtime. It manages language switching, initializing settings, and refreshing all localized objects in the scene.
It is automatically initialized when needed; you do not need to manually add it to your scene.
Public Properties
| Property | Type | Description |
|---|---|---|
instance | LocalizationManager | The static singleton instance of the manager. |
currentLanguage | LocalizationLanguage | The currently active language asset. |
settings | LocalizationSettings | Reference to the active settings asset. |
GoogleSheets | GoogleSheetsHandler | Access to the Google Sheets handler for fetching data. |
Public Methods
| Method | Description |
|---|---|
SetLanguage(string targetID) | Sets the current language using its ID (e.g., "en-US"). |
SetLanguage(int index) | Sets the current language using its index in the settings list. |
SetLanguage(LocalizationLanguage language) | Sets the current language using a direct asset reference. |
GetCurrentLanguage() | Returns the currently active LocalizationLanguage asset. |
GetCurrentLanguageName(bool includeID) | Returns the name of the current language. Set includeID to true to append the ID (e.g., "English (en-US)"). |
GetSettings() | Returns the active LocalizationSettings asset. |
RefreshAllObjects() | Forces all localized objects in the scene to update their content. |
Events
| Event | Type | Description |
|---|---|---|
OnLanguageSet | Action<LocalizationLanguage> | Triggered whenever the language is successfully changed. |
Scripting API
using UnityEngine;
using Evo.Localization;
public class LocalizationManagerExample : MonoBehaviour
{
public LocalizationLanguage specificLanguage;
void Start()
{
// Set language by ID
// Switches language to "en-US" and refreshes all objects
LocalizationManager.SetLanguage("en-US");
// Set language by asset reference
LocalizationManager.SetLanguage(specificLanguage);
// Set language by index
// Switches to the first language in the settings list
LocalizationManager.SetLanguage(0);
// Get the current language name (e.g., "English (en-US)")
Debug.Log($"Current Language: {LocalizationManager.GetCurrentLanguageName()}");
// Get the current language name without ID (e.g., "English")
Debug.Log($"Current Language (without ID): {LocalizationManager.GetCurrentLanguageName(false)}");
// Get the current localized name (e.g., "日本語")
Debug.Log($"Current Language (Localized): {LocalizationManager.GetCurrentLocalizedLanguageName()}");
}
void OnEnable()
{
// Subscribe to language changes
LocalizationManager.OnLanguageSet += OnLanguageChanged;
}
void OnDisable()
{
// Unsubscribe to avoid memory leaks
LocalizationManager.OnLanguageSet -= OnLanguageChanged;
}
void OnLanguageChanged(LocalizationLanguage newLanguage)
{
// Trigger logic when language updates
Debug.Log($"Language changed to: {newLanguage.languageName}");
}
}