internationalizing_games.rst 4.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132
  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. The **Remaps** tab
  32. can be used for this:
  33. .. image:: img/localization_remaps.png
  34. Select the resource to be remapped, then add some alternatives for each
  35. locale.
  36. Converting keys to text
  37. -----------------------
  38. Some controls, such as :ref:`Button <class_Button>` and :ref:`Label <class_Label>`,
  39. will automatically fetch a translation if their text matches a translation key.
  40. For example, if a label's text is "MAIN_SCREEN_GREETING1" and that key exists
  41. in the current translation, then the text will automatically be translated.
  42. This automatic translation behavior may be undesirable in certain cases. For
  43. instance, when using a Label to display a player's name, you most likely don't
  44. want the player's name to be translated if it matches a translation key. To
  45. disable automatic translation on a specific node, use
  46. :ref:`Object.set_message_translation<class_Object_method_set_message_translation>`
  47. and send a :ref:`Object.notification<class_Object_method_notification>` to update the
  48. translation::
  49. func _ready():
  50. # This assumes you have a node called "Label" as a child of the node
  51. # that has the script attached.
  52. var label = get_node("Label")
  53. label.set_message_translation(false)
  54. label.notification(NOTIFICATION_TRANSLATION_CHANGED)
  55. For more complex UI nodes such as OptionButtons, you may have to use this instead::
  56. func _ready():
  57. var option_button = get_node("OptionButton")
  58. option_button.set_message_translation(false)
  59. option_button.notification(NOTIFICATION_TRANSLATION_CHANGED)
  60. option_button.get_popup().set_message_translation(false)
  61. option_button.get_popup().notification(NOTIFICATION_TRANSLATION_CHANGED)
  62. In code, the :ref:`Object.tr() <class_Object_method_tr>`
  63. function can be used. This will just look up the text in the
  64. translations and convert it if found:
  65. ::
  66. level.set_text(tr("LEVEL_5_NAME"))
  67. status.set_text(tr("GAME_STATUS_" + str(status_index)))
  68. Making controls resizable
  69. --------------------------
  70. The same text in different languages can vary greatly in length. For
  71. this, make sure to read the tutorial on :ref:`doc_size_and_anchors`, as
  72. dynamically adjusting control sizes may help.
  73. :ref:`Container <class_Container>` can be useful, as well as the text wrapping
  74. options available in :ref:`Label <class_Label>`.
  75. TranslationServer
  76. -----------------
  77. Godot has a server handling low-level translation management
  78. called the :ref:`TranslationServer <class_TranslationServer>`.
  79. Translations can be added or removed during run-time;
  80. the current language can also be changed at run-time.
  81. Command line
  82. ------------
  83. Language can be tested when running Godot from the command line.
  84. For example, to test a game in French, the following argument can be
  85. supplied:
  86. .. code-block:: shell
  87. godot --language fr
  88. Translating the project name
  89. ----------------------------
  90. The project name becomes the app name when exporting to different
  91. operating systems and platforms. To specify the project name in more
  92. than one language, create a new setting ``application/name`` in the **Project
  93. Settings** and append the locale identifier to it.
  94. For instance, for Spanish, this would be ``application/name_es``:
  95. .. image:: img/localized_name.png
  96. If you are unsure about the language code to use, refer to the
  97. :ref:`list of locale codes <doc_locales>`.