From 45c004cde3d76a8cdfe438ba7a2ad20a952c6aa6 Mon Sep 17 00:00:00 2001 From: Remi Rampin Date: Sat, 12 Oct 2019 18:44:42 -0400 Subject: [PATCH] Add babel-godot, Python tool to i18n strings --- tutorials/i18n/localization_using_gettext.rst | 39 ++++++++++++++++++- 1 file changed, 37 insertions(+), 2 deletions(-) diff --git a/tutorials/i18n/localization_using_gettext.rst b/tutorials/i18n/localization_using_gettext.rst index 126599af8..f6cd26bf5 100644 --- a/tutorials/i18n/localization_using_gettext.rst +++ b/tutorials/i18n/localization_using_gettext.rst @@ -58,8 +58,8 @@ install them. - **Linux:** On most distributions, install the ``gettext`` package from your distribution's package manager. -Creating the PO template ------------------------- +Creating the PO template (POT) manually +--------------------------------------- Godot currently doesn't support extracting source strings using ``xgettext``, so the ``.pot`` file must be created manually. This file can be placed anywhere @@ -85,6 +85,41 @@ the translated string. The ``msgstr`` value in PO template files (``.pot``) should **always** be empty. Localization will be done in the generated ``.po`` files instead. +Creating the PO template (POT) using pybabel +-------------------------------------------- + +The Python tool pybabel has support for Godot and can be used to automatically +create and update the POT file from your scene files and scripts. + +After installing ``babel`` and ``babel-godot``, for example using pip: + +:: + + pip install babel babel-godot + +Write a mapping file (for example ``babelrc``) which will indicate which files +pybabel needs to process (note that we process GDScript as Python, which is +generally sufficient): + +:: + + [python: **.gd] + encoding = utf-8 + + [godot_scene: **.tscn] + encoding = utf-8 + +You can then run pybabel like so: + +:: + + pybabel extract -F babelrc -k text -k LineEdit/placeholder_text -k tr -o godot-l10n.pot . + +Use the ``-k`` option to specify what needs to be extracted. In this case, +arguments to :ref:`tr() ` will be translated, as well +as properties named "text" (commonly used by Control nodes) and LineEdit's +"placeholder_text" property. + Creating a messages file from a PO template -------------------------------------------