Debian Codegraph @

docs/cmdline.rst

raw
1 .. -*- mode: rst; encoding: utf-8 -*-
2
3 .. _cmdline:
4
5 ======================
6 Command-Line Interface
7 ======================
8
9 Babel includes a command-line interface for working with message catalogs,
10 similar to the various GNU ``gettext`` tools commonly available on Linux/Unix
11 systems.
12
13
14 When properly installed, Babel provides a script called ``pybabel``::
15
16 $ pybabel --help
17 Usage: pybabel command [options] [args]
18
19 Options:
20 --version show program's version number and exit
21 -h, --help show this help message and exit
22 --list-locales print all known locales and exit
23 -v, --verbose print as much as possible
24 -q, --quiet print as little as possible
25
26 commands:
27 compile compile message catalogs to MO files
28 extract extract messages from source files and generate a POT file
29 init create new message catalogs from a POT file
30 update update existing message catalogs from a POT file
31
32 The ``pybabel`` script provides a number of sub-commands that do the actual
33 work. Those sub-commands are described below.
34
35
36 compile
37 =======
38
39 The ``compile`` sub-command can be used to compile translation catalogs into
40 binary MO files::
41
42 $ pybabel compile --help
43 Usage: pybabel compile [options]
44
45 compile message catalogs to MO files
46
47 Options:
48 -h, --help show this help message and exit
49 -D DOMAIN, --domain=DOMAIN
50 domains of PO files (space separated list, default
51 'messages')
52 -d DIRECTORY, --directory=DIRECTORY
53 path to base directory containing the catalogs
54 -i INPUT_FILE, --input-file=INPUT_FILE
55 name of the input file
56 -o OUTPUT_FILE, --output-file=OUTPUT_FILE
57 name of the output file (default
58 '<output_dir>/<locale>/LC_MESSAGES/<domain>.mo')
59 -l LOCALE, --locale=LOCALE
60 locale of the catalog to compile
61 -f, --use-fuzzy also include fuzzy translations
62 --statistics print statistics about translations
63
64 If ``directory`` is specified, but ``output-file`` is not, the default filename
65 of the output file will be::
66
67 <directory>/<locale>/LC_MESSAGES/<domain>.mo
68
69 If neither the ``input_file`` nor the ``locale`` option is set, this command
70 looks for all catalog files in the base directory that match the given domain,
71 and compiles each of them to MO files in the same directory.
72
73
74 extract
75 =======
76
77 The ``extract`` sub-command can be used to extract localizable messages from
78 a collection of source files::
79
80 $ pybabel extract --help
81 Usage: pybabel extract [options] <input-paths>
82
83 extract messages from source files and generate a POT file
84
85 Options:
86 -h, --help show this help message and exit
87 --charset=CHARSET charset to use in the output file (default "utf-8")
88 -k KEYWORDS, --keywords=KEYWORDS, --keyword=KEYWORDS
89 space-separated list of keywords to look for in
90 addition to the defaults (may be repeated multiple
91 times)
92 --no-default-keywords
93 do not include the default keywords
94 -F MAPPING_FILE, --mapping-file=MAPPING_FILE, --mapping=MAPPING_FILE
95 path to the mapping configuration file
96 --no-location do not include location comments with filename and
97 line number
98 --add-location=ADD_LOCATION
99 location lines format. If it is not given or "full",
100 it generates the lines with both file name and line
101 number. If it is "file", the line number part is
102 omitted. If it is "never", it completely suppresses
103 the lines (same as --no-location).
104 --omit-header do not include msgid "" entry in header
105 -o OUTPUT_FILE, --output-file=OUTPUT_FILE, --output=OUTPUT_FILE
106 name of the output file
107 -w WIDTH, --width=WIDTH
108 set output line width (default 76)
109 --no-wrap do not break long message lines, longer than the
110 output line width, into several lines
111 --sort-output generate sorted output (default False)
112 --sort-by-file sort output by file location (default False)
113 --msgid-bugs-address=MSGID_BUGS_ADDRESS
114 set report address for msgid
115 --copyright-holder=COPYRIGHT_HOLDER
116 set copyright holder in output
117 --project=PROJECT set project name in output
118 --version=VERSION set project version in output
119 -c ADD_COMMENTS, --add-comments=ADD_COMMENTS
120 place comment block with TAG (or those preceding
121 keyword lines) in output file. Separate multiple TAGs
122 with commas(,)
123 -s, --strip-comments, --strip-comment-tags
124 strip the comment TAGs from the comments.
125 --input-dirs=INPUT_DIRS
126 alias for input-paths (does allow files as well as
127 directories).
128 --ignore-dirs=IGNORE_DIRS
129 Patterns for directories to ignore when scanning for
130 messages. Separate multiple patterns with spaces
131 (default ".* ._")
132 --header-comment=HEADER_COMMENT
133 header comment for the catalog
134
135
136 The meaning of ``--keyword`` values is as follows:
137
138 - Pass a simple identifier like ``_`` to extract the first (and only the first)
139 argument of all function calls to ``_``,
140
141 - To extract other arguments than the first, add a colon and the argument
142 indices separated by commas. For example, the ``dngettext`` function
143 typically expects translatable strings as second and third arguments,
144 so you could pass ``dngettext:2,3``.
145
146 - Some arguments should not be interpreted as translatable strings, but
147 context strings. For that, append "c" to the argument index. For example:
148 ``pgettext:1c,2``.
149
150 - In C++ and Python, you may have functions that behave differently
151 depending on how many arguments they take. For this use case, you can
152 add an integer followed by "t" after the colon. In this case, the
153 keyword will only match a function invocation if it has the specified
154 total number of arguments. For example, if you have a function
155 ``foo`` that behaves as ``gettext`` (argument is a message) or
156 ``pgettext`` (arguments are a context and a message) depending on
157 whether it takes one or two arguments, you can pass
158 ``--keyword=foo:1,1t --keyword=foo:1c,2,2t``.
159
160 The default keywords are equivalent to passing ::
161
162 --keyword=_
163 --keyword=gettext
164 --keyword=ngettext:1,2
165 --keyword=ugettext
166 --keyword=ungettext:1,2
167 --keyword=dgettext:2
168 --keyword=dngettext:2,3
169 --keyword=N_
170 --keyword=pgettext:1c,2
171 --keyword=npgettext:1c,2,3
172
173
174
175 init
176 ====
177
178 The `init` sub-command creates a new translations catalog based on a PO
179 template file::
180
181 $ pybabel init --help
182 Usage: pybabel init [options]
183
184 create new message catalogs from a POT file
185
186 Options:
187 -h, --help show this help message and exit
188 -D DOMAIN, --domain=DOMAIN
189 domain of PO file (default 'messages')
190 -i INPUT_FILE, --input-file=INPUT_FILE
191 name of the input file
192 -d OUTPUT_DIR, --output-dir=OUTPUT_DIR
193 path to output directory
194 -o OUTPUT_FILE, --output-file=OUTPUT_FILE
195 name of the output file (default
196 '<output_dir>/<locale>/LC_MESSAGES/<domain>.po')
197 -l LOCALE, --locale=LOCALE
198 locale for the new localized catalog
199 -w WIDTH, --width=WIDTH
200 set output line width (default 76)
201 --no-wrap do not break long message lines, longer than the
202 output line width, into several lines
203
204 update
205 ======
206
207 The `update` sub-command updates an existing new translations catalog based on
208 a PO template file::
209
210 $ pybabel update --help
211 Usage: pybabel update [options]
212
213 update existing message catalogs from a POT file
214
215 Options:
216 -h, --help show this help message and exit
217 -D DOMAIN, --domain=DOMAIN
218 domain of PO file (default 'messages')
219 -i INPUT_FILE, --input-file=INPUT_FILE
220 name of the input file
221 -d OUTPUT_DIR, --output-dir=OUTPUT_DIR
222 path to base directory containing the catalogs
223 -o OUTPUT_FILE, --output-file=OUTPUT_FILE
224 name of the output file (default
225 '<output_dir>/<locale>/LC_MESSAGES/<domain>.po')
226 --omit-header do not include msgid entry in header
227 -l LOCALE, --locale=LOCALE
228 locale of the catalog to compile
229 -w WIDTH, --width=WIDTH
230 set output line width (default 76)
231 --no-wrap do not break long message lines, longer than the
232 output line width, into several lines
233 --ignore-obsolete whether to omit obsolete messages from the output
234 --init-missing if any output files are missing, initialize them first
235 -N, --no-fuzzy-matching
236 do not use fuzzy matching
237 --update-header-comment
238 update target header comment
239 --previous keep previous msgids of translated messages
240
241
242 If ``output_dir`` is specified, but ``output-file`` is not, the default
243 filename of the output file will be::
244
245 <directory>/<locale>/LC_MESSAGES/<domain>.mo
246
247 If neither the ``output_file`` nor the ``locale`` option is set, this command
248 looks for all catalog files in the base directory that match the given domain,
249 and updates each of them.