4
|
1 .. -*- mode: rst; encoding: utf-8 -*-
|
|
2
|
|
3 ================================
|
|
4 Distutils/Setuptools Integration
|
|
5 ================================
|
|
6
|
|
7 Babel provides commands for integration into ``setup.py`` scripts, based on
|
|
8 either the ``distutils`` package that is part of the Python standard library,
|
|
9 or the third-party ``setuptools`` package.
|
|
10
|
|
11 These commands are available by default when Babel has been properly installed,
|
|
12 and ``setup.py`` is using ``setuptools``. For projects that use plain old
|
42
|
13 ``distutils``, the commands need to be registered explicitly, for example:
|
|
14
|
|
15 .. code-block:: python
|
4
|
16
|
|
17 from distutils.core import setup
|
|
18 from babel.catalog import frontend as babel
|
|
19
|
|
20 setup(
|
|
21 ...
|
|
22 cmd_class = {'extract_messages': babel.extract_messages}
|
|
23 )
|
|
24
|
|
25
|
|
26 .. contents:: Contents
|
|
27 :depth: 2
|
|
28 .. sectnum::
|
|
29
|
|
30
|
|
31 extract_messages
|
|
32 ================
|
|
33
|
|
34 The ``extract_messages`` command is comparabe to the GNU ``xgettext`` program:
|
|
35 it can extract localizable messages from a variety of difference source files,
|
|
36 and generate a PO (portable object) template file from the collected messages.
|
|
37
|
|
38 If the command has been correctly installed or registered, another project's
|
|
39 ``setup.py`` script should allow you to use the command::
|
|
40
|
|
41 $ ./setup.py extract_messages --help
|
|
42 Global options:
|
|
43 --verbose (-v) run verbosely (default)
|
|
44 --quiet (-q) run quietly (turns verbosity off)
|
|
45 --dry-run (-n) don't actually do anything
|
|
46 --help (-h) show detailed help message
|
|
47
|
|
48 Options for 'extract_messages' command:
|
|
49 --charset charset to use in the output
|
|
50 --keywords (-k) comma-separated list of keywords to look for in addition
|
|
51 to the defaults
|
|
52 --no-location do not write filename/lineno location comments
|
|
53 --output-file filename of the output PO file
|
|
54
|
|
55 Running the command will produce a PO file::
|
|
56
|
|
57 $ ./setup.py extract_messages --output-file webapp/locales/messages.pot
|
|
58 running extract_messages
|
|
59 extracting messages from 'webapp'
|
|
60 extracting messages from 'webparts'
|
|
61 writing PO file to webapp/locales/messages.pot
|
|
62
|
|
63
|
|
64 Options
|
|
65 -------
|
|
66
|
|
67 As shown in the ``--help`` output above, the ``extract_messages`` command
|
|
68 accepts the following options:
|
|
69
|
|
70 ``--charset``
|
|
71 The character set / encoding to use in the generated PO file.
|
|
72 ``--keywords``
|
|
73 A comma-separated list of keywords (function names) to look for in addition
|
|
74 to the default keywords
|
|
75 ``--no-location``
|
|
76 If this flag is set, location comments will not be included in the generated
|
|
77 PO file.
|
|
78 ``--output-file`` or ``-o``
|
|
79 The path to the PO file that should be generated
|
|
80
|