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
负责语言翻译的服务器。
描述
翻译服务器是负责管理所有语言翻译的 API 后端。
翻译存储在翻译域 TranslationDomain 中,可以通过名称访问。最常用的翻译域是主翻译域。主翻译域始终存在,可以通过空 StringName 访问。翻译服务器为直接访问主翻译域提供了封装方法,无需先获取翻译域。自定义翻译域主要用于编辑器插件等高阶用法。以 godot.
开头的名称是引擎内部保留名称。
教程
属性
|
方法
void |
add_translation(translation: Translation) |
void |
clear() |
compare_locales(locale_a: String, locale_b: String) const |
|
get_all_countries() const |
|
get_all_languages() const |
|
get_all_scripts() const |
|
get_country_name(country: String) const |
|
get_language_name(language: String) const |
|
get_loaded_locales() const |
|
get_locale() const |
|
get_locale_name(locale: String) const |
|
get_or_add_domain(domain: StringName) |
|
get_script_name(script: String) const |
|
get_translation_object(locale: String) |
|
has_domain(domain: StringName) const |
|
pseudolocalize(message: StringName) const |
|
void |
|
void |
remove_domain(domain: StringName) |
void |
remove_translation(translation: Translation) |
void |
set_locale(locale: String) |
standardize_locale(locale: String, add_defaults: bool = false) const |
|
translate(message: StringName, context: StringName = &"") const |
|
translate_plural(message: StringName, plural_message: StringName, n: int, context: StringName = &"") const |
属性说明
bool pseudolocalization_enabled = false
🔗
如果为 true
,则在主翻译域中启用伪本地化。详见 ProjectSettings.internationalization/pseudolocalization/use_pseudolocalization。
方法说明
void add_translation(translation: Translation) 🔗
在主翻译域中添加翻译。
void clear() 🔗
在主翻译域中移除所有翻译。
int compare_locales(locale_a: String, locale_b: String) const 🔗
比较两个区域设置,返回 0
(不匹配)和 10
(完全匹配)之间的相似度得分。
PackedStringArray get_all_countries() const 🔗
返回已知地区代码的数组。
PackedStringArray get_all_languages() const 🔗
返回已知语言代码的数组。
PackedStringArray get_all_scripts() const 🔗
返回已知文字代码的数组。
String get_country_name(country: String) const 🔗
返回地区代码 country
的可读地区名称。
String get_language_name(language: String) const 🔗
返回语言代码 language
的可读语言名称。
PackedStringArray get_loaded_locales() const 🔗
返回项目中所有已加载的区域设置的数组。
返回项目的当前区域设置。
查询用户系统的区域设置请参阅 OS.get_locale() 和 OS.get_locale_language()。
String get_locale_name(locale: String) const 🔗
返回区域设置的语言及其变体。例如,"en_US"
将返回 "English (United States)"
。
TranslationDomain get_or_add_domain(domain: StringName) 🔗
返回给定名称对应的翻译域。如果不存在使用该名称的翻译域,则会创建并添加一个空的翻译域。
String get_script_name(script: String) const 🔗
返回文字代码 script
的可读文字名称。
返回编辑器的当前区域设置。
注意:从导出后的项目中调用时,返回值与 get_locale() 相同。
Translation get_translation_object(locale: String) 🔗
返回主翻译域中与 locale
最为匹配的 Translation 实例。如果没有能够匹配的翻译则返回 null
。
bool has_domain(domain: StringName) const 🔗
如果存在指定名称的翻译域,则返回 true
。
StringName pseudolocalize(message: StringName) const 🔗
根据传入的 message
返回伪本地化字符串。
注意:该方法始终使用主翻译域。
void reload_pseudolocalization() 🔗
重新解析伪本地化选项,并为主翻译域重新加载翻译。
void remove_domain(domain: StringName) 🔗
移除指定名称的翻译域。
注意:尝试移除主翻译域会发生错误。
void remove_translation(translation: Translation) 🔗
在主翻译域中移除给定的翻译。
void set_locale(locale: String) 🔗
设置项目的区域设置。locale
字符串将被标准化,以匹配已知的区域设置(例如 en-US
将与 en_US
匹配)。
如果已经为新区域设置预先加载了翻译,则它们将被应用。
String standardize_locale(locale: String, add_defaults: bool = false) const 🔗
返回标准化后的 locale
字符串,与已知的区域设置匹配(例如 en-US
将与 en_US
匹配)。如果 add_defaults
为 true
,则可以为区域设置添加默认文字和地区。
StringName translate(message: StringName, context: StringName = &"") const 🔗
返回当前区域设置下,给定消息和上下文对应的翻译。
注意:该方法始终使用主翻译域。
StringName translate_plural(message: StringName, plural_message: StringName, n: int, context: StringName = &"") const 🔗
返回当前区域设置下,与给定消息、复数消息和上下文对应的翻译。
数字 n
是复数对象的数量。翻译系统会根据这个数字来针对所选语言获取正确的复数形式。
注意:该方法始终使用主翻译域。