1
2
3 from translate.convert import po2html
4 from translate.convert import test_convert
5 from translate.misc import wStringIO
6
17
19 """simple po to html test"""
20 htmlsource = '<p>A sentence.</p>'
21 posource = '''#: html:3\nmsgid "A sentence."\nmsgstr "'n Sin."\n'''
22 htmlexpected = '''<p>'n Sin.</p>'''
23 assert htmlexpected in self.converthtml(posource, htmlsource)
24
26 """Test that a po file can be merged into a template with linebreaks in it."""
27 htmlsource = '''<html>
28 <head>
29 </head>
30 <body>
31 <div>
32 A paragraph is a section in a piece of writing, usually highlighting a
33 particular point or topic. It always begins on a new line and usually
34 with indentation, and it consists of at least one sentence.
35 </div>
36 </body>
37 </html>
38 '''
39 posource = '''#: None:1
40 msgid ""
41 "A paragraph is a section in a piece of writing, usually highlighting a "
42 "particular point or topic. It always begins on a new line and usually with "
43 "indentation, and it consists of at least one sentence."
44 msgstr ""
45 "'n Paragraaf is 'n afdeling in 'n geskrewe stuk wat gewoonlik 'n spesifieke "
46 "punt uitlig. Dit begin altyd op 'n nuwe lyn (gewoonlik met indentasie) en "
47 "dit bestaan uit ten minste een sin."
48 '''
49 htmlexpected = '''<body>
50 <div>'n Paragraaf is 'n afdeling in 'n geskrewe stuk wat gewoonlik
51 'n spesifieke punt uitlig. Dit begin altyd op 'n nuwe lyn
52 (gewoonlik met indentasie) en dit bestaan uit ten minste een
53 sin.</div>
54 </body>'''
55 assert htmlexpected.replace("\n", " ") in self.converthtml(posource, htmlsource).replace("\n", " ")
56
58 """Tests that entities are handled correctly"""
59 htmlsource = '<p>5 less than 6</p>'
60 posource = '#:html:3\nmsgid "5 less than 6"\nmsgstr "5 < 6"\n'
61 htmlexpected = '<p>5 < 6</p>'
62 assert htmlexpected in self.converthtml(posource, htmlsource)
63
64 htmlsource = '<p>Fish & chips</p>'
65 posource = '#: html:3\nmsgid "Fish & chips"\nmsgstr "Vis & skyfies"\n'
66 htmlexpected = '<p>Vis & skyfies</p>'
67 assert htmlexpected in self.converthtml(posource, htmlsource)
68
70 """Tests that PO escapes are correctly handled"""
71 htmlsource = '<div>Row 1<br />Row 2</div>'
72 posource = '#: html:3\nmsgid "Row 1\\n"\n"Row 2"\nmsgstr "Ry 1\\n"\n"Ry 2"\n'
73 htmlexpected = '<div>Ry 1<br />Ry 2</div>'
74 assert htmlexpected in self.converthtml(posource, htmlsource)
75
76 htmlsource = '<p>"leverage"</p>'
77 posource = '#: html3\nmsgid "\\"leverage\\""\nmsgstr "\\"ek is dom\\""\n'
78 htmlexpected = '<p>"ek is dom"</p>'
79 assert htmlexpected in self.converthtml(posource, htmlsource)
80
81
83 """Tests running actual po2oo commands on files"""
84 convertmodule = po2html
85
93