localization_using_spreadsheets.rst 6.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154
  1. .. _doc_localization_using_spreadsheets:
  2. Localization using spreadsheets
  3. ===============================
  4. Spreadsheets are one of the most common formats for localizing games.
  5. In Godot, spreadsheets are supported through the CSV format. This
  6. guide explains how to work with CSVs.
  7. The CSV files **must** be saved with UTF-8 encoding
  8. without a `byte order mark <https://en.wikipedia.org/wiki/Byte_order_mark>`__.
  9. .. warning::
  10. By default, Microsoft Excel will always save CSV files with ANSI encoding
  11. rather than UTF-8. There is no built-in way to do this, but there are
  12. workarounds as described
  13. `here <https://stackoverflow.com/questions/4221176/excel-to-csv-with-utf8-encoding>`__.
  14. We recommend using `LibreOffice <https://www.libreoffice.org/>`__ or Google Sheets instead.
  15. Formatting
  16. ----------
  17. CSV files must be formatted as follows:
  18. +--------+----------+----------+----------+
  19. | keys | <lang1> | <lang2> | <langN> |
  20. +========+==========+==========+==========+
  21. | KEY1 | string | string | string |
  22. +--------+----------+----------+----------+
  23. | KEY2 | string | string | string |
  24. +--------+----------+----------+----------+
  25. | KEYN | string | string | string |
  26. +--------+----------+----------+----------+
  27. The "lang" tags must represent a language, which must be one of the :ref:`valid
  28. locales <doc_locales>` supported by the engine, or they must start with an underscore (``_``),
  29. which means the related column is served as comment and won't be imported.
  30. The ``KEY`` tags must be unique and represent a string universally. By convention, these are
  31. usually in uppercase to differentiate them from other strings. These keys will be replaced at
  32. runtime by the matching translated string. Note that the case is important:
  33. ``KEY1`` and ``Key1`` will be different keys.
  34. The top-left cell is ignored and can be left empty or having any content.
  35. Here's an example:
  36. +-------+-----------------------+------------------------+------------------------------+
  37. | keys | en | es | ja |
  38. +=======+=======================+========================+==============================+
  39. | GREET | Hello, friend! | Hola, amigo! | こんにちは |
  40. +-------+-----------------------+------------------------+------------------------------+
  41. | ASK | How are you? | Cómo está? | 元気ですか |
  42. +-------+-----------------------+------------------------+------------------------------+
  43. | BYE | Goodbye | Adiós | さようなら |
  44. +-------+-----------------------+------------------------+------------------------------+
  45. | QUOTE | "Hello" said the man. | "Hola" dijo el hombre. | 「こんにちは」男は言いました |
  46. +-------+-----------------------+------------------------+------------------------------+
  47. The same example is shown below as a comma-separated plain text file,
  48. which should be the result of editing the above in a spreadsheet.
  49. When editing the plain text version, be sure to enclose with double
  50. quotes any message that contains commas, line breaks or double quotes,
  51. so that commas are not parsed as delimiters, line breaks don't create new
  52. entries and double quotes are not parsed as enclosing characters. Be sure
  53. to escape any double quotes a message may contain by preceding them with
  54. another double quote. Alternatively, you can select another delimiter than
  55. comma in the import options.
  56. .. code-block:: none
  57. keys,en,es,ja
  58. GREET,"Hello, friend!","Hola, amigo!",こんにちは
  59. ASK,How are you?,Cómo está?,元気ですか
  60. BYE,Goodbye,Adiós,さようなら
  61. QUOTE,"""Hello"" said the man.","""Hola"" dijo el hombre.",「こんにちは」男は言いました
  62. Specifying plural forms
  63. ~~~~~~~~~~~~~~~~~~~~~~~
  64. Since Godot 4.6, it is possible to specify
  65. :ref:`plural forms <doc_internationalizing_games_pluralization>` in CSV files.
  66. This is done by adding a column named ``?plural`` anywhere in the table
  67. (except on the first column, which is reserved for translation keys).
  68. By convention, it's recommended to place it on the second column.
  69. Note that in the example below, the key column is the one that contains English
  70. localization.
  71. .. code-block:: none
  72. en,?plural,fr,ru,ja,zh
  73. ?pluralrule,,nplurals=2; plural=(n >= 2);,,
  74. There is %d apple,There are %d apples,Il y a %d pomme,Есть %d яблоко,リンゴが%d個あります,那里有%d个苹果
  75. ,,Il y a %d pommes,Есть %d яблока,,
  76. ,,,Есть %d яблок,,
  77. .. note::
  78. Automatic Control translation is not supported when using plural forms. You must
  79. translate the string manually using :ref:`tr_n()<class_Object_method_tr_n>`.
  80. Specifying translation contexts
  81. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  82. Since Godot 4.6, it is possible to specify
  83. :ref:`translation contexts <doc_internationalizing_games_translation_contexts>`
  84. in CSV files. This can be used to disambiguate identical source strings that
  85. have different meanings. While this is generally not needed when using translation
  86. keys ``LIKE_THIS``, it's useful when using plain English text as translation keys.
  87. This is done by adding a column named ``?context`` column anywhere in the table
  88. (except on the first column, which is reserved for translation keys).
  89. By convention, it's recommended to place it on the second column, or after
  90. ``?plural`` if it's also used. Note that in the example below, the key column
  91. is the one that contains English localization.
  92. .. code-block:: none
  93. en,?context,fr,ru,ja,zh
  94. Letter,Alphabet,Lettre,Буква,字母,字母
  95. Letter,Message,Courrier,Письмо,手紙,信件
  96. .. note::
  97. Automatic Control translation is not supported when using context. You must
  98. translate the string manually using :ref:`tr() <class_Object_method_tr>`
  99. or :ref:`tr_n() <class_Object_method_tr_n>`.
  100. CSV importer
  101. ------------
  102. Godot will treat CSV files as translations by default. It will import them
  103. and generate one or more compressed translation resource files next to it.
  104. Importing will also add the translation to the list of
  105. translations to load when the game runs, specified in project.godot (or the
  106. project settings). Godot allows loading and removing translations at
  107. runtime as well.
  108. Select the ``.csv`` file and access the **Import** dock to define import
  109. options. You can toggle the compression of the imported translations, and
  110. select the delimiter to use when parsing the CSV file.
  111. .. image:: img/import_csv.webp
  112. Be sure to click **Reimport** after any change to these options.
  113. Loading the CSV file as a translation
  114. -------------------------------------
  115. Once a CSV file is imported, it is **not** automatically registered as a translation
  116. source for the project. Remember to follow the steps described in
  117. :ref:`doc_internationalizing_games_configuring_imported_translation` so that the
  118. translation is actually used when running the project.