{!See https://docs.google.com/document/d/1takg_GmIBBKKTj-GHZCwzxohpQz7Bhekivkk72kYMtE/edit for reference implementation of OneTrust, dataLayer and GTM} {!OneTrust Cookies Consent} {!OneTrust Cookies Consent end} {!dataLayer initialization push} {!dataLayer initialization push end} {!Google Tag Manager} {!Google Tag Manager end} Localization | App UI | 0.6.5
docs.unity3d.com
Search Results for

    Show / Hide Table of Contents

    Localization

    Introduction

    App UI provides localization features through the Localization Unity package from UPM.

    ContextProvider

    The ContextProvider element is a component that provides the ApplicationContext to its children. With this component, you can define the global context for your application, or override the context for a specific part of your UI. In terms of localization, the ContextProvider is used to define the current locale identifier for the current scope of the application.

    Note

    For more information about the ContextProvider, see the ContextProvider documentation.

    Here is an example of how to get a the localized string of a given entry using the locale defined inside the ApplicationContext:

    
    using Unity.AppUI.UI;
    using UnityEngine.UIElements;
    
    public class MyComponent : VisualElement
    {
        [...]
    
        public void OnButtonClick()
        {
            var locale = this.GetContext().locale;
            var translatedString = LocalizationSettings.Instance.GetLocalizedString("table_name", "entry_key", locale);
        }
    }
    
    

    Note that the Localization Unity package also provides features for pluralization and formatting of localized strings. You can find more information about these features in their package documentation.

    App UI Localized elements

    Every App UI element that displays text supports localization. If an element has a text, title or label property for example, you can define its value with a string starting with @, which enables localization for the element. The string value is then used as the resource key for the localized string. If the resource key is not found, the string value is used as the displayed text.

    The naming convention for the resource key is the following:

    @<table_name>:<entry_key>
    

    Here is an example of how to use localization with a button:

    • UXML

      <appui:Button title="@table_name:entry_key" />
      
    • C#

      myButton.title = "@table_name:entry_key";
      
    In This Article
    Back to top
    Copyright © 2023 Unity Technologies — Trademarks and terms of use
    • Legal
    • Privacy Policy
    • Cookie Policy
    • Do Not Sell or Share My Personal Information
    • Your Privacy Choices (Cookie Settings)