internationalizing_games.rst 9.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228
  1. .. _doc_internationalizing_games:
  2. Internationalizing games
  3. ========================
  4. Introduction
  5. ------------
  6. Sería excelente que el mundo hablara solo un idioma (It would be great if the
  7. world spoke only one language). Unfortunately for
  8. us developers, that is not the case. While indie or niche games usually
  9. do not need localization, games targeting a more massive market
  10. often require localization. Godot offers many tools to make this process
  11. more straightforward, so this tutorial is more like a collection of
  12. tips and tricks.
  13. Localization is usually done by specific studios hired for the job and,
  14. despite the huge amount of software and file formats available for this,
  15. the most common way to do localization to this day is still with
  16. spreadsheets. The process of creating the spreadsheets and importing
  17. them is already covered in the :ref:`doc_importing_translations` tutorial,
  18. so this one could be seen more like a follow-up to that one.
  19. .. note:: We will be using the official demo as an example; you can
  20. `download it from the Asset Library <https://godotengine.org/asset-library/asset/134>`_.
  21. Configuring the imported translation
  22. ------------------------------------
  23. Translations can get updated and re-imported when they change, but
  24. they still have to be added to the project. This is done in
  25. **Project → Project Settings → Localization**:
  26. .. image:: img/localization_dialog.png
  27. The above dialog is used to add or remove translations project-wide.
  28. Localizing resources
  29. --------------------
  30. It is also possible to instruct Godot to use alternate versions of
  31. assets (resources) depending on the current language. This can be used for
  32. localized images such as in-game billboards or localized voices.
  33. The **Remaps** tab can be used for this:
  34. .. image:: img/localization_remaps.png
  35. Select the resource to be remapped then add some alternatives for each locale.
  36. .. note::
  37. The resource remapping system isn't supported for DynamicFonts. To use
  38. different fonts depending on the language's script, use the DynamicFont
  39. fallback system instead, which lets you define as many fallback fonts as you
  40. want.
  41. The upside of the DynamicFont fallback system is that it works regardless of
  42. the current language, making it ideal for things like multiplayer chat where
  43. the text language may not match the client's language.
  44. Converting keys to text
  45. -----------------------
  46. Some controls, such as :ref:`Button <class_Button>` and :ref:`Label <class_Label>`,
  47. will automatically fetch a translation if their text matches a translation key.
  48. For example, if a label's text is "MAIN_SCREEN_GREETING1" and that key exists
  49. in the current translation, then the text will automatically be translated.
  50. This automatic translation behavior may be undesirable in certain cases. For
  51. instance, when using a Label to display a player's name, you most likely don't
  52. want the player's name to be translated if it matches a translation key. To
  53. disable automatic translation on a specific node, use
  54. :ref:`Object.set_message_translation<class_Object_method_set_message_translation>`
  55. and send a :ref:`Object.notification<class_Object_method_notification>` to update the
  56. translation::
  57. func _ready():
  58. # This assumes you have a node called "Label" as a child of the node
  59. # that has the script attached.
  60. var label = get_node("Label")
  61. label.set_message_translation(false)
  62. label.notification(NOTIFICATION_TRANSLATION_CHANGED)
  63. For more complex UI nodes such as OptionButtons, you may have to use this instead::
  64. func _ready():
  65. var option_button = get_node("OptionButton")
  66. option_button.set_message_translation(false)
  67. option_button.notification(NOTIFICATION_TRANSLATION_CHANGED)
  68. option_button.get_popup().set_message_translation(false)
  69. option_button.get_popup().notification(NOTIFICATION_TRANSLATION_CHANGED)
  70. In code, the :ref:`Object.tr() <class_Object_method_tr>`
  71. function can be used. This will just look up the text in the
  72. translations and convert it if found:
  73. ::
  74. level.set_text(tr("LEVEL_5_NAME"))
  75. status.set_text(tr("GAME_STATUS_" + str(status_index)))
  76. .. note::
  77. If no text is displayed after changing the language, try to use a different
  78. font. The default project font only supports a subset of the Latin-1 character set,
  79. which cannot be used to display languages like Russian or Chinese.
  80. A good resource for multilingual fonts is `Noto Fonts <https://www.google.com/get/noto/>`__.
  81. Make sure to download the correct variation if you're using a less common
  82. language.
  83. Once you've downloaded the font, load the TTF file into a DynamicFont
  84. resource and use it as a custom font of your Control node. For better
  85. reusability, associate a new a Theme resource to your root Control node and
  86. define the DynamicFont as the Default Font in the theme.
  87. Making controls resizable
  88. --------------------------
  89. The same text in different languages can vary greatly in length. For
  90. this, make sure to read the tutorial on :ref:`doc_size_and_anchors`, as
  91. dynamically adjusting control sizes may help.
  92. :ref:`Container <class_Container>` can be useful, as well as the text wrapping
  93. options available in :ref:`Label <class_Label>`.
  94. TranslationServer
  95. -----------------
  96. Godot has a server handling low-level translation management
  97. called the :ref:`TranslationServer <class_TranslationServer>`.
  98. Translations can be added or removed during run-time;
  99. the current language can also be changed at run-time.
  100. Bidirectional text and UI Mirroring
  101. -----------------------------------
  102. Arabic and Hebrew are written from right to left (except for the numbers and Latin
  103. words mixed in), and the user interface for these languages should be mirrored as well.
  104. In some languages the shape of a glyph changes depending on the surrounding characters.
  105. Support for bidirectional writing systems and UI mirroring is transparent, you don't
  106. usually need to change anything or have any knowledge of the specific writing system.
  107. For RTL languages, Godot will automatically do the following changes to the UI:
  108. - Mirrors left/right anchors and margins.
  109. - Swaps left and right text alignment.
  110. - Mirrors horizontal order of the child controls in the containers, and items in Tree/ItemList controls.
  111. - Uses mirrored order of the internal control elements (e.g. OptionButton dropdown button, checkbox alignment, List column order, Tree item icons and connecting line alignment, e.t.c.), in some cases mirrored controls use separate theme styles.
  112. - Coordinate system is not mirrored, and non-UI nodes (sprites, e.t.c) are not affected.x
  113. It is possible to override text and control layout direction by using the following control properties:
  114. - ``text_direction``, sets the base text direction. When set to "auto", direction depends on the first strong directional character in the text according to the Unicode Bidirectional Algorithm,
  115. - ``language``, overrides current project locale.
  116. - ``structured_text_bidi_override property`` and ``_structured_text_parser callback``, enables special handling for structured text.
  117. - ``layout_direction``, overrides control mirroring.
  118. .. image:: img/ui_mirror.png
  119. Adding break iterator data to exported project
  120. ----------------------------------------------
  121. Some languages are written without spaces, and word and line breaking requires more than rules over character sequences.
  122. Godot includes ICU rule and dictionary based, break iterator data, but this data is not included into exported projects by default.
  123. To include it go to **Project → Project Settings → Localization → Text Server Data** and click **Install support data...**. Break iterator data is about 4 MB large.
  124. .. image:: img/icu_data.png
  125. Structured text BiDi override
  126. -----------------------------
  127. Unicode BiDi algorithm is designed to work with natural text and it's incapable of
  128. handling text with the higher level order, like file names, URIs, email addresses,
  129. regular expressions or source code.
  130. .. image:: img/bidi_override.png
  131. For example, the path for this shown directory structure will be displayed incorrectly
  132. (top "LineEdit" control). "File" type structured text override splits text into segments,
  133. then BiDi algorithm is applied to each of them individually to correctly display directory
  134. names in any language and preserve correct order of the folders (bottom "LineEdit" control).
  135. Custom callbacks provide a way to override BiDi for the other types of structured text.
  136. Localizing numbers
  137. ------------------
  138. Controls specifically designed for number input or output (e.g. ProgressBar, SpinBox)
  139. will use localized numbering system automatically, for the other control
  140. :ref:`TextServer.format_number(string, language) <class_TextServer_method_format_number>`
  141. can be used to convert Western Arabic numbers (0..9) to the localized numbering system
  142. and :ref:`TextServer.parse_number(string, language) <class_TextServer_method_parse_number>`
  143. to convert it back.
  144. Localizing icons and images
  145. ---------------------------
  146. Icons with left and right pointing arrows which may need to be reversed for Arabic
  147. and Hebrew locales, in case they indicate movement or direction (e.g. back/forward
  148. buttons), otherwise they can remain the same.
  149. Command line
  150. ------------
  151. Language can be tested when running Godot from the command line.
  152. For example, to test a game in French, the following argument can be
  153. supplied:
  154. .. code-block:: shell
  155. godot --language fr
  156. Translating the project name
  157. ----------------------------
  158. The project name becomes the app name when exporting to different
  159. operating systems and platforms. To specify the project name in more
  160. than one language, create a new setting ``application/name`` in the **Project
  161. Settings** and append the locale identifier to it.
  162. For instance, for Spanish, this would be ``application/name_es``:
  163. .. image:: img/localized_name.png
  164. If you are unsure about the language code to use, refer to the
  165. :ref:`list of locale codes <doc_locales>`.