Rietveld Code Review Tool
Help | Bug tracker | Discussion group | Source code | Sign in
(48)

Delta Between Two Patch Sets: translate/convert/test_xliff2po.py

Issue 65: xliff2po & po2xliff should handle context SVN Base: https://translate.svn.sourceforge.net/svnroot/translate/src/trunk/
Left Patch Set: Added "id's" to context-group names Created 1 year, 4 months ago
Right Patch Set: Created 1 year, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Please Sign in to add in-line comments.
Jump to:
Left: View regular side by side diff
Right: View regular side by side diff
LEFTRIGHT
1 #!/usr/bin/env python 1 #!/usr/bin/env python
2 2
3 from translate.convert import xliff2po 3 from translate.convert import xliff2po
4 from translate.misc import wStringIO 4 from translate.misc import wStringIO
5 5
6 class TestXLIFF2PO: 6 class TestXLIFF2PO:
7 xliffskeleton = '''<?xml version="1.0" ?> 7 xliffskeleton = '''<?xml version="1.0" ?>
8 <xliff version="1.1" xmlns="urn:oasis:names:tc:xliff:document:1.1"> 8 <xliff version="1.1" xmlns="urn:oasis:names:tc:xliff:document:1.1">
9 <file original="filename.po" source-language="en-US" datatype="po"> 9 <file original="filename.po" source-language="en-US" datatype="po">
10 <body> 10 <body>
11 %s 11 %s
12 </body> 12 </body>
13 </file> 13 </file>
14 </xliff>''' 14 </xliff>'''
15 15
16 def xliff2po(self, xliffsource): 16 def xliff2po(self, xliffsource):
17 """helper that converts xliff source to po source without requiring file s""" 17 """helper that converts xliff source to po source without requiring file s"""
18 inputfile = wStringIO.StringIO(xliffsource) 18 inputfile = wStringIO.StringIO(xliffsource)
19 convertor = xliff2po.xliff2po() 19 convertor = xliff2po.xliff2po()
20 outputpo = convertor.convertstore(inputfile) 20 outputpo = convertor.convertstore(inputfile)
21 print "The generated po:" 21 print "The generated po:"
22 print type(outputpo) 22 print type(outputpo)
23 print str(outputpo) 23 print str(outputpo)
24 return outputpo 24 return outputpo
25 25
26 def test_minimal(self): 26 def test_minimal(self):
27 minixlf = self.xliffskeleton % '''<trans-unit> 27 minixlf = self.xliffskeleton % '''<trans-unit>
28 <source>red</source> 28 <source>red</source>
29 <target>rooi</target> 29 <target>rooi</target>
30 </trans-unit>''' 30 </trans-unit>'''
31 pofile = self.xliff2po(minixlf) 31 pofile = self.xliff2po(minixlf)
32 assert len(pofile.units) == 1 32 assert len(pofile.units) == 1
33 assert pofile.translate("red") == "rooi" 33 assert pofile.translate("red") == "rooi"
34 assert pofile.translate("bla") is None 34 assert pofile.translate("bla") is None
35 35
36 def test_basic(self): 36 def test_basic(self):
37 headertext = '''Project-Id-Version: program 2.1-branch 37 headertext = '''Project-Id-Version: program 2.1-branch
38 Report-Msgid-Bugs-To: 38 Report-Msgid-Bugs-To:
39 POT-Creation-Date: 2006-01-09 07:15+0100 39 POT-Creation-Date: 2006-01-09 07:15+0100
40 PO-Revision-Date: 2004-03-30 17:02+0200 40 PO-Revision-Date: 2004-03-30 17:02+0200
41 Last-Translator: Zuza Software Foundation &lt;xxx@translate.org.za> 41 Last-Translator: Zuza Software Foundation &lt;xxx@translate.org.za>
42 Language-Team: Afrikaans &lt;translate-discuss-xxx@lists.sourceforge.net> 42 Language-Team: Afrikaans &lt;translate-discuss-xxx@lists.sourceforge.net>
43 MIME-Version: 1.0 43 MIME-Version: 1.0
44 Content-Type: text/plain; charset=UTF-8 44 Content-Type: text/plain; charset=UTF-8
45 Content-Transfer-Encoding: 8bit''' 45 Content-Transfer-Encoding: 8bit'''
46 46
47 minixlf = (self.xliffskeleton % '''<trans-unit id="1" restype="x-gettext -domain-header" approved="no" xml:space="preserve"> 47 minixlf = (self.xliffskeleton % '''<trans-unit id="1" restype="x-gettext -domain-header" approved="no" xml:space="preserve">
48 <source>%s</source> 48 <source>%s</source>
49 <target>%s</target> 49 <target>%s</target>
50 <note from="po-translator">Zulu translation of program ABC</note> 50 <note from="po-translator">Zulu translation of program ABC</note>
(...skipping 77 matching lines...) Show 10 above Show 10 below
128 128
129 def test_fuzzy(self): 129 def test_fuzzy(self):
130 """Tests fuzzyness""" 130 """Tests fuzzyness"""
131 minixlf = self.xliffskeleton % '''<trans-unit approved="no"> 131 minixlf = self.xliffskeleton % '''<trans-unit approved="no">
132 <source>book</source> 132 <source>book</source>
133 </trans-unit> 133 </trans-unit>
134 <trans-unit id="2" approved="yes"> 134 <trans-unit id="2" approved="yes">
135 <source>nonsense</source> 135 <source>nonsense</source>
136 <target>matlhapolosa</target> 136 <target>matlhapolosa</target>
137 </trans-unit> 137 </trans-unit>
138 <trans-unit id="2" approved="no"> 138 <trans-unit id="2" approved="no">
139 <source>verb</source> 139 <source>verb</source>
140 <target state="needs-review-translation">lediri</target> 140 <target state="needs-review-translation">lediri</target>
141 </trans-unit>''' 141 </trans-unit>'''
142 pofile = self.xliff2po(minixlf) 142 pofile = self.xliff2po(minixlf)
143 assert pofile.translate("nonsense") == "matlhapolosa" 143 assert pofile.translate("nonsense") == "matlhapolosa"
144 assert pofile.translate("verb") == "lediri" 144 assert pofile.translate("verb") == "lediri"
145 assert pofile.translate("book") is None 145 assert pofile.translate("book") is None
146 assert pofile.translate("bla") is None 146 assert pofile.translate("bla") is None
147 assert len(pofile.units) == 3 147 assert len(pofile.units) == 3
148 #TODO: decide if this one should be fuzzy: 148 #TODO: decide if this one should be fuzzy:
149 #assert pofile.units[0].isfuzzy() 149 #assert pofile.units[0].isfuzzy()
150 assert not pofile.units[1].isfuzzy() 150 assert not pofile.units[1].isfuzzy()
151 assert pofile.units[2].isfuzzy() 151 assert pofile.units[2].isfuzzy()
152 152
153 def test_plurals(self): 153 def test_plurals(self):
154 """Tests fuzzyness""" 154 """Tests fuzzyness"""
155 minixlf = self.xliffskeleton % '''<group restype="x-gettext-plurals"> 155 minixlf = self.xliffskeleton % '''<group restype="x-gettext-plurals">
156 <trans-unit id="1[0]" xml:space="preserve"> 156 <trans-unit id="1[0]" xml:space="preserve">
157 <source>cow</source> 157 <source>cow</source>
158 <target>inkomo</target> 158 <target>inkomo</target>
159 </trans-unit> 159 </trans-unit>
160 <trans-unit id="1[1]" xml:space="preserve"> 160 <trans-unit id="1[1]" xml:space="preserve">
161 <source>cows</source> 161 <source>cows</source>
162 <target>iinkomo</target> 162 <target>iinkomo</target>
163 </trans-unit> 163 </trans-unit>
164 </group>''' 164 </group>'''
165 pofile = self.xliff2po(minixlf) 165 pofile = self.xliff2po(minixlf)
166 print str(pofile) 166 print str(pofile)
167 potext = str(pofile) 167 potext = str(pofile)
168 assert len(pofile.units) == 1 168 assert len(pofile.units) == 1
169 assert potext.index('msgid_plural "cows"') 169 assert potext.index('msgid_plural "cows"')
170 assert potext.index('msgstr[0] "inkomo"') 170 assert potext.index('msgstr[0] "inkomo"')
171 assert potext.index('msgstr[1] "iinkomo"') 171 assert potext.index('msgstr[1] "iinkomo"')
172 172
173 def test_xliff_with_context(self): 173 def test_xliff_with_context(self):
174 """tests if we support context strings""" 174 """tests if we support context strings"""
175 minixlf = self.xliffskeleton % '''<trans-unit id="1"> 175 minixlf = self.xliffskeleton % '''<trans-unit id="1">
176 <source>gold</source> 176 <source>gold</source>
177 <target>ouro</target> 177 <target>ouro</target>
178 <context-group name="po-msgctxt" purpose="match information"> 178 <context-group name="po-1025" purpose="match information">
179 <context context-type="x-po-msgctxt">the precious</context> 179 <context context-type="x-unknown">the precious</context>
180 </context-group> 180 </context-group>
181 </trans-unit>''' 181 </trans-unit>'''
182 pofile = self.xliff2po(minixlf) 182 pofile = self.xliff2po(minixlf)
183 unit = pofile.units[0] 183 unit = pofile.units[0]
184 assert unit.getcontext() == "the precious" 184 assert unit.getcontext() == "the precious"
185 185
186 186
187 class TestBasicXLIFF2PO(TestXLIFF2PO): 187 class TestBasicXLIFF2PO(TestXLIFF2PO):
188 """This tests a basic XLIFF file without xmlns attribute""" 188 """This tests a basic XLIFF file without xmlns attribute"""
189 189
190 xliffskeleton = '''<?xml version="1.0" ?> 190 xliffskeleton = '''<?xml version="1.0" ?>
191 <xliff version="1.1"> 191 <xliff version="1.1">
192 <file original="filename.po" source-language="en-US" datatype="po"> 192 <file original="filename.po" source-language="en-US" datatype="po">
193 <body> 193 <body>
194 %s 194 %s
195 </body> 195 </body>
196 </file> 196 </file>
197 </xliff>''' 197 </xliff>'''
LEFTRIGHT

Powered by Google App Engine
This is Rietveld r159