1
2
3 from translate.convert import po2oo
4 from translate.convert import oo2po
5 from translate.convert import test_convert
6 from translate.misc import wStringIO
7 from translate.storage import po
8 import warnings
9 import os
10
13 warnings.resetwarnings()
14
16 warnings.resetwarnings()
17
18 - def convertoo(self, posource, ootemplate, language="en-US"):
25
27 oointro, oooutro = r'svx source\dialog\numpages.src 0 string RID_SVXPAGE_NUM_OPTIONS STR_BULLET 0 en-US ', ' 2002-02-02 02:02:02' + '\r\n'
28 oosource = oointro + entitystring + oooutro
29 ooinputfile = wStringIO.StringIO(oosource)
30 ooinputfile2 = wStringIO.StringIO(oosource)
31 pooutputfile = wStringIO.StringIO()
32 oo2po.convertoo(ooinputfile, pooutputfile, ooinputfile2, targetlanguage='en-US')
33 posource = pooutputfile.getvalue()
34 poinputfile = wStringIO.StringIO(posource)
35 ootemplatefile = wStringIO.StringIO(oosource)
36 oooutputfile = wStringIO.StringIO()
37 po2oo.convertoo(poinputfile, oooutputfile, ootemplatefile, targetlanguage="en-US")
38 ooresult = oooutputfile.getvalue()
39 print "original oo:\n", oosource, "po version:\n", posource, "output oo:\n", ooresult
40 assert ooresult.startswith(oointro) and ooresult.endswith(oooutro)
41 return ooresult[len(oointro):-len(oooutro)]
42
44 """Checks that the round-tripped string is the same as the original"""
45 assert self.roundtripstring(oosource) == oosource
46
48 """checks that the convertoo function is working"""
49 oobase = r'svx source\dialog\numpages.src 0 string RID_SVXPAGE_NUM_OPTIONS STR_BULLET 0 %s %s 20050924 09:13:58' + '\r\n'
50 posource = '''#: numpages.src#RID_SVXPAGE_NUM_OPTIONS.STR_BULLET.string.text\nmsgid "Simple String"\nmsgstr "Dimpled Ring"\n'''
51 ootemplate = oobase % ('en-US', 'Simple String')
52 ooexpected = oobase % ('zu', 'Dimpled Ring')
53 newoo = self.convertoo(posource, ootemplate, language="zu")
54 assert newoo == ootemplate + ooexpected
55
64
70
83
90
92
93
94
95
96 """checks that (escaped) quotes in strings make it through a oo->po->oo roundtrip"""
97 self.check_roundtrip(" ")
98 self.check_roundtrip(u"\u00a0")
99
101 """test to ensure that we revert to the default timestamp"""
102 oointro, oooutro = r'svx source\dialog\numpages.src 0 string RID_SVXPAGE_NUM_OPTIONS STR_BULLET 0 en-US Text ', '\r\n'
103 posource = '''#: numpages.src#RID_SVXPAGE_NUM_OPTIONS.STR_BULLET.string.text\nmsgid "Text"\nmsgstr "Text"\n'''
104 inputfile = wStringIO.StringIO(posource)
105 outputfile = wStringIO.StringIO()
106 templatefile = wStringIO.StringIO(oointro + '20050924 09:13:58' + oooutro)
107 assert po2oo.convertoo(inputfile, outputfile, templatefile, targetlanguage="en-US")
108 assert outputfile.getvalue() == oointro + '2002-02-02 02:02:02' + oooutro
109
111 """test to ensure that we convert escapes correctly"""
112 oosource = r'svx source\dialog\numpages.src 0 string RID_SVXPAGE_NUM_OPTIONS STR_BULLET 0 en-US Column1\tColumn2\r\n 2002-02-02 02:02:02' + '\r\n'
113 posource = '''#: numpages.src#RID_SVXPAGE_NUM_OPTIONS.STR_BULLET.string.text\nmsgid "Column1\\tColumn2\\r\\n"\nmsgstr "Kolom1\\tKolom2\\r\\n"\n'''
114 inputfile = wStringIO.StringIO(posource)
115 outputfile = wStringIO.StringIO()
116 templatefile = wStringIO.StringIO(oosource)
117 assert po2oo.convertoo(inputfile, outputfile, templatefile, targetlanguage="af-ZA")
118 assert "\tKolom1\\tKolom2\\r\\n\t" in outputfile.getvalue()
119
121 """test to ensure that we convert helpcontent escapes correctly"""
122
123
124
125 oosource = r'helpcontent2 source\text\shared\3dsettings_toolbar.xhp 0 help par_idN1056A 0 en-US \<ahelp hid=\".\"\>The 3D-Settings toolbar controls properties of selected 3D objects.\</ahelp\> 2002-02-02 02:02:02' + '\r\n'
126 posource = r'''#: 3dsettings_toolbar.xhp#par_idN1056A.help.text
127 msgid ""
128 "<ahelp hid=\".\">The 3D-Settings toolbar controls properties of selected 3D "
129 "ob jects.</ahelp>"
130 msgstr ""
131 "<ahelp hid=\".\" >Zeee 3DDDD-Settings toolbar controls properties of selected 3D "
132 "objects.</ahelp>"
133 '''
134 inputfile = wStringIO.StringIO(posource)
135 outputfile = wStringIO.StringIO()
136 templatefile = wStringIO.StringIO(oosource)
137 assert po2oo.convertoo(inputfile, outputfile, templatefile, targetlanguage="af-ZA")
138 assert r"\<ahelp hid=\".\" \>Zeee 3DDDD-Settings toolbar controls properties of selected 3D objects.\</ahelp\>" in outputfile.getvalue()
139
141 """test to ensure that we convert helpcontent escapes correctly"""
142 oosource = r'helpcontent2 source\text\scalc\05\empty_cells.xhp 0 help par_id2629474 0 en-US A1: <empty> 2002-02-02 02:02:02' + '\r\n'
143 posource = r'''#: empty_cells.xhp#par_id2629474.help.text
144 msgid "A1: <empty>"
145 msgstr "Aa1: <empty>"
146 '''
147 inputfile = wStringIO.StringIO(posource)
148 outputfile = wStringIO.StringIO()
149 templatefile = wStringIO.StringIO(oosource)
150 assert po2oo.convertoo(inputfile, outputfile, templatefile, targetlanguage="af-ZA")
151 assert r"Aa1: <empty>" in outputfile.getvalue()
152
154 """Tests running actual po2oo commands on files"""
155 convertmodule = po2oo
156
158 """tests getting help"""
159 options = test_convert.TestConvertCommand.test_help(self)
160 options = self.help_check(options, "--source-language=LANG")
161 options = self.help_check(options, "--language=LANG")
162 options = self.help_check(options, "-T, --keeptimestamp")
163 options = self.help_check(options, "--nonrecursiveoutput")
164 options = self.help_check(options, "--nonrecursivetemplate")
165 options = self.help_check(options, "--filteraction")
166 options = self.help_check(options, "--fuzzy")
167 options = self.help_check(options, "--nofuzzy")
168 options = self.help_check(options, "-t TEMPLATE, --template=TEMPLATE")
169 options = self.help_check(options, "--multifile=MULTIFILESTYLE", last=True)
170
171 - def merge2oo(self, oosource, posource):
172 """helper that merges po translations to oo source through files"""
173 outputoo = convertor.convertstore(inputpo)
174 return outputoo
175
176 - def convertoo(self, posource, ootemplate, language="en-US"):
177 """helper to exercise the command line function"""
178 self.create_testfile(os.path.join("input", "svx", "source", "dialog.po"), posource)
179 self.create_testfile("input.oo", ootemplate)
180 self.run_command("input", "output.oo", template="input.oo", language=language, keeptimestamp=True)
181 return self.read_testfile("output.oo")
182