1
2
3
4 from translate.convert import oo2po
5 from translate.convert import po2oo
6 from translate.convert import test_convert
7 from translate.misc import wStringIO
8 from translate.storage import po
9 from translate.storage.poheader import poheader
10 from translate.storage import oo
11 import os
12
14 target_filetype = po.pofile
15 conversion_module = oo2po
16 conversion_class = oo2po.oo2po
17
18 - def convert(self, oosource, sourcelanguage='en-US', targetlanguage='af-ZA'):
19 """helper that converts oo source to po source without requiring files"""
20 inputoo = oo.oofile(oosource)
21 convertor = self.conversion_class(sourcelanguage, targetlanguage)
22 outputpo = convertor.convertstore(inputoo)
23 return outputpo
24
34
36 """Convert the supplied string as part of an OpenOffice.org GSI file to po and back.
37
38 Return the string once it has been through all the conversions."""
39
40 ootemplate = r'helpcontent2 %s 0 help par_id3150670 35 0 en-US %s 2002-02-02 02:02:02'
41
42 oosource = ootemplate % (filename, entitystring)
43 ooinputfile = wStringIO.StringIO(oosource)
44 ootemplatefile = wStringIO.StringIO(oosource)
45 pooutputfile = wStringIO.StringIO()
46
47 self.conversion_module.convertoo(ooinputfile, pooutputfile, ootemplatefile, targetlanguage='en-US')
48 posource = pooutputfile.getvalue()
49
50 poinputfile = wStringIO.StringIO(posource)
51 ootemplatefile = wStringIO.StringIO(oosource)
52 oooutputfile = wStringIO.StringIO()
53 po2oo.convertoo(poinputfile, oooutputfile, ootemplatefile, targetlanguage="en-US")
54 ooresult = oooutputfile.getvalue()
55 print "original oo:\n", oosource, "po version:\n", posource, "output oo:\n", ooresult
56 return ooresult.split('\t')[10]
57
61
63 """checks that a simple oo entry converts properly to a po entry"""
64 oosource = r'svx source\dialog\numpages.src 0 string RID_SVXPAGE_NUM_OPTIONS STR_BULLET 0 en-US Character 20050924 09:13:58'
65 pofile = self.convert(oosource)
66 pounit = self.singleelement(pofile)
67 assert pounit.source == "Character"
68 assert pounit.target == ""
69
71 """checks that a simple oo entry converts escapes properly to a po entry"""
72 oosource = r"wizards source\formwizard\dbwizres.src 0 string RID_DB_FORM_WIZARD_START + 19 0 en-US Newline \n Newline Tab \t Tab CR \r CR 20050924 09:13:58"
73 pofile = self.convert(oosource)
74 pounit = self.singleelement(pofile)
75 poelementsrc = str(pounit)
76 print poelementsrc
77 assert "Newline \n Newline" in pounit.source
78 assert "Tab \t Tab" in pounit.source
79 assert "CR \r CR" in pounit.source
80
82 self.check_roundtrip('strings.src', r'The given command is not a SELECT statement.\nOnly queries are allowed.')
83 self.check_roundtrip('source\ui\dlg\AutoControls_tmpl.hrc', r';\t59\t,\t44\t:\t58\t{Tab}\t9\t{Space}\t32')
84 self.check_roundtrip('inc_openoffice\windows\msi_languages\Nsis.ulf', r'The installation files must be unpacked and copied to your hard disk in preparation for the installation. After that, the %PRODUCTNAME installation will start automatically.\r\n\r\nClick \'Next\' to continue.')
85 self.check_roundtrip('file.xhp', r'\<asdf\>')
86 self.check_roundtrip('file.xhp', r'\<asdf prop=\"value\"\>')
87 self.check_roundtrip('file.xhp', r'\<asdf prop=\"value\"\>marked up text\</asdf\>')
88 self.check_roundtrip('file.xhp', r'\<asdf prop=\"value>>\"\>')
89 self.check_roundtrip('file.xhp', r'''\<asdf prop=\"value>>\"\>'Next'>> or "<<Previous"\</asdf\>''')
90 self.check_roundtrip('address_auto.xhp', r'''example, \<item type=\"literal\"\>'Harry\\'s Bar'.\</item\>''')
91
93 """check items that are only special instances of whitespce"""
94
95 self.check_roundtrip('choose_chart_type.xhp', r' ')
96 self.check_roundtrip('choose_chart_type.xhp', '\xc2\xa0')
97
99 oosource = r"helpcontent2 source\text\shared\01\02100001.xhp 0 help par_id3150670 35 0 en-US \\< 2002-02-02 02:02:02"
100 pofile = self.convert(oosource)
101 pounit = self.singleelement(pofile)
102 poelementsrc = str(pounit)
103 print poelementsrc
104 assert pounit.source == r"\<"
105
107 """checks that a helpcontent2 entry converts escapes properly to a po entry"""
108 oosource = r"helpcontent2 source\text\smath\guide\parentheses.xhp 0 help par_id3150344 4 0 en-US size *2 \\langle x \\rangle 2002-02-02 02:02:02"
109 pofile = self.convert(oosource)
110 pounit = self.singleelement(pofile)
111 poelementsrc = str(pounit)
112 print poelementsrc
113 assert pounit.source == r'size *2 \langle x \rangle'
114
116 """tests the we have the correct url for reporting msgid bugs"""
117 oosource = r"wizards source\formwizard\dbwizres.src 0 string RID_DB_FORM_WIZARD_START + 19 0 en-US Newline \n Newline Tab \t Tab CR \r CR 20050924 09:13:58"
118 bug_url = '''http://qa.openoffice.org/issues/enter_bug.cgi''' + ('''?subcomponent=ui&comment=&short_desc=Localization issue in file: &component=l10n&form_name=enter_issue''').replace(" ", "%20").replace(":", "%3A")
119 pofile = self.convert(oosource)
120 assert pofile.units[0].isheader()
121 assert pofile.parseheader()["Report-Msgid-Bugs-To"] == bug_url
122
161
163 """Tests running actual oo2po commands on files"""
164 convertmodule = oo2po
165
175
177 """Ensures that the filename is preserved."""
178 oosource = r'svx source\dialog\numpages.src 0 string RID_SVXPAGE_NUM_OPTIONS STR_BULLET 0 en-US Character 20050924 09:13:58'
179 self.create_testfile("snippet.sdf", oosource)
180 oofile = oo.oofile(self.open_testfile("snippet.sdf"))
181 assert oofile.filename.endswith("snippet.sdf")
182 oofile.parse(oosource)
183 assert oofile.filename.endswith("snippet.sdf")
184
186 """tests the simplest possible conversion to a pot file"""
187 oosource = r'svx source\dialog\numpages.src 0 string RID_SVXPAGE_NUM_OPTIONS STR_BULLET 0 en-US Character 20050924 09:13:58'
188 self.create_testfile("simple.oo", oosource)
189 self.run_command("simple.oo", "simple.pot", pot=True, nonrecursiveinput=True)
190 pofile = self.target_filetype(self.open_testfile("simple.pot"))
191 poelement = self.singleelement(pofile)
192 assert poelement.source == "Character"
193 assert poelement.target == ""
194
196 """tests the simplest possible conversion to a po file"""
197 oosource1 = r'svx source\dialog\numpages.src 0 string RID_SVXPAGE_NUM_OPTIONS STR_BULLET 0 en-US Character 20050924 09:13:58'
198 oosource2 = r'svx source\dialog\numpages.src 0 string RID_SVXPAGE_NUM_OPTIONS STR_BULLET 0 ku Karakter 20050924 09:13:58'
199 self.create_testfile("simple.oo", oosource1 + "\n" + oosource2)
200 self.run_command("simple.oo", "simple.po", lang="ku", nonrecursiveinput=True)
201 pofile = self.target_filetype(self.open_testfile("simple.po"))
202 poelement = self.singleelement(pofile)
203 assert poelement.source == "Character"
204 assert poelement.target == "Karakter"
205
207 """tests the --multifile=onefile option and make sure it doesn't produce a directory"""
208 oosource = r'svx source\dialog\numpages.src 0 string RID_SVXPAGE_NUM_OPTIONS STR_BULLET 0 en-US Character 20050924 09:13:58'
209 self.create_testfile("simple.oo", oosource)
210 self.run_command("simple.oo", "simple.pot", pot=True, multifile="onefile")
211 assert os.path.isfile(self.get_testfilename("simple.pot"))
212
214 """test that removing of duplicates works correctly (bug 171)"""
215 oosource = r'''
216 sd source\ui\animations\SlideTransitionPane.src 0 checkbox DLG_SLIDE_TRANSITION_PANE CB_AUTO_PREVIEW HID_SD_SLIDETRANSITIONPANE_CB_AUTO_PREVIEW 1 en-US Automatic preview 20060725 03:26:42
217 sd source\ui\animations\AnimationSchemesPane.src 0 checkbox DLG_ANIMATION_SCHEMES_PANE CB_AUTO_PREVIEW HID_SD_ANIMATIONSCHEMESPANE_CB_AUTO_PREVIEW 1 en-US Automatic preview 20060725 03:26:42
218 sd source\ui\animations\CustomAnimationCreateDialog.src 0 checkbox RID_TP_CUSTOMANIMATION_ENTRANCE CBX_PREVIEW 143 en-US Automatic preview 20060725 03:26:42
219 sd source\ui\animations\CustomAnimationCreateDialog.src 0 checkbox RID_TP_CUSTOMANIMATION_ENTRANCE CBX_PREVIEW 143 fr Aperçu automatique 20060725 03:26:42
220 sd source\ui\animations\CustomAnimationSchemesPane.src 0 checkbox DLG_CUSTOMANIMATION_SCHEMES_PANE 4 0 en-US Automatic preview 20060725 03:26:42
221 sd source\ui\animations\CustomAnimationSchemesPane.src 0 checkbox DLG_CUSTOMANIMATION_SCHEMES_PANE 4 0 fr Aperçu automatique 20060725 03:26:42
222 '''
223 self.create_testfile("simple.oo", oosource)
224 self.run_command("simple.oo", "simple.po", language="fr", multifile="onefile", error="traceback", duplicates="merge")
225 pofile = self.target_filetype(self.open_testfile("simple.po"))
226 assert len(pofile.units) == 2
227 assert pofile.units[1].target == u"Aperçu automatique"
228