| 1 | <?xml version="1.0" encoding="UTF-8" ?> |
| 2 | <class name="Translation" inherits="Resource" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="../class.xsd"> |
| 3 | <brief_description> |
| 4 | A language translation that maps a collection of strings to their individual translations. |
| 5 | </brief_description> |
| 6 | <description> |
| 7 | [Translation] maps a collection of strings to their individual translations, and also provides convenience methods for pluralization. |
| 8 | A [Translation] consists of messages. A message is identified by its context and untranslated string. Unlike [url=https://www.gnu.org/software/gettext/]gettext[/url], using an empty context string in Godot means not using any context. |
| 9 | </description> |
| 10 | <tutorials> |
| 11 | <link title="Internationalizing games">$DOCS_URL/tutorials/i18n/internationalizing_games.html</link> |
| 12 | <link title="Localization using gettext">$DOCS_URL/tutorials/i18n/localization_using_gettext.html</link> |
| 13 | <link title="Locales">$DOCS_URL/tutorials/i18n/locales.html</link> |
| 14 | </tutorials> |
| 15 | <methods> |
| 16 | <method name="_get_message" qualifiers="virtual const"> |
| 17 | <return type="StringName" /> |
| 18 | <param index="0" name="src_message" type="StringName" /> |
| 19 | <param index="1" name="context" type="StringName" /> |
| 20 | <description> |
| 21 | Virtual method to override [method get_message]. |
| 22 | </description> |
| 23 | </method> |
| 24 | <method name="_get_plural_message" qualifiers="virtual const"> |
| 25 | <return type="StringName" /> |
| 26 | <param index="0" name="src_message" type="StringName" /> |
| 27 | <param index="1" name="src_plural_message" type="StringName" /> |
| 28 | <param index="2" name="n" type="int" /> |
| 29 | <param index="3" name="context" type="StringName" /> |
| 30 | <description> |
| 31 | Virtual method to override [method get_plural_message]. |
| 32 | </description> |
| 33 | </method> |
| 34 | <method name="add_message"> |
| 35 | <return type="void" /> |
| 36 | <param index="0" name="src_message" type="StringName" /> |
| 37 | <param index="1" name="xlated_message" type="StringName" /> |
| 38 | <param index="2" name="context" type="StringName" default="&""" /> |
| 39 | <description> |
| 40 | Adds a message if nonexistent, followed by its translation. |
| 41 | An additional context could be used to specify the translation context or differentiate polysemic words. |
| 42 | </description> |
| 43 | </method> |
| 44 | <method name="add_plural_message"> |
| 45 | <return type="void" /> |
| 46 | <param index="0" name="src_message" type="StringName" /> |
| 47 | <param index="1" name="xlated_messages" type="PackedStringArray" /> |
| 48 | <param index="2" name="context" type="StringName" default="&""" /> |
| 49 | <description> |
| 50 | Adds a message involving plural translation if nonexistent, followed by its translation. |
| 51 | An additional context could be used to specify the translation context or differentiate polysemic words. |
| 52 | </description> |
| 53 | </method> |
| 54 | <method name="erase_message"> |
| 55 | <return type="void" /> |
| 56 | <param index="0" name="src_message" type="StringName" /> |
| 57 | <param index="1" name="context" type="StringName" default="&""" /> |
| 58 | <description> |
| 59 | Erases a message. |
| 60 | </description> |
| 61 | </method> |
| 62 | <method name="get_message" qualifiers="const"> |
| 63 | <return type="StringName" /> |
| 64 | <param index="0" name="src_message" type="StringName" /> |
| 65 | <param index="1" name="context" type="StringName" default="&""" /> |
| 66 | <description> |
| 67 | Returns a message's translation. |
| 68 | </description> |
| 69 | </method> |
| 70 | <method name="get_message_count" qualifiers="const"> |
| 71 | <return type="int" /> |
| 72 | <description> |
| 73 | Returns the number of existing messages. |
| 74 | </description> |
| 75 | </method> |
| 76 | <method name="get_message_list" qualifiers="const"> |
| 77 | <return type="PackedStringArray" /> |
| 78 | <description> |
| 79 | Returns the keys of all messages, that is, the context and untranslated strings of each message. |
| 80 | [b]Note:[/b] 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 ([code]U+0004[/code]). This is done for compatibility purposes. |
| 81 | [codeblock] |
| 82 | for key in translation.get_message_list(): |
| 83 | var p = key.find("\u0004") |
| 84 | if p == -1: |
| 85 | var untranslated = key |
| 86 | print("Message %s" % untranslated) |
| 87 | else: |
| 88 | var context = key.substr(0, p) |
| 89 | var untranslated = key.substr(p + 1) |
| 90 | print("Message %s with context %s" % [untranslated, context]) |
| 91 | [/codeblock] |
| 92 | </description> |
| 93 | </method> |
| 94 | <method name="get_plural_message" qualifiers="const"> |
| 95 | <return type="StringName" /> |
| 96 | <param index="0" name="src_message" type="StringName" /> |
| 97 | <param index="1" name="src_plural_message" type="StringName" /> |
| 98 | <param index="2" name="n" type="int" /> |
| 99 | <param index="3" name="context" type="StringName" default="&""" /> |
| 100 | <description> |
| 101 | Returns a message's translation involving plurals. |
| 102 | The number [param n] is the number or quantity of the plural object. It will be used to guide the translation system to fetch the correct plural form for the selected language. |
| 103 | [b]Note:[/b] Plurals are only supported in [url=$DOCS_URL/tutorials/i18n/localization_using_gettext.html]gettext-based translations (PO)[/url], not CSV. |
| 104 | </description> |
| 105 | </method> |
| 106 | <method name="get_translated_message_list" qualifiers="const"> |
| 107 | <return type="PackedStringArray" /> |
| 108 | <description> |
| 109 | Returns all the translated strings. |
| 110 | </description> |
| 111 | </method> |
| 112 | </methods> |
| 113 | <members> |
| 114 | <member name="locale" type="String" setter="set_locale" getter="get_locale" default=""en""> |
| 115 | The locale of the translation. |
| 116 | </member> |
| 117 | <member name="plural_rules_override" type="String" setter="set_plural_rules_override" getter="get_plural_rules_override" default=""""> |
| 118 | The plural rules string to enforce. See [url=https://www.gnu.org/software/gettext/manual/html_node/Plural-forms.html]GNU gettext[/url] for examples and more info. |
| 119 | If empty or invalid, default plural rules from [method TranslationServer.get_plural_rules] are used. The English plural rules are used as a fallback. |
| 120 | </member> |
| 121 | </members> |
| 122 | </class> |