importing_translations.rst 5.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117
  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, or they must start with an underscore (`_`),
  49. which means the related column is served as comment and won't be imported.
  50. The "KEY" tags must be unique and represent a string universally (they are usually in
  51. uppercase, to differentiate from other strings). These keys will be replaced at
  52. runtime by the matching translated string. Note that the case is important,
  53. "KEY1" and "Key1" will be different keys.
  54. The top-left cell is ignored and can be left empty or having any content.
  55. Here's an example:
  56. +-------+-----------------------+------------------------+------------------------------+
  57. | keys | en | es | ja |
  58. +=======+=======================+========================+==============================+
  59. | GREET | Hello, friend! | Hola, amigo! | こんにちは |
  60. +-------+-----------------------+------------------------+------------------------------+
  61. | ASK | How are you? | Cómo está? | 元気ですか |
  62. +-------+-----------------------+------------------------+------------------------------+
  63. | BYE | Goodbye | Adiós | さようなら |
  64. +-------+-----------------------+------------------------+------------------------------+
  65. | QUOTE | "Hello" said the man. | "Hola" dijo el hombre. | 「こんにちは」男は言いました |
  66. +-------+-----------------------+------------------------+------------------------------+
  67. The same example is shown below as a comma-separated plain text file,
  68. which should be the result of editing the above in a spreadsheet.
  69. When editing the plain text version, be sure to enclose with double
  70. quotes any message that contains commas, line breaks or double quotes,
  71. so that commas are not parsed as delimiters, line breaks don't create new
  72. entries and double quotes are not parsed as enclosing characters. Be sure
  73. to escape any double quotes a message may contain by preceding them with
  74. another double quote. Alternatively, you can select another delimiter than
  75. comma in the import options.
  76. .. code-block:: none
  77. keys,en,es,ja
  78. GREET,"Hello, friend!","Hola, amigo!",こんにちは
  79. ASK,How are you?,Cómo está?,元気ですか
  80. BYE,Goodbye,Adiós,さようなら
  81. QUOTE,"""Hello"" said the man.","""Hola"" dijo el hombre.",「こんにちは」男は言いました
  82. CSV importer
  83. ------------
  84. Godot will treat CSV files as translations by default. It will import them
  85. and generate one or more compressed translation resource files next to it.
  86. Importing will also add the translation to the list of
  87. translations to load when the game runs, specified in project.godot (or the
  88. project settings). Godot allows loading and removing translations at
  89. runtime as well.
  90. Select the ``.csv`` file and access the **Import** dock to define import
  91. options. You can toggle the compression of the imported translations, and
  92. select the delimiter to use when parsing the CSV file.
  93. .. image:: img/import_csv.png
  94. Be sure to click **Reimport** after any change to these options.