1
1
.. _doc_localization_using_gettext :
2
2
3
- Localization using gettext
4
- ==========================
3
+ Localization using gettext (PO files)
4
+ =====================================
5
5
6
6
In addition to importing translations in
7
7
:ref: `CSV format <doc_localization_using_spreadsheets >`, Godot also
@@ -13,27 +13,35 @@ supports loading translation files written in the GNU gettext format
13
13
It's written with C projects in mind, but much of the advice
14
14
also applies to Godot (with the exception of ``xgettext ``).
15
15
16
+ For the complete documentation, see `GNU Gettext <https://www.gnu.org/software/gettext/manual/gettext.html >`_.
17
+
16
18
Advantages
17
19
----------
18
20
19
21
- gettext is a standard format, which can be edited using any text editor
20
- or GUI editors such as `Poedit <https://poedit.net/ >`_.
22
+ or GUI editors such as `Poedit <https://poedit.net/ >`_. This can be significant
23
+ as it provides a lot of tools for translators, such as marking outdated
24
+ strings, finding strings that haven't been translated etc.
25
+ - gettext supports plurals and context.
21
26
- gettext is supported by translation platforms such as
22
27
`Transifex <https://www.transifex.com/ >`_ and `Weblate <https://weblate.org/ >`_,
23
28
which makes it easier for people to collaborate to localization.
24
- - Compared to CSV, gettext works better with version control systems like Git,
29
+ - Compared to CSV, gettext files work better with version control systems like Git,
25
30
as each locale has its own messages file.
26
- - Multiline strings are more convenient to edit in gettext files compared
31
+ - Multiline strings are more convenient to edit in gettext PO files compared
27
32
to CSV files.
28
33
29
34
Disadvantages
30
35
-------------
31
36
32
- - gettext is a more complex format than CSV and can be harder to grasp for
37
+ - gettext PO files have a more complex format than CSV and can be harder to grasp for
33
38
people new to software localization.
34
39
- People who maintain localization files will have to install gettext tools
35
40
on their system. However, as Godot supports using text-based message files
36
41
(``.po ``), translators can test their work without having to install gettext tools.
42
+ - gettext PO files usually use English as the base language. Translators will use
43
+ this base language to translate to other languages. You could still user other
44
+ languages as the base language, but this is not common.
37
45
38
46
Installing gettext tools
39
47
------------------------
@@ -53,6 +61,9 @@ install them.
53
61
- **Linux: ** On most distributions, install the ``gettext `` package from
54
62
your distribution's package manager.
55
63
64
+ For a GUI tool you can get Poedit from its `Official website <https://poedit.net/ >`_.
65
+ The basic version is open source and available under the MIT license.
66
+
56
67
Creating the PO template
57
68
------------------------
58
69
@@ -193,8 +204,10 @@ saved as ``fr.po~`` in this example), remove the ``--backup=none`` argument.
193
204
Checking the validity of a PO file or template
194
205
----------------------------------------------
195
206
196
- It is possible to check whether a gettext file's syntax is valid by running
197
- the command below:
207
+ It is possible to check whether a gettext file's syntax is valid.
208
+
209
+ If you open with Poeditor, it will display the appropriate warnings if there's some
210
+ syntax errors. You can also verify by running the gettext command below:
198
211
199
212
.. code-block :: shell
200
213
@@ -266,3 +279,46 @@ These comments must be placed either on the same line as the recognized pattern
266
279
# TRANSLATORS: This is a reference to Lewis Carroll's poem "Jabberwocky",
267
280
# make sure to keep this as it is important to the plot.
268
281
say(tr("He took his vorpal sword in hand. The end?"))
282
+
283
+ Using context
284
+ -------------
285
+
286
+ The ``context `` parameter can be used to differentiate the situation where a translation
287
+ is used, or to differentiate polysemic words (words with multiple meanings).
288
+
289
+ For example:
290
+
291
+ ::
292
+
293
+ tr("Start", "Main Menu")
294
+ tr("End", "Main Menu")
295
+ tr("Shop", "Main Menu")
296
+ tr("Shop", "In Game")
297
+
298
+ Updating PO files
299
+ -----------------
300
+
301
+ Some time or later, you'll add new content to our game, and there will be new strings that need to be translated. When this happens, you'll
302
+ need to update the existing PO files to include the new strings.
303
+
304
+ First, generate a new POT file containing all the existing strings plus the newly added strings. After that, merge the existing
305
+ PO files with the new POT file. There are two ways to do this:
306
+
307
+ - Use a gettext editor, and it should have an option to update a PO file from a POT file.
308
+
309
+ - Use the gettext ``msgmerge `` tool:
310
+
311
+ .. code-block :: shell
312
+
313
+ # The order matters: specify the message file *then* the PO template!
314
+ msgmerge --update --backup=none fr.po messages.pot
315
+
316
+ If you want to keep a backup of the original message file (which would be saved as ``fr.po~ `` in this example),
317
+ remove the ``--backup=none `` argument.
318
+
319
+ POT generation custom plugin
320
+ ----------------------------
321
+
322
+ If you have any extra file format to deal with, you could write a custom plugin to parse and and extract the strings from the custom file.
323
+ This custom plugin will extract the strings and write into the POT file when you hit **Generate POT **. To learn more about how to
324
+ create the translation parser plugin, see :ref: `EditorTranslationParserPlugin <class_EditorTranslationParserPlugin >`.
0 commit comments