This scons tool is a part of scons &t-link-gettext; toolset. It provides
scons interface to xgettext(1)
program, which extracts internationalized messages from source code. The tool
provides &b-POTUpdate; builder to make PO
Template files.
POTSUFFIX
POTUPDATE_ALIAS
XGETTEXTCOM
XGETTEXTCOMSTR
XGETTEXTFLAGS
XGETTEXTFROM
XGETTEXTFROMPREFIX
XGETTEXTFROMSUFFIX
XGETTEXTPATH
XGETTEXTPATHPREFIX
XGETTEXTPATHSUFFIX
_XGETTEXTDOMAIN
_XGETTEXTFROMFLAGS
_XGETTEXTPATHFLAGS
POTDOMAIN
The builder belongs to &t-link-xgettext; tool. The builder updates target
POT file if exists or creates one if it doesn't. The node is
not built by default (i.e. it is Ignored from
'.'), but only on demand (i.e. when given
POT file is required or when special alias is invoked). This
builder adds its targe node (messages.pot, say) to a
special alias (pot-update by default, see
&cv-link-POTUPDATE_ALIAS;) so you can update/create them easily with
scons pot-update. The file is not written until there is no
real change in internationalized messages (or in comments that enter
POT file).
You may see xgettext(1) being invoked by the
&t-link-xgettext; tool even if there is no real change in internationalized
messages (so the POT file is not being updated). This
happens every time a source file has changed. In such case we invoke
xgettext(1) and compare its output with the content of
POT file to decide whether the file should be updated or
not.
Example 1.
Let's create po/ directory and place following
SConstruct script there:
# SConstruct in 'po/' subdir
env = Environment( tools = ['default', 'xgettext'] )
env.POTUpdate(['foo'], ['../a.cpp', '../b.cpp'])
env.POTUpdate(['bar'], ['../c.cpp', '../d.cpp'])
Then invoke scons few times:
user@host:$ scons # Does not create foo.pot nor bar.pot
user@host:$ scons foo.pot # Updates or creates foo.pot
user@host:$ scons pot-update # Updates or creates foo.pot and bar.pot
user@host:$ scons -c # Does not clean foo.pot nor bar.pot.
the results shall be as the comments above say.
Example 2.
The &b-POTUpdate; builder may be used with no target specified, in which
case default target messages.pot will be used. The
default target may also be overriden by setting &cv-link-POTDOMAIN; construction
variable or providing it as an override to &b-POTUpdate; builder:
# SConstruct script
env = Environment( tools = ['default', 'xgettext'] )
env['POTDOMAIN'] = "foo"
env.POTUpdate(source = ["a.cpp", "b.cpp"]) # Creates foo.pot ...
env.POTUpdate(POTDOMAIN = "bar", source = ["c.cpp", "d.cpp"]) # and bar.pot
Example 3.
The sources may be specified within separate file, for example
POTFILES.in:
# POTFILES.in in 'po/' subdirectory
../a.cpp
../b.cpp
# end of file
The name of the file (POTFILES.in) containing the list of
sources is provided via &cv-link-XGETTEXTFROM;:
# SConstruct file in 'po/' subdirectory
env = Environment( tools = ['default', 'xgettext'] )
env.POTUpdate(XGETTEXTFROM = 'POTFILES.in')
Example 4.
You may use &cv-link-XGETTEXTPATH; to define source search path. Assume, for
example, that you have files a.cpp,
b.cpp, po/SConstruct,
po/POTFILES.in. Then your POT-related
files could look as below:
# POTFILES.in in 'po/' subdirectory
a.cpp
b.cpp
# end of file
# SConstruct file in 'po/' subdirectory
env = Environment( tools = ['default', 'xgettext'] )
env.POTUpdate(XGETTEXTFROM = 'POTFILES.in', XGETTEXTPATH='../')
Example 5.
Multiple search directories may be defined within a list, i.e.
XGETTEXTPATH = ['dir1', 'dir2', ...]. The order in the list
determines the search order of source files. The path to the first file found
is used.
Let's create 0/1/po/SConstruct script:
# SConstruct file in '0/1/po/' subdirectory
env = Environment( tools = ['default', 'xgettext'] )
env.POTUpdate(XGETTEXTFROM = 'POTFILES.in', XGETTEXTPATH=['../', '../../'])
and 0/1/po/POTFILES.in:
# POTFILES.in in '0/1/po/' subdirectory
a.cpp
# end of file
Write two *.cpp files, the first one is
0/a.cpp:
/* 0/a.cpp */
gettext("Hello from ../../a.cpp")
and the second is 0/1/a.cpp:
/* 0/1/a.cpp */
gettext("Hello from ../a.cpp")
then run scons. You'll obtain 0/1/po/messages.pot with the
message "Hello from ../a.cpp". When you reverse order in
$XGETTEXTFOM, i.e. when you write SConscript as
# SConstruct file in '0/1/po/' subdirectory
env = Environment( tools = ['default', 'xgettext'] )
env.POTUpdate(XGETTEXTFROM = 'POTFILES.in', XGETTEXTPATH=['../../', '../'])
then the messages.pot will contain
msgid "Hello from ../../a.cpp" line and not
msgid "Hello from ../a.cpp".
Suffix used for PO Template files (default: '.pot').
See &t-link-xgettext; tool and &b-link-POTUpdate; builder.
Name of the common phony target for all PO Templates created with
&b-link-POUpdate; (default: 'pot-update').
See &t-link-xgettext; tool and &b-link-POTUpdate; builder.
Path to xgettext(1) program (found via
Detect()).
See &t-link-xgettext; tool and &b-link-POTUpdate; builder.
Complete xgettext command line.
See &t-link-xgettext; tool and &b-link-POTUpdate; builder.
A string that is shown when xgettext(1) command is invoked
(default: '', which means "print &cv-link-XGETTEXTCOM;").
See &t-link-xgettext; tool and &b-link-POTUpdate; builder.
Additional flags to xgettext(1).
See &t-link-xgettext; tool and &b-link-POTUpdate; builder.
Name of file containing list of xgettext(1)'s source
files. Autotools' users know this as POTFILES.in so they
will in most cases set XGETTEXTFROM="POTFILES.in" here.
The &cv-XGETTEXTFROM; files have same syntax and semantics as the well known
GNU POTFILES.in.
See &t-link-xgettext; tool and &b-link-POTUpdate; builder.
List of directories, there xgettext(1) will look for
source files (default: []).
This variable works only together with &cv-link-XGETTEXTFROM;
See also &t-link-xgettext; tool and &b-link-POTUpdate; builder.
This flag is used to add single search path to
xgettext(1)'s commandline (default:
'-D').
(default: '')
This flag is used to add single &cv-link-XGETTEXTFROM; file to
xgettext(1)'s commandline (default:
'-f').
(default: '')
Internal "macro". Generates xgettext domain name
form source and target (default: '${TARGET.filebase}').
Internal "macro". Genrates list of -D<dir> flags
from the &cv-link-XGETTEXTPATH; list.
Internal "macro". Generates list of -f<file> flags
from &cv-link-XGETTEXTFROM;.