Skip to content

Commit 51c4208

Browse files
authored
Merge pull request #10342 from dalexeev/pot-gen-doc-gdscript-comments
POT Generator: Document `TRANSLATORS:` and `NO_TRANSLATE` comments
2 parents e26f77c + 17c8c22 commit 51c4208

File tree

1 file changed

+39
-0
lines changed

1 file changed

+39
-0
lines changed

tutorials/i18n/localization_using_gettext.rst

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,9 @@ top-right corner, then specify the path to the output file. This file can be
7878
placed anywhere in the project directory, but it's recommended to keep it in a
7979
subdirectory such as ``locale``, as each locale will be defined in its own file.
8080

81+
See :ref:`below <doc_localization_using_gettext_gdscript>` for how to add comments for translators
82+
or exclude some strings from being added to the PO template for GDScript files.
83+
8184
You can then move over to
8285
:ref:`creating a messages file from a PO template <doc_localization_using_gettext_messages_file>`.
8386

@@ -226,3 +229,39 @@ wish to decompile an MO file into a text-based PO file, you can do so with:
226229
227230
The decompiled file will not include comments or fuzzy strings, as these are
228231
never compiled in the MO file in the first place.
232+
233+
.. _doc_localization_using_gettext_gdscript:
234+
235+
Extracting localizable strings from GDScript files
236+
--------------------------------------------------
237+
238+
The built-in `editor plugin <https://github.com/godotengine/godot/blob/master/modules/gdscript/editor/gdscript_translation_parser_plugin.h>`_
239+
recognizes a variety of patterns in source code to extract localizable strings
240+
from GDScript files, including but not limited to the following:
241+
242+
- ``tr()``, ``tr_n()``, ``atr()``, and ``atr_n()`` calls;
243+
- assigning properties ``text``, ``placeholder_text``, and ``tooltip_text``;
244+
- ``add_tab()``, ``add_item()``, ``set_tab_title()``, and other calls;
245+
- ``FileDialog`` filters like ``"*.png ; PNG Images"``.
246+
247+
.. note::
248+
249+
The argument or right operand must be a constant string, otherwise the plugin
250+
will not be able to evaluate the expression and will ignore it.
251+
252+
If the plugin extracts unnecessary strings, you can ignore them with the ``NO_TRANSLATE`` comment.
253+
You can also provide additional information for translators using the ``TRANSLATORS:`` comment.
254+
These comments must be placed either on the same line as the recognized pattern or precede it.
255+
256+
::
257+
258+
$CharacterName.text = "???" # NO_TRANSLATE
259+
260+
# NO_TRANSLATE: Language name.
261+
$TabContainer.set_tab_title(0, "Python")
262+
263+
item.text = "Tool" # TRANSLATORS: Up to 10 characters.
264+
265+
# TRANSLATORS: This is a reference to Lewis Carroll's poem "Jabberwocky",
266+
# make sure to keep this as it is important to the plot.
267+
say(tr("He took his vorpal sword in hand. The end?"))

0 commit comments

Comments
 (0)