Logo

Localization Manager

Runtime controller for handling languages and events

Overview

A singleton MonoBehaviour 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 API

Properties

PropertyTypeDescription
InstanceLocalizationManagerThe static singleton instance of the manager.
CurrentLanguageLocalizationLanguageThe currently active language asset.
SettingsLocalizationSettingsReference to the active settings asset.
DefaultLanguageLocalizationLanguageThe language used for fallback.
GoogleSheetsEvo.Localization.Integrations.GoogleSheetsRuntime pull handler, available when Google Sheets was enabled at initialization.

Only Instance is static; access the other properties through LocalizationManager.Instance. Instance can be null before initialization. Call IsLocalizationAvailable() or a getter such as GetSettings() in Play Mode to initialize the manager before accessing it.

Methods

MethodDescription
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)").
IsLocalizationAvailable()Initializes the manager if needed in Play Mode and reports whether settings and a current language are available.
GetCurrentLocalizedLanguageName(bool includeID = true)Returns the native language name, optionally including its ID.
GetSettings()Returns the active LocalizationSettings asset.
RefreshAllObjects()Refreshes active, enabled, registered Localized Objects except those using OnDemand.

Events

EventTypeDescription
OnLanguageSetAction<LocalizationLanguage>Triggered when the language changes and when Google Sheets data changes or is cleared; the language can remain the same.

Example

LocalizationManagerExample.cs
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}");
    }
}

On this page