Bind UI Toolkit elements to localized strings and assets.
Every localized reference type, such as LocalizedString and LocalizedTexture, is also a UI Toolkit runtime data binding and a UI Toolkit XML (UXML) object. The same type works three ways: as a field in the Inspector window, as a binding authored in UI Builder or UXML, and as a binding created in code. Bound values update automatically when the user switches language.
Before you start, make sure you have the following:
To bind a property to a localized value in UI Builder:
Label.For asset-typed properties, use the matching type, for example LocalizedTexture for a background image.
The reference types are UXML objects, so a binding can live in the UXML itself:
<ui:UXML xmlns:ui="UnityEngine.UIElements" xmlns:loc="Unity.Localization">
<ui:Label>
<Bindings>
<loc:LocalizedString property="text" table="My Strings" entry="greeting" />
</Bindings>
</ui:Label>
</ui:UXML>
A binding created in code follows the same pattern as any custom binding:
Label label = root.Q<Label>("title");
LocalizedString binding = new LocalizedString();
binding.SetReference("My Strings", "greeting");
label.SetBinding("text", binding);
Two built-in controls appear in the UI Builder library under Controls:
LanguageDropdown: A dropdown that lists the enabled locales.LanguageRadioButtonGroup: A group of radio buttons, one per enabled locale.Both fill themselves from the available locales and apply the user’s choice, with no additional setup code required. Refer to Create a language selection menu.