After preparing the sources, the programmer creates a PO template file.
This section explains how to use xgettext
for this purpose.
xgettext
creates a file named ‘domainname.po’. You
should then rename it to ‘domainname.pot’. (Why doesn't
xgettext
create it under the name ‘domainname.pot’
right away? The answer is: for historical reasons. When xgettext
was specified, the distinction between a PO file and PO file template
was fuzzy, and the suffix ‘.pot’ wasn't in use at that time.)
xgettext
Programxgettext [option] [inputfile] ...
The xgettext
program extracts translatable strings from given
input files.
If inputfile is ‘-’, standard input is read.
If the output file is ‘-’ or ‘/dev/stdout’, the output is written to standard output.
C
, C++
, ObjectiveC
, PO
, Shell
,
Python
, Lisp
, EmacsLisp
, librep
, Scheme
,
Smalltalk
, Java
, JavaProperties
, C#
, awk
,
YCP
, Tcl
, Perl
, PHP
, GCC-source
,
NXStringTable
, RST
, Glade
, Lua
, JavaScript
,
Vala
, GSettings
, Desktop
.
--language=C++
.
By default the language is guessed depending on the input file name extension.
By default the input files are assumed to be in ASCII.
/* This is the first comment. */ gettext ("foo"); /* This is the second comment: not extracted */ gettext ( "bar"); gettext ( /* This is the third comment. */ "baz");The second comment line will not be extracted, because there is one blank line between the comment line and the keyword.
...
"'`
*
or -
xgettext:
special comment in the source file. For example, if you specify the
--check=space-ellipsis
option, but want to suppress the check on
a particular string, add the following comment:
/* xgettext: no-space-ellipsis-check */ gettext ("We really want a space before ellipsis here ...");The
xgettext:
comment can be followed by flags separated with a
comma. The possible flags are of the form ‘[no-]name-check’,
where name is the name of a valid syntax check. If a flag is
prefixed by no-
, the meaning is negated.
Some tests apply the checks to each sentence within the msgid, rather
than the whole string. xgettext detects the end of sentence by
performing a pattern match, which usually looks for a period followed by
a certain number of spaces. The number is specified with the
--sentence-end
option.
xgettext
looks
for strings in the first argument of each call to the function or macro
id. If keywordspec is of the form
‘id:argnum’, xgettext
looks for strings in the
argnumth argument of the call. If keywordspec is of the form
‘id:argnum1,argnum2’, xgettext
looks for
strings in the argnum1st argument and in the argnum2nd argument
of the call, and treats them as singular/plural variants for a message
with plural handling. Also, if keywordspec is of the form
‘id:contextargnumc,argnum’ or
‘id:argnum,contextargnumc’, xgettext
treats
strings in the contextargnumth argument as a context specifier.
And, as a special-purpose support for GNOME, if keywordspec is of the
form ‘id:argnumg’, xgettext
recognizes the
argnumth argument as a string with context, using the GNOME glib
syntax ‘"msgctxt|msgid"’.
xgettext
recognizes this
argument specification only if the number of actual arguments is equal to
totalnumargs. This is useful for disambiguating overloaded function
calls in C++.
xgettext
, when
extracting a message from the specified argument strings, adds an extracted
comment xcomment to the message. Note that when used through a normal
shell command line, the double-quotes around the xcomment need to be
escaped.
This option has an effect with most languages, namely C, C++, ObjectiveC,
Shell, Python, Lisp, EmacsLisp, librep, Java, C#, awk, Tcl, Perl, PHP,
GCC-source, Glade, Lua, JavaScript, Vala, GSettings, Desktop.
The default keyword specifications, which are always looked for if not
explicitly disabled, are language dependent. They are:
gettext
, dgettext:2
,
dcgettext:2
, ngettext:1,2
, dngettext:2,3
,
dcngettext:2,3
, gettext_noop
, and pgettext:1c,2
,
dpgettext:2c,3
, dcpgettext:2c,3
, npgettext:1c,2,3
,
dnpgettext:2c,3,4
, dcnpgettext:2c,3,4
.
NSLocalizedString
, _
,
NSLocalizedStaticString
, __
.
gettext
, ngettext:1,2
, eval_gettext
,
eval_ngettext:1,2
.
gettext
, ugettext
, dgettext:2
,
ngettext:1,2
, ungettext:1,2
, dngettext:2,3
, _
.
gettext
, ngettext:1,2
, gettext-noop
.
_
.
_
.
gettext
, ngettext:1,2
, gettext-noop
.
GettextResource.gettext:2
,
GettextResource.ngettext:2,3
, GettextResource.pgettext:2c,3
,
GettextResource.npgettext:2c,3,4
, gettext
, ngettext:1,2
,
pgettext:1c,2
, npgettext:1c,2,3
, getString
.
GetString
, GetPluralString:1,2
,
GetParticularString:1c,2
, GetParticularPluralString:1c,2,3
.
dcgettext
, dcngettext:1,2
.
::msgcat::mc
.
gettext
, %gettext
, $gettext
, dgettext:2
,
dcgettext:2
, ngettext:1,2
, dngettext:2,3
,
dcngettext:2,3
, gettext_noop
.
_
, gettext
, dgettext:2
, dcgettext:2
,
ngettext:1,2
, dngettext:2,3
, dcngettext:2,3
.
label
, title
, text
, format
,
copyright
, comments
, preview_text
, tooltip
.
_
, gettext.gettext
, gettext.dgettext:2
,
gettext.dcgettext:2
, gettext.ngettext:1,2
,
gettext.dngettext:2,3
, gettext.dcngettext:2,3
.
_
, gettext
, dgettext:2
,
dcgettext:2
, ngettext:1,2
, dngettext:2,3
,
pgettext:1c,2
, dpgettext:2c,3
.
_
, Q_
, N_
, NC_
, dgettext:2
,
dcgettext:2
, ngettext:1,2
, dngettext:2,3
,
dpgettext:2c,3
, dpgettext2:2c,3
.
Name
, GenericName
, Comment
,
Icon
, Keywords
.
--flag=function:arg:lang-format
is that in language lang, the specified function expects as
argth argument a format string. (For those of you familiar with
GCC function attributes, --flag=function:arg:c-format
is
roughly equivalent to the declaration
‘__attribute__ ((__format__ (__printf__, arg, ...)))’ attached
to function in a C source file.)
For example, if you use the ‘error’ function from GNU libc, you can
specify its behaviour through --flag=error:3:c-format
. The effect of
this specification is that xgettext
will mark as format strings all
gettext
invocations that occur as argth argument of
function.
This is useful when such strings contain no format string directives:
together with the checks done by ‘msgfmt -c’ it will ensure that
translators cannot accidentally use format string directives that would
lead to a crash at runtime.
--flag=function:arg:pass-lang-format
is that in language lang, if the function call occurs in a
position that must yield a format string, then its argth argument
must yield a format string of the same type as well. (If you know GCC
function attributes, the --flag=function:arg:pass-c-format
option is roughly equivalent to the declaration
‘__attribute__ ((__format_arg__ (arg)))’ attached to function
in a C source file.)
For example, if you use the ‘_’ shortcut for the gettext
function,
you should use --flag=_:1:pass-c-format
. The effect of this
specification is that xgettext
will propagate a format string
requirement for a _("string")
call to its first argument, the literal
"string"
, and thus mark it as a format string.
This is useful when such strings contain no format string directives:
together with the checks done by ‘msgfmt -c’ it will ensure that
translators cannot accidentally use format string directives that would
lead to a crash at runtime.
c-format
and possible-c-format
to show who was
responsible for marking a message as a format string. The latter form is
used if the xgettext
program decided, the former form is used if
the programmer prescribed it.
By default only the c-format
form is used. The translator should
not have to care about these details.
This implementation of xgettext
is able to process a few awkward
cases, like strings in preprocessor macros, ANSI concatenation of
adjacent strings, and escaped end of lines for continued strings.
--color
option for details.
--color
.
See section 9.11.3 The --style
option for details.
--no-location
).
.properties
syntax. Note
that this file format doesn't support plural forms and silently drops
obsolete messages.
.strings
syntax.
Note that this file format doesn't support plural forms.
.gmo
files. With --omit-header
,
two invocations of xgettext
on the same files with the same
options at different times are guaranteed to produce the same results.
Note that using this option will lead to an error if the resulting file
would not entirely be in ASCII.
xgettext
was first used in the GNU project.
Go to the first, previous, next, last section, table of contents.