1
2
3 from translate.convert import pot2po
4 from translate.convert import test_convert
5 from translate.misc import wStringIO
6 from translate.storage import po
7 import warnings
8
11 warnings.resetwarnings()
12
14 warnings.resetwarnings()
15
27
34
36 """checks that the convertpot function is working for a simple file initialisation"""
37 potsource = '''#: simple.label%ssimple.accesskey\nmsgid "A &hard coded newline.\\n"\nmsgstr ""\n''' % po.lsep
38 newpo = self.convertpot(potsource)
39 assert str(self.singleunit(newpo)) == potsource
40
42 """checks that the convertpot function is working for initialising plurals correctly"""
43 potsource = r'''msgid ""
44 msgstr""
45
46 msgid "%d manual"
47 msgid_plural "%d manuals"
48 msgstr[0] ""
49 msgstr[1] ""
50 '''
51 posource = r'''msgid ""
52 msgstr""
53 "Plural-Forms: nplurals=1; plural=0;\n"
54 '''
55
56 poexpected = r'''msgid "%d manual"
57 msgid_plural "%d manuals"
58 msgstr[0] ""
59 '''
60 newpo = self.convertpot(potsource, posource)
61 assert str(self.singleunit(newpo)) == poexpected
62
64 """checks that the convertpot function is working for a simple merge"""
65 potsource = '''#: simple.label%ssimple.accesskey\nmsgid "A &hard coded newline.\\n"\nmsgstr ""\n''' % po.lsep
66 posource = '''#: simple.label%ssimple.accesskey\nmsgid "A &hard coded newline.\\n"\nmsgstr "&Hart gekoeerde nuwe lyne\\n"\n''' % po.lsep
67 newpo = self.convertpot(potsource, posource)
68 assert str(self.singleunit(newpo)) == posource
69
71 """test that when we merge PO files with a fuzzy message that it remains fuzzy"""
72 potsource = '''#: simple.label%ssimple.accesskey\nmsgid "A &hard coded newline.\\n"\nmsgstr ""\n''' % po.lsep
73 posource = '''#: simple.label%ssimple.accesskey\n#, fuzzy\nmsgid "A &hard coded newline.\\n"\nmsgstr "&Hart gekoeerde nuwe lyne\\n"\n''' % po.lsep
74 newpo = self.convertpot(potsource, posource)
75 assert str(self.singleunit(newpo)) == posource
76
78 """test that when we merge PO files with a fuzzy message that it remains fuzzy"""
79 potsource = r'''#: file.cpp:2
80 msgid "%d manual"
81 msgid_plural "%d manuals"
82 msgstr[0] ""
83 msgstr[1] ""
84 '''
85 posource = r'''#: file.cpp:3
86 #, fuzzy
87 msgid "%d manual"
88 msgid_plural "%d manuals"
89 msgstr[0] "%d handleiding."
90 msgstr[1] "%d handleidings."
91 '''
92
93 poexpected = r'''#: file.cpp:2
94 #, fuzzy
95 msgid "%d manual"
96 msgid_plural "%d manuals"
97 msgstr[0] "%d handleiding."
98 msgstr[1] "%d handleidings."
99 '''
100 newpo = self.convertpot(potsource, posource)
101 assert str(self.singleunit(newpo)) == poexpected
102
104 """tests that if the msgid changes but the location stays the same that we merge"""
105 potsource = '''#: simple.label\n#: simple.accesskey\nmsgid "Its &hard coding a newline.\\n"\nmsgstr ""\n'''
106 posource = '''#: simple.label\n#: simple.accesskey\nmsgid "A &hard coded newline.\\n"\nmsgstr "&Hart gekoeerde nuwe lyne\\n"\n'''
107 poexpected = '''#: simple.label\n#: simple.accesskey\n#, fuzzy\nmsgid "Its &hard coding a newline.\\n"\nmsgstr "&Hart gekoeerde nuwe lyne\\n"\n'''
108 newpo = self.convertpot(potsource, posource)
109 print newpo
110 assert str(self.singleunit(newpo)) == poexpected
111
113 """tests that if the location changes but the msgid stays the same that we merge"""
114 potsource = '''#: new_simple.label%snew_simple.accesskey\nmsgid "A &hard coded newline.\\n"\nmsgstr ""\n''' % po.lsep
115 posource = '''#: simple.label%ssimple.accesskey\nmsgid "A &hard coded newline.\\n"\nmsgstr "&Hart gekoeerde nuwe lyne\\n"\n''' % po.lsep
116 poexpected = '''#: new_simple.label%snew_simple.accesskey\nmsgid "A &hard coded newline.\\n"\nmsgstr "&Hart gekoeerde nuwe lyne\\n"\n''' % po.lsep
117 newpo = self.convertpot(potsource, posource)
118 print newpo
119 assert str(self.singleunit(newpo)) == poexpected
120
122 """test that even if the location changes that if the msgid only has whitespace changes we can still merge"""
123 potsource = '''#: singlespace.label%ssinglespace.accesskey\nmsgid "&We have spaces"\nmsgstr ""\n''' % po.lsep
124 posource = '''#: doublespace.label%sdoublespace.accesskey\nmsgid "&We have spaces"\nmsgstr "&One het spasies"\n''' % po.lsep
125 poexpected = '''#: singlespace.label%ssinglespace.accesskey\n#, fuzzy\nmsgid "&We have spaces"\nmsgstr "&One het spasies"\n''' % po.lsep
126 newpo = self.convertpot(potsource, posource)
127 print newpo
128 assert str(self.singleunit(newpo)) == poexpected
129
131 """test that when we have a PO in ambiguous (Gettext form) and merge with disamabiguous (KDE comment form)
132 that we don't duplicate the location #: comments"""
133 potsource = '''#: location.c:1\nmsgid ""\n"_: location.c:1\\n"\n"Source"\nmsgstr ""\n\n''' + \
134 '''#: location.c:10\nmsgid ""\n"_: location.c:10\\n"\n"Source"\nmsgstr ""\n'''
135 posource = '''#: location.c:1\n#: location.c:10\nmsgid "Source"\nmsgstr "Target"\n\n'''
136 poexpected1 = '''#: location.c:1\nmsgid ""\n"_: location.c:1\\n"\n"Source"\nmsgstr "Target"\n'''
137 poexpected2 = '''#: location.c:10\nmsgid ""\n"_: location.c:10\\n"\n"Source"\nmsgstr "Target"\n'''
138 newpo = self.convertpot(potsource, posource)
139 print "Expected:\n", poexpected1, "Actual:\n", newpo.units[1]
140 assert str(newpo.units[1]) == poexpected1
141 assert str(newpo.units[2]) == poexpected2
142
144 """test that a change in the accelerator localtion still allows merging"""
145 potsource = '''#: someline.c\nmsgid "A&bout"\nmsgstr ""\n'''
146 posource = '''#: someline.c\nmsgid "&About"\nmsgstr "&Info"\n'''
147 poexpected = '''#: someline.c\nmsgid "A&bout"\nmsgstr "&Info"\n'''
148 newpo = self.convertpot(potsource, posource)
149 print newpo
150 assert str(self.singleunit(newpo)) == poexpected
151
153 """Checks that the correct formatting is preserved when pot an po lines differ."""
154 potsource = '''#: simple.label\nmsgid "Line split "\n"differently"\nmsgstr ""\n'''
155 posource = '''#: simple.label\nmsgid "Line"\n" split differently"\nmsgstr "Lyne verskillend gesny"\n'''
156 newpo = self.convertpot(potsource, posource)
157 newpounit = self.singleunit(newpo)
158 assert str(newpounit) == posource
159
167
176
185
207
225
261
263 """ensure that we can merge plural messages"""
264 potsource = '''msgid "One"\nmsgid_plural "Two"\nmsgstr[0] ""\nmsgstr[1] ""\n'''
265 posource = '''msgid "One"\nmsgid_plural "Two"\nmsgstr[0] "Een"\nmsgstr[1] "Twee"\nmsgstr[2] "Drie"\n'''
266 newpo = self.convertpot(potsource, posource)
267 print newpo
268 newpounit = self.singleunit(newpo)
269 assert str(newpounit) == posource
270
272 """check that we obsolete messages no longer present in the new file"""
273 potsource = ''
274 posource = '# Some comment\n#. Extracted comment\n#: obsoleteme:10\nmsgid "One"\nmsgstr "Een"\n'
275 expected = '# Some comment\n#~ msgid "One"\n#~ msgstr "Een"\n'
276 newpo = self.convertpot(potsource, posource)
277 print str(newpo)
278 newpounit = self.singleunit(newpo)
279 assert str(newpounit) == expected
280
282 """check that we don't obsolete (and keep) untranslated messages"""
283 potsource = ''
284 posource = '#: obsoleteme:10\nmsgid "One"\nmsgstr ""\n'
285 newpo = self.convertpot(potsource, posource)
286 print str(newpo)
287
288 assert len(newpo.units) == 1
289
291 """test to check that we place new blank message before obsolete messages"""
292 potsource = '''#: newline.c\nmsgid "&About"\nmsgstr ""\n'''
293 posource = '''#~ msgid "Old"\n#~ msgstr "Oud"\n'''
294 newpo = self.convertpot(potsource, posource)
295 assert len(newpo.units) == 3
296 assert newpo.units[0].isheader()
297 assert newpo.units[2].isobsolete()
298 assert str(newpo.units[1]) == potsource
299 assert str(newpo.units[2]) == posource
300
301
302 posource2 = '''msgid "Old"\nmsgstr "Oud"\n'''
303 newpo = self.convertpot(potsource, posource)
304 assert len(newpo.units) == 3
305 assert newpo.units[0].isheader()
306 assert newpo.units[2].isobsolete()
307 assert str(newpo.units[1]) == potsource
308 assert str(newpo.units[2]) == posource
309
311 """check that we can reuse old obsolete messages if the message comes back"""
312 potsource = '''#: resurect.c\nmsgid "&About"\nmsgstr ""\n'''
313 posource = '''#~ msgid "&About"\n#~ msgstr "&Omtrent"\n'''
314 expected = '''#: resurect.c\nmsgid "&About"\nmsgstr "&Omtrent"\n'''
315 newpo = self.convertpot(potsource, posource)
316 print newpo
317 assert len(newpo.units) == 2
318 assert newpo.units[0].isheader()
319 newpounit = self.singleunit(newpo)
320 assert str(newpounit) == expected
321
335
337 """test to check that we initialise the header correctly"""
338 potsource = r'''#, fuzzy
339 msgid ""
340 msgstr ""
341 "Project-Id-Version: PACKAGE VERSION\n"
342 "Report-Msgid-Bugs-To: new@example.com\n"
343 "POT-Creation-Date: 2006-11-11 11:11+0000\n"
344 "PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n"
345 "Last-Translator: FULL NAME <EMAIL@ADDRESS>\n"
346 "Language-Team: LANGUAGE <LL@li.org>\n"
347 "MIME-Version: 1.0\n"
348 "Content-Type: text/plain; charset=UTF-8\n"
349 "Content-Transfer-Encoding: 8bit\n"
350 "Plural-Forms: nplurals=INTEGER; plural=EXPRESSION;\n"
351 "X-Generator: Translate Toolkit 0.10rc2\n"
352 '''
353 posource = r'''msgid ""
354 msgstr ""
355 "Project-Id-Version: Pootle 0.10\n"
356 "Report-Msgid-Bugs-To: old@example.com\n"
357 "POT-Creation-Date: 2006-01-01 01:01+0100\n"
358 "PO-Revision-Date: 2006-09-09 09:09+0900\n"
359 "Last-Translator: Joe Translate <joe@example.com>\n"
360 "Language-Team: Pig Latin <piglatin@example.com>\n"
361 "MIME-Version: 1.0\n"
362 "Content-Type: text/plain; charset=UTF-8\n"
363 "Content-Transfer-Encoding: 8bit\n"
364 "Plural-Forms: nplurals=2; plural=(n != 1);\n"
365 "X-Generator: Translate Toolkit 0.9\n"
366 '''
367 expected = r'''msgid ""
368 msgstr ""
369 "Project-Id-Version: Pootle 0.10\n"
370 "Report-Msgid-Bugs-To: new@example.com\n"
371 "POT-Creation-Date: 2006-11-11 11:11+0000\n"
372 "PO-Revision-Date: 2006-09-09 09:09+0900\n"
373 "Last-Translator: Joe Translate <joe@example.com>\n"
374 "Language-Team: Pig Latin <piglatin@example.com>\n"
375 "MIME-Version: 1.0\n"
376 "Content-Type: text/plain; charset=UTF-8\n"
377 "Content-Transfer-Encoding: 8bit\n"
378 "Plural-Forms: nplurals=2; plural=(n != 1);\n"
379 "X-Generator: Translate Toolkit 0.10rc2\n"
380 '''
381 newpo = self.convertpot(potsource, posource)
382 print 'Output Header:\n%s' % newpo
383 print 'Expected Header:\n%s' % expected
384 assert str(newpo) == expected
385
395
413
415 """Tests running actual pot2po commands on files"""
416 convertmodule = pot2po
417
426