方言

From Valve Developer Community
Jump to: navigation, search
Dead End - Icon.png
This article has no links to other VDC articles. Please help improve this article by adding links that are relevant to the context within the existing text.
January 2024


... Icon-Important.png

为了让Panorama支持多语言,大多数UI都会使用本地化标识而不是简单的给用户看的字符。这些标识让程序根据用户的语言选择,正确地应用对应的语言环境。 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.

在XML文件中,方言标识标有“#”前缀,并可以按以下的标准文本被使用: <Label text="#hello_message" /> 当UI被加载完成后,这些带标识的文本会自动被替换成方言文件中对应的字符:

 "hello_message" "Hello, world!"

注意: 和大多数Panorama的文件不同,方言文件放在game/ 下而不是content

在dotaAddon中,方言文件在:game/dota_addons/ADDON_NAME/panorama/localization/addon_LANGUAGE_NAME.txt

在很多情况下,你需要方言字符中包含一些动态的内容。这可以通过使用“会话变量”来实现。这些设置在板上的变量可以被本地化文件引用。

 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}."

{{注意|如果你在Javascript中动态地设置了一个标签的文本,它是不会自动使用方言的。如果要同样动态地给这个标签分派一个方言标识,你需要在Javascript中把这个字符也进行方言翻译(这种方法只能给会话变量有限的支持)。

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