5 This file is processed by the bin/SConsDoc.py module.
6 See its __doc__ string for a discussion of the format.
10 <!ENTITY % scons SYSTEM '../../doc/scons.mod'>
12 <!ENTITY % builders-mod SYSTEM '../../doc/generated/builders.mod'>
14 <!ENTITY % functions-mod SYSTEM '../../doc/generated/functions.mod'>
16 <!ENTITY % tools-mod SYSTEM '../../doc/generated/tools.mod'>
18 <!ENTITY % variables-mod SYSTEM '../../doc/generated/variables.mod'>
22 <sconsdoc xmlns="http://www.scons.org/dbxsd/v1.0"
23 xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
24 xsi:schemaLocation="http://www.scons.org/dbxsd/v1.0 http://www.scons.org/dbxsd/v1.0/scons.xsd">
26 <tool name="xgettext">
29 This scons tool is a part of scons &t-link-gettext; toolset. It provides
30 scons interface to <command>xgettext(1)</command>
31 program, which extracts internationalized messages from source code. The tool
32 provides &b-POTUpdate; builder to make <literal>PO</literal>
33 <emphasis>Template</emphasis> files.
37 <item>POTSUFFIX</item>
38 <item>POTUPDATE_ALIAS</item>
39 <item>XGETTEXTCOM</item>
40 <item>XGETTEXTCOMSTR</item>
41 <item>XGETTEXTFLAGS</item>
42 <item>XGETTEXTFROM</item>
43 <item>XGETTEXTFROMPREFIX</item>
44 <item>XGETTEXTFROMSUFFIX</item>
45 <item>XGETTEXTPATH</item>
46 <item>XGETTEXTPATHPREFIX</item>
47 <item>XGETTEXTPATHSUFFIX</item>
48 <item>_XGETTEXTDOMAIN</item>
49 <item>_XGETTEXTFROMFLAGS</item>
50 <item>_XGETTEXTPATHFLAGS</item>
53 <item>POTDOMAIN</item>
57 <builder name="POTUpdate">
60 The builder belongs to &t-link-xgettext; tool. The builder updates target
61 <literal>POT</literal> file if exists or creates one if it doesn't. The node is
62 not built by default (i.e. it is <literal>Ignore</literal>d from
63 <literal>'.'</literal>), but only on demand (i.e. when given
64 <literal>POT</literal> file is required or when special alias is invoked). This
65 builder adds its targe node (<filename>messages.pot</filename>, say) to a
66 special alias (<literal>pot-update</literal> by default, see
67 &cv-link-POTUPDATE_ALIAS;) so you can update/create them easily with
68 <command>scons pot-update</command>. The file is not written until there is no
69 real change in internationalized messages (or in comments that enter
70 <literal>POT</literal> file).
74 <note> <para>You may see <command>xgettext(1)</command> being invoked by the
75 &t-link-xgettext; tool even if there is no real change in internationalized
76 messages (so the <literal>POT</literal> file is not being updated). This
77 happens every time a source file has changed. In such case we invoke
78 <command>xgettext(1)</command> and compare its output with the content of
79 <literal>POT</literal> file to decide whether the file should be updated or
84 <emphasis>Example 1.</emphasis>
85 Let's create <filename>po/</filename> directory and place following
86 <filename>SConstruct</filename> script there:
89 # SConstruct in 'po/' subdir
90 env = Environment( tools = ['default', 'xgettext'] )
91 env.POTUpdate(['foo'], ['../a.cpp', '../b.cpp'])
92 env.POTUpdate(['bar'], ['../c.cpp', '../d.cpp'])
95 Then invoke scons few times:
98 user@host:$ scons # Does not create foo.pot nor bar.pot
99 user@host:$ scons foo.pot # Updates or creates foo.pot
100 user@host:$ scons pot-update # Updates or creates foo.pot and bar.pot
101 user@host:$ scons -c # Does not clean foo.pot nor bar.pot.
104 the results shall be as the comments above say.
108 <emphasis>Example 2.</emphasis>
109 The &b-POTUpdate; builder may be used with no target specified, in which
110 case default target <filename>messages.pot</filename> will be used. The
111 default target may also be overridden by setting &cv-link-POTDOMAIN; construction
112 variable or providing it as an override to &b-POTUpdate; builder:
116 env = Environment( tools = ['default', 'xgettext'] )
117 env['POTDOMAIN'] = "foo"
118 env.POTUpdate(source = ["a.cpp", "b.cpp"]) # Creates foo.pot ...
119 env.POTUpdate(POTDOMAIN = "bar", source = ["c.cpp", "d.cpp"]) # and bar.pot
123 <emphasis>Example 3.</emphasis>
124 The sources may be specified within separate file, for example
125 <filename>POTFILES.in</filename>:
128 # POTFILES.in in 'po/' subdirectory
134 The name of the file (<filename>POTFILES.in</filename>) containing the list of
135 sources is provided via &cv-link-XGETTEXTFROM;:
138 # SConstruct file in 'po/' subdirectory
139 env = Environment( tools = ['default', 'xgettext'] )
140 env.POTUpdate(XGETTEXTFROM = 'POTFILES.in')
144 <emphasis>Example 4.</emphasis>
145 You may use &cv-link-XGETTEXTPATH; to define source search path. Assume, for
146 example, that you have files <filename>a.cpp</filename>,
147 <filename>b.cpp</filename>, <filename>po/SConstruct</filename>,
148 <filename>po/POTFILES.in</filename>. Then your <literal>POT</literal>-related
149 files could look as below:
152 # POTFILES.in in 'po/' subdirectory
159 # SConstruct file in 'po/' subdirectory
160 env = Environment( tools = ['default', 'xgettext'] )
161 env.POTUpdate(XGETTEXTFROM = 'POTFILES.in', XGETTEXTPATH='../')
165 <emphasis>Example 5.</emphasis>
166 Multiple search directories may be defined within a list, i.e.
167 <literal>XGETTEXTPATH = ['dir1', 'dir2', ...]</literal>. The order in the list
168 determines the search order of source files. The path to the first file found
173 Let's create <filename>0/1/po/SConstruct</filename> script:
176 # SConstruct file in '0/1/po/' subdirectory
177 env = Environment( tools = ['default', 'xgettext'] )
178 env.POTUpdate(XGETTEXTFROM = 'POTFILES.in', XGETTEXTPATH=['../', '../../'])
181 and <filename>0/1/po/POTFILES.in</filename>:
184 # POTFILES.in in '0/1/po/' subdirectory
189 Write two <filename>*.cpp</filename> files, the first one is
190 <filename>0/a.cpp</filename>:
194 gettext("Hello from ../../a.cpp")
197 and the second is <filename>0/1/a.cpp</filename>:
201 gettext("Hello from ../a.cpp")
204 then run scons. You'll obtain <literal>0/1/po/messages.pot</literal> with the
205 message <literal>"Hello from ../a.cpp"</literal>. When you reverse order in
206 <varname>$XGETTEXTFOM</varname>, i.e. when you write SConscript as
209 # SConstruct file in '0/1/po/' subdirectory
210 env = Environment( tools = ['default', 'xgettext'] )
211 env.POTUpdate(XGETTEXTFROM = 'POTFILES.in', XGETTEXTPATH=['../../', '../'])
214 then the <filename>messages.pot</filename> will contain
215 <literal>msgid "Hello from ../../a.cpp"</literal> line and not
216 <literal>msgid "Hello from ../a.cpp"</literal>.
222 <!-- %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% -->
223 <cvar name="POTSUFFIX">
226 Suffix used for PO Template files (default: <literal>'.pot'</literal>).
227 See &t-link-xgettext; tool and &b-link-POTUpdate; builder.
231 <!-- %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% -->
232 <cvar name="POTUPDATE_ALIAS">
235 Name of the common phony target for all PO Templates created with
236 &b-link-POUpdate; (default: <literal>'pot-update'</literal>).
237 See &t-link-xgettext; tool and &b-link-POTUpdate; builder.
241 <!-- %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% -->
242 <cvar name="XGETTEXT">
245 Path to <command>xgettext(1)</command> program (found via
246 <function>Detect()</function>).
247 See &t-link-xgettext; tool and &b-link-POTUpdate; builder.
251 <!-- %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% -->
252 <cvar name="XGETTEXTCOM">
255 Complete xgettext command line.
256 See &t-link-xgettext; tool and &b-link-POTUpdate; builder.
260 <!-- %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% -->
261 <cvar name="XGETTEXTCOMSTR">
264 A string that is shown when <command>xgettext(1)</command> command is invoked
265 (default: <literal>''</literal>, which means "print &cv-link-XGETTEXTCOM;").
266 See &t-link-xgettext; tool and &b-link-POTUpdate; builder.
270 <!-- %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% -->
271 <cvar name="XGETTEXTFLAGS">
274 Additional flags to <command>xgettext(1)</command>.
275 See &t-link-xgettext; tool and &b-link-POTUpdate; builder.
279 <!-- %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% -->
280 <cvar name="XGETTEXTFROM">
283 Name of file containing list of <command>xgettext(1)</command>'s source
284 files. Autotools' users know this as <filename>POTFILES.in</filename> so they
285 will in most cases set <literal>XGETTEXTFROM="POTFILES.in"</literal> here.
286 The &cv-XGETTEXTFROM; files have same syntax and semantics as the well known
287 GNU <filename>POTFILES.in</filename>.
288 See &t-link-xgettext; tool and &b-link-POTUpdate; builder.
292 <!-- %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% -->
293 <cvar name="XGETTEXTPATH">
296 List of directories, there <command>xgettext(1)</command> will look for
297 source files (default: <literal>[]</literal>).
299 This variable works only together with &cv-link-XGETTEXTFROM;
301 See also &t-link-xgettext; tool and &b-link-POTUpdate; builder.
305 <!-- %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% -->
306 <cvar name="XGETTEXTPATHPREFIX">
309 This flag is used to add single search path to
310 <command>xgettext(1)</command>'s commandline (default:
311 <literal>'-D'</literal>).
315 <!-- %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% -->
316 <cvar name="XGETTEXTPATHSUFFIX">
319 (default: <literal>''</literal>)
323 <!-- %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% -->
324 <cvar name="XGETTEXTFROMPREFIX">
327 This flag is used to add single &cv-link-XGETTEXTFROM; file to
328 <command>xgettext(1)</command>'s commandline (default:
329 <literal>'-f'</literal>).
333 <!-- %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% -->
334 <cvar name="XGETTEXTFROMSUFFIX">
337 (default: <literal>''</literal>)
341 <!-- %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% -->
342 <cvar name="_XGETTEXTDOMAIN">
345 Internal "macro". Generates <command>xgettext</command> domain name
346 form source and target (default: <literal>'${TARGET.filebase}'</literal>).
350 <!-- %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% -->
351 <cvar name="_XGETTEXTFROMFLAGS">
354 Internal "macro". Genrates list of <literal>-D<dir></literal> flags
355 from the &cv-link-XGETTEXTPATH; list.
359 <!-- %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% -->
360 <cvar name="_XGETTEXTPATHFLAGS">
363 Internal "macro". Generates list of <literal>-f<file></literal> flags
364 from &cv-link-XGETTEXTFROM;.