UI Toolbox logoUI Toolbox

Localization

The toolbox controls show some texts on their own, for example OK, Cancel, Next, Today, None and "No results". ToolboxText (UIToolbox) holds them. Each text has a key, such as ToolboxText.CANCEL ("tb.cancel"), and an English default in ToolboxText.Defaults.

Member Use
Lookup A Func<string, string?> that returns the translation of a key. Null or an empty string gives the English default.
Refresh() Call it after a language change. The controls on a panel read their texts again, and the controls that format numbers and dates use CultureInfo.CurrentCulture again.
Get(key) The translation, else the English default, else the key.
Track(element, apply) Runs apply now and after each Refresh while the element is on a panel. Use it for your own texts.
SetText(element, key), SetTooltip(element, key) Track for one text or tooltip.

The window chrome buttons have the tooltips ToolboxText.MINIMIZE, MAXIMIZE and CLOSE. When a click restores the window, the minimize or maximize button has the tooltip ToolboxText.RESTORE. The tab close button has the tooltip ToolboxText.CLOSE_TAB. The chrome sets these tooltips, so a tooltip in a custom chrome template does not stay.

Call Lookup, Refresh and Get on the main thread. Set the culture yourself: Refresh does not change CultureInfo.CurrentCulture.

ToolboxText.Lookup = key => myTranslations.TryGetValue(key, out var text) ? text : null;
CultureInfo.CurrentCulture = CultureInfo.GetCultureInfo("fr-FR");
ToolboxText.Refresh();

SearchDropdown no longer has the NO_RESULTS_TEXT, SEARCHING_TEXT and SEARCH_FAILED_TEXT constants. Use ToolboxText.NO_RESULTS, ToolboxText.SEARCHING and ToolboxText.SEARCH_FAILED with ToolboxText.Get.

The Localization example

The Localization example (Assets/UIToolbox/Examples/Localization) connects ToolboxText to a JSON string table, Strings.json. It needs no package, so it works in each Unity 6 version. Strings.json has a list of locale codes and, for each key, one text per locale:

{ "locales": ["en-US", "fr-FR"], "entries": [ { "key": "tb.next", "values": ["Next", "Suivant"] } ] }

To use the Unity Localization package (com.unity.localization) instead, set ToolboxText.Lookup to a function that reads your string table, and call ToolboxText.Refresh() in the SelectedLocaleChanged event.

An open MessageBox keeps its message in the old language after a locale change. Only its buttons change.