cmlenz@4: .. -*- mode: rst; encoding: utf-8 -*- cmlenz@4: cmlenz@4: ================================ cmlenz@4: Distutils/Setuptools Integration cmlenz@4: ================================ cmlenz@4: cmlenz@4: Babel provides commands for integration into ``setup.py`` scripts, based on cmlenz@4: either the ``distutils`` package that is part of the Python standard library, cmlenz@4: or the third-party ``setuptools`` package. cmlenz@4: cmlenz@4: These commands are available by default when Babel has been properly installed, cmlenz@4: and ``setup.py`` is using ``setuptools``. For projects that use plain old cmlenz@42: ``distutils``, the commands need to be registered explicitly, for example: cmlenz@42: cmlenz@42: .. code-block:: python cmlenz@4: cmlenz@4: from distutils.core import setup cmlenz@56: from babel.messages import frontend as babel cmlenz@4: cmlenz@4: setup( cmlenz@4: ... cmlenz@4: cmd_class = {'extract_messages': babel.extract_messages} cmlenz@4: ) cmlenz@4: cmlenz@4: cmlenz@4: .. contents:: Contents cmlenz@4: :depth: 2 cmlenz@4: .. sectnum:: cmlenz@4: cmlenz@4: cmlenz@4: extract_messages cmlenz@4: ================ cmlenz@4: cmlenz@4: The ``extract_messages`` command is comparabe to the GNU ``xgettext`` program: cmlenz@4: it can extract localizable messages from a variety of difference source files, cmlenz@4: and generate a PO (portable object) template file from the collected messages. cmlenz@4: cmlenz@4: If the command has been correctly installed or registered, another project's cmlenz@4: ``setup.py`` script should allow you to use the command:: cmlenz@4: cmlenz@4: $ ./setup.py extract_messages --help cmlenz@4: Global options: cmlenz@4: --verbose (-v) run verbosely (default) cmlenz@4: --quiet (-q) run quietly (turns verbosity off) cmlenz@4: --dry-run (-n) don't actually do anything cmlenz@4: --help (-h) show detailed help message cmlenz@79: cmlenz@4: Options for 'extract_messages' command: cmlenz@51: --charset charset to use in the output file cmlenz@51: --keywords (-k) space-separated list of keywords to look for in cmlenz@51: addition to the defaults cmlenz@51: --no-default-keywords do not include the default keywords cmlenz@51: --mapping-file (-F) path to the mapping configuration file cmlenz@51: --no-location do not include location comments with filename and cmlenz@51: line number cmlenz@51: --omit-header do not include msgid "" entry in header cmlenz@51: --output-file (-o) name of the output file cmlenz@51: --width (-w) set output line width (default 76) cmlenz@51: --no-wrap do not break long message lines, longer than the cmlenz@51: output line width, into several lines cmlenz@79: --sort-output generate sorted output (default False) cmlenz@79: --sort-by-file sort output by file location (default False) palgarvio@80: --msgid-bugs-address set report address for msgid palgarvio@81: --copyright-holder set copyright holder in output cmlenz@64: --input-dirs directories that should be scanned for messages cmlenz@79: cmlenz@79: usage: setup.py [global_opts] cmd1 [cmd1_opts] [cmd2 [cmd2_opts] ...] cmlenz@79: or: setup.py --help [cmd1 cmd2 ...] cmlenz@79: or: setup.py --help-commands cmlenz@79: or: setup.py cmd --help cmlenz@4: palgarvio@53: Running the command will produce a PO template file:: cmlenz@4: cmlenz@51: $ ./setup.py extract_messages --output-file foobar/locale/messages.pot cmlenz@4: running extract_messages cmlenz@51: extracting messages from foobar/__init__.py cmlenz@51: extracting messages from foobar/core.py cmlenz@51: ... palgarvio@53: writing PO template file to foobar/locale/messages.pot cmlenz@51: cmlenz@51: cmlenz@51: Method Mapping cmlenz@51: -------------- cmlenz@51: cmlenz@51: The mapping of file patterns to extraction methods (and options) can be cmlenz@51: specified using a configuration file that is pointed to using the cmlenz@51: ``--mapping-file`` option shown above. Alternatively, you can configure the cmlenz@51: mapping directly in ``setup.py`` using a keyword argument to the ``setup()`` cmlenz@51: function: cmlenz@51: cmlenz@51: .. code-block:: python cmlenz@51: cmlenz@51: setup(... cmlenz@51: cmlenz@51: message_extractors = { cmlenz@64: 'foobar': [ cmlenz@64: ('**.py', ('python', None), cmlenz@64: ('**/templates/**.html', ('genshi', None), cmlenz@64: ('**/templates/**.txt', ('genshi', { cmlenz@64: 'template_class': 'genshi.template.text.TextTemplate' cmlenz@64: }) cmlenz@64: ], cmlenz@51: }, cmlenz@51: cmlenz@51: ... cmlenz@51: ) cmlenz@4: cmlenz@4: cmlenz@4: Options cmlenz@4: ------- cmlenz@4: cmlenz@4: As shown in the ``--help`` output above, the ``extract_messages`` command cmlenz@4: accepts the following options: cmlenz@4: cmlenz@51: +-----------------------------+----------------------------------------------+ cmlenz@51: | Option | Description | cmlenz@51: +=============================+==============================================+ cmlenz@51: | ``--charset`` | charset to use in the output file | cmlenz@51: +-----------------------------+----------------------------------------------+ cmlenz@51: | ``--keywords`` (``-k``) | space-separated list of keywords to look for | cmlenz@51: | | in addition to the defaults | cmlenz@51: +-----------------------------+----------------------------------------------+ cmlenz@51: | ``--no-default-keywords`` | do not include the default keywords | cmlenz@51: +-----------------------------+----------------------------------------------+ cmlenz@51: | ``--mapping-file`` (``-F``) | path to the mapping configuration file | cmlenz@51: +-----------------------------+----------------------------------------------+ cmlenz@51: | ``--no-location`` | do not include location comments with | cmlenz@51: | | filename and line number | cmlenz@51: +-----------------------------+----------------------------------------------+ cmlenz@51: | ``--omit-header`` | do not include msgid "" entry in header | cmlenz@51: +-----------------------------+----------------------------------------------+ cmlenz@51: | ``--output-file`` (``-o``) | name of the output file | cmlenz@51: +-----------------------------+----------------------------------------------+ cmlenz@51: | ``--width`` (``-w``) | set output line width (default 76) | cmlenz@51: +-----------------------------+----------------------------------------------+ cmlenz@51: | ``--no-wrap`` | do not break long message lines, longer than | cmlenz@51: | | the output line width, into several lines | cmlenz@51: +-----------------------------+----------------------------------------------+ cmlenz@64: | ``--input-dirs`` | directories that should be scanned for | cmlenz@64: | | messages | cmlenz@64: +-----------------------------+----------------------------------------------+