When properly installed, Babel provides a script called ``pybabel``::
- $ pybabel --help
+ $ pybabel --help
usage: pybabel command [options] [args]
options:
binary MO files::
$ pybabel compile --help
- usage: pybabel compile [options]
+ usage: pybabel compile [options]
compile message catalogs to MO files
template file::
$ pybabel init --help
- usage: pybabel init [options]
+ usage: pybabel init [options]
create new message catalogs from a POT file
a PO template file::
$ pybabel update --help
- usage: pybabel update [options]
+ usage: pybabel update [options]
update existing message catalogs from a POT file
.. code-block:: ini
# Extraction from Python source files
-
+
[python: **.py]
-
+
# Extraction from Genshi HTML and text templates
-
+
[genshi: **/templates/**.html]
ignore_tags = script,style
include_attrs = alt title summary
-
+
[genshi: **/templates/**.txt]
template_class = genshi.template:TextTemplate
encoding = ISO-8819-15
for comments. Empty lines are ignored, too.
.. note:: if you're performing message extraction using the command Babel
- provides for integration into ``setup.py`` scripts, you can also
- provide this configuration in a different way, namely as a keyword
- argument to the ``setup()`` function. See `Distutils/Setuptools
+ provides for integration into ``setup.py`` scripts, you can also
+ provide this configuration in a different way, namely as a keyword
+ argument to the ``setup()`` function. See `Distutils/Setuptools
Integration`_ for more information.
.. _`distutils/setuptools integration`: setup.html
Default Extraction Methods
--------------------------
-Babel comes with a few builtin extractors: ``python`` (which extracts
+Babel comes with a few builtin extractors: ``python`` (which extracts
messages from Python source files), ``javascript``, and ``ignore`` (which
extracts nothing).
The ``python`` extractor is by default mapped to the glob pattern ``**.py``,
-meaning it'll be applied to all files with the ``.py`` extension in any
+meaning it'll be applied to all files with the ``.py`` extension in any
directory. If you specify your own mapping configuration, this default mapping
is discarded, so you need to explicitly add it to your mapping (as shown in the
example above.)
Referencing Extraction Methods
------------------------------
-To be able to use short extraction method names such as “genshi”, you need to
+To be able to use short extraction method names such as “genshi”, you need to
have `pkg_resources`_ installed, and the package implementing that extraction
method needs to have been installed with its meta data (the `egg-info`_).
-If this is not possible for some reason, you need to map the short names to
-fully qualified function names in an extract section in the mapping
+If this is not possible for some reason, you need to map the short names to
+fully qualified function names in an extract section in the mapping
configuration. For example:
.. code-block:: ini
# Some custom extraction method
-
+
[extractors]
custom = mypackage.module:extract_custom
-
+
[custom: **.ctm]
some_option = foo
def extract_xxx(fileobj, keywords, comment_tags, options):
"""Extract messages from XXX files.
-
+
:param fileobj: the file-like object the messages should be extracted
from
:param keywords: a list of keywords (i.e. function names) that should
from distutils.core import setup
from babel.messages import frontend as babel
-
+
setup(
...
cmdclass = {'compile_catalog': babel.compile_catalog,
--quiet (-q) run quietly (turns verbosity off)
--dry-run (-n) don't actually do anything
--help (-h) show detailed help message
-
+
Options for 'compile_catalog' command:
...
--quiet (-q) run quietly (turns verbosity off)
--dry-run (-n) don't actually do anything
--help (-h) show detailed help message
-
+
Options for 'extract_messages' command:
...
.. code-block:: python
setup(...
-
+
message_extractors = {
'foobar': [
('**.py', 'python', None),
})
],
},
-
+
...
)