Skip to main content
Folder: Assets/_Molca/_Core/Localization/
Namespace: Molca.Localization
Core localization combines Unity Localization tables with Molca runtime helpers:
  • LocalizationModule (SettingModule) stores supported languages and active language code.
  • LocalizationManager (RuntimeSubsystem) bridges locale switching, text refresh, and dynamic runtime entries.
  • LocalizedText and DynamicLocalization are component/field helpers for UI text flows.

LocalizationModule (SettingModule)

File: LocalizationModule.cs
Create asset: Molca → Settings → Localization
  • Languages: array of language entries (name, Code, Flag sprite).
  • ActiveLanguage is persisted in module settings (SaveSettings / LoadSettings).
  • Runtime helpers: LanguageCode, ActiveLanguageEntry, GetFlagForLanguage(code).
Register this module on Global Settings.

LocalizationManager (RuntimeSubsystem)

File: LocalizationManager.cs Place on the RuntimeManager prefab. During initialize it waits for Unity Localization initialization, loads the active language from LocalizationModule, then applies it through LocalizationSettings.SelectedLocale.
  • Language switch API: LocalizationManager.SetLanguage(langCode)
  • Refresh path: locale change triggers TypedEvents.LanguageChanged.Dispatch(...) and refreshes registered localized texts.
  • Dynamic table key: Dynamic (used by UpdateEntry / GetLocale).
  • Also exposes helpers: GetLocalizedString(collectionName, entryKey) and GetLocalizedStringAsync(key).

LocalizedText (TMP component)

File: LocalizedText.cs
Requirement: TextMeshProUGUI
LocalizedText registers itself with LocalizationManager, subscribes to LocalizedString.StringChanged, then updates TMP text and rebuilds layout. Optional LocalizedTextStyleInfo assets (see Styles/) apply font/size presets.

DynamicLocalization (serializable field helper)

Files: DynamicLocalization.cs, DynamicLocalizationEntry.cs Use for runtime-managed strings (e.g. content loaded from API or generated labels):
  • Supports direct LocalizedString mode or per-language fallback list.
  • Init(key) syncs entries into the runtime Dynamic table through LocalizationManager.UpdateEntry(...).
  • GetLocalizedString() resolves current language with fallback to local entries/default language.

Code

Switch language from UI:
using Molca;
using Molca.Localization;
using UnityEngine;

public class LanguageSwitchButton : MonoBehaviour
{
    public async void SetToIndonesian()
    {
        await RuntimeManager.WaitForInitialization();
        LocalizationManager.SetLanguage("id");
    }
}
Bind a LocalizedString to a LocalizedText component:
using Molca.Localization;
using UnityEngine;

public class LabelBinder : MonoBehaviour
{
    [SerializeField] private LocalizedText localizedText;

    public void BindRuntimeKey(string key)
    {
        var loc = RuntimeManager.GetSubsystem<LocalizationManager>()?.GetLocale(key);
        if (loc != null)
            localizedText.SetLocalizedString(loc);
    }
}
  • Global Settings — register LocalizationModule
  • EventDispatcher — locale changes dispatch via TypedEvents.LanguageChanged
  • UI widgetsLanguageDropdown integrates with LocalizationManager.SetLanguage(...)

Unity Editor

LocalizationModule asset with Languages list (name/code/flag), RuntimeManager prefab with LocalizationManager, and a TMP object with LocalizedText.

LocalizationModule, LocalizationManager, and LocalizedText in Unity Inspector