Dota 2 Workshop Tools/Panorama/Localization: Difference between revisions

From Valve Developer Community
Jump to navigation Jump to search
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:
   <code><Label text="#hello_message" /></code>
   <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:
   <code>"hello_message" "Hello, world!"</code>
   <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:
   <code><font color=red>game/</font>dota_addons/ADDON_NAME/panorama/localization/addon_LANGUAGE_NAME.txt</code>
   <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: 


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:'''
  <code>XML:
<source lang="xml"><Label id="msg" text="#MessageText" /></source> 
    <Label id="msg" text="#MessageText" />
    
    
  Javascript:
'''Javascript:'''
    $("#msg").SetDialogVariable( "adjective", "favorite" );
<source lang="javascript">$("#msg").SetDialogVariable( "adjective", "favorite" );
    $("#msg").SetDialogVariableInt( "number", 2 );
$("#msg").SetDialogVariableInt( "number", 2 );</source> 
 
'''Localization file:'''
<source>"MessageText" "My {s:adjective} number is {d:number}."</source> 
    
    
  Localization file:
    "MessageText" "My {s:adjective} number is {d:number}."</code>
{{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.)}}


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