class_translationserver.rst 21 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283
  1. :github_url: hide
  2. .. Generated automatically by doc/tools/make_rst.py in Godot's source tree.
  3. .. DO NOT EDIT THIS FILE, but the TranslationServer.xml source instead.
  4. .. The source is found in doc/classes or modules/<name>/doc_classes.
  5. .. _class_TranslationServer:
  6. TranslationServer
  7. =================
  8. **Inherits:** :ref:`Object<class_Object>`
  9. Server that manages all translations.
  10. Description
  11. -----------
  12. Server that manages all translations. Translations can be set to it and removed from it.
  13. Tutorials
  14. ---------
  15. - :doc:`Internationalizing games <../tutorials/i18n/internationalizing_games>`
  16. - :doc:`Locales <../tutorials/i18n/locales>`
  17. Properties
  18. ----------
  19. +-------------------------+------------------------------------------------------------------------------------------------+-----------+
  20. | :ref:`bool<class_bool>` | :ref:`pseudolocalization_enabled<class_TranslationServer_property_pseudolocalization_enabled>` | ``false`` |
  21. +-------------------------+------------------------------------------------------------------------------------------------+-----------+
  22. Methods
  23. -------
  24. +---------------------------------------------------+-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  25. | void | :ref:`add_translation<class_TranslationServer_method_add_translation>` **(** :ref:`Translation<class_Translation>` translation **)** |
  26. +---------------------------------------------------+-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  27. | void | :ref:`clear<class_TranslationServer_method_clear>` **(** **)** |
  28. +---------------------------------------------------+-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  29. | :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| |
  30. +---------------------------------------------------+-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  31. | :ref:`PackedStringArray<class_PackedStringArray>` | :ref:`get_all_countries<class_TranslationServer_method_get_all_countries>` **(** **)** |const| |
  32. +---------------------------------------------------+-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  33. | :ref:`PackedStringArray<class_PackedStringArray>` | :ref:`get_all_languages<class_TranslationServer_method_get_all_languages>` **(** **)** |const| |
  34. +---------------------------------------------------+-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  35. | :ref:`PackedStringArray<class_PackedStringArray>` | :ref:`get_all_scripts<class_TranslationServer_method_get_all_scripts>` **(** **)** |const| |
  36. +---------------------------------------------------+-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  37. | :ref:`String<class_String>` | :ref:`get_country_name<class_TranslationServer_method_get_country_name>` **(** :ref:`String<class_String>` country **)** |const| |
  38. +---------------------------------------------------+-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  39. | :ref:`String<class_String>` | :ref:`get_language_name<class_TranslationServer_method_get_language_name>` **(** :ref:`String<class_String>` language **)** |const| |
  40. +---------------------------------------------------+-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  41. | :ref:`Array<class_Array>` | :ref:`get_loaded_locales<class_TranslationServer_method_get_loaded_locales>` **(** **)** |const| |
  42. +---------------------------------------------------+-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  43. | :ref:`String<class_String>` | :ref:`get_locale<class_TranslationServer_method_get_locale>` **(** **)** |const| |
  44. +---------------------------------------------------+-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  45. | :ref:`String<class_String>` | :ref:`get_locale_name<class_TranslationServer_method_get_locale_name>` **(** :ref:`String<class_String>` locale **)** |const| |
  46. +---------------------------------------------------+-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  47. | :ref:`String<class_String>` | :ref:`get_script_name<class_TranslationServer_method_get_script_name>` **(** :ref:`String<class_String>` script **)** |const| |
  48. +---------------------------------------------------+-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  49. | :ref:`String<class_String>` | :ref:`get_tool_locale<class_TranslationServer_method_get_tool_locale>` **(** **)** |
  50. +---------------------------------------------------+-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  51. | :ref:`Translation<class_Translation>` | :ref:`get_translation_object<class_TranslationServer_method_get_translation_object>` **(** :ref:`String<class_String>` locale **)** |
  52. +---------------------------------------------------+-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  53. | :ref:`StringName<class_StringName>` | :ref:`pseudolocalize<class_TranslationServer_method_pseudolocalize>` **(** :ref:`StringName<class_StringName>` message **)** |const| |
  54. +---------------------------------------------------+-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  55. | void | :ref:`reload_pseudolocalization<class_TranslationServer_method_reload_pseudolocalization>` **(** **)** |
  56. +---------------------------------------------------+-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  57. | void | :ref:`remove_translation<class_TranslationServer_method_remove_translation>` **(** :ref:`Translation<class_Translation>` translation **)** |
  58. +---------------------------------------------------+-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  59. | void | :ref:`set_locale<class_TranslationServer_method_set_locale>` **(** :ref:`String<class_String>` locale **)** |
  60. +---------------------------------------------------+-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  61. | :ref:`String<class_String>` | :ref:`standardize_locale<class_TranslationServer_method_standardize_locale>` **(** :ref:`String<class_String>` locale **)** |const| |
  62. +---------------------------------------------------+-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  63. | :ref:`StringName<class_StringName>` | :ref:`translate<class_TranslationServer_method_translate>` **(** :ref:`StringName<class_StringName>` message, :ref:`StringName<class_StringName>` context="" **)** |const| |
  64. +---------------------------------------------------+-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  65. | :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| |
  66. +---------------------------------------------------+-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  67. Property Descriptions
  68. ---------------------
  69. .. _class_TranslationServer_property_pseudolocalization_enabled:
  70. - :ref:`bool<class_bool>` **pseudolocalization_enabled**
  71. +-----------+---------------------------------------+
  72. | *Default* | ``false`` |
  73. +-----------+---------------------------------------+
  74. | *Setter* | set_pseudolocalization_enabled(value) |
  75. +-----------+---------------------------------------+
  76. | *Getter* | is_pseudolocalization_enabled() |
  77. +-----------+---------------------------------------+
  78. If ``true``, enables the use of pseudolocalization. See :ref:`ProjectSettings.internationalization/pseudolocalization/use_pseudolocalization<class_ProjectSettings_property_internationalization/pseudolocalization/use_pseudolocalization>` for details.
  79. Method Descriptions
  80. -------------------
  81. .. _class_TranslationServer_method_add_translation:
  82. - void **add_translation** **(** :ref:`Translation<class_Translation>` translation **)**
  83. Adds a :ref:`Translation<class_Translation>` resource.
  84. ----
  85. .. _class_TranslationServer_method_clear:
  86. - void **clear** **(** **)**
  87. Clears the server from all translations.
  88. ----
  89. .. _class_TranslationServer_method_compare_locales:
  90. - :ref:`int<class_int>` **compare_locales** **(** :ref:`String<class_String>` locale_a, :ref:`String<class_String>` locale_b **)** |const|
  91. Compares two locales and return similarity score between ``0``\ (no match) and ``10``\ (full match).
  92. ----
  93. .. _class_TranslationServer_method_get_all_countries:
  94. - :ref:`PackedStringArray<class_PackedStringArray>` **get_all_countries** **(** **)** |const|
  95. Returns array of known country codes.
  96. ----
  97. .. _class_TranslationServer_method_get_all_languages:
  98. - :ref:`PackedStringArray<class_PackedStringArray>` **get_all_languages** **(** **)** |const|
  99. Returns array of known language codes.
  100. ----
  101. .. _class_TranslationServer_method_get_all_scripts:
  102. - :ref:`PackedStringArray<class_PackedStringArray>` **get_all_scripts** **(** **)** |const|
  103. Returns array of known script codes.
  104. ----
  105. .. _class_TranslationServer_method_get_country_name:
  106. - :ref:`String<class_String>` **get_country_name** **(** :ref:`String<class_String>` country **)** |const|
  107. Returns readable country name for the ``country`` code.
  108. ----
  109. .. _class_TranslationServer_method_get_language_name:
  110. - :ref:`String<class_String>` **get_language_name** **(** :ref:`String<class_String>` language **)** |const|
  111. Returns readable language name for the ``language`` code.
  112. ----
  113. .. _class_TranslationServer_method_get_loaded_locales:
  114. - :ref:`Array<class_Array>` **get_loaded_locales** **(** **)** |const|
  115. Returns an array of all loaded locales of the project.
  116. ----
  117. .. _class_TranslationServer_method_get_locale:
  118. - :ref:`String<class_String>` **get_locale** **(** **)** |const|
  119. Returns the current locale of the project.
  120. 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.
  121. ----
  122. .. _class_TranslationServer_method_get_locale_name:
  123. - :ref:`String<class_String>` **get_locale_name** **(** :ref:`String<class_String>` locale **)** |const|
  124. Returns a locale's language and its variant (e.g. ``"en_US"`` would return ``"English (United States)"``).
  125. ----
  126. .. _class_TranslationServer_method_get_script_name:
  127. - :ref:`String<class_String>` **get_script_name** **(** :ref:`String<class_String>` script **)** |const|
  128. Returns readable script name for the ``script`` code.
  129. ----
  130. .. _class_TranslationServer_method_get_tool_locale:
  131. - :ref:`String<class_String>` **get_tool_locale** **(** **)**
  132. Returns the current locale of the editor.
  133. \ **Note:** When called from an exported project returns the same value as :ref:`get_locale<class_TranslationServer_method_get_locale>`.
  134. ----
  135. .. _class_TranslationServer_method_get_translation_object:
  136. - :ref:`Translation<class_Translation>` **get_translation_object** **(** :ref:`String<class_String>` locale **)**
  137. Returns the :ref:`Translation<class_Translation>` instance based on the ``locale`` passed in.
  138. It will return ``null`` if there is no :ref:`Translation<class_Translation>` instance that matches the ``locale``.
  139. ----
  140. .. _class_TranslationServer_method_pseudolocalize:
  141. - :ref:`StringName<class_StringName>` **pseudolocalize** **(** :ref:`StringName<class_StringName>` message **)** |const|
  142. Returns the pseudolocalized string based on the ``p_message`` passed in.
  143. ----
  144. .. _class_TranslationServer_method_reload_pseudolocalization:
  145. - void **reload_pseudolocalization** **(** **)**
  146. Reparses the pseudolocalization options and reloads the translation.
  147. ----
  148. .. _class_TranslationServer_method_remove_translation:
  149. - void **remove_translation** **(** :ref:`Translation<class_Translation>` translation **)**
  150. Removes the given translation from the server.
  151. ----
  152. .. _class_TranslationServer_method_set_locale:
  153. - void **set_locale** **(** :ref:`String<class_String>` locale **)**
  154. 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``).
  155. If translations have been loaded beforehand for the new locale, they will be applied.
  156. ----
  157. .. _class_TranslationServer_method_standardize_locale:
  158. - :ref:`String<class_String>` **standardize_locale** **(** :ref:`String<class_String>` locale **)** |const|
  159. Returns ``locale`` string standardized to match known locales (e.g. ``en-US`` would be matched to ``en_US``).
  160. ----
  161. .. _class_TranslationServer_method_translate:
  162. - :ref:`StringName<class_StringName>` **translate** **(** :ref:`StringName<class_StringName>` message, :ref:`StringName<class_StringName>` context="" **)** |const|
  163. Returns the current locale's translation for the given message (key) and context.
  164. ----
  165. .. _class_TranslationServer_method_translate_plural:
  166. - :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|
  167. Returns the current locale's translation for the given message (key), plural_message and context.
  168. 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.
  169. .. |virtual| replace:: :abbr:`virtual (This method should typically be overridden by the user to have any effect.)`
  170. .. |const| replace:: :abbr:`const (This method has no side effects. It doesn't modify any of the instance's member variables.)`
  171. .. |vararg| replace:: :abbr:`vararg (This method accepts any number of arguments after the ones described here.)`
  172. .. |constructor| replace:: :abbr:`constructor (This method is used to construct a type.)`
  173. .. |static| replace:: :abbr:`static (This method doesn't need an instance to be called, so it can be called directly using the class name.)`
  174. .. |operator| replace:: :abbr:`operator (This method describes a valid operator to use with this type as left-hand operand.)`