> ## Documentation Index
> Fetch the complete documentation index at: https://docs-unity.molca.id/llms.txt
> Use this file to discover all available pages before exploring further.

# Localization

> LocalizationModule settings, LocalizationManager subsystem, LocalizedText, and dynamic runtime entries.

**Folder:** `Packages/com.molca.core/Runtime/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](/setup/global-settings).

## LocalizationManager (`RuntimeSubsystem`)

**File:** `LocalizationManager.cs`

Place on the [RuntimeManager](/core/runtime-manager) 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:

```csharp theme={null}
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:

```csharp theme={null}
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);
    }
}
```

## Related

* [Global Settings](/setup/global-settings) — register **`LocalizationModule`**
* [EventDispatcher](/core/event-dispatcher) — locale changes dispatch via `TypedEvents.LanguageChanged`
* [UI widgets](/shared/ui-widgets) — `LanguageDropdown` integrates with `LocalizationManager.SetLanguage(...)`

## Unity Editor

<Frame caption="Localization settings and runtime components">
  <img src="https://mintcdn.com/ptmolcateknologinusantara/jus_XMBZ8O0U_mpA/images/features/core/localization-inspector.png?fit=max&auto=format&n=jus_XMBZ8O0U_mpA&q=85&s=6ff1e07f80f225406b7011806f232ecb" alt="Localization Inspector" width="892" height="263" data-path="images/features/core/localization-inspector.png" />
</Frame>
