Attention: Here be dragons
This is the latest
(unstable) version of this documentation, which may document features
not available in or compatible with released stable versions of Godot.
Checking the stable version of the documentation...
TranslationServer¶
继承: Object
负责语言翻译的服务器。
描述¶
管理所有语言翻译的服务器。可以向其中添加翻译,也可以从中移除翻译。
教程¶
属性¶
|
方法¶
void |
add_translation ( Translation translation ) |
void |
clear ( ) |
compare_locales ( String locale_a, String locale_b ) const |
|
get_all_countries ( ) const |
|
get_all_languages ( ) const |
|
get_all_scripts ( ) const |
|
get_country_name ( String country ) const |
|
get_language_name ( String language ) const |
|
get_loaded_locales ( ) const |
|
get_locale ( ) const |
|
get_locale_name ( String locale ) const |
|
get_script_name ( String script ) const |
|
get_tool_locale ( ) |
|
get_translation_object ( String locale ) |
|
pseudolocalize ( StringName message ) const |
|
void |
|
void |
remove_translation ( Translation translation ) |
void |
set_locale ( String locale ) |
standardize_locale ( String locale ) const |
|
translate ( StringName message, StringName context="" ) const |
|
translate_plural ( StringName message, StringName plural_message, int n, StringName context="" ) const |
属性说明¶
bool pseudolocalization_enabled = false
如果为 true
,则启用伪本地化。有关详细信息,请参阅 ProjectSettings.internationalization/pseudolocalization/use_pseudolocalization。
方法说明¶
void add_translation ( Translation translation )
添加一个 Translation 资源。
void clear ( )
清除服务器中的所有翻译。
int compare_locales ( String locale_a, String locale_b ) const
比较两个区域设置,返回 0
(不匹配)和 10
(完全匹配)之间的相似度得分。
PackedStringArray get_all_countries ( ) const
返回已知地区代码的数组。
PackedStringArray get_all_languages ( ) const
返回已知语言代码的数组。
PackedStringArray get_all_scripts ( ) const
返回已知文字代码的数组。
String get_country_name ( String country ) const
返回地区代码 country
的可读地区名称。
String get_language_name ( String language ) const
返回语言代码 language
的可读语言名称。
PackedStringArray get_loaded_locales ( ) const
返回项目中所有已加载的区域设置的数组。
String get_locale ( ) const
返回项目的当前区域设置。
查询用户系统的区域设置请参阅 OS.get_locale 和 OS.get_locale_language。
String get_locale_name ( String locale ) const
返回区域设置的语言及其变体。例如,"en_US"
将返回 "English (United States)"
。
String get_script_name ( String script ) const
返回文字代码 script
的可读文字名称。
String get_tool_locale ( )
返回编辑器的当前区域设置。
注意:从导出后的项目中调用时,返回值与 get_locale 相同。
Translation get_translation_object ( String locale )
根据传入的 locale
返回 Translation 实例。
如果没有与 locale
匹配的 Translation 实例,则返回 null
。
StringName pseudolocalize ( StringName message ) const
根据传入的 message
返回伪本地化字符串。
void reload_pseudolocalization ( )
重新解析伪本地化选项,并重新加载翻译。
void remove_translation ( Translation translation )
从服务器中删除给定的翻译。
void set_locale ( String locale )
设置项目的区域设置。locale
字符串将被标准化,以匹配已知的区域设置(例如 en-US
将与 en_US
匹配)。
如果已经为新区域设置预先加载了翻译,则它们将被应用。
String standardize_locale ( String locale ) const
返回标准化的 locale
字符串,以匹配已知的区域设置(例如 en-US
将与 en_US
匹配)。
StringName translate ( StringName message, StringName context="" ) const
返回给定消息(键)和上下文的翻译,使用当前区域设置。
StringName translate_plural ( StringName message, StringName plural_message, int n, StringName context="" ) const
返回给定消息(键)、复数消息和上下文的翻译,使用当前区域设置。
数字 n
是复数对象的数量。翻译系统会根据这个数字来针对所选语言获取正确的复数形式。