xref: /netbsd-src/external/gpl2/gettext/dist/gettext-tools/doc/xgettext.texi (revision 946379e7b37692fc43f68eb0d1c10daa0a7f3b6c)
1@pindex xgettext
2@cindex @code{xgettext} program, usage
3@example
4xgettext [@var{option}] [@var{inputfile}] @dots{}
5@end example
6
7The @code{xgettext} program extracts translatable strings from given
8input files.
9
10@subsection Input file location
11
12@table @samp
13@item @var{inputfile} @dots{}
14Input files.
15
16@item -f @var{file}
17@itemx --files-from=@var{file}
18@opindex -f@r{, @code{xgettext} option}
19@opindex --files-from@r{, @code{xgettext} option}
20Read the names of the input files from @var{file} instead of getting
21them from the command line.
22
23@item -D @var{directory}
24@itemx --directory=@var{directory}
25@opindex -D@r{, @code{xgettext} option}
26@opindex --directory@r{, @code{xgettext} option}
27Add @var{directory} to the list of directories.  Source files are
28searched relative to this list of directories.  The resulting @file{.po}
29file will be written relative to the current directory, though.
30
31@end table
32
33If @var{inputfile} is @samp{-}, standard input is read.
34
35@subsection Output file location
36
37@table @samp
38@item -d @var{name}
39@itemx --default-domain=@var{name}
40@opindex -d@r{, @code{xgettext} option}
41@opindex --default-domain@r{, @code{xgettext} option}
42Use @file{@var{name}.po} for output (instead of @file{messages.po}).
43
44@item -o @var{file}
45@itemx --output=@var{file}
46@opindex -o@r{, @code{xgettext} option}
47@opindex --output@r{, @code{xgettext} option}
48Write output to specified file (instead of @file{@var{name}.po} or
49@file{messages.po}).
50
51@item -p @var{dir}
52@itemx --output-dir=@var{dir}
53@opindex -p@r{, @code{xgettext} option}
54@opindex --output-dir@r{, @code{xgettext} option}
55Output files will be placed in directory @var{dir}.
56
57@end table
58
59@cindex output to stdout, @code{xgettext}
60If the output @var{file} is @samp{-} or @samp{/dev/stdout}, the output
61is written to standard output.
62
63@subsection Choice of input file language
64
65@table @samp
66@item -L @var{name}
67@itemx --language=@var{name}
68@opindex -L@r{, @code{xgettext} option}
69@opindex --language@r{, @code{xgettext} option}
70@cindex supported languages, @code{xgettext}
71Specifies the language of the input files.  The supported languages
72are @code{C}, @code{C++}, @code{ObjectiveC}, @code{PO}, @code{Python},
73@code{Lisp}, @code{EmacsLisp}, @code{librep}, @code{Scheme}, @code{Smalltalk},
74@code{Java}, @code{JavaProperties}, @code{C#}, @code{awk}, @code{YCP},
75@code{Tcl}, @code{Perl}, @code{PHP}, @code{GCC-source}, @code{NXStringTable},
76@code{RST}, @code{Glade}.
77
78@item -C
79@itemx --c++
80@opindex -C@r{, @code{xgettext} option}
81@opindex --c++@r{, @code{xgettext} option}
82This is a shorthand for @code{--language=C++}.
83
84@end table
85
86By default the language is guessed depending on the input file name
87extension.
88
89@subsection Input file interpretation
90
91@table @samp
92@item --from-code=@var{name}
93@opindex --from-code@r{, @code{xgettext} option}
94Specifies the encoding of the input files.  This option is needed only
95if some untranslated message strings or their corresponding comments
96contain non-ASCII characters.  Note that Tcl and Glade input files are
97always assumed to be in UTF-8, regardless of this option.
98
99@end table
100
101By default the input files are assumed to be in ASCII.
102
103@subsection Operation mode
104
105@table @samp
106@item -j
107@itemx --join-existing
108@opindex -j@r{, @code{xgettext} option}
109@opindex --join-existing@r{, @code{xgettext} option}
110Join messages with existing file.
111
112@item -x @var{file}
113@itemx --exclude-file=@var{file}
114@opindex -x@r{, @code{xgettext} option}
115@opindex --exclude-file@r{, @code{xgettext} option}
116Entries from @var{file} are not extracted.  @var{file} should be a PO or
117POT file.
118
119@item -c [@var{tag}]
120@itemx --add-comments[=@var{tag}]
121@opindex -c@r{, @code{xgettext} option}
122@opindex --add-comments@r{, @code{xgettext} option}
123Place comment block with @var{tag} (or those preceding keyword lines)
124in output file.
125
126@end table
127
128@subsection Language specific options
129
130@table @samp
131@item -a
132@itemx --extract-all
133@opindex -a@r{, @code{xgettext} option}
134@opindex --extract-all@r{, @code{xgettext} option}
135Extract all strings.
136
137This option has an effect with most languages, namely C, C++, ObjectiveC,
138Shell, Python, Lisp, EmacsLisp, librep, Java, C#, awk, Tcl, Perl, PHP,
139GCC-source, Glade.
140
141@item -k @var{keywordspec}
142@itemx --keyword[=@var{keywordspec}]
143@opindex -k@r{, @code{xgettext} option}
144@opindex --keyword@r{, @code{xgettext} option}
145Additional keyword to be looked for (without @var{keywordspec} means not to
146use default keywords).
147
148@cindex adding keywords, @code{xgettext}
149@cindex context, argument specification in @code{xgettext}
150If @var{keywordspec} is a C identifier @var{id}, @code{xgettext} looks
151for strings in the first argument of each call to the function or macro
152@var{id}.  If @var{keywordspec} is of the form
153@samp{@var{id}:@var{argnum}}, @code{xgettext} looks for strings in the
154@var{argnum}th argument of the call.  If @var{keywordspec} is of the form
155@samp{@var{id}:@var{argnum1},@var{argnum2}}, @code{xgettext} looks for
156strings in the @var{argnum1}st argument and in the @var{argnum2}nd argument
157of the call, and treats them as singular/plural variants for a message
158with plural handling.  Also, if @var{keywordspec} is of the form
159@samp{@var{id}:@var{contextargnum}c,@var{argnum}} or
160@samp{@var{id}:@var{argnum},@var{contextargnum}c}, @code{xgettext} treats
161strings in the @var{contextargnum}th argument as a context specifier.
162And, as a special-purpose support for GNOME, if @var{keywordspec} is of the
163form @samp{@var{id}:@var{argnum}g}, @code{xgettext} recognizes the
164@var{argnum}th argument as a string with context, using the GNOME @code{glib}
165syntax @samp{"msgctxt|msgid"}.
166@*
167Furthermore, if @var{keywordspec} is of the form
168@samp{@var{id}:@dots{},@var{totalnumargs}t}, @code{xgettext} recognizes this
169argument specification only if the number of actual arguments is equal to
170@var{totalnumargs}.  This is useful for disambiguating overloaded function
171calls in C++.
172@*
173Finally, if @var{keywordspec} is of the form
174@samp{@var{id}:@var{argnum}...,"@var{xcomment}"}, @code{xgettext}, when
175extracting a message from the specified argument strings, adds an extracted
176comment @var{xcomment} to the message.  Note that when used through a normal
177shell command line, the double-quotes around the @var{xcomment} need to be
178escaped.
179
180This option has an effect with most languages, namely C, C++, ObjectiveC,
181Shell, Python, Lisp, EmacsLisp, librep, Java, C#, awk, Tcl, Perl, PHP,
182GCC-source, Glade.
183
184The default keyword specifications, which are always looked for if not
185explicitly disabled, are language dependent.  They are:
186
187@itemize
188@item
189For C, C++, and GCC-source: @code{gettext}, @code{dgettext:2},
190@code{dcgettext:2}, @code{ngettext:1,2}, @code{dngettext:2,3},
191@code{dcngettext:2,3}, @code{gettext_noop}, and @code{pgettext:1c,2},
192@code{dpgettext:2c,3}, @code{dcpgettext:2c,3}, @code{npgettext:1c,2,3},
193@code{dnpgettext:2c,3,4}, @code{dcnpgettext:2c,3,4}.
194
195@item
196For Objective C: Like for C, and also @code{NSLocalizedString}, @code{_},
197@code{NSLocalizedStaticString}, @code{__}.
198
199@item
200For Shell scripts: @code{gettext}, @code{ngettext:1,2}, @code{eval_gettext},
201@code{eval_ngettext:1,2}.
202
203@item
204For Python: @code{gettext}, @code{ugettext}, @code{dgettext:2},
205@code{ngettext:1,2}, @code{ungettext:1,2}, @code{dngettext:2,3}, @code{_}.
206
207@item
208For Lisp: @code{gettext}, @code{ngettext:1,2}, @code{gettext-noop}.
209
210@item
211For EmacsLisp: @code{_}.
212
213@item
214For librep: @code{_}.
215
216@item
217For Scheme: @code{gettext}, @code{ngettext:1,2}, @code{gettext-noop}.
218
219@item
220For Java: @code{GettextResource.gettext:2},
221@code{GettextResource.ngettext:2,3}, @code{gettext}, @code{ngettext:1,2},
222@code{getString}.
223
224@item
225For C#: @code{GetString}, @code{GetPluralString:1,2}.
226
227@item
228For awk: @code{dcgettext}, @code{dcngettext:1,2}.
229
230@item
231For Tcl: @code{::msgcat::mc}.
232
233@item
234For Perl: @code{gettext}, @code{%gettext}, @code{$gettext}, @code{dgettext:2},
235@code{dcgettext:2}, @code{ngettext:1,2}, @code{dngettext:2,3},
236@code{dcngettext:2,3}, @code{gettext_noop}.
237
238@item
239For PHP: @code{_}, @code{gettext}, @code{dgettext:2}, @code{dcgettext:2},
240@code{ngettext:1,2}, @code{dngettext:2,3}, @code{dcngettext:2,3}.
241
242@item
243For Glade 1: @code{label}, @code{title}, @code{text}, @code{format},
244@code{copyright}, @code{comments}, @code{preview_text}, @code{tooltip}.
245@end itemize
246
247To disable the default keyword specifications, the option @samp{-k} or
248@samp{--keyword} or @samp{--keyword=}, without a @var{keywordspec}, can be
249used.
250
251@item --flag=@var{word}:@var{arg}:@var{flag}
252@opindex --flag@r{, @code{xgettext} option}
253Specifies additional flags for strings occurring as part of the @var{arg}th
254argument of the function @var{word}.  The possible flags are the possible
255format string indicators, such as @samp{c-format}, and their negations,
256such as @samp{no-c-format}, possibly prefixed with @samp{pass-}.
257@*
258@cindex function attribute, __format__
259The meaning of @code{--flag=@var{function}:@var{arg}:@var{lang}-format}
260is that in language @var{lang}, the specified @var{function} expects as
261@var{arg}th argument a format string.  (For those of you familiar with
262GCC function attributes, @code{--flag=@var{function}:@var{arg}:c-format} is
263roughly equivalent to the declaration
264@samp{__attribute__ ((__format__ (__printf__, @var{arg}, ...)))} attached
265to @var{function} in a C source file.)
266For example, if you use the @samp{error} function from GNU libc, you can
267specify its behaviour through @code{--flag=error:3:c-format}.  The effect of
268this specification is that @code{xgettext} will mark as format strings all
269@code{gettext} invocations that occur as @var{arg}th argument of
270@var{function}.
271This is useful when such strings contain no format string directives:
272together with the checks done by @samp{msgfmt -c} it will ensure that
273translators cannot accidentally use format string directives that would
274lead to a crash at runtime.
275@*
276@cindex function attribute, __format_arg__
277The meaning of @code{--flag=@var{function}:@var{arg}:pass-@var{lang}-format}
278is that in language @var{lang}, if the @var{function} call occurs in a
279position that must yield a format string, then its @var{arg}th argument
280must yield a format string of the same type as well.  (If you know GCC
281function attributes, the @code{--flag=@var{function}:@var{arg}:pass-c-format}
282option is roughly equivalent to the declaration
283@samp{__attribute__ ((__format_arg__ (@var{arg})))} attached to @var{function}
284in a C source file.)
285For example, if you use the @samp{_} shortcut for the @code{gettext} function,
286you should use @code{--flag=_:1:pass-c-format}.  The effect of this
287specification is that @code{xgettext} will propagate a format string
288requirement for a @code{_("string")} call to its first argument, the literal
289@code{"string"}, and thus mark it as a format string.
290This is useful when such strings contain no format string directives:
291together with the checks done by @samp{msgfmt -c} it will ensure that
292translators cannot accidentally use format string directives that would
293lead to a crash at runtime.
294@*
295This option has an effect with most languages, namely C, C++, ObjectiveC,
296Shell, Python, Lisp, EmacsLisp, librep, Scheme, Java, C#, awk, YCP, Tcl, Perl, PHP,
297GCC-source.
298
299@item -T
300@itemx --trigraphs
301@opindex -T@r{, @code{xgettext} option}
302@opindex --trigraphs@r{, @code{xgettext} option}
303@cindex C trigraphs
304Understand ANSI C trigraphs for input.
305@*
306This option has an effect only with the languages C, C++, ObjectiveC.
307
308@item --qt
309@opindex --qt@r{, @code{xgettext} option}
310@cindex Qt format strings
311Recognize Qt format strings.
312@*
313This option has an effect only with the language C++.
314
315@item --boost
316@opindex --boost@r{, @code{xgettext} option}
317@cindex Boost format strings
318Recognize Boost format strings.
319@*
320This option has an effect only with the language C++.
321
322@item --debug
323@opindex --debug@r{, @code{xgettext} option}
324@cindex debugging messages marked as format strings
325Use the flags @code{c-format} and @code{possible-c-format} to show who was
326responsible for marking a message as a format string.  The latter form is
327used if the @code{xgettext} program decided, the format form is used if
328the programmer prescribed it.
329
330By default only the @code{c-format} form is used.  The translator should
331not have to care about these details.
332
333@end table
334
335This implementation of @code{xgettext} is able to process a few awkward
336cases, like strings in preprocessor macros, ANSI concatenation of
337adjacent strings, and escaped end of lines for continued strings.
338
339@subsection Output details
340
341@c --no-escape and --escape omitted on purpose.  They are not useful.
342
343@table @samp
344@item --force-po
345@opindex --force-po@r{, @code{xgettext} option}
346Always write an output file even if no message is defined.
347
348@item -i
349@itemx --indent
350@opindex -i@r{, @code{xgettext} option}
351@opindex --indent@r{, @code{xgettext} option}
352Write the .po file using indented style.
353
354@item --no-location
355@opindex --no-location@r{, @code{xgettext} option}
356Do not write @samp{#: @var{filename}:@var{line}} lines.
357
358@item -n
359@itemx --add-location
360@opindex -n@r{, @code{xgettext} option}
361@opindex --add-location@r{, @code{xgettext} option}
362Generate @samp{#: @var{filename}:@var{line}} lines (default).
363
364@item --strict
365@opindex --strict@r{, @code{xgettext} option}
366Write out a strict Uniforum conforming PO file.  Note that this
367Uniforum format should be avoided because it doesn't support the
368GNU extensions.
369
370@item --properties-output
371@opindex --properties-output@r{, @code{xgettext} option}
372Write out a Java ResourceBundle in Java @code{.properties} syntax.  Note
373that this file format doesn't support plural forms and silently drops
374obsolete messages.
375
376@item --stringtable-output
377@opindex --stringtable-output@r{, @code{xgettext} option}
378Write out a NeXTstep/GNUstep localized resource file in @code{.strings} syntax.
379Note that this file format doesn't support plural forms.
380
381@item -w @var{number}
382@itemx --width=@var{number}
383@opindex -w@r{, @code{xgettext} option}
384@opindex --width@r{, @code{xgettext} option}
385Set the output page width.  Long strings in the output files will be
386split across multiple lines in order to ensure that each line's width
387(= number of screen columns) is less or equal to the given @var{number}.
388
389@item --no-wrap
390@opindex --no-wrap@r{, @code{xgettext} option}
391Do not break long message lines.  Message lines whose width exceeds the
392output page width will not be split into several lines.  Only file reference
393lines which are wider than the output page width will be split.
394
395@item -s
396@itemx --sort-output
397@opindex -s@r{, @code{xgettext} option}
398@opindex --sort-output@r{, @code{xgettext} option}
399@cindex sorting output of @code{xgettext}
400Generate sorted output.  Note that using this option makes it much harder
401for the translator to understand each message's context.
402
403@item -F
404@itemx --sort-by-file
405@opindex -F@r{, @code{xgettext} option}
406@opindex --sort-by-file@r{, @code{xgettext} option}
407Sort output by file location.
408
409@item --omit-header
410@opindex --omit-header@r{, @code{xgettext} option}
411Don't write header with @samp{msgid ""} entry.
412
413@cindex testing @file{.po} files for equivalence
414This is useful for testing purposes because it eliminates a source
415of variance for generated @code{.gmo} files.  With @code{--omit-header},
416two invocations of @code{xgettext} on the same files with the same
417options at different times are guaranteed to produce the same results.
418
419@item --copyright-holder=@var{string}
420@opindex --copyright-holder@r{, @code{xgettext} option}
421Set the copyright holder in the output.  @var{string} should be the
422copyright holder of the surrounding package.  (Note that the msgstr
423strings, extracted from the package's sources, belong to the copyright
424holder of the package.)  Translators are expected to transfer or disclaim
425the copyright for their translations, so that package maintainers can
426distribute them without legal risk.  If @var{string} is empty, the output
427files are marked as being in the public domain; in this case, the translators
428are expected to disclaim their copyright, again so that package maintainers
429can distribute them without legal risk.
430
431The default value for @var{string} is the Free Software Foundation, Inc.,
432simply because @code{xgettext} was first used in the GNU project.
433
434@item --foreign-user
435@opindex --foreign-user@r{, @code{xgettext} option}
436Omit FSF copyright in output.  This option is equivalent to
437@samp{--copyright-holder=''}.  It can be useful for packages outside the GNU
438project that want their translations to be in the public domain.
439
440@item --msgid-bugs-address=@var{email@@address}
441@opindex --msgid-bugs-address@r{, @code{xgettext} option}
442Set the reporting address for msgid bugs.  This is the email address or URL
443to which the translators shall report bugs in the untranslated strings:
444
445@itemize -
446@item Strings which are not entire sentences, see the maintainer guidelines
447in @ref{Preparing Strings}.
448@item Strings which use unclear terms or require additional context to be
449understood.
450@item Strings which make invalid assumptions about notation of date, time or
451money.
452@item Pluralisation problems.
453@item Incorrect English spelling.
454@item Incorrect formatting.
455@end itemize
456
457It can be your email address, or a mailing list address where translators
458can write to without being subscribed, or the URL of a web page through
459which the translators can contact you.
460
461The default value is empty, which means that translators will be clueless!
462Don't forget to specify this option.
463
464@item -m [@var{string}]
465@itemx --msgstr-prefix[=@var{string}]
466@opindex -m@r{, @code{xgettext} option}
467@opindex --msgstr-prefix@r{, @code{xgettext} option}
468Use @var{string} (or "" if not specified) as prefix for msgstr entries.
469
470@item -M [@var{string}]
471@itemx --msgstr-suffix[=@var{string}]
472@opindex -M@r{, @code{xgettext} option}
473@opindex --msgstr-suffix@r{, @code{xgettext} option}
474Use @var{string} (or "" if not specified) as suffix for msgstr entries.
475
476@end table
477
478@subsection Informative output
479
480@table @samp
481@item -h
482@itemx --help
483@opindex -h@r{, @code{xgettext} option}
484@opindex --help@r{, @code{xgettext} option}
485Display this help and exit.
486
487@item -V
488@itemx --version
489@opindex -V@r{, @code{xgettext} option}
490@opindex --version@r{, @code{xgettext} option}
491Output version information and exit.
492
493@end table
494