Translation

继承: Resource < RefCounted < Object

派生: OptimizedTranslation

语言翻译,能够将一组字符串映射到对应的翻译。

描述

Translation maps a collection of strings to their individual translations, and also provides convenience methods for pluralization.

A Translation consists of messages. A message is identified by its context and untranslated string. Unlike gettext, using an empty context string in Godot means not using any context.

教程

属性

String

locale

"en"

String

plural_rules_override

""

方法

StringName

_get_message(src_message: StringName, context: StringName) virtual const

StringName

_get_plural_message(src_message: StringName, src_plural_message: StringName, n: int, context: StringName) virtual const

void

add_message(src_message: StringName, xlated_message: StringName, context: StringName = &"")

void

add_plural_message(src_message: StringName, xlated_messages: PackedStringArray, context: StringName = &"")

void

erase_message(src_message: StringName, context: StringName = &"")

StringName

get_message(src_message: StringName, context: StringName = &"") const

int

get_message_count() const

PackedStringArray

get_message_list() const

StringName

get_plural_message(src_message: StringName, src_plural_message: StringName, n: int, context: StringName = &"") const

PackedStringArray

get_translated_message_list() const


属性说明

String locale = "en" 🔗

翻译的区域设置。


String plural_rules_override = "" 🔗

  • void set_plural_rules_override(value: String)

  • String get_plural_rules_override()

The plural rules string to enforce. See GNU gettext for examples and more info.

If empty or invalid, default plural rules from TranslationServer.get_plural_rules() are used. The English plural rules are used as a fallback.


方法说明

StringName _get_message(src_message: StringName, context: StringName) virtual const 🔗

覆盖 get_message() 的虚方法。


StringName _get_plural_message(src_message: StringName, src_plural_message: StringName, n: int, context: StringName) virtual const 🔗

覆盖 get_plural_message() 的虚方法。


void add_message(src_message: StringName, xlated_message: StringName, context: StringName = &"") 🔗

如果不存在,则添加一条消息,后跟其翻译。

可以使用一个额外的上下文,来指定翻译上下文或区分多义词。


void add_plural_message(src_message: StringName, xlated_messages: PackedStringArray, context: StringName = &"") 🔗

Adds a message involving plural translation if nonexistent, followed by its translation.

An additional context could be used to specify the translation context or differentiate polysemic words.


void erase_message(src_message: StringName, context: StringName = &"") 🔗

删除信息。


StringName get_message(src_message: StringName, context: StringName = &"") const 🔗

返回信息的翻译。


int get_message_count() const 🔗

返回现有信息的数量。


PackedStringArray get_message_list() const 🔗

Returns the keys of all messages, that is, the context and untranslated strings of each message.

Note: If a message does not use a context, the corresponding element is the untranslated string. Otherwise, the corresponding element is the context and untranslated string separated by the EOT character (U+0004). This is done for compatibility purposes.

for key in translation.get_message_list():
    var p = key.find("\u0004")
    if p == -1:
        var untranslated = key
        print("Message %s" % untranslated)
    else:
        var context = key.substr(0, p)
        var untranslated = key.substr(p + 1)
        print("Message %s with context %s" % [untranslated, context])

StringName get_plural_message(src_message: StringName, src_plural_message: StringName, n: int, context: StringName = &"") const 🔗

返回一条消息涉及复数的翻译。

数字 n 是复数对象的数目或数量。它将被用于指导翻译系统为所选语言获取正确的复数形式。

注意:基于 gettext 的翻译(PO)支持复数,CSV 不支持。


PackedStringArray get_translated_message_list() const 🔗

Returns all the translated strings.