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.

TranslationDomain

继承: RefCounted < Object

独立的 Translation 资源合集。

描述

TranslationDomain 即翻译域,是一种独立的 Translation 资源合集。可以向其中添加和删除翻译。

如果你想处理的是主翻译域,使用 TranslationServer 上的封装方法更方便。

属性

bool

pseudolocalization_accents_enabled

true

bool

pseudolocalization_double_vowels_enabled

false

bool

pseudolocalization_enabled

false

float

pseudolocalization_expansion_ratio

0.0

bool

pseudolocalization_fake_bidi_enabled

false

bool

pseudolocalization_override_enabled

false

String

pseudolocalization_prefix

"["

bool

pseudolocalization_skip_placeholders_enabled

true

String

pseudolocalization_suffix

"]"

方法

void

add_translation(translation: Translation)

void

clear()

Translation

get_translation_object(locale: String) const

StringName

pseudolocalize(message: StringName) const

void

remove_translation(translation: Translation)

StringName

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

StringName

translate_plural(message: StringName, message_plural: StringName, n: int, context: StringName = &"") const


属性说明

bool pseudolocalization_accents_enabled = true 🔗

  • void set_pseudolocalization_accents_enabled(value: bool)

  • bool is_pseudolocalization_accents_enabled()

伪本地化时将所有字符替换为对应的带重音的版本。

注意:更新该属性不会自动更新场景树中的文本。请在完成修改伪本地化相关选项后,手动传播 MainLoop.NOTIFICATION_TRANSLATION_CHANGED 通知。


bool pseudolocalization_double_vowels_enabled = false 🔗

  • void set_pseudolocalization_double_vowels_enabled(value: bool)

  • bool is_pseudolocalization_double_vowels_enabled()

伪本地化时重复元音字母,用于模拟因本地化导致文本变长的效果。

注意:更新该属性不会自动更新场景树中的文本。请在完成修改伪本地化相关选项后,手动传播 MainLoop.NOTIFICATION_TRANSLATION_CHANGED 通知。


bool pseudolocalization_enabled = false 🔗

  • void set_pseudolocalization_enabled(value: bool)

  • bool is_pseudolocalization_enabled()

如果为 true,则为项目启用伪本地化。可以用来发现未翻译的字符串,也可以用来发现将项目本地化为字符串比源语言更长的语言时可能出现的布局问题。

注意:更新该属性不会自动更新场景树中的文本。请在完成修改伪本地化相关选项后,手动传播 MainLoop.NOTIFICATION_TRANSLATION_CHANGED 通知。


float pseudolocalization_expansion_ratio = 0.0 🔗

  • void set_pseudolocalization_expansion_ratio(value: float)

  • float get_pseudolocalization_expansion_ratio()

伪本地化时使用的扩展率。0.3 会将字符串的长度增加 30%,对于大多数实际情况而言足够了。

注意:更新该属性不会自动更新场景树中的文本。请在完成修改伪本地化相关选项后,手动传播 MainLoop.NOTIFICATION_TRANSLATION_CHANGED 通知。


bool pseudolocalization_fake_bidi_enabled = false 🔗

  • void set_pseudolocalization_fake_bidi_enabled(value: bool)

  • bool is_pseudolocalization_fake_bidi_enabled()

如果为 true,则在启用伪本地化时模拟双向(从右至左)文本。可以用来发现将项目本地化为阿拉伯语和希伯来语等 RTL 语言时可能出现的 RTL 布局和 UI 镜像问题。

注意:更新该属性不会自动更新场景树中的文本。请在完成修改伪本地化相关选项后,手动传播 MainLoop.NOTIFICATION_TRANSLATION_CHANGED 通知。


bool pseudolocalization_override_enabled = false 🔗

  • void set_pseudolocalization_override_enabled(value: bool)

  • bool is_pseudolocalization_override_enabled()

将字符串中的所有字符都替换为 *。可用于发现无法本地化的字符串。

注意:更新该属性不会自动更新场景树中的文本。请在完成修改伪本地化相关选项后,手动传播 MainLoop.NOTIFICATION_TRANSLATION_CHANGED 通知。


String pseudolocalization_prefix = "[" 🔗

  • void set_pseudolocalization_prefix(value: String)

  • String get_pseudolocalization_prefix()

在伪本地化字符串前添加的前缀。

注意:更新该属性不会自动更新场景树中的文本。请在完成修改伪本地化相关选项后,手动传播 MainLoop.NOTIFICATION_TRANSLATION_CHANGED 通知。


bool pseudolocalization_skip_placeholders_enabled = true 🔗

  • void set_pseudolocalization_skip_placeholders_enabled(value: bool)

  • bool is_pseudolocalization_skip_placeholders_enabled()

伪本地化时跳过 %s%f 等用于字符串格式化的占位符。可用于识别需要额外的控制字符才能正确显示的字符串。

注意:更新该属性不会自动更新场景树中的文本。请在完成修改伪本地化相关选项后,手动传播 MainLoop.NOTIFICATION_TRANSLATION_CHANGED 通知。


String pseudolocalization_suffix = "]" 🔗

  • void set_pseudolocalization_suffix(value: String)

  • String get_pseudolocalization_suffix()

在伪本地化字符串后添加的后缀。

注意:更新该属性不会自动更新场景树中的文本。请在完成修改伪本地化相关选项后,手动传播 MainLoop.NOTIFICATION_TRANSLATION_CHANGED 通知。


方法说明

void add_translation(translation: Translation) 🔗

添加翻译。


void clear() 🔗

移除所有翻译。


Translation get_translation_object(locale: String) const 🔗

返回与 locale 最为匹配的 Translation 实例。如果没有能够匹配的翻译则返回 null


StringName pseudolocalize(message: StringName) const 🔗

根据传入的 message 返回伪本地化字符串。


void remove_translation(translation: Translation) 🔗

移除给定的翻译。


StringName translate(message: StringName, context: StringName = &"") const 🔗

返回当前区域设置下,与给定消息和上下文对应的翻译。


StringName translate_plural(message: StringName, message_plural: StringName, n: int, context: StringName = &"") const 🔗

返回当前区域设置下,与给定消息、复数消息和上下文对应的翻译。

数字 n 是复数对象的数量。翻译系统会根据这个数字来针对所选语言获取正确的复数形式。