Browse Source

Add babel-godot, Python tool to i18n strings

Remi Rampin 5 năm trước cách đây
mục cha
commit
45c004cde3
1 tập tin đã thay đổi với 37 bổ sung2 xóa
  1. 37 2
      tutorials/i18n/localization_using_gettext.rst

+ 37 - 2
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() <class_Object_method_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
 -------------------------------------------