Search Unity

  1. Good news ✨ We have more Unite Now videos available for you to watch on-demand! Come check them out and ask our experts any questions!
    Dismiss Notice

Feature Request UXML Text preprocessor

Discussion in 'UI Toolkit' started by Guedez, Jul 7, 2020.

  1. Guedez

    Guedez

    Joined:
    Jun 1, 2012
    Posts:
    497
    I want to be able to, before a UXML is used, be able to read it's contents as text, and spout out a new text content to be used instead.
    I need this for my translation solution. Currently, it reads the XML, uses a regex to find anything enclosed in "$$", and replaces it with it's entry in the translation file
    Example:
    Code (CSharp):
    1. <XmlLayout xmlns="XmlLayout"
    2.            xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    3.            xsi:schemaLocation="XmlLayout ../../../../../libs/Plugins/XmlLayout/XmlLayout/Configuration/XmlLayout.xsd">
    4.     <Defaults>
    5.         <Text class="SectionTitle" minHeight="40" color="rgb(1,1,1)" fontsize="20" font="Interface/Ubuntu-Medium"/>
    6.         <Text class="SectionTextRight" minHeight="23" alignment="UpperRight" color="rgb(0.5,0.5,0.5)" fontsize="16" font="Interface/Ubuntu-Medium"/>
    7.         <Text class="SectionTextLeft" minHeight="23" alignment="UpperLeft" color="rgb(0.5,0.5,0.5)" fontsize="16" font="Interface/Ubuntu-Medium"/>
    8.     </Defaults>
    9.  
    10.     <VerticalLayout width="130" height="90">
    11.         <Text class="SectionTitle" width="130" height="40">$$UIComposition$$</Text>
    12.         <HorizontalLayout>
    13.             <VerticalLayout width="80" height="50" padding = "2,2,2,2">
    14.                 <Override type="UnityEngine.UI.LayoutElement, UnityEngine.UI, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null" preferredWidth="0" flexibleWidth="99999"/>
    15.                 <Text class="SectionTextRight" name="water">$$UIWater$$:</Text>
    16.                 <Text class="SectionTextRight" name="fat">$$UIFat$$:</Text>
    17.             </VerticalLayout>
    18.             <VerticalLayout width="50" height="50" padding = "2,2,2,2">
    19.                 <Override type="UnityEngine.UI.LayoutElement, UnityEngine.UI, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null" minWidth="55" preferredWidth="0" flexibleWidth="1"/>
    20.                 <Text class="SectionTextLeft" name="waterValue">0</Text>
    21.                 <Text class="SectionTextLeft" name="fatValue">0</Text>
    22.             </VerticalLayout>
    23.         </HorizontalLayout>
    24.     </VerticalLayout>
    25. </XmlLayout>
    If the selected language is english:
    $$UIComposition$$
    will be detected and changed to
    Composition

    $$UIWater$$
    will be detected and changed to
    Water

    $$UIFat$$
    will be detected and changed to
    Fat

    only then, will the XML processor read the contents and make a hierarchy with it
     
  2. uDamian

    uDamian

    Unity Technologies

    Joined:
    Dec 11, 2017
    Posts:
    945
    We don't have our UXML importer open enough to allow for this level of customization. We are still deciding how to implement proper support for localization in UI Toolkit and this may be something we built-in. Until then, you might be able to do something involving a different extension asset, like ".myuxml", that you write your own importer for and it generates a ".uxml" sub-asset which then gets imported with our importer.
     
    Kirsche likes this.
  3. WAYN_Games

    WAYN_Games

    Joined:
    Mar 16, 2019
    Posts:
    450
    Will the unity localization package("com.unity.localization": "0.7.1-preview") be considered for integration in UI Toolkit ?
     
  4. uDamian

    uDamian

    Unity Technologies

    Joined:
    Dec 11, 2017
    Posts:
    945
    It's one of the pieces of the future complete puzzle, yes.
     
    WAYN_Games likes this.
unityunity