importing_translations.rst 5.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116
  1. .. _doc_importing_translations:
  2. Importing translations
  3. ======================
  4. Games and internationalization
  5. ------------------------------
  6. The gaming community isn't monolingual or monocultural. It's made up of
  7. many different languages and cultures - just like the Godot community!
  8. If you want to allow players to experience your game in their language,
  9. one of things you'll need to provide is text translations, which Godot
  10. supports via internationalized text.
  11. In regular desktop or mobile applications, internationalized text is
  12. usually located in resource files (or .po files for GNU stuff). Games,
  13. however, can use several orders of magnitude more text than
  14. applications, so they must support efficient methods for dealing with
  15. loads of multilingual text.
  16. There are two approaches to generate multilingual language games and
  17. applications. Both are based on a key:value system. The first is to use
  18. one of the languages as the key (usually English), the second is to use a
  19. specific identifier. The first approach is probably easier for
  20. development if a game is released first in English, later in other
  21. languages, but a complete nightmare if working with many languages at
  22. the same time.
  23. In general, games use the second approach and a unique ID is used for
  24. each string. This allows you to revise the text while it is being
  25. translated to other languages. The unique ID can be a number, a string,
  26. or a string with a number (it's just a unique string anyway).
  27. .. note:: If you need a more powerful file format, Godot also supports
  28. loading translations written in the gettext ``.po`` format. See
  29. :ref:`doc_localization_using_gettext` for details.
  30. Translation format
  31. ------------------
  32. To complete the picture and allow efficient support for translations,
  33. Godot has a special importer that can read CSV files. Most spreadsheet
  34. editors can export to this format, so the only requirement is that the files
  35. have a special arrangement. The CSV files **must** be saved with UTF-8 encoding
  36. without a `byte order mark <https://en.wikipedia.org/wiki/Byte_order_mark>`__.
  37. CSV files must be formatted as follows:
  38. +--------+----------+----------+----------+
  39. | keys | <lang1> | <lang2> | <langN> |
  40. +========+==========+==========+==========+
  41. | KEY1 | string | string | string |
  42. +--------+----------+----------+----------+
  43. | KEY2 | string | string | string |
  44. +--------+----------+----------+----------+
  45. | KEYN | string | string | string |
  46. +--------+----------+----------+----------+
  47. The "lang" tags must represent a language, which must be one of the :ref:`valid
  48. locales <doc_locales>` supported by the engine. The "KEY" tags must be
  49. unique and represent a string universally (they are usually in
  50. uppercase, to differentiate from other strings). These keys will be replaced at
  51. runtime by the matching translated string. Note that the case is important,
  52. "KEY1" and "Key1" will be different keys.
  53. The top-left cell is ignored and can be left empty or having any content.
  54. Here's an example:
  55. +-------+-----------------------+------------------------+------------------------------+
  56. | keys | en | es | ja |
  57. +=======+=======================+========================+==============================+
  58. | GREET | Hello, friend! | Hola, amigo! | こんにちは |
  59. +-------+-----------------------+------------------------+------------------------------+
  60. | ASK | How are you? | Cómo está? | 元気ですか |
  61. +-------+-----------------------+------------------------+------------------------------+
  62. | BYE | Goodbye | Adiós | さようなら |
  63. +-------+-----------------------+------------------------+------------------------------+
  64. | QUOTE | "Hello" said the man. | "Hola" dijo el hombre. | 「こんにちは」男は言いました |
  65. +-------+-----------------------+------------------------+------------------------------+
  66. The same example is shown below as a comma-separated plain text file,
  67. which should be the result of editing the above in a spreadsheet.
  68. When editing the plain text version, be sure to enclose with double
  69. quotes any message that contains commas, line breaks or double quotes,
  70. so that commas are not parsed as delimiters, line breaks don't create new
  71. entries and double quotes are not parsed as enclosing characters. Be sure
  72. to escape any double quotes a message may contain by preceding them with
  73. another double quote. Alternatively, you can select another delimiter than
  74. comma in the import options.
  75. .. code-block:: none
  76. keys,en,es,ja
  77. GREET,"Hello, friend!","Hola, amigo!",こんにちは
  78. ASK,How are you?,Cómo está?,元気ですか
  79. BYE,Goodbye,Adiós,さようなら
  80. QUOTE,"""Hello"" said the man.","""Hola"" dijo el hombre.",「こんにちは」男は言いました
  81. CSV importer
  82. ------------
  83. Godot will treat CSV files as translations by default. It will import them
  84. and generate one or more compressed translation resource files next to it.
  85. Importing will also add the translation to the list of
  86. translations to load when the game runs, specified in project.godot (or the
  87. project settings). Godot allows loading and removing translations at
  88. runtime as well.
  89. Select the ``.csv`` file and access the **Import** dock to define import
  90. options. You can toggle the compression of the imported translations, and
  91. select the delimiter to use when parsing the CSV file.
  92. .. image:: img/import_csv.png
  93. Be sure to click **Reimport** after any change to these options.