Localization
Inventool works with Unity's Localization package, which you should already have installed. It's recommended to check out Unity's official localization documentation to get an understanding of it.
You will need to know how to:
Add locales.
Create localization tables.
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 window has a Localization Settings 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:
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;
}
}
}
Last updated