Skip to content

03. x:Uids

tetherscript edited this page Jan 31, 2025 · 1 revision

x:Uid properties are typically used to identify .xaml elements that require translation.

In this Translator app, only elements with an x:Uid property, specified in XamlElements.json, and have a property with a valid hint token will be detected for translation.

Examples

1. Same String: 'Close' but Different Element Types

The naming of these x:Uids are important because different element types use different properties for their text.

Ex. <Button x:Uid="Test_btn"> is good and <Button x:Uid="Test"> is bad.

For example:

  • A Button uses the Content property.
  • A TextBlock uses the Text property.

If you were to use x:Uid="Close" for both elements, the target app would fail to start because it may try to put a value into a property that does not exist in the element type.

The suffix (e.g., _btn, _bn, _bt, _button) does not matter, but it helps to be consistent.

Important Note:

  • Do not use decimals (.) in the x:Uid. It is not a valid c# or json identifier. It will be rejected by the Translator app scan function.

    Ex. x:Uid="Close.btn". Translator app would find this x:Uid and append a .Text or .Content or whatever to it. That makes two decimals, and an invalid c# identifier. So it is rejected. There is an example of this in the sample apps.

Example Code:

<Button>
  x:Uid="Close_btn"
  Content="@Close"
</Button>

<TextBlock>
  x:Uid="Close_tb"
  Text="@Close"
</TextBlock>
  1. Same string but different length context and constraints. You can have the same strings ex. '@Enter your name here', '@@Enter your name here', '!Enter your name here' and '!!Enter your name here' if you need that kind of flexibility.
<TextBlock>
  x:Uid="EnterYourNameHere_btn"
  Content="@Enter your name here" //no size constraint
</TextBlock>

<TextBlock>
  x:Uid="EnterYourNameHere_tb"
  Text="@@Enter your name here" //size constrained
</TextBlock>
Clone this wiki locally