TranslationDomain
继承: RefCounted < Object
独立的 Translation 资源合集。
描述
TranslationDomain 即翻译域,是一种独立的 Translation 资源合集。可以向其中添加和删除翻译。
如果你想处理的是主翻译域,使用 TranslationServer 上的封装方法更方便。
属性
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
方法
void |
add_translation(translation: Translation) |
void |
clear() |
find_translations(locale: String, exact: bool) const |
|
get_locale_override() const |
|
get_translation_object(locale: String) const |
|
get_translations() const |
|
has_translation(translation: Translation) const |
|
has_translation_for_locale(locale: String, exact: bool) const |
|
pseudolocalize(message: StringName) const |
|
void |
remove_translation(translation: Translation) |
void |
set_locale_override(locale: String) |
translate(message: StringName, context: StringName = &"") const |
|
translate_plural(message: StringName, message_plural: StringName, n: int, context: StringName = &"") const |
属性说明
如果为 true,则启用翻译。否则 translate() 和 translate_plural() 会返回未经修改的输入消息,忽略当前区域设置。
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 🔗
如果为 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 = "[" 🔗
在伪本地化字符串前添加的前缀。
注意:更新该属性不会自动更新场景树中的文本。请在完成修改伪本地化相关选项后,手动传播 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 = "]" 🔗
在伪本地化字符串后添加的后缀。
注意:更新该属性不会自动更新场景树中的文本。请在完成修改伪本地化相关选项后,手动传播 MainLoop.NOTIFICATION_TRANSLATION_CHANGED 通知。
方法说明
void add_translation(translation: Translation) 🔗
添加翻译。
void clear() 🔗
移除所有翻译。
Array[Translation] find_translations(locale: String, exact: bool) const 🔗
Returns the Translation instances that match locale (see TranslationServer.compare_locales()). If exact is true, only instances whose locale exactly equals locale will be returned.
String get_locale_override() const 🔗
返回翻译域的区域设置覆盖项。如果禁用区域设置覆盖则返回空字符串。
Translation get_translation_object(locale: String) const 🔗
已弃用: Use find_translations() instead.
返回与 locale 最为匹配的 Translation 实例。如果没有能够匹配的翻译则返回 null。
Array[Translation] get_translations() const 🔗
Returns all available Translation instances as added by add_translation().
bool has_translation(translation: Translation) const 🔗
Returns true if this translation domain contains the given translation.
bool has_translation_for_locale(locale: String, exact: bool) const 🔗
Returns true if there are any Translation instances that match locale (see TranslationServer.compare_locales()). If exact is true, only instances whose locale exactly equals locale are considered.
StringName pseudolocalize(message: StringName) const 🔗
根据传入的 message 返回伪本地化字符串。
void remove_translation(translation: Translation) 🔗
移除给定的翻译。
void set_locale_override(locale: String) 🔗
设置翻译域的区域设置覆盖项。
如果 locale 为空字符串则禁用区域设置覆盖。否则会将 locale 进行标准化,匹配已知区域设置(例如 en-US 会与 en_US 匹配)。
注意:调用该方法不会自动更新场景树中的文本。请手动传播 MainLoop.NOTIFICATION_TRANSLATION_CHANGED 信号。
StringName translate(message: StringName, context: StringName = &"") const 🔗
返回当前区域设置下,与给定消息和上下文对应的翻译。
StringName translate_plural(message: StringName, message_plural: StringName, n: int, context: StringName = &"") const 🔗
返回当前区域设置下,与给定消息、复数消息和上下文对应的翻译。
数字 n 是复数对象的数量。翻译系统会根据这个数字来针对所选语言获取正确的复数形式。