Skip to content

Commit 91b4f4f

Browse files
committed
Clarify how to define a context-sensitive string in Localization using gettext
1 parent 4bb75ac commit 91b4f4f

File tree

1 file changed

+21
-7
lines changed

1 file changed

+21
-7
lines changed

tutorials/i18n/localization_using_gettext.rst

Lines changed: 21 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ Advantages
2121
- gettext is a standard format, which can be edited using any text editor
2222
or GUI editors such as `Poedit <https://poedit.net/>`_. This can be significant
2323
as it provides a lot of tools for translators, such as marking outdated
24-
strings, finding strings that haven't been translated etc.
24+
strings, finding strings that haven't been translated etc.
2525
- gettext supports plurals and context.
2626
- gettext is supported by translation platforms such as
2727
`Transifex <https://www.transifex.com/>`_ and `Weblate <https://weblate.org/>`_,
@@ -39,8 +39,8 @@ Disadvantages
3939
- People who maintain localization files will have to install gettext tools
4040
on their system. However, as Godot supports using text-based message files
4141
(``.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
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
4444
languages as the base language, but this is not common.
4545

4646
Installing gettext tools
@@ -286,7 +286,7 @@ Using context
286286
The ``context`` parameter can be used to differentiate the situation where a translation
287287
is used, or to differentiate polysemic words (words with multiple meanings).
288288

289-
For example:
289+
For example:
290290

291291
::
292292

@@ -295,13 +295,27 @@ For example:
295295
tr("Shop", "Main Menu")
296296
tr("Shop", "In Game")
297297

298+
In a gettext PO file, a string with a context can be defined as follows:
299+
300+
::
301+
302+
# Example of a string with a translation context.
303+
msgctxt "Main Menu"
304+
msgid "Shop"
305+
msgstr ""
306+
307+
# A different source string that is identical, but with a different context.
308+
msgctxt "In Game"
309+
msgid "Shop"
310+
msgstr ""
311+
298312
Updating PO files
299313
-----------------
300314

301315
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
302316
need to update the existing PO files to include the new strings.
303317

304-
First, generate a new POT file containing all the existing strings plus the newly added strings. After that, merge the existing
318+
First, generate a new POT file containing all the existing strings plus the newly added strings. After that, merge the existing
305319
PO files with the new POT file. There are two ways to do this:
306320

307321
- Use a gettext editor, and it should have an option to update a PO file from a POT file.
@@ -313,12 +327,12 @@ PO files with the new POT file. There are two ways to do this:
313327
# The order matters: specify the message file *then* the PO template!
314328
msgmerge --update --backup=none fr.po messages.pot
315329
316-
If you want to keep a backup of the original message file (which would be saved as ``fr.po~`` in this example),
330+
If you want to keep a backup of the original message file (which would be saved as ``fr.po~`` in this example),
317331
remove the ``--backup=none`` argument.
318332

319333
POT generation custom plugin
320334
----------------------------
321335

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.
336+
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.
323337
This custom plugin will extract the strings and write into the POT file when you hit **Generate POT**. To learn more about how to
324338
create the translation parser plugin, see :ref:`EditorTranslationParserPlugin <class_EditorTranslationParserPlugin>`.

0 commit comments

Comments
 (0)