# Localization

The Dialogue module localizes text inside **[Script](scripts.md)** assets. Your menus, item names, and other interface text stay with Unity's Localization package or your existing localization system. Keep their language settings in sync so conversations and menus use the same language.

## Setting up locales

A **Locale** is one language your game supports. Define your locales before exporting Script text for translation.

!!! info "Locale IDs use restricted characters"
    A Locale ID accepts letters, digits, hyphens (`-`), and underscores (`_`).

    Use a two-letter language code such as `en` or `es`. Add a country code when dialects need separate translations, such as `en_US` and `en_GB`.

Open the **Dialogue Settings** window at `Window` &rarr; `Visual Script` &rarr; `Settings` and select **Dialogue**.

![Dialogue section of the Settings window](assets/settings.jpg)

Click **Add Locale…**.

| Field        | Controls                                                                                 |
| :--- | :--- |
| **ID**       | The identifier — `es`, `en_US`.                                                          |
| **Language** | The system language this locale corresponds to, used to pick a language on first launch. |

The first locale in the list is the **main language**, marked with a yellow `(main)` tag. Choose the language you write your Scripts in.

!!! success "Dialogue selects a matching system language"
    On first launch, Dialogue compares each **Language** field with the player's system language. If one of your locales matches, that's the language the conversation uses. If none matches, Dialogue uses the main language.

## Exporting for translation

!!! tip "Translate last"
    Finish and proofread a Script before exporting it. Each line you change afterward needs another translation in every supported language.

Select the **[Script](scripts.md)** asset and open the **Settings** tab.

![Script Settings in the Unity Inspector](assets/script-settings.jpg)

Before exporting, click **Generate IDs** to add an identifier to every line that doesn't have one. Dialogue uses those IDs to match translations to their source lines; a line without an ID can't be translated.

Click **Export…** and select a location for the comma-separated values (CSV) file.

![Example of an exported translation CSV file](assets/translation-csv-file.jpg)

You can hand this file to a translator, who can edit it in a spreadsheet without opening Unity.

| Column          | Contains                                                                                     |
| :--- | :--- |
| **ID**          | The line's identifier. Do not change it because it links the translation to the source line. |
| **Actor**       | The speaker, which gives the translator context.                                             |
| **Text**        | The original line.                                                                           |
| **Translation** | The translated line. This column is empty on export.                                         |
| **Notes**       | Commands and developer notes attached to the line.                                           |

!!! tip "Strip the columns you don't need before importing"
    The importer reads only **ID** and **Translation**. Remove the other columns from the completed file to reduce the asset's runtime memory cost.

## Importing translations

Import the completed CSV file as a Text Asset. Then select the **[Script](scripts.md)**, open **Settings**, and assign the file to its locale.

![Setup for translating a Script to another language](assets/translation-example-entry.jpg)

!!! info "The main language uses the Script's source text"
    You don't need a translation file for the language you wrote the Script in. Dialogue uses the source text for that locale, so create files only for the other languages.

When Dialogue switches to a locale linked by the Script, the translated text replaces the source text.

!!! tip "Every linked translation loads with the Script"
    A **[Script](scripts.md)** is a `ScriptableObject`, so loading it also loads every referenced translation file. This includes files for inactive locales.

    For projects with many locales, the **Addressables** extension loads only the active translation on demand.

## Changing the language

Use the **Change Language** Instruction.

![Change Language instruction](assets/translation-instruction-change-language.jpg)

The **Locale** field takes the ID of the locale to switch to.

!!! success "The switch is immediate, even mid-conversation"
    You can change the language while a conversation is running. The displayed text updates immediately, without restarting the Script or reloading the scene.

!!! tip "Change both at once"
    Dialogue keeps its active locale separate from the main localization system. Run **Change Language** whenever that system switches language so interface text and conversations remain consistent.

## Where to go next

- **[Scripts](scripts.md)** — generate line IDs and assign translation files.
- **[Language syntax](syntax.md#metadata)** — inspect the metadata that identifies translatable lines.
- **[Dialogue component](dialogue.md)** — play a localized Script.
