Mercurial > babel > old > mirror
annotate doc/setup.txt @ 177:47f6c31e9a24
Changed the `__repr__` output to include the flags(it can be changed back, but it was usefull to implement the fuzzy header parsing).
The `Catalog` class now also includes an extra attribute, '''`fuzzy`''', which is the fuzzy bit of the catalog header.
The above change allows the `compile_catalog` frontends to only compile catalogs '''not''' marked as fuzzy, unless `--use-fuzzy` is passed.
Added tests to check header fuzzy bit parsing.
author | palgarvio |
---|---|
date | Tue, 26 Jun 2007 16:46:56 +0000 |
parents | 661cb602781d |
children | 6138ea7ef7a8 |
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 ... | |
162 | 22 cmd_class = {'compile_catalog': babel.compile_catalog, |
23 'extract_messages': babel.extract_messages, | |
92 | 24 'new_catalog': babel.new_catalog} |
4 | 25 ) |
26 | |
27 | |
28 .. contents:: Contents | |
29 :depth: 2 | |
30 .. sectnum:: | |
31 | |
32 | |
162 | 33 compile_catalog |
34 =============== | |
35 | |
36 The ``compile_catalog`` command is similar to the GNU ``msgfmt`` tool, in that | |
37 it takes a message catalog from a PO file and compiles it to a binary MO file. | |
38 | |
39 If the command has been correctly installed or registered, a project's | |
40 ``setup.py`` script should allow you to use the command:: | |
41 | |
42 $ ./setup.py compile_catalog --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 | |
48 | |
49 Options for 'compile_catalog' command: | |
50 ... | |
51 | |
52 Running the command will produce a PO template file:: | |
53 | |
54 $ ./setup.py compile_catalog --directory foobar/locale --locale pt_BR | |
55 running compile_catalog | |
56 compiling catalog to to foobar/locale/pt_BR/LC_MESSAGES/messages.mo | |
57 | |
58 | |
59 Options | |
60 ------- | |
61 | |
62 The ``compile_catalog`` command accepts the following options: | |
63 | |
64 +-----------------------------+----------------------------------------------+ | |
65 | Option | Description | | |
66 +=============================+==============================================+ | |
67 | ``--domain`` | domain of the PO file (defaults to | | |
68 | | lower-cased project name) | | |
69 +-----------------------------+----------------------------------------------+ | |
70 | ``--directory`` (``-d``) | name of the base directory | | |
71 +-----------------------------+----------------------------------------------+ | |
72 | ``--input-file`` (``-i``) | name of the input file | | |
73 +-----------------------------+----------------------------------------------+ | |
74 | ``--output-file`` (``-o``) | name of the output file | | |
75 +-----------------------------+----------------------------------------------+ | |
76 | ``--locale`` | locale for the new localized string | | |
77 +-----------------------------+----------------------------------------------+ | |
78 | ``--use-fuzzy`` | also include "fuzzy" translations | | |
79 +-----------------------------+----------------------------------------------+ | |
80 | |
81 If ``directory`` is specified, but ``output-file`` is not, the default filename | |
82 of the output file will be:: | |
83 | |
84 <output_dir>/<locale>/LC_MESSAGES/<domain>.mo | |
85 | |
86 These options can either be specified on the command-line, or in the | |
87 ``setup.cfg`` file. | |
88 | |
89 | |
4 | 90 extract_messages |
91 ================ | |
92 | |
92 | 93 The ``extract_messages`` command is comparable to the GNU ``xgettext`` program: |
4 | 94 it can extract localizable messages from a variety of difference source files, |
95 and generate a PO (portable object) template file from the collected messages. | |
96 | |
162 | 97 If the command has been correctly installed or registered, a project's |
4 | 98 ``setup.py`` script should allow you to use the command:: |
99 | |
100 $ ./setup.py extract_messages --help | |
101 Global options: | |
102 --verbose (-v) run verbosely (default) | |
103 --quiet (-q) run quietly (turns verbosity off) | |
104 --dry-run (-n) don't actually do anything | |
105 --help (-h) show detailed help message | |
79 | 106 |
4 | 107 Options for 'extract_messages' command: |
92 | 108 ... |
4 | 109 |
53
52dbebdd3789
Fixed a bug regarding plural msgid's handling when writing the `.pot` file.
palgarvio
parents:
51
diff
changeset
|
110 Running the command will produce a PO template file:: |
4 | 111 |
51
3664c93860f1
Support a `message_extractors` keyword argument directly in `setup()`. Closes #4.
cmlenz
parents:
42
diff
changeset
|
112 $ ./setup.py extract_messages --output-file foobar/locale/messages.pot |
4 | 113 running extract_messages |
51
3664c93860f1
Support a `message_extractors` keyword argument directly in `setup()`. Closes #4.
cmlenz
parents:
42
diff
changeset
|
114 extracting messages from foobar/__init__.py |
3664c93860f1
Support a `message_extractors` keyword argument directly in `setup()`. Closes #4.
cmlenz
parents:
42
diff
changeset
|
115 extracting messages from foobar/core.py |
3664c93860f1
Support a `message_extractors` keyword argument directly in `setup()`. Closes #4.
cmlenz
parents:
42
diff
changeset
|
116 ... |
53
52dbebdd3789
Fixed a bug regarding plural msgid's handling when writing the `.pot` file.
palgarvio
parents:
51
diff
changeset
|
117 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
|
118 |
3664c93860f1
Support a `message_extractors` keyword argument directly in `setup()`. Closes #4.
cmlenz
parents:
42
diff
changeset
|
119 |
3664c93860f1
Support a `message_extractors` keyword argument directly in `setup()`. Closes #4.
cmlenz
parents:
42
diff
changeset
|
120 Method Mapping |
3664c93860f1
Support a `message_extractors` keyword argument directly in `setup()`. Closes #4.
cmlenz
parents:
42
diff
changeset
|
121 -------------- |
3664c93860f1
Support a `message_extractors` keyword argument directly in `setup()`. Closes #4.
cmlenz
parents:
42
diff
changeset
|
122 |
3664c93860f1
Support a `message_extractors` keyword argument directly in `setup()`. Closes #4.
cmlenz
parents:
42
diff
changeset
|
123 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
|
124 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
|
125 ``--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
|
126 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
|
127 function: |
3664c93860f1
Support a `message_extractors` keyword argument directly in `setup()`. Closes #4.
cmlenz
parents:
42
diff
changeset
|
128 |
3664c93860f1
Support a `message_extractors` keyword argument directly in `setup()`. Closes #4.
cmlenz
parents:
42
diff
changeset
|
129 .. code-block:: python |
3664c93860f1
Support a `message_extractors` keyword argument directly in `setup()`. Closes #4.
cmlenz
parents:
42
diff
changeset
|
130 |
3664c93860f1
Support a `message_extractors` keyword argument directly in `setup()`. Closes #4.
cmlenz
parents:
42
diff
changeset
|
131 setup(... |
3664c93860f1
Support a `message_extractors` keyword argument directly in `setup()`. Closes #4.
cmlenz
parents:
42
diff
changeset
|
132 |
3664c93860f1
Support a `message_extractors` keyword argument directly in `setup()`. Closes #4.
cmlenz
parents:
42
diff
changeset
|
133 message_extractors = { |
64
7eb6fea17864
The order of extraction methods is now preserved (see #10).
cmlenz
parents:
56
diff
changeset
|
134 'foobar': [ |
119
c84f629da9de
Made new frontend tests more ''unit-y'', i.e. calling the APIs directly instead of launching the scripts.
cmlenz
parents:
92
diff
changeset
|
135 ('**.py', 'python', None), |
c84f629da9de
Made new frontend tests more ''unit-y'', i.e. calling the APIs directly instead of launching the scripts.
cmlenz
parents:
92
diff
changeset
|
136 ('**/templates/**.html', 'genshi', None), |
c84f629da9de
Made new frontend tests more ''unit-y'', i.e. calling the APIs directly instead of launching the scripts.
cmlenz
parents:
92
diff
changeset
|
137 ('**/templates/**.txt', 'genshi', { |
146 | 138 'template_class': 'genshi.template:TextTemplate' |
64
7eb6fea17864
The order of extraction methods is now preserved (see #10).
cmlenz
parents:
56
diff
changeset
|
139 }) |
7eb6fea17864
The order of extraction methods is now preserved (see #10).
cmlenz
parents:
56
diff
changeset
|
140 ], |
51
3664c93860f1
Support a `message_extractors` keyword argument directly in `setup()`. Closes #4.
cmlenz
parents:
42
diff
changeset
|
141 }, |
3664c93860f1
Support a `message_extractors` keyword argument directly in `setup()`. Closes #4.
cmlenz
parents:
42
diff
changeset
|
142 |
3664c93860f1
Support a `message_extractors` keyword argument directly in `setup()`. Closes #4.
cmlenz
parents:
42
diff
changeset
|
143 ... |
3664c93860f1
Support a `message_extractors` keyword argument directly in `setup()`. Closes #4.
cmlenz
parents:
42
diff
changeset
|
144 ) |
4 | 145 |
146 | |
147 Options | |
148 ------- | |
149 | |
92 | 150 The ``extract_messages`` command accepts the following options: |
4 | 151 |
51
3664c93860f1
Support a `message_extractors` keyword argument directly in `setup()`. Closes #4.
cmlenz
parents:
42
diff
changeset
|
152 +-----------------------------+----------------------------------------------+ |
3664c93860f1
Support a `message_extractors` keyword argument directly in `setup()`. Closes #4.
cmlenz
parents:
42
diff
changeset
|
153 | Option | Description | |
3664c93860f1
Support a `message_extractors` keyword argument directly in `setup()`. Closes #4.
cmlenz
parents:
42
diff
changeset
|
154 +=============================+==============================================+ |
3664c93860f1
Support a `message_extractors` keyword argument directly in `setup()`. Closes #4.
cmlenz
parents:
42
diff
changeset
|
155 | ``--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
|
156 +-----------------------------+----------------------------------------------+ |
3664c93860f1
Support a `message_extractors` keyword argument directly in `setup()`. Closes #4.
cmlenz
parents:
42
diff
changeset
|
157 | ``--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
|
158 | | in addition to the defaults | |
3664c93860f1
Support a `message_extractors` keyword argument directly in `setup()`. Closes #4.
cmlenz
parents:
42
diff
changeset
|
159 +-----------------------------+----------------------------------------------+ |
3664c93860f1
Support a `message_extractors` keyword argument directly in `setup()`. Closes #4.
cmlenz
parents:
42
diff
changeset
|
160 | ``--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
|
161 +-----------------------------+----------------------------------------------+ |
3664c93860f1
Support a `message_extractors` keyword argument directly in `setup()`. Closes #4.
cmlenz
parents:
42
diff
changeset
|
162 | ``--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
|
163 +-----------------------------+----------------------------------------------+ |
3664c93860f1
Support a `message_extractors` keyword argument directly in `setup()`. Closes #4.
cmlenz
parents:
42
diff
changeset
|
164 | ``--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
|
165 | | filename and line number | |
3664c93860f1
Support a `message_extractors` keyword argument directly in `setup()`. Closes #4.
cmlenz
parents:
42
diff
changeset
|
166 +-----------------------------+----------------------------------------------+ |
3664c93860f1
Support a `message_extractors` keyword argument directly in `setup()`. Closes #4.
cmlenz
parents:
42
diff
changeset
|
167 | ``--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
|
168 +-----------------------------+----------------------------------------------+ |
3664c93860f1
Support a `message_extractors` keyword argument directly in `setup()`. Closes #4.
cmlenz
parents:
42
diff
changeset
|
169 | ``--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
|
170 +-----------------------------+----------------------------------------------+ |
3664c93860f1
Support a `message_extractors` keyword argument directly in `setup()`. Closes #4.
cmlenz
parents:
42
diff
changeset
|
171 | ``--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
|
172 +-----------------------------+----------------------------------------------+ |
3664c93860f1
Support a `message_extractors` keyword argument directly in `setup()`. Closes #4.
cmlenz
parents:
42
diff
changeset
|
173 | ``--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
|
174 | | the output line width, into several lines | |
3664c93860f1
Support a `message_extractors` keyword argument directly in `setup()`. Closes #4.
cmlenz
parents:
42
diff
changeset
|
175 +-----------------------------+----------------------------------------------+ |
64
7eb6fea17864
The order of extraction methods is now preserved (see #10).
cmlenz
parents:
56
diff
changeset
|
176 | ``--input-dirs`` | directories that should be scanned for | |
7eb6fea17864
The order of extraction methods is now preserved (see #10).
cmlenz
parents:
56
diff
changeset
|
177 | | messages | |
7eb6fea17864
The order of extraction methods is now preserved (see #10).
cmlenz
parents:
56
diff
changeset
|
178 +-----------------------------+----------------------------------------------+ |
92 | 179 | ``--sort-output`` | generate sorted output (default False) | |
180 +-----------------------------+----------------------------------------------+ | |
181 | ``--sort-by-file`` | sort output by file location (default False) | | |
182 +-----------------------------+----------------------------------------------+ | |
183 | ``--msgid-bugs-address`` | set email address for message bug reports | | |
184 +-----------------------------+----------------------------------------------+ | |
185 | ``--copyright-holder`` | set copyright holder in output | | |
186 +-----------------------------+----------------------------------------------+ | |
187 | ``--add-comments (-c)`` | place comment block with TAG (or those | | |
188 | | preceding keyword lines) in output file. | | |
189 | | Separate multiple TAGs with commas(,) | | |
190 +-----------------------------+----------------------------------------------+ | |
191 | |
192 These options can either be specified on the command-line, or in the | |
193 ``setup.cfg`` file. In the latter case, the options above become entries of the | |
194 section ``[extract_messages]``, and the option names are changed to use | |
195 underscore characters instead of dashes, for example: | |
196 | |
197 .. code-block:: ini | |
198 | |
199 [extract_messages] | |
200 keywords = _, gettext, ngettext | |
201 mapping_file = babel.cfg | |
202 width = 80 | |
203 | |
204 This would be equivalent to invoking the command from the command-line as | |
205 follows:: | |
206 | |
207 $ setup.py extract_messages -k _ -k gettext -k ngettext -F mapping.cfg -w 80 | |
208 | |
209 Any path names are interpreted relative to the location of the ``setup.py`` | |
210 file. For boolean options, use "true" or "false" values. | |
211 | |
212 | |
213 new_catalog | |
214 =========== | |
215 | |
216 The ``new_catalog`` command is basically equivalent to the GNU ``msginit`` | |
217 program: it creates a new translation catalog based on a PO template file (POT). | |
218 | |
162 | 219 If the command has been correctly installed or registered, a project's |
92 | 220 ``setup.py`` script should allow you to use the command:: |
221 | |
222 $ ./setup.py new_catalog --help | |
223 Global options: | |
224 --verbose (-v) run verbosely (default) | |
225 --quiet (-q) run quietly (turns verbosity off) | |
226 --dry-run (-n) don't actually do anything | |
227 --help (-h) show detailed help message | |
228 | |
229 Options for 'new_catalog' command: | |
230 ... | |
231 | |
232 Running the command will produce a PO file:: | |
233 | |
234 $ ./setup.py new_catalog -l fr -i foobar/locales/messages.pot \ | |
235 -o foobar/locales/fr/messages.po | |
236 running new_catalog | |
237 creating catalog 'foobar/locales/fr/messages.po' based on 'foobar/locales/messages.pot' | |
238 | |
239 | |
240 Options | |
241 ------- | |
242 | |
243 The ``new_catalog`` command accepts the following options: | |
244 | |
245 +-----------------------------+----------------------------------------------+ | |
246 | Option | Description | | |
247 +=============================+==============================================+ | |
248 | ``--domain`` | domain of the PO file (defaults to | | |
249 | | lower-cased project name) | | |
250 +-----------------------------+----------------------------------------------+ | |
251 | ``--input-file`` (``-i``) | name of the input file | | |
252 +-----------------------------+----------------------------------------------+ | |
253 | ``--output-dir`` (``-d``) | name of the output directory | | |
254 +-----------------------------+----------------------------------------------+ | |
255 | ``--output-file`` (``-o``) | name of the output file | | |
256 +-----------------------------+----------------------------------------------+ | |
257 | ``--locale`` | locale for the new localized string | | |
258 +-----------------------------+----------------------------------------------+ | |
259 | ``--omit-header`` | do not include msgid "" entry in header | | |
260 +-----------------------------+----------------------------------------------+ | |
261 | ``--first-author`` | name of the first author | | |
262 +-----------------------------+----------------------------------------------+ | |
263 | ``--first-author-email`` | email address of the first author | | |
264 +-----------------------------+----------------------------------------------+ | |
265 | |
266 If ``output-dir`` is specified, but ``output-file`` is not, the default filename | |
267 of the output file will be:: | |
268 | |
269 <output_dir>/<locale>/LC_MESSAGES/<domain>.po | |
270 | |
271 These options can either be specified on the command-line, or in the | |
272 ``setup.cfg`` file. |