Extract translatable strings from given input files
- Invocation
- Copyright
Usage:
esgettext-xgettext [OPTIONS] [INPUTFILE]...
The script esgettext-xgettext
extracts strings from your JavaScript/TypeScript
and HTML (todo!) sources. Its command-line interface is mostly compatible
with xgettext
from GNU
gettext.
All non-option command-line arguments are treated as input source files to
scan for translatable messages. But in general you will use the option
--files-from
to pass the list of input source files.
Get the list of input files from FILE
.
By convention, this file is called POTFILES
.
If an input file is -
, standard input is read.
Add DIRECTORY
to the list of directories to search for input files.
You can also specify this as esgettext.directory
in package.json
with
the option --package-json
.
Use NAME.po
as output (instead of messages.po
).
You can also specify this as esgettext.textdomain
in package.json
with
the option --package-json
.
Write output to the specified file. If the output file is -
, output is
written to standard output.
The value will be intelligently guessed from your package.json
with
the option --package-json
.
Place output files in the specified directory.
Assume the specified language (JavaScript, TypeScript, HTML). TODO! HTML is not yet supported.
By default, the language is guessed depending on the input file name extension.
Assume NAME
as the encoding of input files.
By default the input files are assumed to be in ASCII.
Join messages with existing output file.
Entries from FILE.po
are not extracted.
Place comment blocks starting with TAG and preceding keyword lines in output
file. By convention, TAG
is normally the string TRANSLATORS:
.
Example:
// TRANSLATORS: "Sun" is the abbreviation for "Sunday", not our star.
days[0] = gtx.gettext('Sun');
Place all comment blocks preceding keyword lines in output file.
Extract all strings.
Look for WORD
as an additional keyword. Passing the option without an argument
sets the list of recognized keywords to the empty list.
If you are using @esgettext/runtime, and just use the supported keywords, you don't have to bother about specifying keywords yourself because the default list will do for you.
In its simplest form, a keyword is just the name of a method or function:
$ esgettext-xgettext --keyword=gettext
This would extract the (first!) argument of gettext('Hello, world!')
or
some.object.gettext('Hello, world!')
.
It is equivalent to this invocation:
$ esgettext-xgettext --keyword=gettext:1
This translates to "extract the 1st argument of all invocations to gettext()
".
If a function has a singular and plural argument, you can specify that like this:
$ esgettext-xgettext --keyword=ngettext:1,2
This would extract the first argument to ngettext()
as the singular form, and
the second argument as the plural form. The first number is always treated as
the index of the singular, and the second one as the index of the plural
argument.
If the function also has a message context argument, you can specify this as follows:
$ esgettext-xgettext --keyword=npgettext:1c,2,3
The first argument is then treated as the message context, the second one is the singular form, and the third argument is the plural form.
You an also specify the total number of arguments that you expect:
$ esgettext-xgettext --keyword=npgettext:1c,2,3,3t
Now, the invocation is only recognized when the total number of arguments is exactly 3.
Finally, you can also automatically add a comment to the output po file for certain keywords, by addding it in double-quotes:
$ esgettext-xgettext --keyword=npgettext:1c,2,3,"\"Plural and Context\""
This would add the comment "Plural and Context" to each extracted entry in the po file.
Note that you have to escape the double-quotes from the shell. A slightly more readable way to do this is:
$ esgettext-xgettext --keyword=npgettext:1c,2,3,'"Plural and Context"'
Set additional flag FLAG
for the ARG
th argument to method WORD
. Passing
the option without an argument resets the list of flags to empty.
If you are using @esgettext/runtime, and just use the supported keywords, you don't have to bother about specifying flags yourself because the default list will do for you.
Flags are best explained with an example. The method __x()
for instance has the signature:
__x(MSGID, PLACEHOLDERS)
For example
__x("Hello, {name}!", { name: user.firstName })
The corresponding entry in the po file looks like this:
#, perl-brace-format
msgid "Hello, {name}!"
msgstr ""
This is achieved because the default list of flags contains
--flag=__x:1:perl-brace-format
with the meaning that the 1
st argument to
__x
should have the flag perl-brace-format
.
The flags can also be negated (--flag=__y:2:no-perl-brace-format
) or
prefixed with pass
(--flag=__z:3:pass-perl-brace-format
).
Only accept method calls of instances WORD
.
This is useful for avoiding false positives. For example, if you know that the
your Textdomain
instance is always called gtx
, you can pass
--instance=gtx
. This has the effect that arguments to gtx.__()
are
extracted but arguments to something.else.__()
are ignored.
Note that this option is specific to esgettext-xgettext
and not supported
by GNU xgettext.
The program normally terminates successfully without writing a catalog if the
catalog would be empty. The option --force-po
ensures that a catalog is
always written.
Sets the output page width to WIDTH
.
Do not break long message lines, longer than the output page width, into several lines.
Sort the entries in the output alphanumerically by msgid
(original string).
Sort the entries in the output alphanumerically by the filename of the corresponding source file.
Don't write header with msgid ""
entry.
This entry is the first one in po files and contains meta information about the catalog.
Read default values for catalog meta information in the header from the
JSON file FILENAME
(or package.json
if no filename argument is provided).
The following values for command-line options are supported:
{
"name": "PACKAGE-NAME",
"version": "PACKAGE-VERSION",
"author": "COPYRIGHT-HOLDER",
"bugs": {
"url": "MSGID-BUGS-ADDRESS"
},
"esgettext": {
"msgid-bugs-address": "MSGID-BUGS-ADDRESS",
"textdomain": "DOMAIN",
"directory": "DIRECTORY"
},
"output": "..."
}
The default value for the option --output
is guessed based on the textdomain
and output directory.
The value of esgettext.msgid-bugs-address
takes precedence over bugs.url
.
Note that this option is specific to esgettext-xgettext
and not supported
by GNU xgettext.
Set copyright holder in output.
You can also specify this as author
in package.json
with
the option --package-json
.
Omit Free Software Foundation (FSF) copyright in output for foreign user.
Set the package name in output.
You can also specify this as name
in package.json
with
the option --package-json
.
Set the package version in output.
You can also specify this as version
in package.json
with
the option --package-json
.
Set report address for msgid bugs
You can also specify this as esgettext.msgid-bugs-address
or bugs.url
in package.json
with the option --package-json
.
Use STRING
or "" as prefix for msgstr values.
Use STRING
or "" as suffix for msgstr values.
Display usage information
Display the tool's version.
Be verbose.
Copyright (C) 2020-2024 Guido Flohr [email protected], all rights reserved.
This software is available under the terms and conditions of the WFTPL.