Dota 2 Workshop Tools/Panorama/Localization: Difference between revisions
m (Removed protection from "Dota 2 Workshop Tools/Panorama/Localization") |
(Better formatting) |
||
Line 3: | Line 3: | ||
In your XML localization tokens are prefixed with a '#' symbol and can be used as regular text: | In your XML localization tokens are prefixed with a '#' symbol and can be used as regular text: | ||
< | <source lang="xml"><Label text="#hello_message" /></source> | ||
When this UI is loaded, the token will be automatically replaced with a string from the corresponding localization file: | When this UI is loaded, the token will be automatically replaced with a string from the corresponding localization file: | ||
< | <source>"hello_message" "Hello, world!"</source> | ||
'''Note''': Unlike most content for Panorama, the localization files live in the <font color=red>game/</font> tree instead of <font color=red>content</font>. | '''Note''': Unlike most content for Panorama, the localization files live in the <font color=red>game/</font> tree instead of <font color=red>content</font>. | ||
For Dota addons, localization files live here: | For Dota addons, localization files live here: | ||
< | <source>game/dota_addons/ADDON_NAME/panorama/localization/addon_LANGUAGE_NAME.txt</source> | ||
== Dynamic data == | |||
In many cases you may have dynamic data that you need to inject into a localization string. This is achieved using "dialog variables" set on the panel that can be referenced by the localization file: | |||
'''XML:''' | |||
<source lang="xml"><Label id="msg" text="#MessageText" /></source> | |||
'''Javascript:''' | |||
<source lang="javascript">$("#msg").SetDialogVariable( "adjective", "favorite" ); | |||
$("#msg").SetDialogVariableInt( "number", 2 );</source> | |||
'''Localization file:''' | |||
<source>"MessageText" "My {s:adjective} number is {d:number}."</source> | |||
{{note|If you dynamically set the text of a label from Javascript, it will NOT automatically localize the string. If you need to dynamically assign a localization token to a label, you need to localize the string in Javascript. (This technique has limited support for dialog variables.)}} | {{note|If you dynamically set the text of a label from Javascript, it will NOT automatically localize the string. If you need to dynamically assign a localization token to a label, you need to localize the string in Javascript. (This technique has limited support for dialog variables.)}} | ||
< | <source lang="javascript">$( "#PanelID" ).text = $.Localize( "#LocalizationToken" );</source> | ||
{{shortpagetitle}} | {{shortpagetitle}} | ||
[[Category:Dota 2 Workshop Tools]] | [[Category:Dota 2 Workshop Tools]] | ||
[[Category:Panorama]] | [[Category:Panorama]] |
Revision as of 04:48, 11 October 2018
In order to support multiple languages, most Panorama UIs are built with references to "localization tokens" instead of literal user-facing strings. These tokens are then dynamically replaced with the correct localized string depending on the user's language selection.
In your XML localization tokens are prefixed with a '#' symbol and can be used as regular text:
<Label text="#hello_message" />
When this UI is loaded, the token will be automatically replaced with a string from the corresponding localization file:
"hello_message" "Hello, world!"
Note: Unlike most content for Panorama, the localization files live in the game/ tree instead of content.
For Dota addons, localization files live here:
game/dota_addons/ADDON_NAME/panorama/localization/addon_LANGUAGE_NAME.txt
Dynamic data
In many cases you may have dynamic data that you need to inject into a localization string. This is achieved using "dialog variables" set on the panel that can be referenced by the localization file:
XML:
<Label id="msg" text="#MessageText" />
Javascript:
$("#msg").SetDialogVariable( "adjective", "favorite" );
$("#msg").SetDialogVariableInt( "number", 2 );
Localization file:
"MessageText" "My {s:adjective} number is {d:number}."

$( "#PanelID" ).text = $.Localize( "#LocalizationToken" );