Up to date

This page is up to date for Godot 4.2. If you still find outdated information, please open an issue.

TranslationServer

继承: Object

负责语言翻译的服务器。

描述

管理所有语言翻译的服务器。可以向其中添加翻译,也可以从中移除翻译。

教程

属性

bool

pseudolocalization_enabled

false

方法

void

add_translation ( Translation translation )

void

clear ( )

int

compare_locales ( String locale_a, String locale_b ) const

PackedStringArray

get_all_countries ( ) const

PackedStringArray

get_all_languages ( ) const

PackedStringArray

get_all_scripts ( ) const

String

get_country_name ( String country ) const

String

get_language_name ( String language ) const

PackedStringArray

get_loaded_locales ( ) const

String

get_locale ( ) const

String

get_locale_name ( String locale ) const

String

get_script_name ( String script ) const

String

get_tool_locale ( )

Translation

get_translation_object ( String locale )

StringName

pseudolocalize ( StringName message ) const

void

reload_pseudolocalization ( )

void

remove_translation ( Translation translation )

void

set_locale ( String locale )

String

standardize_locale ( String locale ) const

StringName

translate ( StringName message, StringName context="" ) const

StringName

translate_plural ( StringName message, StringName plural_message, int n, StringName context="" ) const


属性说明

bool pseudolocalization_enabled = false

  • void set_pseudolocalization_enabled ( bool value )

  • bool is_pseudolocalization_enabled ( )

如果为 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_localeOS.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 是复数对象的数量。翻译系统会根据这个数字来针对所选语言获取正确的复数形式。