Mercurial > babel > old > mirror
annotate doc/setup.txt @ 97:debd9ac3bb4d
Fix for #11 (use local timezone in timestamps of generated POT).
author | cmlenz |
---|---|
date | Tue, 12 Jun 2007 18:40:39 +0000 |
parents | 6d1a7777003e |
children | c84f629da9de |
rev | line source |
---|---|
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 | |
56
27d55a07c897
Rename the `babel.catalog` package to `babel.messages` for consistency with the other package names.
cmlenz
parents:
53
diff
changeset
|
18 from babel.messages import frontend as babel |
4 | 19 |
20 setup( | |
21 ... | |
92 | 22 cmd_class = {'extract_messages': babel.extract_messages, |
23 'new_catalog': babel.new_catalog} | |
4 | 24 ) |
25 | |
26 | |
27 .. contents:: Contents | |
28 :depth: 2 | |
29 .. sectnum:: | |
30 | |
31 | |
32 extract_messages | |
33 ================ | |
34 | |
92 | 35 The ``extract_messages`` command is comparable to the GNU ``xgettext`` program: |
4 | 36 it can extract localizable messages from a variety of difference source files, |
37 and generate a PO (portable object) template file from the collected messages. | |
38 | |
39 If the command has been correctly installed or registered, another project's | |
40 ``setup.py`` script should allow you to use the command:: | |
41 | |
42 $ ./setup.py extract_messages --help | |
43 Global options: | |
44 --verbose (-v) run verbosely (default) | |
45 --quiet (-q) run quietly (turns verbosity off) | |
46 --dry-run (-n) don't actually do anything | |
47 --help (-h) show detailed help message | |
79 | 48 |
4 | 49 Options for 'extract_messages' command: |
92 | 50 ... |
4 | 51 |
53
52dbebdd3789
Fixed a bug regarding plural msgid's handling when writing the `.pot` file.
palgarvio
parents:
51
diff
changeset
|
52 Running the command will produce a PO template file:: |
4 | 53 |
51
3664c93860f1
Support a `message_extractors` keyword argument directly in `setup()`. Closes #4.
cmlenz
parents:
42
diff
changeset
|
54 $ ./setup.py extract_messages --output-file foobar/locale/messages.pot |
4 | 55 running extract_messages |
51
3664c93860f1
Support a `message_extractors` keyword argument directly in `setup()`. Closes #4.
cmlenz
parents:
42
diff
changeset
|
56 extracting messages from foobar/__init__.py |
3664c93860f1
Support a `message_extractors` keyword argument directly in `setup()`. Closes #4.
cmlenz
parents:
42
diff
changeset
|
57 extracting messages from foobar/core.py |
3664c93860f1
Support a `message_extractors` keyword argument directly in `setup()`. Closes #4.
cmlenz
parents:
42
diff
changeset
|
58 ... |
53
52dbebdd3789
Fixed a bug regarding plural msgid's handling when writing the `.pot` file.
palgarvio
parents:
51
diff
changeset
|
59 writing PO template file to foobar/locale/messages.pot |
51
3664c93860f1
Support a `message_extractors` keyword argument directly in `setup()`. Closes #4.
cmlenz
parents:
42
diff
changeset
|
60 |
3664c93860f1
Support a `message_extractors` keyword argument directly in `setup()`. Closes #4.
cmlenz
parents:
42
diff
changeset
|
61 |
3664c93860f1
Support a `message_extractors` keyword argument directly in `setup()`. Closes #4.
cmlenz
parents:
42
diff
changeset
|
62 Method Mapping |
3664c93860f1
Support a `message_extractors` keyword argument directly in `setup()`. Closes #4.
cmlenz
parents:
42
diff
changeset
|
63 -------------- |
3664c93860f1
Support a `message_extractors` keyword argument directly in `setup()`. Closes #4.
cmlenz
parents:
42
diff
changeset
|
64 |
3664c93860f1
Support a `message_extractors` keyword argument directly in `setup()`. Closes #4.
cmlenz
parents:
42
diff
changeset
|
65 The mapping of file patterns to extraction methods (and options) can be |
3664c93860f1
Support a `message_extractors` keyword argument directly in `setup()`. Closes #4.
cmlenz
parents:
42
diff
changeset
|
66 specified using a configuration file that is pointed to using the |
3664c93860f1
Support a `message_extractors` keyword argument directly in `setup()`. Closes #4.
cmlenz
parents:
42
diff
changeset
|
67 ``--mapping-file`` option shown above. Alternatively, you can configure the |
3664c93860f1
Support a `message_extractors` keyword argument directly in `setup()`. Closes #4.
cmlenz
parents:
42
diff
changeset
|
68 mapping directly in ``setup.py`` using a keyword argument to the ``setup()`` |
3664c93860f1
Support a `message_extractors` keyword argument directly in `setup()`. Closes #4.
cmlenz
parents:
42
diff
changeset
|
69 function: |
3664c93860f1
Support a `message_extractors` keyword argument directly in `setup()`. Closes #4.
cmlenz
parents:
42
diff
changeset
|
70 |
3664c93860f1
Support a `message_extractors` keyword argument directly in `setup()`. Closes #4.
cmlenz
parents:
42
diff
changeset
|
71 .. code-block:: python |
3664c93860f1
Support a `message_extractors` keyword argument directly in `setup()`. Closes #4.
cmlenz
parents:
42
diff
changeset
|
72 |
3664c93860f1
Support a `message_extractors` keyword argument directly in `setup()`. Closes #4.
cmlenz
parents:
42
diff
changeset
|
73 setup(... |
3664c93860f1
Support a `message_extractors` keyword argument directly in `setup()`. Closes #4.
cmlenz
parents:
42
diff
changeset
|
74 |
3664c93860f1
Support a `message_extractors` keyword argument directly in `setup()`. Closes #4.
cmlenz
parents:
42
diff
changeset
|
75 message_extractors = { |
64
7eb6fea17864
The order of extraction methods is now preserved (see #10).
cmlenz
parents:
56
diff
changeset
|
76 'foobar': [ |
7eb6fea17864
The order of extraction methods is now preserved (see #10).
cmlenz
parents:
56
diff
changeset
|
77 ('**.py', ('python', None), |
7eb6fea17864
The order of extraction methods is now preserved (see #10).
cmlenz
parents:
56
diff
changeset
|
78 ('**/templates/**.html', ('genshi', None), |
7eb6fea17864
The order of extraction methods is now preserved (see #10).
cmlenz
parents:
56
diff
changeset
|
79 ('**/templates/**.txt', ('genshi', { |
7eb6fea17864
The order of extraction methods is now preserved (see #10).
cmlenz
parents:
56
diff
changeset
|
80 'template_class': 'genshi.template.text.TextTemplate' |
7eb6fea17864
The order of extraction methods is now preserved (see #10).
cmlenz
parents:
56
diff
changeset
|
81 }) |
7eb6fea17864
The order of extraction methods is now preserved (see #10).
cmlenz
parents:
56
diff
changeset
|
82 ], |
51
3664c93860f1
Support a `message_extractors` keyword argument directly in `setup()`. Closes #4.
cmlenz
parents:
42
diff
changeset
|
83 }, |
3664c93860f1
Support a `message_extractors` keyword argument directly in `setup()`. Closes #4.
cmlenz
parents:
42
diff
changeset
|
84 |
3664c93860f1
Support a `message_extractors` keyword argument directly in `setup()`. Closes #4.
cmlenz
parents:
42
diff
changeset
|
85 ... |
3664c93860f1
Support a `message_extractors` keyword argument directly in `setup()`. Closes #4.
cmlenz
parents:
42
diff
changeset
|
86 ) |
4 | 87 |
88 | |
89 Options | |
90 ------- | |
91 | |
92 | 92 The ``extract_messages`` command accepts the following options: |
4 | 93 |
51
3664c93860f1
Support a `message_extractors` keyword argument directly in `setup()`. Closes #4.
cmlenz
parents:
42
diff
changeset
|
94 +-----------------------------+----------------------------------------------+ |
3664c93860f1
Support a `message_extractors` keyword argument directly in `setup()`. Closes #4.
cmlenz
parents:
42
diff
changeset
|
95 | Option | Description | |
3664c93860f1
Support a `message_extractors` keyword argument directly in `setup()`. Closes #4.
cmlenz
parents:
42
diff
changeset
|
96 +=============================+==============================================+ |
3664c93860f1
Support a `message_extractors` keyword argument directly in `setup()`. Closes #4.
cmlenz
parents:
42
diff
changeset
|
97 | ``--charset`` | charset to use in the output file | |
3664c93860f1
Support a `message_extractors` keyword argument directly in `setup()`. Closes #4.
cmlenz
parents:
42
diff
changeset
|
98 +-----------------------------+----------------------------------------------+ |
3664c93860f1
Support a `message_extractors` keyword argument directly in `setup()`. Closes #4.
cmlenz
parents:
42
diff
changeset
|
99 | ``--keywords`` (``-k``) | space-separated list of keywords to look for | |
3664c93860f1
Support a `message_extractors` keyword argument directly in `setup()`. Closes #4.
cmlenz
parents:
42
diff
changeset
|
100 | | in addition to the defaults | |
3664c93860f1
Support a `message_extractors` keyword argument directly in `setup()`. Closes #4.
cmlenz
parents:
42
diff
changeset
|
101 +-----------------------------+----------------------------------------------+ |
3664c93860f1
Support a `message_extractors` keyword argument directly in `setup()`. Closes #4.
cmlenz
parents:
42
diff
changeset
|
102 | ``--no-default-keywords`` | do not include the default keywords | |
3664c93860f1
Support a `message_extractors` keyword argument directly in `setup()`. Closes #4.
cmlenz
parents:
42
diff
changeset
|
103 +-----------------------------+----------------------------------------------+ |
3664c93860f1
Support a `message_extractors` keyword argument directly in `setup()`. Closes #4.
cmlenz
parents:
42
diff
changeset
|
104 | ``--mapping-file`` (``-F``) | path to the mapping configuration file | |
3664c93860f1
Support a `message_extractors` keyword argument directly in `setup()`. Closes #4.
cmlenz
parents:
42
diff
changeset
|
105 +-----------------------------+----------------------------------------------+ |
3664c93860f1
Support a `message_extractors` keyword argument directly in `setup()`. Closes #4.
cmlenz
parents:
42
diff
changeset
|
106 | ``--no-location`` | do not include location comments with | |
3664c93860f1
Support a `message_extractors` keyword argument directly in `setup()`. Closes #4.
cmlenz
parents:
42
diff
changeset
|
107 | | filename and line number | |
3664c93860f1
Support a `message_extractors` keyword argument directly in `setup()`. Closes #4.
cmlenz
parents:
42
diff
changeset
|
108 +-----------------------------+----------------------------------------------+ |
3664c93860f1
Support a `message_extractors` keyword argument directly in `setup()`. Closes #4.
cmlenz
parents:
42
diff
changeset
|
109 | ``--omit-header`` | do not include msgid "" entry in header | |
3664c93860f1
Support a `message_extractors` keyword argument directly in `setup()`. Closes #4.
cmlenz
parents:
42
diff
changeset
|
110 +-----------------------------+----------------------------------------------+ |
3664c93860f1
Support a `message_extractors` keyword argument directly in `setup()`. Closes #4.
cmlenz
parents:
42
diff
changeset
|
111 | ``--output-file`` (``-o``) | name of the output file | |
3664c93860f1
Support a `message_extractors` keyword argument directly in `setup()`. Closes #4.
cmlenz
parents:
42
diff
changeset
|
112 +-----------------------------+----------------------------------------------+ |
3664c93860f1
Support a `message_extractors` keyword argument directly in `setup()`. Closes #4.
cmlenz
parents:
42
diff
changeset
|
113 | ``--width`` (``-w``) | set output line width (default 76) | |
3664c93860f1
Support a `message_extractors` keyword argument directly in `setup()`. Closes #4.
cmlenz
parents:
42
diff
changeset
|
114 +-----------------------------+----------------------------------------------+ |
3664c93860f1
Support a `message_extractors` keyword argument directly in `setup()`. Closes #4.
cmlenz
parents:
42
diff
changeset
|
115 | ``--no-wrap`` | do not break long message lines, longer than | |
3664c93860f1
Support a `message_extractors` keyword argument directly in `setup()`. Closes #4.
cmlenz
parents:
42
diff
changeset
|
116 | | the output line width, into several lines | |
3664c93860f1
Support a `message_extractors` keyword argument directly in `setup()`. Closes #4.
cmlenz
parents:
42
diff
changeset
|
117 +-----------------------------+----------------------------------------------+ |
64
7eb6fea17864
The order of extraction methods is now preserved (see #10).
cmlenz
parents:
56
diff
changeset
|
118 | ``--input-dirs`` | directories that should be scanned for | |
7eb6fea17864
The order of extraction methods is now preserved (see #10).
cmlenz
parents:
56
diff
changeset
|
119 | | messages | |
7eb6fea17864
The order of extraction methods is now preserved (see #10).
cmlenz
parents:
56
diff
changeset
|
120 +-----------------------------+----------------------------------------------+ |
92 | 121 | ``--sort-output`` | generate sorted output (default False) | |
122 +-----------------------------+----------------------------------------------+ | |
123 | ``--sort-by-file`` | sort output by file location (default False) | | |
124 +-----------------------------+----------------------------------------------+ | |
125 | ``--msgid-bugs-address`` | set email address for message bug reports | | |
126 +-----------------------------+----------------------------------------------+ | |
127 | ``--copyright-holder`` | set copyright holder in output | | |
128 +-----------------------------+----------------------------------------------+ | |
129 | ``--add-comments (-c)`` | place comment block with TAG (or those | | |
130 | | preceding keyword lines) in output file. | | |
131 | | Separate multiple TAGs with commas(,) | | |
132 +-----------------------------+----------------------------------------------+ | |
133 | |
134 These options can either be specified on the command-line, or in the | |
135 ``setup.cfg`` file. In the latter case, the options above become entries of the | |
136 section ``[extract_messages]``, and the option names are changed to use | |
137 underscore characters instead of dashes, for example: | |
138 | |
139 .. code-block:: ini | |
140 | |
141 [extract_messages] | |
142 keywords = _, gettext, ngettext | |
143 mapping_file = babel.cfg | |
144 width = 80 | |
145 | |
146 This would be equivalent to invoking the command from the command-line as | |
147 follows:: | |
148 | |
149 $ setup.py extract_messages -k _ -k gettext -k ngettext -F mapping.cfg -w 80 | |
150 | |
151 Any path names are interpreted relative to the location of the ``setup.py`` | |
152 file. For boolean options, use "true" or "false" values. | |
153 | |
154 | |
155 new_catalog | |
156 =========== | |
157 | |
158 The ``new_catalog`` command is basically equivalent to the GNU ``msginit`` | |
159 program: it creates a new translation catalog based on a PO template file (POT). | |
160 | |
161 If the command has been correctly installed or registered, another project's | |
162 ``setup.py`` script should allow you to use the command:: | |
163 | |
164 $ ./setup.py new_catalog --help | |
165 Global options: | |
166 --verbose (-v) run verbosely (default) | |
167 --quiet (-q) run quietly (turns verbosity off) | |
168 --dry-run (-n) don't actually do anything | |
169 --help (-h) show detailed help message | |
170 | |
171 Options for 'new_catalog' command: | |
172 ... | |
173 | |
174 Running the command will produce a PO file:: | |
175 | |
176 $ ./setup.py new_catalog -l fr -i foobar/locales/messages.pot \ | |
177 -o foobar/locales/fr/messages.po | |
178 running new_catalog | |
179 creating catalog 'foobar/locales/fr/messages.po' based on 'foobar/locales/messages.pot' | |
180 | |
181 | |
182 Options | |
183 ------- | |
184 | |
185 The ``new_catalog`` command accepts the following options: | |
186 | |
187 +-----------------------------+----------------------------------------------+ | |
188 | Option | Description | | |
189 +=============================+==============================================+ | |
190 | ``--domain`` | domain of the PO file (defaults to | | |
191 | | lower-cased project name) | | |
192 +-----------------------------+----------------------------------------------+ | |
193 | ``--input-file`` (``-i``) | name of the input file | | |
194 +-----------------------------+----------------------------------------------+ | |
195 | ``--output-dir`` (``-d``) | name of the output directory | | |
196 +-----------------------------+----------------------------------------------+ | |
197 | ``--output-file`` (``-o``) | name of the output file | | |
198 +-----------------------------+----------------------------------------------+ | |
199 | ``--locale`` | locale for the new localized string | | |
200 +-----------------------------+----------------------------------------------+ | |
201 | ``--omit-header`` | do not include msgid "" entry in header | | |
202 +-----------------------------+----------------------------------------------+ | |
203 | ``--first-author`` | name of the first author | | |
204 +-----------------------------+----------------------------------------------+ | |
205 | ``--first-author-email`` | email address of the first author | | |
206 +-----------------------------+----------------------------------------------+ | |
207 | |
208 If ``output-dir`` is specified, but ``output-file`` is not, the default filename | |
209 of the output file will be:: | |
210 | |
211 <output_dir>/<locale>/LC_MESSAGES/<domain>.po | |
212 | |
213 These options can either be specified on the command-line, or in the | |
214 ``setup.cfg`` file. |