class_translationserver.rst 23 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392
  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/4.0/doc/tools/make_rst.py.
  5. .. XML source: https://github.com/godotengine/godot/tree/4.0/doc/classes/TranslationServer.xml.
  6. .. _class_TranslationServer:
  7. TranslationServer
  8. =================
  9. **Inherits:** :ref:`Object<class_Object>`
  10. The server responsible for language translations.
  11. .. rst-class:: classref-introduction-group
  12. Description
  13. -----------
  14. The server that manages all language translations. Translations can be added to or removed from it.
  15. .. rst-class:: classref-introduction-group
  16. Tutorials
  17. ---------
  18. - :doc:`Internationalizing games <../tutorials/i18n/internationalizing_games>`
  19. - :doc:`Locales <../tutorials/i18n/locales>`
  20. .. rst-class:: classref-reftable-group
  21. Properties
  22. ----------
  23. .. table::
  24. :widths: auto
  25. +-------------------------+------------------------------------------------------------------------------------------------+-----------+
  26. | :ref:`bool<class_bool>` | :ref:`pseudolocalization_enabled<class_TranslationServer_property_pseudolocalization_enabled>` | ``false`` |
  27. +-------------------------+------------------------------------------------------------------------------------------------+-----------+
  28. .. rst-class:: classref-reftable-group
  29. Methods
  30. -------
  31. .. table::
  32. :widths: auto
  33. +---------------------------------------------------+-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  34. | void | :ref:`add_translation<class_TranslationServer_method_add_translation>` **(** :ref:`Translation<class_Translation>` translation **)** |
  35. +---------------------------------------------------+-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  36. | void | :ref:`clear<class_TranslationServer_method_clear>` **(** **)** |
  37. +---------------------------------------------------+-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  38. | :ref:`int<class_int>` | :ref:`compare_locales<class_TranslationServer_method_compare_locales>` **(** :ref:`String<class_String>` locale_a, :ref:`String<class_String>` locale_b **)** |const| |
  39. +---------------------------------------------------+-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  40. | :ref:`PackedStringArray<class_PackedStringArray>` | :ref:`get_all_countries<class_TranslationServer_method_get_all_countries>` **(** **)** |const| |
  41. +---------------------------------------------------+-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  42. | :ref:`PackedStringArray<class_PackedStringArray>` | :ref:`get_all_languages<class_TranslationServer_method_get_all_languages>` **(** **)** |const| |
  43. +---------------------------------------------------+-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  44. | :ref:`PackedStringArray<class_PackedStringArray>` | :ref:`get_all_scripts<class_TranslationServer_method_get_all_scripts>` **(** **)** |const| |
  45. +---------------------------------------------------+-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  46. | :ref:`String<class_String>` | :ref:`get_country_name<class_TranslationServer_method_get_country_name>` **(** :ref:`String<class_String>` country **)** |const| |
  47. +---------------------------------------------------+-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  48. | :ref:`String<class_String>` | :ref:`get_language_name<class_TranslationServer_method_get_language_name>` **(** :ref:`String<class_String>` language **)** |const| |
  49. +---------------------------------------------------+-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  50. | :ref:`PackedStringArray<class_PackedStringArray>` | :ref:`get_loaded_locales<class_TranslationServer_method_get_loaded_locales>` **(** **)** |const| |
  51. +---------------------------------------------------+-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  52. | :ref:`String<class_String>` | :ref:`get_locale<class_TranslationServer_method_get_locale>` **(** **)** |const| |
  53. +---------------------------------------------------+-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  54. | :ref:`String<class_String>` | :ref:`get_locale_name<class_TranslationServer_method_get_locale_name>` **(** :ref:`String<class_String>` locale **)** |const| |
  55. +---------------------------------------------------+-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  56. | :ref:`String<class_String>` | :ref:`get_script_name<class_TranslationServer_method_get_script_name>` **(** :ref:`String<class_String>` script **)** |const| |
  57. +---------------------------------------------------+-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  58. | :ref:`String<class_String>` | :ref:`get_tool_locale<class_TranslationServer_method_get_tool_locale>` **(** **)** |
  59. +---------------------------------------------------+-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  60. | :ref:`Translation<class_Translation>` | :ref:`get_translation_object<class_TranslationServer_method_get_translation_object>` **(** :ref:`String<class_String>` locale **)** |
  61. +---------------------------------------------------+-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  62. | :ref:`StringName<class_StringName>` | :ref:`pseudolocalize<class_TranslationServer_method_pseudolocalize>` **(** :ref:`StringName<class_StringName>` message **)** |const| |
  63. +---------------------------------------------------+-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  64. | void | :ref:`reload_pseudolocalization<class_TranslationServer_method_reload_pseudolocalization>` **(** **)** |
  65. +---------------------------------------------------+-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  66. | void | :ref:`remove_translation<class_TranslationServer_method_remove_translation>` **(** :ref:`Translation<class_Translation>` translation **)** |
  67. +---------------------------------------------------+-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  68. | void | :ref:`set_locale<class_TranslationServer_method_set_locale>` **(** :ref:`String<class_String>` locale **)** |
  69. +---------------------------------------------------+-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  70. | :ref:`String<class_String>` | :ref:`standardize_locale<class_TranslationServer_method_standardize_locale>` **(** :ref:`String<class_String>` locale **)** |const| |
  71. +---------------------------------------------------+-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  72. | :ref:`StringName<class_StringName>` | :ref:`translate<class_TranslationServer_method_translate>` **(** :ref:`StringName<class_StringName>` message, :ref:`StringName<class_StringName>` context="" **)** |const| |
  73. +---------------------------------------------------+-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  74. | :ref:`StringName<class_StringName>` | :ref:`translate_plural<class_TranslationServer_method_translate_plural>` **(** :ref:`StringName<class_StringName>` message, :ref:`StringName<class_StringName>` plural_message, :ref:`int<class_int>` n, :ref:`StringName<class_StringName>` context="" **)** |const| |
  75. +---------------------------------------------------+-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  76. .. rst-class:: classref-section-separator
  77. ----
  78. .. rst-class:: classref-descriptions-group
  79. Property Descriptions
  80. ---------------------
  81. .. _class_TranslationServer_property_pseudolocalization_enabled:
  82. .. rst-class:: classref-property
  83. :ref:`bool<class_bool>` **pseudolocalization_enabled** = ``false``
  84. .. rst-class:: classref-property-setget
  85. - void **set_pseudolocalization_enabled** **(** :ref:`bool<class_bool>` value **)**
  86. - :ref:`bool<class_bool>` **is_pseudolocalization_enabled** **(** **)**
  87. If ``true``, enables the use of pseudolocalization. See :ref:`ProjectSettings.internationalization/pseudolocalization/use_pseudolocalization<class_ProjectSettings_property_internationalization/pseudolocalization/use_pseudolocalization>` for details.
  88. .. rst-class:: classref-section-separator
  89. ----
  90. .. rst-class:: classref-descriptions-group
  91. Method Descriptions
  92. -------------------
  93. .. _class_TranslationServer_method_add_translation:
  94. .. rst-class:: classref-method
  95. void **add_translation** **(** :ref:`Translation<class_Translation>` translation **)**
  96. Adds a :ref:`Translation<class_Translation>` resource.
  97. .. rst-class:: classref-item-separator
  98. ----
  99. .. _class_TranslationServer_method_clear:
  100. .. rst-class:: classref-method
  101. void **clear** **(** **)**
  102. Clears the server from all translations.
  103. .. rst-class:: classref-item-separator
  104. ----
  105. .. _class_TranslationServer_method_compare_locales:
  106. .. rst-class:: classref-method
  107. :ref:`int<class_int>` **compare_locales** **(** :ref:`String<class_String>` locale_a, :ref:`String<class_String>` locale_b **)** |const|
  108. Compares two locales and returns a similarity score between ``0`` (no match) and ``10`` (full match).
  109. .. rst-class:: classref-item-separator
  110. ----
  111. .. _class_TranslationServer_method_get_all_countries:
  112. .. rst-class:: classref-method
  113. :ref:`PackedStringArray<class_PackedStringArray>` **get_all_countries** **(** **)** |const|
  114. Returns an array of known country codes.
  115. .. rst-class:: classref-item-separator
  116. ----
  117. .. _class_TranslationServer_method_get_all_languages:
  118. .. rst-class:: classref-method
  119. :ref:`PackedStringArray<class_PackedStringArray>` **get_all_languages** **(** **)** |const|
  120. Returns array of known language codes.
  121. .. rst-class:: classref-item-separator
  122. ----
  123. .. _class_TranslationServer_method_get_all_scripts:
  124. .. rst-class:: classref-method
  125. :ref:`PackedStringArray<class_PackedStringArray>` **get_all_scripts** **(** **)** |const|
  126. Returns an array of known script codes.
  127. .. rst-class:: classref-item-separator
  128. ----
  129. .. _class_TranslationServer_method_get_country_name:
  130. .. rst-class:: classref-method
  131. :ref:`String<class_String>` **get_country_name** **(** :ref:`String<class_String>` country **)** |const|
  132. Returns a readable country name for the ``country`` code.
  133. .. rst-class:: classref-item-separator
  134. ----
  135. .. _class_TranslationServer_method_get_language_name:
  136. .. rst-class:: classref-method
  137. :ref:`String<class_String>` **get_language_name** **(** :ref:`String<class_String>` language **)** |const|
  138. Returns a readable language name for the ``language`` code.
  139. .. rst-class:: classref-item-separator
  140. ----
  141. .. _class_TranslationServer_method_get_loaded_locales:
  142. .. rst-class:: classref-method
  143. :ref:`PackedStringArray<class_PackedStringArray>` **get_loaded_locales** **(** **)** |const|
  144. Returns an array of all loaded locales of the project.
  145. .. rst-class:: classref-item-separator
  146. ----
  147. .. _class_TranslationServer_method_get_locale:
  148. .. rst-class:: classref-method
  149. :ref:`String<class_String>` **get_locale** **(** **)** |const|
  150. Returns the current locale of the project.
  151. See also :ref:`OS.get_locale<class_OS_method_get_locale>` and :ref:`OS.get_locale_language<class_OS_method_get_locale_language>` to query the locale of the user system.
  152. .. rst-class:: classref-item-separator
  153. ----
  154. .. _class_TranslationServer_method_get_locale_name:
  155. .. rst-class:: classref-method
  156. :ref:`String<class_String>` **get_locale_name** **(** :ref:`String<class_String>` locale **)** |const|
  157. Returns a locale's language and its variant (e.g. ``"en_US"`` would return ``"English (United States)"``).
  158. .. rst-class:: classref-item-separator
  159. ----
  160. .. _class_TranslationServer_method_get_script_name:
  161. .. rst-class:: classref-method
  162. :ref:`String<class_String>` **get_script_name** **(** :ref:`String<class_String>` script **)** |const|
  163. Returns a readable script name for the ``script`` code.
  164. .. rst-class:: classref-item-separator
  165. ----
  166. .. _class_TranslationServer_method_get_tool_locale:
  167. .. rst-class:: classref-method
  168. :ref:`String<class_String>` **get_tool_locale** **(** **)**
  169. Returns the current locale of the editor.
  170. \ **Note:** When called from an exported project returns the same value as :ref:`get_locale<class_TranslationServer_method_get_locale>`.
  171. .. rst-class:: classref-item-separator
  172. ----
  173. .. _class_TranslationServer_method_get_translation_object:
  174. .. rst-class:: classref-method
  175. :ref:`Translation<class_Translation>` **get_translation_object** **(** :ref:`String<class_String>` locale **)**
  176. Returns the :ref:`Translation<class_Translation>` instance based on the ``locale`` passed in.
  177. It will return ``null`` if there is no :ref:`Translation<class_Translation>` instance that matches the ``locale``.
  178. .. rst-class:: classref-item-separator
  179. ----
  180. .. _class_TranslationServer_method_pseudolocalize:
  181. .. rst-class:: classref-method
  182. :ref:`StringName<class_StringName>` **pseudolocalize** **(** :ref:`StringName<class_StringName>` message **)** |const|
  183. Returns the pseudolocalized string based on the ``message`` passed in.
  184. .. rst-class:: classref-item-separator
  185. ----
  186. .. _class_TranslationServer_method_reload_pseudolocalization:
  187. .. rst-class:: classref-method
  188. void **reload_pseudolocalization** **(** **)**
  189. Reparses the pseudolocalization options and reloads the translation.
  190. .. rst-class:: classref-item-separator
  191. ----
  192. .. _class_TranslationServer_method_remove_translation:
  193. .. rst-class:: classref-method
  194. void **remove_translation** **(** :ref:`Translation<class_Translation>` translation **)**
  195. Removes the given translation from the server.
  196. .. rst-class:: classref-item-separator
  197. ----
  198. .. _class_TranslationServer_method_set_locale:
  199. .. rst-class:: classref-method
  200. void **set_locale** **(** :ref:`String<class_String>` locale **)**
  201. Sets the locale of the project. The ``locale`` string will be standardized to match known locales (e.g. ``en-US`` would be matched to ``en_US``).
  202. If translations have been loaded beforehand for the new locale, they will be applied.
  203. .. rst-class:: classref-item-separator
  204. ----
  205. .. _class_TranslationServer_method_standardize_locale:
  206. .. rst-class:: classref-method
  207. :ref:`String<class_String>` **standardize_locale** **(** :ref:`String<class_String>` locale **)** |const|
  208. Returns a ``locale`` string standardized to match known locales (e.g. ``en-US`` would be matched to ``en_US``).
  209. .. rst-class:: classref-item-separator
  210. ----
  211. .. _class_TranslationServer_method_translate:
  212. .. rst-class:: classref-method
  213. :ref:`StringName<class_StringName>` **translate** **(** :ref:`StringName<class_StringName>` message, :ref:`StringName<class_StringName>` context="" **)** |const|
  214. Returns the current locale's translation for the given message (key) and context.
  215. .. rst-class:: classref-item-separator
  216. ----
  217. .. _class_TranslationServer_method_translate_plural:
  218. .. rst-class:: classref-method
  219. :ref:`StringName<class_StringName>` **translate_plural** **(** :ref:`StringName<class_StringName>` message, :ref:`StringName<class_StringName>` plural_message, :ref:`int<class_int>` n, :ref:`StringName<class_StringName>` context="" **)** |const|
  220. Returns the current locale's translation for the given message (key), plural message and context.
  221. 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.
  222. .. |virtual| replace:: :abbr:`virtual (This method should typically be overridden by the user to have any effect.)`
  223. .. |const| replace:: :abbr:`const (This method has no side effects. It doesn't modify any of the instance's member variables.)`
  224. .. |vararg| replace:: :abbr:`vararg (This method accepts any number of arguments after the ones described here.)`
  225. .. |constructor| replace:: :abbr:`constructor (This method is used to construct a type.)`
  226. .. |static| replace:: :abbr:`static (This method doesn't need an instance to be called, so it can be called directly using the class name.)`
  227. .. |operator| replace:: :abbr:`operator (This method describes a valid operator to use with this type as left-hand operand.)`