class_translation.rst 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279
  1. :github_url: hide
  2. .. DO NOT EDIT THIS FILE!!!
  3. .. Generated automatically from Godot engine sources.
  4. .. Generator: https://github.com/godotengine/godot/tree/master/doc/tools/make_rst.py.
  5. .. XML source: https://github.com/godotengine/godot/tree/master/doc/classes/Translation.xml.
  6. .. _class_Translation:
  7. Translation
  8. ===========
  9. **Inherits:** :ref:`Resource<class_Resource>` **<** :ref:`RefCounted<class_RefCounted>` **<** :ref:`Object<class_Object>`
  10. **Inherited By:** :ref:`OptimizedTranslation<class_OptimizedTranslation>`
  11. A language translation that maps a collection of strings to their individual translations.
  12. .. rst-class:: classref-introduction-group
  13. Description
  14. -----------
  15. **Translation** maps a collection of strings to their individual translations, and also provides convenience methods for pluralization.
  16. A **Translation** consists of messages. A message is identified by its context and untranslated string. Unlike `gettext <https://www.gnu.org/software/gettext/>`__, using an empty context string in Godot means not using any context.
  17. .. rst-class:: classref-introduction-group
  18. Tutorials
  19. ---------
  20. - :doc:`Internationalizing games <../tutorials/i18n/internationalizing_games>`
  21. - :doc:`Localization using gettext <../tutorials/i18n/localization_using_gettext>`
  22. - :doc:`Locales <../tutorials/i18n/locales>`
  23. .. rst-class:: classref-reftable-group
  24. Properties
  25. ----------
  26. .. table::
  27. :widths: auto
  28. +-----------------------------+--------------------------------------------------------------------------------+----------+
  29. | :ref:`String<class_String>` | :ref:`locale<class_Translation_property_locale>` | ``"en"`` |
  30. +-----------------------------+--------------------------------------------------------------------------------+----------+
  31. | :ref:`String<class_String>` | :ref:`plural_rules_override<class_Translation_property_plural_rules_override>` | ``""`` |
  32. +-----------------------------+--------------------------------------------------------------------------------+----------+
  33. .. rst-class:: classref-reftable-group
  34. Methods
  35. -------
  36. .. table::
  37. :widths: auto
  38. +---------------------------------------------------+-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  39. | :ref:`StringName<class_StringName>` | :ref:`_get_message<class_Translation_private_method__get_message>`\ (\ src_message\: :ref:`StringName<class_StringName>`, context\: :ref:`StringName<class_StringName>`\ ) |virtual| |const| |
  40. +---------------------------------------------------+-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  41. | :ref:`StringName<class_StringName>` | :ref:`_get_plural_message<class_Translation_private_method__get_plural_message>`\ (\ src_message\: :ref:`StringName<class_StringName>`, src_plural_message\: :ref:`StringName<class_StringName>`, n\: :ref:`int<class_int>`, context\: :ref:`StringName<class_StringName>`\ ) |virtual| |const| |
  42. +---------------------------------------------------+-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  43. | |void| | :ref:`add_message<class_Translation_method_add_message>`\ (\ src_message\: :ref:`StringName<class_StringName>`, xlated_message\: :ref:`StringName<class_StringName>`, context\: :ref:`StringName<class_StringName>` = &""\ ) |
  44. +---------------------------------------------------+-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  45. | |void| | :ref:`add_plural_message<class_Translation_method_add_plural_message>`\ (\ src_message\: :ref:`StringName<class_StringName>`, xlated_messages\: :ref:`PackedStringArray<class_PackedStringArray>`, context\: :ref:`StringName<class_StringName>` = &""\ ) |
  46. +---------------------------------------------------+-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  47. | |void| | :ref:`erase_message<class_Translation_method_erase_message>`\ (\ src_message\: :ref:`StringName<class_StringName>`, context\: :ref:`StringName<class_StringName>` = &""\ ) |
  48. +---------------------------------------------------+-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  49. | :ref:`StringName<class_StringName>` | :ref:`get_message<class_Translation_method_get_message>`\ (\ src_message\: :ref:`StringName<class_StringName>`, context\: :ref:`StringName<class_StringName>` = &""\ ) |const| |
  50. +---------------------------------------------------+-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  51. | :ref:`int<class_int>` | :ref:`get_message_count<class_Translation_method_get_message_count>`\ (\ ) |const| |
  52. +---------------------------------------------------+-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  53. | :ref:`PackedStringArray<class_PackedStringArray>` | :ref:`get_message_list<class_Translation_method_get_message_list>`\ (\ ) |const| |
  54. +---------------------------------------------------+-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  55. | :ref:`StringName<class_StringName>` | :ref:`get_plural_message<class_Translation_method_get_plural_message>`\ (\ src_message\: :ref:`StringName<class_StringName>`, src_plural_message\: :ref:`StringName<class_StringName>`, n\: :ref:`int<class_int>`, context\: :ref:`StringName<class_StringName>` = &""\ ) |const| |
  56. +---------------------------------------------------+-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  57. | :ref:`PackedStringArray<class_PackedStringArray>` | :ref:`get_translated_message_list<class_Translation_method_get_translated_message_list>`\ (\ ) |const| |
  58. +---------------------------------------------------+-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  59. .. rst-class:: classref-section-separator
  60. ----
  61. .. rst-class:: classref-descriptions-group
  62. Property Descriptions
  63. ---------------------
  64. .. _class_Translation_property_locale:
  65. .. rst-class:: classref-property
  66. :ref:`String<class_String>` **locale** = ``"en"`` :ref:`🔗<class_Translation_property_locale>`
  67. .. rst-class:: classref-property-setget
  68. - |void| **set_locale**\ (\ value\: :ref:`String<class_String>`\ )
  69. - :ref:`String<class_String>` **get_locale**\ (\ )
  70. The locale of the translation.
  71. .. rst-class:: classref-item-separator
  72. ----
  73. .. _class_Translation_property_plural_rules_override:
  74. .. rst-class:: classref-property
  75. :ref:`String<class_String>` **plural_rules_override** = ``""`` :ref:`🔗<class_Translation_property_plural_rules_override>`
  76. .. rst-class:: classref-property-setget
  77. - |void| **set_plural_rules_override**\ (\ value\: :ref:`String<class_String>`\ )
  78. - :ref:`String<class_String>` **get_plural_rules_override**\ (\ )
  79. The plural rules string to enforce. See `GNU gettext <https://www.gnu.org/software/gettext/manual/html_node/Plural-forms.html>`__ for examples and more info.
  80. If empty or invalid, default plural rules from :ref:`TranslationServer.get_plural_rules()<class_TranslationServer_method_get_plural_rules>` are used. The English plural rules are used as a fallback.
  81. .. rst-class:: classref-section-separator
  82. ----
  83. .. rst-class:: classref-descriptions-group
  84. Method Descriptions
  85. -------------------
  86. .. _class_Translation_private_method__get_message:
  87. .. rst-class:: classref-method
  88. :ref:`StringName<class_StringName>` **_get_message**\ (\ src_message\: :ref:`StringName<class_StringName>`, context\: :ref:`StringName<class_StringName>`\ ) |virtual| |const| :ref:`🔗<class_Translation_private_method__get_message>`
  89. Virtual method to override :ref:`get_message()<class_Translation_method_get_message>`.
  90. .. rst-class:: classref-item-separator
  91. ----
  92. .. _class_Translation_private_method__get_plural_message:
  93. .. rst-class:: classref-method
  94. :ref:`StringName<class_StringName>` **_get_plural_message**\ (\ src_message\: :ref:`StringName<class_StringName>`, src_plural_message\: :ref:`StringName<class_StringName>`, n\: :ref:`int<class_int>`, context\: :ref:`StringName<class_StringName>`\ ) |virtual| |const| :ref:`🔗<class_Translation_private_method__get_plural_message>`
  95. Virtual method to override :ref:`get_plural_message()<class_Translation_method_get_plural_message>`.
  96. .. rst-class:: classref-item-separator
  97. ----
  98. .. _class_Translation_method_add_message:
  99. .. rst-class:: classref-method
  100. |void| **add_message**\ (\ src_message\: :ref:`StringName<class_StringName>`, xlated_message\: :ref:`StringName<class_StringName>`, context\: :ref:`StringName<class_StringName>` = &""\ ) :ref:`🔗<class_Translation_method_add_message>`
  101. Adds a message if nonexistent, followed by its translation.
  102. An additional context could be used to specify the translation context or differentiate polysemic words.
  103. .. rst-class:: classref-item-separator
  104. ----
  105. .. _class_Translation_method_add_plural_message:
  106. .. rst-class:: classref-method
  107. |void| **add_plural_message**\ (\ src_message\: :ref:`StringName<class_StringName>`, xlated_messages\: :ref:`PackedStringArray<class_PackedStringArray>`, context\: :ref:`StringName<class_StringName>` = &""\ ) :ref:`🔗<class_Translation_method_add_plural_message>`
  108. Adds a message involving plural translation if nonexistent, followed by its translation.
  109. An additional context could be used to specify the translation context or differentiate polysemic words.
  110. .. rst-class:: classref-item-separator
  111. ----
  112. .. _class_Translation_method_erase_message:
  113. .. rst-class:: classref-method
  114. |void| **erase_message**\ (\ src_message\: :ref:`StringName<class_StringName>`, context\: :ref:`StringName<class_StringName>` = &""\ ) :ref:`🔗<class_Translation_method_erase_message>`
  115. Erases a message.
  116. .. rst-class:: classref-item-separator
  117. ----
  118. .. _class_Translation_method_get_message:
  119. .. rst-class:: classref-method
  120. :ref:`StringName<class_StringName>` **get_message**\ (\ src_message\: :ref:`StringName<class_StringName>`, context\: :ref:`StringName<class_StringName>` = &""\ ) |const| :ref:`🔗<class_Translation_method_get_message>`
  121. Returns a message's translation.
  122. .. rst-class:: classref-item-separator
  123. ----
  124. .. _class_Translation_method_get_message_count:
  125. .. rst-class:: classref-method
  126. :ref:`int<class_int>` **get_message_count**\ (\ ) |const| :ref:`🔗<class_Translation_method_get_message_count>`
  127. Returns the number of existing messages.
  128. .. rst-class:: classref-item-separator
  129. ----
  130. .. _class_Translation_method_get_message_list:
  131. .. rst-class:: classref-method
  132. :ref:`PackedStringArray<class_PackedStringArray>` **get_message_list**\ (\ ) |const| :ref:`🔗<class_Translation_method_get_message_list>`
  133. Returns the keys of all messages, that is, the context and untranslated strings of each message.
  134. \ **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.
  135. ::
  136. for key in translation.get_message_list():
  137. var p = key.find("\u0004")
  138. if p == -1:
  139. var untranslated = key
  140. print("Message %s" % untranslated)
  141. else:
  142. var context = key.substr(0, p)
  143. var untranslated = key.substr(p + 1)
  144. print("Message %s with context %s" % [untranslated, context])
  145. .. rst-class:: classref-item-separator
  146. ----
  147. .. _class_Translation_method_get_plural_message:
  148. .. rst-class:: classref-method
  149. :ref:`StringName<class_StringName>` **get_plural_message**\ (\ src_message\: :ref:`StringName<class_StringName>`, src_plural_message\: :ref:`StringName<class_StringName>`, n\: :ref:`int<class_int>`, context\: :ref:`StringName<class_StringName>` = &""\ ) |const| :ref:`🔗<class_Translation_method_get_plural_message>`
  150. Returns a message's translation involving plurals.
  151. The number ``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.
  152. \ **Note:** Plurals are only supported in :doc:`gettext-based translations (PO) <../tutorials/i18n/localization_using_gettext>`, not CSV.
  153. .. rst-class:: classref-item-separator
  154. ----
  155. .. _class_Translation_method_get_translated_message_list:
  156. .. rst-class:: classref-method
  157. :ref:`PackedStringArray<class_PackedStringArray>` **get_translated_message_list**\ (\ ) |const| :ref:`🔗<class_Translation_method_get_translated_message_list>`
  158. Returns all the translated strings.
  159. .. |virtual| replace:: :abbr:`virtual (This method should typically be overridden by the user to have any effect.)`
  160. .. |required| replace:: :abbr:`required (This method is required to be overridden when extending its base class.)`
  161. .. |const| replace:: :abbr:`const (This method has no side effects. It doesn't modify any of the instance's member variables.)`
  162. .. |vararg| replace:: :abbr:`vararg (This method accepts any number of arguments after the ones described here.)`
  163. .. |constructor| replace:: :abbr:`constructor (This method is used to construct a type.)`
  164. .. |static| replace:: :abbr:`static (This method doesn't need an instance to be called, so it can be called directly using the class name.)`
  165. .. |operator| replace:: :abbr:`operator (This method describes a valid operator to use with this type as left-hand operand.)`
  166. .. |bitfield| replace:: :abbr:`BitField (This value is an integer composed as a bitmask of the following flags.)`
  167. .. |void| replace:: :abbr:`void (No return value.)`