Localization

From Valve Developer Community
< Dota 2 Workshop Tools‎ | Panorama
Revision as of 14:08, 16 June 2015 by Michaelc (talk | contribs) (1 revision)
Jump to navigation Jump to search

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


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}."
Note.pngNote: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.)
 $( "#PanelID" ).text = $.Localize( "#LocalizationToken" );