2
|
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
|
|
13 ``distutils``, the commands need to be registered explicitly, for example::
|
|
14
|
|
15 from distutils.core import setup
|
|
16 from babel.catalog import frontend as babel
|
|
17
|
|
18 setup(
|
|
19 ...
|
|
20 cmd_class = {'extract_messages': babel.extract_messages}
|
|
21 )
|
|
22
|
|
23
|
|
24 .. contents:: Contents
|
|
25 :depth: 2
|
|
26 .. sectnum::
|
|
27
|
|
28
|
|
29 extract_messages
|
|
30 ================
|
|
31
|
|
32 The ``extract_messages`` command is comparabe to the GNU ``xgettext`` program:
|
|
33 it can extract localizable messages from a variety of difference source files,
|
|
34 and generate a PO (portable object) template file from the collected messages.
|
|
35
|
|
36 If the command has been correctly installed or registered, another project's
|
|
37 ``setup.py`` script should allow you to use the command::
|
|
38
|
|
39 $ ./setup.py extract_messages --help
|
|
40 Global options:
|
|
41 --verbose (-v) run verbosely (default)
|
|
42 --quiet (-q) run quietly (turns verbosity off)
|
|
43 --dry-run (-n) don't actually do anything
|
|
44 --help (-h) show detailed help message
|
|
45
|
|
46 Options for 'extract_messages' command:
|
|
47 --charset charset to use in the output
|
|
48 --keywords (-k) comma-separated list of keywords to look for in addition
|
|
49 to the defaults
|
|
50 --no-location do not write filename/lineno location comments
|
|
51 --output-file filename of the output PO file
|
|
52
|
|
53 Running the command will produce a PO file::
|
|
54
|
|
55 $ ./setup.py extract_messages --output-file webapp/locales/messages.pot
|
|
56 running extract_messages
|
|
57 extracting messages from 'webapp'
|
|
58 extracting messages from 'webparts'
|
|
59 writing PO file to webapp/locales/messages.pot
|
|
60
|
|
61
|
|
62 Options
|
|
63 -------
|
|
64
|
|
65 As shown in the ``--help`` output above, the ``extract_messages`` command
|
|
66 accepts the following options:
|
|
67
|
|
68 ``--charset``
|
|
69 The character set / encoding to use in the generated PO file.
|
|
70 ``--keywords``
|
|
71 A comma-separated list of keywords (function names) to look for in addition
|
|
72 to the default keywords
|
|
73 ``--no-location``
|
|
74 If this flag is set, location comments will not be included in the generated
|
|
75 PO file.
|
|
76 ``--output-file`` or ``-o``
|
|
77 The path to the PO file that should be generated
|
|
78
|