3 SPDX-FileCopyrightText: Copyright The SCons Foundation (https://scons.org)
4 SPDX-License-Identifier: MIT
5 SPDX-FileType: DOCUMENTATION
7 This file is processed by the bin/SConsDoc.py module.
11 <!ENTITY % scons SYSTEM '../../doc/scons.mod'>
13 <!ENTITY % builders-mod SYSTEM '../../doc/generated/builders.mod'>
15 <!ENTITY % functions-mod SYSTEM '../../doc/generated/functions.mod'>
17 <!ENTITY % tools-mod SYSTEM '../../doc/generated/tools.mod'>
19 <!ENTITY % variables-mod SYSTEM '../../doc/generated/variables.mod'>
23 <sconsdoc xmlns="http://www.scons.org/dbxsd/v1.0"
24 xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
25 xsi:schemaLocation="http://www.scons.org/dbxsd/v1.0 http://www.scons.org/dbxsd/v1.0/scons.xsd">
27 <tool name="xgettext">
30 This tool is a part of the &t-link-gettext; toolset. It provides
31 &SCons; an interface to the <command>xgettext(1)</command>
32 program, which extracts internationalized messages from source code.
33 The tool sets up the &b-POTUpdate; builder to make <literal>PO</literal>
34 <emphasis>Template</emphasis> files.
38 <item>POTSUFFIX</item>
39 <item>POTUPDATE_ALIAS</item>
40 <item>XGETTEXTCOM</item>
41 <item>XGETTEXTCOMSTR</item>
42 <item>XGETTEXTFLAGS</item>
43 <item>XGETTEXTFROM</item>
44 <item>XGETTEXTFROMPREFIX</item>
45 <item>XGETTEXTFROMSUFFIX</item>
46 <item>XGETTEXTPATH</item>
47 <item>XGETTEXTPATHPREFIX</item>
48 <item>XGETTEXTPATHSUFFIX</item>
49 <item>_XGETTEXTDOMAIN</item>
50 <item>_XGETTEXTFROMFLAGS</item>
51 <item>_XGETTEXTPATHFLAGS</item>
54 <item>POTDOMAIN</item>
58 <builder name="POTUpdate">
61 The builder is set up by the &t-link-xgettext; tool,
62 part of the &t-link-gettext; toolset.
63 The builder updates the target
64 <literal>POT</literal> file if exists or creates it if it doesn't.
65 The target node is <emphasis>not</emphasis>
66 selected for building by default (e.g. <userinput>scons .</userinput>),
67 but only on demand (i.e. when the given
68 <literal>POT</literal> file is required or when special alias is invoked).
69 This builder adds its target node (<filename>messages.pot</filename>, say) to a
70 special alias (<literal>pot-update</literal> by default, see
71 &cv-link-POTUPDATE_ALIAS;) so you can update/create them easily with
72 <userinput>scons pot-update</userinput>. The file is not written until there is no
73 real change in internationalized messages (or in comments that enter
74 <literal>POT</literal> file).
78 <note> <para>You may see <command>xgettext(1)</command> being invoked by the
79 &t-link-xgettext; tool even if there is no real change in internationalized
80 messages (so the <literal>POT</literal> file is not being updated). This
81 happens every time a source file has changed. In such case we invoke
82 <command>xgettext(1)</command> and compare its output with the content of
83 <literal>POT</literal> file to decide whether the file should be updated or
88 <emphasis>Example 1.</emphasis>
89 Let's create <filename>po/</filename> directory and place following
90 <filename>SConstruct</filename> script there:
92 <programlisting language="python">
93 # SConstruct in 'po/' subdir
94 env = Environment(tools=['default', 'xgettext'])
95 env.POTUpdate(['foo'], ['../a.cpp', '../b.cpp'])
96 env.POTUpdate(['bar'], ['../c.cpp', '../d.cpp'])
99 Then invoke scons few times:
102 $ scons # Does not create foo.pot nor bar.pot
103 $ scons foo.pot # Updates or creates foo.pot
104 $ scons pot-update # Updates or creates foo.pot and bar.pot
105 $ scons -c # Does not clean foo.pot nor bar.pot.
108 the results shall be as the comments above say.
112 <emphasis>Example 2.</emphasis>
113 The <parameter>target</parameter> argument can be omitted, in which
114 case the default target name <filename>messages.pot</filename> is used.
115 The target may also be overridden by setting the &cv-link-POTDOMAIN;
116 &consvar; or providing it as an override to the &b-POTUpdate; builder:
118 <programlisting language="python">
120 env = Environment(tools=['default', 'xgettext'])
121 env['POTDOMAIN'] = "foo"
122 env.POTUpdate(source=["a.cpp", "b.cpp"]) # Creates foo.pot ...
123 env.POTUpdate(POTDOMAIN="bar", source=["c.cpp", "d.cpp"]) # and bar.pot
127 <emphasis>Example 3.</emphasis>
128 The <parameter>source</parameter> parameter may also be omitted,
129 if it is specified in a separate file, for example
130 <filename>POTFILES.in</filename>:
133 # POTFILES.in in 'po/' subdirectory
139 The name of the file (<filename>POTFILES.in</filename>) containing the list of
140 sources is provided via &cv-link-XGETTEXTFROM;:
142 <programlisting language="python">
143 # SConstruct file in 'po/' subdirectory
144 env = Environment(tools=['default', 'xgettext'])
145 env.POTUpdate(XGETTEXTFROM='POTFILES.in')
149 <emphasis>Example 4.</emphasis>
150 You can use &cv-link-XGETTEXTPATH; to define the source search path.
151 Assume, for example, that you have files <filename>a.cpp</filename>,
152 <filename>b.cpp</filename>, <filename>po/SConstruct</filename>,
153 <filename>po/POTFILES.in</filename>.
154 Then your <literal>POT</literal>-related files could look like this:
157 # POTFILES.in in 'po/' subdirectory
163 <programlisting language="python">
164 # SConstruct file in 'po/' subdirectory
165 env = Environment(tools=['default', 'xgettext'])
166 env.POTUpdate(XGETTEXTFROM='POTFILES.in', XGETTEXTPATH='../')
170 <emphasis>Example 5.</emphasis>
171 Multiple search directories may be defined as a list, i.e.
172 <literal>XGETTEXTPATH=['dir1', 'dir2', ...]</literal>. The order in the list
173 determines the search order of source files. The path to the first file found
178 Let's create <filename>0/1/po/SConstruct</filename> script:
180 <programlisting language="python">
181 # SConstruct file in '0/1/po/' subdirectory
182 env = Environment(tools=['default', 'xgettext'])
183 env.POTUpdate(XGETTEXTFROM='POTFILES.in', XGETTEXTPATH=['../', '../../'])
186 and <filename>0/1/po/POTFILES.in</filename>:
189 # POTFILES.in in '0/1/po/' subdirectory
194 Write two <filename>*.cpp</filename> files, the first one is
195 <filename>0/a.cpp</filename>:
197 <programlisting language="c++">
199 gettext("Hello from ../../a.cpp")
202 and the second is <filename>0/1/a.cpp</filename>:
204 <programlisting language="c++">
206 gettext("Hello from ../a.cpp")
209 then run scons. You'll obtain <literal>0/1/po/messages.pot</literal> with the
210 message <literal>"Hello from ../a.cpp"</literal>. When you reverse order in
211 <varname>$XGETTEXTFOM</varname>, i.e. when you write SConscript as
213 <programlisting language="python">
214 # SConstruct file in '0/1/po/' subdirectory
215 env = Environment(tools=['default', 'xgettext'])
216 env.POTUpdate(XGETTEXTFROM='POTFILES.in', XGETTEXTPATH=['../../', '../'])
219 then the <filename>messages.pot</filename> will contain
220 <literal>msgid "Hello from ../../a.cpp"</literal> line and not
221 <literal>msgid "Hello from ../a.cpp"</literal>.
227 <cvar name="POTSUFFIX">
230 Suffix used for PO Template files (default: <literal>'.pot'</literal>).
231 See &t-link-xgettext; tool and &b-link-POTUpdate; builder.
236 <cvar name="POTUPDATE_ALIAS">
239 Name of the common phony target for all PO Templates created with
240 &b-link-POUpdate; (default: <literal>'pot-update'</literal>).
241 See &t-link-xgettext; tool and &b-link-POTUpdate; builder.
246 <cvar name="XGETTEXT">
249 Path to <command>xgettext(1)</command> program (found via
250 <function>Detect()</function>).
251 See &t-link-xgettext; tool and &b-link-POTUpdate; builder.
256 <cvar name="XGETTEXTCOM">
259 Complete xgettext command line.
260 See &t-link-xgettext; tool and &b-link-POTUpdate; builder.
265 <cvar name="XGETTEXTCOMSTR">
268 A string that is shown when <command>xgettext(1)</command> command is invoked
269 (default: <literal>''</literal>, which means "print &cv-link-XGETTEXTCOM;").
270 See &t-link-xgettext; tool and &b-link-POTUpdate; builder.
275 <cvar name="XGETTEXTFLAGS">
278 Additional flags to <command>xgettext(1)</command>.
279 See &t-link-xgettext; tool and &b-link-POTUpdate; builder.
284 <cvar name="XGETTEXTFROM">
287 Name of file containing list of <command>xgettext(1)</command>'s source
288 files. Autotools' users know this as <filename>POTFILES.in</filename> so they
289 will in most cases set <literal>XGETTEXTFROM="POTFILES.in"</literal> here.
290 The &cv-XGETTEXTFROM; files have same syntax and semantics as the well known
291 GNU <filename>POTFILES.in</filename>.
292 See &t-link-xgettext; tool and &b-link-POTUpdate; builder.
297 <cvar name="XGETTEXTPATH">
300 List of directories, there <command>xgettext(1)</command> will look for
301 source files (default: <literal>[]</literal>).
303 This variable works only together with &cv-link-XGETTEXTFROM;
305 See also &t-link-xgettext; tool and &b-link-POTUpdate; builder.
310 <cvar name="XGETTEXTPATHPREFIX">
313 This flag is used to add single search path to
314 <command>xgettext(1)</command>'s commandline (default:
315 <literal>'-D'</literal>).
320 <cvar name="XGETTEXTPATHSUFFIX">
323 (default: <literal>''</literal>)
328 <cvar name="XGETTEXTFROMPREFIX">
331 This flag is used to add single &cv-link-XGETTEXTFROM; file to
332 <command>xgettext(1)</command>'s commandline (default:
333 <literal>'-f'</literal>).
338 <cvar name="XGETTEXTFROMSUFFIX">
341 (default: <literal>''</literal>)
346 <cvar name="_XGETTEXTDOMAIN">
349 Internal "macro". Generates <command>xgettext</command> domain name
350 form source and target (default: <literal>'${TARGET.filebase}'</literal>).
355 <cvar name="_XGETTEXTFROMFLAGS">
358 Internal "macro". Genrates list of <literal>-D<dir></literal> flags
359 from the &cv-link-XGETTEXTPATH; list.
364 <cvar name="_XGETTEXTPATHFLAGS">
367 Internal "macro". Generates list of <literal>-f<file></literal> flags
368 from &cv-link-XGETTEXTFROM;.