TranslationServer
继承: Object
负责语言翻译的服务器。
描述
翻译服务器是负责管理所有语言翻译的 API 后端。
翻译存储在翻译域 TranslationDomain 中,可以通过名称访问。最常用的翻译域是主翻译域。主翻译域始终存在,可以通过空 StringName 访问。翻译服务器为直接访问主翻译域提供了封装方法,无需先获取翻译域。自定义翻译域主要用于编辑器插件等高阶用法。以 godot. 开头的名称是引擎内部保留名称。
教程
属性
|
方法
属性说明
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(完全匹配)之间的相似度得分。
Array[Translation] find_translations(locale: String, exact: bool) const 🔗
Returns the Translation instances in the main translation domain that match locale (see compare_locales()). If exact is true, only instances whose locale exactly equals locale will be returned.
String format_number(number: String, locale: String) const 🔗
Converts a number from Western Arabic (0..9) to the numeral system used in the given locale.
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_percent_sign(locale: String) const 🔗
Returns the percent sign used in the given locale.
String get_plural_rules(locale: String) const 🔗
Returns the default plural rules for the locale.
String get_script_name(script: String) const 🔗
返回文字代码 script 的可读文字名称。
返回编辑器的当前区域设置。
注意:从导出后的项目中调用时,返回值与 get_locale() 相同。
Translation get_translation_object(locale: String) 🔗
已弃用: Use find_translations() instead.
返回主翻译域中与 locale 最为匹配的 Translation 实例。如果没有能够匹配的翻译则返回 null。
Array[Translation] get_translations() const 🔗
Returns all available Translation instances in the main translation domain as added by add_translation().
bool has_domain(domain: StringName) const 🔗
如果存在指定名称的翻译域,则返回 true。
bool has_translation(translation: Translation) const 🔗
Returns true if the main translation domain contains the given translation.
bool has_translation_for_locale(locale: String, exact: bool) const 🔗
Returns true if there are any Translation instances in the main translation domain that match locale (see compare_locales()). If exact is true, only instances whose locale exactly equals locale are considered.
String parse_number(number: String, locale: String) const 🔗
Converts number from the numeral system used in the given locale to Western Arabic (0..9).
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 是复数对象的数量。翻译系统会根据这个数字来针对所选语言获取正确的复数形式。
注意:该方法始终使用主翻译域。