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

Side by Side Diff: translate/convert/test_po2xliff.py

Issue 65: xliff2po & po2xliff should handle context SVN Base: https://translate.svn.sourceforge.net/svnroot/translate/src/trunk/
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:
View unified diff
OLDNEW
1 #!/usr/bin/env python 1 #!/usr/bin/env python
2 2
3 from translate.convert import po2xliff 3 from translate.convert import po2xliff
4 from translate.storage import po 4 from translate.storage import po
5 from translate.storage import poxliff 5 from translate.storage import poxliff
6 from translate.storage import lisa 6 from translate.storage import lisa
7 7
8 class TestPO2XLIFF: 8 class TestPO2XLIFF:
9 9
10 def po2xliff(self, posource, sourcelanguage='en', targetlanguage=None): 10 def po2xliff(self, posource, sourcelanguage='en', targetlanguage=None):
11 """helper that converts po source to xliff source without requiring file s""" 11 """helper that converts po source to xliff source without requiring file s"""
12 postore = po.pofile(posource) 12 postore = po.pofile(posource)
13 convertor = po2xliff.po2xliff() 13 convertor = po2xliff.po2xliff()
14 outputxliff = convertor.convertstore(postore, None, sourcelanguage=sourc elanguage, targetlanguage=targetlanguage) 14 outputxliff = convertor.convertstore(postore, None, sourcelanguage=sourc elanguage, targetlanguage=targetlanguage)
15 return poxliff.PoXliffFile(outputxliff) 15 return poxliff.PoXliffFile(outputxliff)
16 16
17 def getnode(self, xliff): 17 def getnode(self, xliff):
18 """Retrieves the trans-unit node from the dom""" 18 """Retrieves the trans-unit node from the dom"""
19 assert len(xliff.units) == 1 19 assert len(xliff.units) == 1
20 unit = xliff.units[0] 20 unit = xliff.units[0]
21 return unit 21 return unit
22 22
23 def test_minimal(self): 23 def test_minimal(self):
24 minipo = '''msgid "red"\nmsgstr "rooi"\n''' 24 minipo = '''msgid "red"\nmsgstr "rooi"\n'''
25 xliff = self.po2xliff(minipo) 25 xliff = self.po2xliff(minipo)
26 print "The generated xml:" 26 print "The generated xml:"
27 print str(xliff) 27 print str(xliff)
28 assert len(xliff.units) == 1 28 assert len(xliff.units) == 1
29 assert xliff.translate("red") == "rooi" 29 assert xliff.translate("red") == "rooi"
30 assert xliff.translate("bla") is None 30 assert xliff.translate("bla") is None
31 31
32 def test_basic(self): 32 def test_basic(self):
33 minipo = """# Afrikaans translation of program ABC 33 minipo = """# Afrikaans translation of program ABC
34 # 34 #
35 msgid "" 35 msgid ""
36 msgstr "" 36 msgstr ""
37 "Project-Id-Version: program 2.1-branch\n" 37 "Project-Id-Version: program 2.1-branch\n"
38 "Report-Msgid-Bugs-To: \n" 38 "Report-Msgid-Bugs-To: \n"
39 "POT-Creation-Date: 2006-01-09 07:15+0100\n" 39 "POT-Creation-Date: 2006-01-09 07:15+0100\n"
40 "PO-Revision-Date: 2004-03-30 17:02+0200\n" 40 "PO-Revision-Date: 2004-03-30 17:02+0200\n"
41 "Last-Translator: Zuza Software Foundation <xxx@translate.org.za>\n" 41 "Last-Translator: Zuza Software Foundation <xxx@translate.org.za>\n"
42 "Language-Team: Afrikaans <translate-discuss-xxx@lists.sourceforge.net>\n" 42 "Language-Team: Afrikaans <translate-discuss-xxx@lists.sourceforge.net>\n"
43 "MIME-Version: 1.0\n" 43 "MIME-Version: 1.0\n"
44 "Content-Type: text/plain; charset=UTF-8\n" 44 "Content-Type: text/plain; charset=UTF-8\n"
45 "Content-Transfer-Encoding: 8bit\n" 45 "Content-Transfer-Encoding: 8bit\n"
46 46
47 # Please remember to do something 47 # Please remember to do something
48 #: ../dir/file.xml.in.h:1 ../dir/file2.xml.in.h:4 48 #: ../dir/file.xml.in.h:1 ../dir/file2.xml.in.h:4
49 msgid "Applications" 49 msgid "Applications"
50 msgstr "Toepassings" 50 msgstr "Toepassings"
(...skipping 196 matching lines...) Show 10 above Show 10 below
247 msgid_plural "cows" 247 msgid_plural "cows"
248 msgstr[0] "inkomo" 248 msgstr[0] "inkomo"
249 msgstr[1] "iinkomo" 249 msgstr[1] "iinkomo"
250 msgstr[2] "iiinkomo" 250 msgstr[2] "iiinkomo"
251 ''' 251 '''
252 xliff = self.po2xliff(minipo) 252 xliff = self.po2xliff(minipo)
253 print "The generated xml:" 253 print "The generated xml:"
254 xmltext = str(xliff) 254 xmltext = str(xliff)
255 print xmltext 255 print xmltext
256 assert len(xliff.units) == 1 256 assert len(xliff.units) == 1
257 assert xliff.translate("cow") == "inkomo" 257 assert xliff.translate("cow") == "inkomo"
258 258
259 def test_language_tags(self): 259 def test_language_tags(self):
260 minipo = r'''msgid "Een" 260 minipo = r'''msgid "Een"
261 msgstr "Uno" 261 msgstr "Uno"
262 ''' 262 '''
263 xliff = self.po2xliff(minipo, "af", "es") 263 xliff = self.po2xliff(minipo, "af", "es")
264 assert xliff.sourcelanguage == "af" 264 assert xliff.sourcelanguage == "af"
265 assert xliff.targetlanguage == "es" 265 assert xliff.targetlanguage == "es"
266 266
267 def test_variables(self): 267 def test_variables(self):
268 minipo = r'''msgid "%s%s%s%s has made %s his or her buddy%s%s" 268 minipo = r'''msgid "%s%s%s%s has made %s his or her buddy%s%s"
269 msgstr "%s%s%s%s het %s sy/haar vriend/vriendin gemaak%s%s"''' 269 msgstr "%s%s%s%s het %s sy/haar vriend/vriendin gemaak%s%s"'''
270 xliff = self.po2xliff(minipo) 270 xliff = self.po2xliff(minipo)
271 print xliff.units[0].source 271 print xliff.units[0].source
272 assert xliff.units[0].source == "%s%s%s%s has made %s his or her buddy%s %s" 272 assert xliff.units[0].source == "%s%s%s%s has made %s his or her buddy%s %s"
273 273
274 def test_approved(self): 274 def test_approved(self):
275 minipo = r'''#, fuzzy 275 minipo = r'''#, fuzzy
276 msgid "two" 276 msgid "two"
277 msgstr "pedi" 277 msgstr "pedi"
278 278
279 msgid "three" 279 msgid "three"
280 msgstr "raro" 280 msgstr "raro"
281 281
282 msgid "four" 282 msgid "four"
283 msgstr "" 283 msgstr ""
284 ''' 284 '''
285 xliff = self.po2xliff(minipo) 285 xliff = self.po2xliff(minipo)
286 print "The generated xml:" 286 print "The generated xml:"
287 xmltext = str(xliff) 287 xmltext = str(xliff)
288 print xmltext 288 print xmltext
289 assert len(xliff.units) == 3 289 assert len(xliff.units) == 3
290 assert xliff.units[0].xmlelement.get("approved") == "no" 290 assert xliff.units[0].xmlelement.get("approved") == "no"
291 assert not xliff.units[0].isapproved() 291 assert not xliff.units[0].isapproved()
292 assert xliff.units[1].xmlelement.get("approved") == "yes" 292 assert xliff.units[1].xmlelement.get("approved") == "yes"
293 assert xliff.units[1].isapproved() 293 assert xliff.units[1].isapproved()
294 assert xliff.units[2].xmlelement.get("approved") == "no" 294 assert xliff.units[2].xmlelement.get("approved") == "no"
295 assert not xliff.units[2].isapproved() 295 assert not xliff.units[2].isapproved()
296 296
297 def test_po_with_msgctxt(self):
298 minipo = 'msgctxt "numbers"\nmsgid "one"\nmsgstr "um"\n'
299 xliff = self.po2xliff(minipo)
300 print str(xliff)
301 node = xliff.units[0].xmlelement
302 contextgroups = node.findall(".//%s" % xliff.namespaced("context-group") )
303 assert len(contextgroups) == 1
304 for group in contextgroups:
305 assert group.get("name") == "po-1025"
306 assert group.get("purpose") == "match information"
307 tuples = self.getcontexttuples(node, xliff.namespace)
308 assert tuples == [('x-unknown', 'numbers')]
OLDNEW

Powered by Google App Engine
This is Rietveld r159