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@162: cmd_class = {'compile_catalog': babel.compile_catalog, cmlenz@162: 'extract_messages': babel.extract_messages, cmlenz@92: 'new_catalog': babel.new_catalog} cmlenz@4: ) cmlenz@4: cmlenz@4: cmlenz@4: .. contents:: Contents cmlenz@4: :depth: 2 cmlenz@4: .. sectnum:: cmlenz@4: cmlenz@4: cmlenz@162: compile_catalog cmlenz@162: =============== cmlenz@162: cmlenz@162: The ``compile_catalog`` command is similar to the GNU ``msgfmt`` tool, in that cmlenz@162: it takes a message catalog from a PO file and compiles it to a binary MO file. cmlenz@162: cmlenz@162: If the command has been correctly installed or registered, a project's cmlenz@162: ``setup.py`` script should allow you to use the command:: cmlenz@162: cmlenz@162: $ ./setup.py compile_catalog --help cmlenz@162: Global options: cmlenz@162: --verbose (-v) run verbosely (default) cmlenz@162: --quiet (-q) run quietly (turns verbosity off) cmlenz@162: --dry-run (-n) don't actually do anything cmlenz@162: --help (-h) show detailed help message cmlenz@162: cmlenz@162: Options for 'compile_catalog' command: cmlenz@162: ... cmlenz@162: cmlenz@162: Running the command will produce a PO template file:: cmlenz@162: cmlenz@162: $ ./setup.py compile_catalog --directory foobar/locale --locale pt_BR cmlenz@162: running compile_catalog cmlenz@162: compiling catalog to to foobar/locale/pt_BR/LC_MESSAGES/messages.mo cmlenz@162: cmlenz@162: cmlenz@162: Options cmlenz@162: ------- cmlenz@162: cmlenz@162: The ``compile_catalog`` command accepts the following options: cmlenz@162: cmlenz@162: +-----------------------------+----------------------------------------------+ cmlenz@162: | Option | Description | cmlenz@162: +=============================+==============================================+ cmlenz@162: | ``--domain`` | domain of the PO file (defaults to | cmlenz@162: | | lower-cased project name) | cmlenz@162: +-----------------------------+----------------------------------------------+ cmlenz@162: | ``--directory`` (``-d``) | name of the base directory | cmlenz@162: +-----------------------------+----------------------------------------------+ cmlenz@162: | ``--input-file`` (``-i``) | name of the input file | cmlenz@162: +-----------------------------+----------------------------------------------+ cmlenz@162: | ``--output-file`` (``-o``) | name of the output file | cmlenz@162: +-----------------------------+----------------------------------------------+ cmlenz@162: | ``--locale`` | locale for the new localized string | cmlenz@162: +-----------------------------+----------------------------------------------+ cmlenz@162: | ``--use-fuzzy`` | also include "fuzzy" translations | cmlenz@162: +-----------------------------+----------------------------------------------+ cmlenz@162: cmlenz@162: If ``directory`` is specified, but ``output-file`` is not, the default filename cmlenz@162: of the output file will be:: cmlenz@162: cmlenz@162: //LC_MESSAGES/.mo cmlenz@162: cmlenz@162: These options can either be specified on the command-line, or in the cmlenz@162: ``setup.cfg`` file. cmlenz@162: cmlenz@162: cmlenz@4: extract_messages cmlenz@4: ================ cmlenz@4: cmlenz@92: The ``extract_messages`` command is comparable 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@162: If the command has been correctly installed or registered, a 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@92: ... 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@119: ('**.py', 'python', None), cmlenz@119: ('**/templates/**.html', 'genshi', None), cmlenz@119: ('**/templates/**.txt', 'genshi', { cmlenz@146: 'template_class': 'genshi.template: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@92: The ``extract_messages`` command 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: +-----------------------------+----------------------------------------------+ cmlenz@92: | ``--sort-output`` | generate sorted output (default False) | cmlenz@92: +-----------------------------+----------------------------------------------+ cmlenz@92: | ``--sort-by-file`` | sort output by file location (default False) | cmlenz@92: +-----------------------------+----------------------------------------------+ cmlenz@92: | ``--msgid-bugs-address`` | set email address for message bug reports | cmlenz@92: +-----------------------------+----------------------------------------------+ cmlenz@92: | ``--copyright-holder`` | set copyright holder in output | cmlenz@92: +-----------------------------+----------------------------------------------+ cmlenz@92: | ``--add-comments (-c)`` | place comment block with TAG (or those | cmlenz@92: | | preceding keyword lines) in output file. | cmlenz@92: | | Separate multiple TAGs with commas(,) | cmlenz@92: +-----------------------------+----------------------------------------------+ cmlenz@92: cmlenz@92: These options can either be specified on the command-line, or in the cmlenz@92: ``setup.cfg`` file. In the latter case, the options above become entries of the cmlenz@92: section ``[extract_messages]``, and the option names are changed to use cmlenz@92: underscore characters instead of dashes, for example: cmlenz@92: cmlenz@92: .. code-block:: ini cmlenz@92: cmlenz@92: [extract_messages] cmlenz@92: keywords = _, gettext, ngettext cmlenz@92: mapping_file = babel.cfg cmlenz@92: width = 80 cmlenz@92: cmlenz@92: This would be equivalent to invoking the command from the command-line as cmlenz@92: follows:: cmlenz@92: cmlenz@92: $ setup.py extract_messages -k _ -k gettext -k ngettext -F mapping.cfg -w 80 cmlenz@92: cmlenz@92: Any path names are interpreted relative to the location of the ``setup.py`` cmlenz@92: file. For boolean options, use "true" or "false" values. cmlenz@92: cmlenz@92: cmlenz@92: new_catalog cmlenz@92: =========== cmlenz@92: cmlenz@92: The ``new_catalog`` command is basically equivalent to the GNU ``msginit`` cmlenz@92: program: it creates a new translation catalog based on a PO template file (POT). cmlenz@92: cmlenz@162: If the command has been correctly installed or registered, a project's cmlenz@92: ``setup.py`` script should allow you to use the command:: cmlenz@92: cmlenz@92: $ ./setup.py new_catalog --help cmlenz@92: Global options: cmlenz@92: --verbose (-v) run verbosely (default) cmlenz@92: --quiet (-q) run quietly (turns verbosity off) cmlenz@92: --dry-run (-n) don't actually do anything cmlenz@92: --help (-h) show detailed help message cmlenz@92: cmlenz@92: Options for 'new_catalog' command: cmlenz@92: ... cmlenz@92: cmlenz@92: Running the command will produce a PO file:: cmlenz@92: cmlenz@92: $ ./setup.py new_catalog -l fr -i foobar/locales/messages.pot \ cmlenz@92: -o foobar/locales/fr/messages.po cmlenz@92: running new_catalog cmlenz@92: creating catalog 'foobar/locales/fr/messages.po' based on 'foobar/locales/messages.pot' cmlenz@92: cmlenz@92: cmlenz@92: Options cmlenz@92: ------- cmlenz@92: cmlenz@92: The ``new_catalog`` command accepts the following options: cmlenz@92: cmlenz@92: +-----------------------------+----------------------------------------------+ cmlenz@92: | Option | Description | cmlenz@92: +=============================+==============================================+ cmlenz@92: | ``--domain`` | domain of the PO file (defaults to | cmlenz@92: | | lower-cased project name) | cmlenz@92: +-----------------------------+----------------------------------------------+ cmlenz@92: | ``--input-file`` (``-i``) | name of the input file | cmlenz@92: +-----------------------------+----------------------------------------------+ cmlenz@92: | ``--output-dir`` (``-d``) | name of the output directory | cmlenz@92: +-----------------------------+----------------------------------------------+ cmlenz@92: | ``--output-file`` (``-o``) | name of the output file | cmlenz@92: +-----------------------------+----------------------------------------------+ cmlenz@92: | ``--locale`` | locale for the new localized string | cmlenz@92: +-----------------------------+----------------------------------------------+ cmlenz@92: | ``--omit-header`` | do not include msgid "" entry in header | cmlenz@92: +-----------------------------+----------------------------------------------+ cmlenz@92: | ``--first-author`` | name of the first author | cmlenz@92: +-----------------------------+----------------------------------------------+ cmlenz@92: | ``--first-author-email`` | email address of the first author | cmlenz@92: +-----------------------------+----------------------------------------------+ cmlenz@92: cmlenz@92: If ``output-dir`` is specified, but ``output-file`` is not, the default filename cmlenz@92: of the output file will be:: cmlenz@92: cmlenz@92: //LC_MESSAGES/.po cmlenz@92: cmlenz@92: These options can either be specified on the command-line, or in the cmlenz@92: ``setup.cfg`` file.