internationalizing_games.rst 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107
  1. .. _doc_internationalizing_games:
  2. Internationalizing games
  3. ========================
  4. Introduction
  5. ------------
  6. *Sería excelente que el mundo hablara solo un idioma.* Unfortunately for
  7. us developers, that is not the case. While indie or niche games usually
  8. do not need localization, games targeting a more massive market
  9. often require localization. Godot offers many tools to make this process
  10. more straightforward, so this tutorial is more like a collection of
  11. tips and tricks.
  12. Localization is usually done by specific studios hired for the job and,
  13. despite the huge amount of software and file formats available for this,
  14. the most common way to do localization to this day is still with
  15. spreadsheets. The process of creating the spreadsheets and importing
  16. them is already covered in the :ref:`doc_importing_translations` tutorial,
  17. so this one could be seen more like a follow-up to that one.
  18. .. note:: We will be using the official demo as an example; you can
  19. `download it from the Asset Library <https://godotengine.org/asset-library/asset/134>`_.
  20. Configuring the imported translation
  21. ------------------------------------
  22. Translations can get updated and re-imported when they change, but
  23. they still have to be added to the project. This is done in
  24. **Project → Project Settings → Localization**:
  25. .. image:: img/localization_dialog.png
  26. The above dialog is used to add or remove translations project-wide.
  27. Localizing resources
  28. --------------------
  29. It is also possible to instruct Godot to use alternate versions of
  30. assets (resources) depending on the current language. The **Remaps** tab
  31. can be used for this:
  32. .. image:: img/localization_remaps.png
  33. Select the resource to be remapped, then add some alternatives for each
  34. locale.
  35. Converting keys to text
  36. -----------------------
  37. Some controls such as :ref:`Button <class_Button>` and :ref:`Label <class_Label>`
  38. will automatically fetch a translation if their text matches a translation key.
  39. For example, if a label's text is "MAIN_SCREEN_GREETING1" and that key exists
  40. in the current translation, then the text will be automatically translated.
  41. In code, the :ref:`Object.tr() <class_Object_tr>`
  42. function can be used. This will just look up the text in the
  43. translations and convert it if found:
  44. ::
  45. level.set_text(tr("LEVEL_5_NAME"))
  46. status.set_text(tr("GAME_STATUS_" + str(status_index)))
  47. Making controls resizable
  48. --------------------------
  49. The same text in different languages can vary greatly in length. For
  50. this, make sure to read the tutorial on :ref:`doc_size_and_anchors`, as
  51. dynamically adjusting control sizes may help.
  52. :ref:`Container <class_Container>` can be useful, as well as the text wrapping
  53. options available in :ref:`Label <class_Label>`.
  54. TranslationServer
  55. -----------------
  56. Godot has a server handling low-level translation management
  57. called the :ref:`TranslationServer <class_TranslationServer>`.
  58. Translations can be added or removed during run-time;
  59. the current language can also be changed at run-time.
  60. Command line
  61. ------------
  62. Language can be tested when running Godot from the command line.
  63. For example, to test a game in French, the following argument can be
  64. supplied:
  65. ::
  66. godot --language fr
  67. Translating the project name
  68. ----------------------------
  69. The project name becomes the app name when exporting to different
  70. operating systems and platforms. To specify the project name in more
  71. than one language, create a new setting ``application/name`` in the **Project
  72. Settings** and append the locale identifier to it.
  73. For instance, for Spanish, this would be ``application/name_es``:
  74. .. image:: img/localized_name.png
  75. If you are unsure about the language code to use, refer to the
  76. :ref:`list of locale codes <doc_locales>`.