# Localization

Inventool **works with Unity's Localization packag**e, which you should already have installed. It's recommended to check out Unity's [official localization documentation](https://docs.unity3d.com/Packages/com.unity.localization@1.5/manual/QuickStartGuide.html) to get an understanding of it.

You will need to know how to:

1. Add locales.
2. Create localization tables.
3. Switch the locale.

## How To Set Up Localization In Inventool

Inventool's UI options all support localization. You just need to make sure the [localization-editor](https://stylishesper.gitbook.io/inventool/editors/localization-editor "mention") window has a [#localization-settings](https://stylishesper.gitbook.io/inventool/menu-options#localization-settings "mention") object, **ensure all fields have a reference to a localization table/key**.

Once this is done, **switching the locale through Unity's Localization API** will update all of Inventool's localized texts.

## Issues With uGUI

Localization may not automatically work for all locales if the uGUI version of the Inventool UI is used. This is because the default TextMeshPro font does not support every character for every language. You will have to switch to a font that supports the current locale for all text objects. This issue does not exist for UI Toolkit, as the default font supports all characters.

Here's an example script that may solve the issue:

```csharp
using UnityEngine;
using TMPro;
using UnityEngine.Localization;
using UnityEngine.Localization.Settings;

public class LocaleFontAutoSwitcher : MonoBehaviour
{
    [System.Serializable]
    public class LocaleFontPair
    {
        public LocaleIdentifier locale;
        public TMP_FontAsset font;
    }

    public LocaleFontPair[] localeFonts;

    void OnEnable()
    {
        LocalizationSettings.SelectedLocaleChanged += OnLocaleChanged;
        ApplyFont(LocalizationSettings.SelectedLocale);
    }

    void OnDisable()
    {
        LocalizationSettings.SelectedLocaleChanged -= OnLocaleChanged;
    }

    void OnLocaleChanged(Locale newLocale)
    {
        ApplyFont(newLocale);
    }

    void ApplyFont(Locale locale)
    {
        TMP_FontAsset selectedFont = null;

        foreach (var pair in localeFonts)
        {
            if (pair.locale == locale.Identifier)
            {
                selectedFont = pair.font;
                break;
            }
        }

        if (selectedFont == null)
        {
            Debug.LogWarning($"No font assigned for locale: {locale.Identifier}");
            return;
        }

        var allTextObjects = GameObject.FindObjectsOfType<TextMeshProUGUI>(true);
        foreach (var tmp in allTextObjects)
        {
            tmp.font = selectedFont;
        }
    }
}

```
