Merge pull request #4655 from bdbaddog/fix_new_ninja_package
[scons.git] / test / gettext / POUpdate / UserExamples.py
blobbe38996d579208904ee714330226a7c2ba5e1e8b
1 #!/usr/bin/env python
3 # __COPYRIGHT__
5 # Permission is hereby granted, free of charge, to any person obtaining
6 # a copy of this software and associated documentation files (the
7 # "Software"), to deal in the Software without restriction, including
8 # without limitation the rights to use, copy, modify, merge, publish,
9 # distribute, sublicense, and/or sell copies of the Software, and to
10 # permit persons to whom the Software is furnished to do so, subject to
11 # the following conditions:
13 # The above copyright notice and this permission notice shall be included
14 # in all copies or substantial portions of the Software.
16 # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY
17 # KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE
18 # WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19 # NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
20 # LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
21 # OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
22 # WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
25 __revision__ = "__FILE__ __REVISION__ __DATE__ __DEVELOPER__"
27 """
28 Make sure, that the examples given in user guide all work.
29 """
31 import TestSCons
33 test = TestSCons.TestSCons()
36 if not test.where_is('msgmerge'):
37 test.skip_test("Could not find 'msgmerge'; skipping test(s)\n")
39 pot_contents = """\
40 # SOME DESCRIPTIVE TITLE.
41 # Copyright (C) YEAR THE PACKAGE'S COPYRIGHT HOLDER
42 # This file is distributed under the same license as the PACKAGE package.
43 # FIRST AUTHOR <EMAIL@ADDRESS>, YEAR.
45 #, fuzzy
46 msgid ""
47 msgstr ""
48 "Project-Id-Version: PACKAGE VERSION\\n"
49 "Report-Msgid-Bugs-To: \\n"
50 "POT-Creation-Date: 2012-05-27 00:35+0200\\n"
51 "PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\\n"
52 "Last-Translator: FULL NAME <EMAIL@ADDRESS>\\n"
53 "Language-Team: LANGUAGE <LL@li.org>\\n"
54 "Language: \\n"
55 "MIME-Version: 1.0\\n"
56 "Content-Type: text/plain; charset=CHARSET\\n"
57 "Content-Transfer-Encoding: 8bit\\n"
59 #: a.cpp:1
60 msgid "Hello from a.cpp"
61 msgstr ""
62 """
64 en_po_contents = """\
65 # English translations for PACKAGE package.
66 # Copyright (C) 2012 THE PACKAGE'S COPYRIGHT HOLDER
67 # This file is distributed under the same license as the PACKAGE package.
68 # Pawel Tomulik <ptomulik@meil.pw.edu.pl>, 2012.
70 msgid ""
71 msgstr ""
72 "Project-Id-Version: PACKAGE VERSION\\n"
73 "Report-Msgid-Bugs-To: \\n"
74 "POT-Creation-Date: 2012-05-27 00:35+0200\\n"
75 "PO-Revision-Date: 2012-05-27 00:37+0200\\n"
76 "Last-Translator: Pawel Tomulik <ptomulik@meil.pw.edu.pl>\\n"
77 "Language-Team: English\\n"
78 "Language: en\\n"
79 "MIME-Version: 1.0\\n"
80 "Content-Type: text/plain; charset=ASCII\\n"
81 "Content-Transfer-Encoding: 8bit\\n"
82 "Plural-Forms: nplurals=2; plural=(n != 1);\\n"
84 #: a.cpp:1
85 msgid "Old message from a.cpp"
86 msgstr "Old message from a.cpp"
87 """
89 pl_po_contents = """\
90 # Polish translations for PACKAGE package.
91 # Copyright (C) 2012 THE PACKAGE'S COPYRIGHT HOLDER
92 # This file is distributed under the same license as the PACKAGE package.
93 # Automatically generated, 2012.
95 msgid ""
96 msgstr ""
97 "Project-Id-Version: PACKAGE VERSION\\n"
98 "Report-Msgid-Bugs-To: \\n"
99 "POT-Creation-Date: 2012-05-27 00:35+0200\\n"
100 "PO-Revision-Date: 2012-05-27 00:35+0200\\n"
101 "Last-Translator: Automatically generated\\n"
102 "Language-Team: none\\n"
103 "Language: pl\\n"
104 "MIME-Version: 1.0\\n"
105 "Content-Type: text/plain; charset=ASCII\\n"
106 "Content-Transfer-Encoding: 8bit\\n"
107 "Plural-Forms: nplurals=3; plural=(n==1 ? 0 : n%10>=2 && n%10<=4 && (n%100<10 "
108 "|| n%100>=20) ? 1 : 2);\\n"
110 #: a.cpp:1
111 msgid "Old message from a.cpp"
112 msgstr "Stara wiadomosc z a.cpp"
115 de_po_contents = """\
116 # German translations for PACKAGE package.
117 # Copyright (C) 2012 THE PACKAGE'S COPYRIGHT HOLDER
118 # This file is distributed under the same license as the PACKAGE package.
119 # Automatically generated, 2012.
121 msgid ""
122 msgstr ""
123 "Project-Id-Version: PACKAGE VERSION\\n"
124 "Report-Msgid-Bugs-To: \\n"
125 "POT-Creation-Date: 2012-05-27 00:35+0200\\n"
126 "PO-Revision-Date: 2012-05-27 00:35+0200\\n"
127 "Last-Translator: Automatically generated\\n"
128 "Language-Team: none\\n"
129 "Language: de\\n"
130 "MIME-Version: 1.0\\n"
131 "Content-Type: text/plain; charset=ASCII\\n"
132 "Content-Transfer-Encoding: 8bit\\n"
133 "Plural-Forms: nplurals=2; plural=(n != 1);\\n"
135 #: a.cpp:1
136 msgid "Old message from a.cpp"
137 msgstr "EINE ALTE Nachricht vom a.cpp"
140 fr_po_contents = """\
141 # French translations for PACKAGE package.
142 # Copyright (C) 2012 THE PACKAGE'S COPYRIGHT HOLDER
143 # This file is distributed under the same license as the PACKAGE package.
144 # Automatically generated, 2012.
146 msgid ""
147 msgstr ""
148 "Project-Id-Version: PACKAGE VERSION\\n"
149 "Report-Msgid-Bugs-To: \\n"
150 "POT-Creation-Date: 2012-05-27 00:35+0200\\n"
151 "PO-Revision-Date: 2012-05-27 00:35+0200\\n"
152 "Last-Translator: Automatically generated\\n"
153 "Language-Team: none\\n"
154 "Language: fr\\n"
155 "MIME-Version: 1.0\\n"
156 "Content-Type: text/plain; charset=ASCII\\n"
157 "Content-Transfer-Encoding: 8bit\\n"
158 "Plural-Forms: nplurals=2; plural=(n > 1);\\n"
160 #: a.cpp:1
161 msgid "Old message from a.cpp"
162 msgstr "Un ancien message du a.cpp"
165 #############################################################################
166 # POUpdate: Example 1
167 #############################################################################
168 test.subdir(['ex1'])
169 test.write( ['ex1', 'SConstruct'],
171 env = Environment( tools = ["default", "msgmerge"] )
172 env.POUpdate(['en','pl']) # messages.pot --&gt; [en.po, pl.po]
173 """)
174 test.write(['ex1', 'messages.pot'], pot_contents)
175 test.write(['ex1', 'en.po'], en_po_contents)
176 test.write(['ex1', 'pl.po'], pl_po_contents)
178 # NOTE: msgmerge(1) prints its messages to stderr, we must ignore them,
179 # So, stderr=None is crucial here. It is no point to match stderr to some
180 # specific valuse; the messages are internationalized :) ).
181 test.run(arguments = 'po-update', chdir = 'ex1', stderr = None)
182 test.must_exist( ['ex1', 'en.po'] )
183 test.must_exist( ['ex1', 'pl.po'] )
184 test.must_contain( ['ex1', 'en.po'], "Hello from a.cpp", mode='r' )
185 test.must_contain( ['ex1', 'pl.po'], "Hello from a.cpp", mode='r' )
187 #############################################################################
188 # POUpdate: Example 2
189 #############################################################################
190 test.subdir(['ex2'])
191 test.write( ['ex2', 'SConstruct'],
193 env = Environment( tools = ["default", "msgmerge"] )
194 env.POUpdate(['en','pl'], ['foo']) # foo.pot --&gt; [en.po, pl.po]
195 """)
197 test.write(['ex2', 'foo.pot'], pot_contents)
198 test.write(['ex2', 'en.po'], en_po_contents)
199 test.write(['ex2', 'pl.po'], pl_po_contents)
201 # NOTE: msgmerge(1) prints all messages to stderr, we must ignore them,
202 # So, stderr=None is crucial here. It is no point to match stderr to some
203 # specific valuse; the messages are internationalized :) ).
204 test.run(arguments = 'po-update', chdir = 'ex2', stderr = None)
205 test.must_exist( ['ex2', 'en.po'] )
206 test.must_exist( ['ex2', 'pl.po'] )
207 test.must_contain( ['ex2', 'en.po'], "Hello from a.cpp", mode='r' )
208 test.must_contain( ['ex2', 'pl.po'], "Hello from a.cpp", mode='r' )
210 #############################################################################
211 # POUpdate: Example 3
212 #############################################################################
213 test.subdir(['ex3'])
214 test.write( ['ex3', 'SConstruct'],
216 env = Environment( tools = ["default", "msgmerge"] )
217 env.POUpdate(['en','pl'], POTDOMAIN='foo') # foo.pot --&gt; [en.po, pl.po]
218 """)
220 test.write(['ex3', 'foo.pot'], pot_contents)
221 test.write(['ex3', 'en.po'], en_po_contents)
222 test.write(['ex3', 'pl.po'], pl_po_contents)
224 # NOTE: msgmerge(1) prints its messages to stderr, we must ignore them,
225 # So, stderr=None is crucial here. It is no point to match stderr to some
226 # specific valuse; the messages are internationalized :) ).
227 test.run(arguments = 'po-update', chdir = 'ex3', stderr = None)
228 test.must_exist( ['ex3', 'en.po'] )
229 test.must_exist( ['ex3', 'pl.po'] )
230 test.must_contain( ['ex3', 'en.po'], "Hello from a.cpp", mode='r' )
231 test.must_contain( ['ex3', 'pl.po'], "Hello from a.cpp", mode='r' )
233 #############################################################################
234 # POUpdate: Example 4
235 #############################################################################
236 test.subdir(['ex4'])
237 test.write( ['ex4', 'SConstruct'],
239 env = Environment( tools = ["default", "msgmerge"] )
240 env.POUpdate(LINGUAS_FILE = 1) # needs 'LINGUAS' file
241 """)
243 test.write(['ex4', 'LINGUAS'],
247 """)
249 test.write(['ex4', 'messages.pot'], pot_contents)
250 test.write(['ex4', 'en.po'], en_po_contents)
251 test.write(['ex4', 'pl.po'], pl_po_contents)
253 # NOTE: msgmerge(1) prints all messages to stderr, we must ignore them,
254 # So, stderr=None is crucial here. It is no point to match stderr to some
255 # specific valuse; the messages are internationalized :) ).
256 test.run(arguments = 'po-update', chdir = 'ex4', stderr = None)
257 test.must_exist( ['ex4', 'messages.pot'] )
258 test.must_exist( ['ex4', 'en.po'] )
259 test.must_exist( ['ex4', 'pl.po'] )
260 test.must_contain( ['ex4', 'en.po'], "Hello from a.cpp", mode='r' )
261 test.must_contain( ['ex4', 'pl.po'], "Hello from a.cpp", mode='r' )
263 #############################################################################
264 # POUpdate: Example 5
265 #############################################################################
266 test.subdir(['ex5'])
267 test.write( ['ex5', 'SConstruct'],
269 env = Environment( tools = ["default", "msgmerge"] )
270 env.POUpdate(LINGUAS_FILE = 1, source = ['foo'])
271 """)
272 test.write(['ex5', 'LINGUAS'],
276 """)
278 test.write(['ex5', 'foo.pot'], pot_contents)
279 test.write(['ex5', 'en.po'], en_po_contents)
280 test.write(['ex5', 'pl.po'], pl_po_contents)
282 # NOTE: msgmerge(1) prints its messages to stderr, we must ignore them,
283 # So, stderr=None is crucial here. It is no point to match stderr to some
284 # specific valuse; the messages are internationalized :) ).
285 test.run(arguments = 'po-update', chdir= 'ex5', stderr = None)
286 test.must_exist( ['ex5', 'en.po'] )
287 test.must_exist( ['ex5', 'pl.po'] )
288 test.must_contain( ['ex5', 'en.po'], "Hello from a.cpp", mode='r' )
289 test.must_contain( ['ex5', 'pl.po'], "Hello from a.cpp", mode='r' )
291 #############################################################################
292 # POUpdate: Example 6
293 #############################################################################
294 test.subdir(['ex6'])
295 test.write( ['ex6', 'SConstruct'],
297 env = Environment( tools = ["default", "msgmerge"] )
298 env.POUpdate(['en', 'pl'], LINGUAS_FILE = 1)
299 """)
300 test.write(['ex6', 'LINGUAS'],
304 """)
305 test.write(['ex6', 'messages.pot'], pot_contents)
306 test.write(['ex6', 'en.po'], en_po_contents)
307 test.write(['ex6', 'pl.po'], pl_po_contents)
308 test.write(['ex6', 'de.po'], de_po_contents)
309 test.write(['ex6', 'fr.po'], fr_po_contents)
311 # Note: msgmerge(1) prints its messages to stderr, we must ignore them,
312 # So, stderr=None is crucial here. It is no point to match stderr to some
313 # specific valuse; the messages are internationalized :) ).
314 test.run(arguments = 'po-update', chdir = 'ex6', stderr = None)
315 test.must_exist( ['ex6', 'en.po'] )
316 test.must_exist( ['ex6', 'pl.po'] )
317 test.must_exist( ['ex6', 'de.po'] )
318 test.must_exist( ['ex6', 'fr.po'] )
319 test.must_contain( ['ex6', 'en.po'], "Hello from a.cpp", mode='r' )
320 test.must_contain( ['ex6', 'pl.po'], "Hello from a.cpp", mode='r' )
321 test.must_contain( ['ex6', 'de.po'], "Hello from a.cpp", mode='r' )
322 test.must_contain( ['ex6', 'fr.po'], "Hello from a.cpp", mode='r' )
324 #############################################################################
325 # POUpdate: Example 7
326 #############################################################################
328 # From this poin we need msginit
330 if not test.where_is('msginit'):
331 test.skip_test("could not find 'msginit'; skipping test(s)\n")
333 test.subdir(['ex7'])
334 test.write( ['ex7', 'SConstruct'],
336 env = Environment( tools = ["default", "msginit", "msgmerge"] )
337 env.POUpdate(LINGUAS_FILE = 1, POAUTOINIT = 1)
338 """)
339 test.write(['ex7', 'LINGUAS'],
343 """)
345 test.write(['ex7', 'messages.pot'], pot_contents)
347 # NOTE: msgmerge(1) prints its messages to stderr, we must ignore them,
348 # So, stderr=None is crucial here. It is no point to match stderr to some
349 # specific valuse; the messages are internationalized :) ).
350 test.run(arguments = 'po-update', chdir= 'ex7', stderr = None)
351 test.must_exist( ['ex7', 'en.po'] )
352 test.must_exist( ['ex7', 'pl.po'] )
353 test.must_contain( ['ex7', 'en.po'], "Hello from a.cpp", mode='r' )
354 test.must_contain( ['ex7', 'pl.po'], "Hello from a.cpp", mode='r' )
356 #############################################################################
357 # POUpdate: Example 8
358 #############################################################################
360 # From this point we need xgettext
362 if not test.where_is('xgettext'):
363 test.skip_test("could not find 'xgettext'; skipping test(s)\n")
365 test.subdir(['ex8'])
366 test.write( ['ex8', 'SConstruct'],
368 env = Environment( tools = ["default", "xgettext", "msginit", "msgmerge"] )
370 # script-wise settings
371 env['POAUTOINIT'] = 1
372 env['LINGUAS_FILE'] = 1
373 env['POTDOMAIN'] = 'foo'
374 env.POTUpdate(source = 'a.cpp')
375 env.POUpdate()
376 """)
377 test.write(['ex8', 'LINGUAS'],
381 """)
382 test.write(['ex8', 'a.cpp'], """ gettext("Hello from a.cpp") """)
384 # Note: msgmerge(1) prints its messages to stderr, we must ignore them,
385 # So, stderr=None is crucial here. It is no point to match stderr to some
386 # specific valuse; the messages are internationalized :) ).
387 test.run(arguments = 'po-update', chdir = 'ex8', stderr = None)
388 test.must_exist( ['ex8', 'foo.pot'] )
389 test.must_exist( ['ex8', 'en.po'] )
390 test.must_exist( ['ex8', 'pl.po'] )
391 test.must_contain( ['ex8', 'en.po'], "Hello from a.cpp", mode='r' )
392 test.must_contain( ['ex8', 'pl.po'], "Hello from a.cpp", mode='r' )
394 test.pass_test()
397 # Local Variables:
398 # tab-width:4
399 # indent-tabs-mode:nil
400 # End:
401 # vim: set expandtab tabstop=4 shiftwidth=4: