| LEFT | RIGHT |
| 1 #!/usr/bin/env python | 1 #!/usr/bin/env python |
| 2 | 2 |
| 3 from translate.storage import poxliff | 3 from translate.storage import poxliff |
| 4 from translate.storage import test_xliff | 4 from translate.storage import test_xliff |
| 5 from translate.misc.multistring import multistring | 5 from translate.misc.multistring import multistring |
| 6 | 6 |
| 7 class TestPOXLIFFUnit(test_xliff.TestXLIFFUnit): | 7 class TestPOXLIFFUnit(test_xliff.TestXLIFFUnit): |
| 8 UnitClass = poxliff.PoXliffUnit | 8 UnitClass = poxliff.PoXliffUnit |
| 9 | 9 |
| 10 def test_plurals(self): | 10 def test_plurals(self): |
| 11 """Tests that plurals are handled correctly.""" | 11 """Tests that plurals are handled correctly.""" |
| 12 unit = self.UnitClass(multistring(["Cow", "Cows"])) | 12 unit = self.UnitClass(multistring(["Cow", "Cows"])) |
| 13 print type(unit.source) | 13 print type(unit.source) |
| 14 print repr(unit.source) | 14 print repr(unit.source) |
| 15 assert isinstance(unit.source, multistring) | 15 assert isinstance(unit.source, multistring) |
| 16 assert unit.source.strings == ["Cow", "Cows"] | 16 assert unit.source.strings == ["Cow", "Cows"] |
| 17 assert unit.source == "Cow" | 17 assert unit.source == "Cow" |
| 18 | 18 |
| 19 unit.target = ["Koei", "Koeie"] | 19 unit.target = ["Koei", "Koeie"] |
| 20 assert isinstance(unit.target, multistring) | 20 assert isinstance(unit.target, multistring) |
| 21 assert unit.target.strings == ["Koei", "Koeie"] | 21 assert unit.target.strings == ["Koei", "Koeie"] |
| 22 assert unit.target == "Koei" | 22 assert unit.target == "Koei" |
| 23 | 23 |
| 24 unit.target = [u"Sk\u00ear", u"Sk\u00eare"] | 24 unit.target = [u"Sk\u00ear", u"Sk\u00eare"] |
| 25 assert isinstance(unit.target, multistring) | 25 assert isinstance(unit.target, multistring) |
| 26 assert unit.target.strings == [u"Sk\u00ear", u"Sk\u00eare"] | 26 assert unit.target.strings == [u"Sk\u00ear", u"Sk\u00eare"] |
| 27 assert unit.target.strings == [u"Sk\u00ear", u"Sk\u00eare"] | 27 assert unit.target.strings == [u"Sk\u00ear", u"Sk\u00eare"] |
| 28 assert unit.target == u"Sk\u00ear" | 28 assert unit.target == u"Sk\u00ear" |
| 29 | 29 |
| 30 def test_ids(self): | 30 def test_ids(self): |
| 31 """Tests that ids are assigned correctly, especially for plurals""" | 31 """Tests that ids are assigned correctly, especially for plurals""" |
| 32 unit = self.UnitClass("gras") | 32 unit = self.UnitClass("gras") |
| 33 assert not unit.getid() | 33 assert not unit.getid() |
| 34 unit.setid("4") | 34 unit.setid("4") |
| 35 assert unit.getid() == "4" | 35 assert unit.getid() == "4" |
| 36 | 36 |
| 37 unit = self.UnitClass(multistring(["shoe", "shoes"])) | 37 unit = self.UnitClass(multistring(["shoe", "shoes"])) |
| 38 assert not unit.getid() | 38 assert not unit.getid() |
| 39 unit.setid("20") | 39 unit.setid("20") |
| 40 assert unit.getid() == "20" | 40 assert unit.getid() == "20" |
| 41 assert unit.units[1].getid() == "20[1]" | 41 assert unit.units[1].getid() == "20[1]" |
| 42 | 42 |
| 43 unit.target = ["utshani", "uutshani", "uuutshani"] | 43 unit.target = ["utshani", "uutshani", "uuutshani"] |
| 44 assert unit.getid() == "20" | 44 assert unit.getid() == "20" |
| 45 assert unit.units[1].getid() == "20[1]" | 45 assert unit.units[1].getid() == "20[1]" |
| 46 | 46 |
| 47 def test_context_message(self): | 47 def test_context_message(self): |
| 48 """tests context messages""" | 48 """tests context messages""" |
| 49 unit = self.UnitClass("Context") | 49 unit = self.UnitClass("Context") |
| 50 assert unit.getcontext_message() == "" | 50 assert unit.getcontext_message() == "" |
| 51 | 51 |
| 52 unit.setcontext_message("Testing") | 52 unit.setcontext_message("Testing") |
| 53 assert unit.getcontext_message() == "Testing" | 53 assert unit.getcontext_message() == "Testing" |
| 54 | 54 |
| 55 unit.setcontext_message("") | 55 unit.setcontext_message("") |
| 56 assert unit.getcontext_message() == "" | 56 assert unit.getcontext_message() == "" |
| 57 | 57 |
| 58 class TestPOXLIFFfile(test_xliff.TestXLIFFfile): | 58 class TestPOXLIFFfile(test_xliff.TestXLIFFfile): |
| 59 StoreClass = poxliff.PoXliffFile | 59 StoreClass = poxliff.PoXliffFile |
| 60 xliffskeleton = '''<?xml version="1.0" ?> | 60 xliffskeleton = '''<?xml version="1.0" ?> |
| 61 <xliff version="1.1" xmlns="urn:oasis:names:tc:xliff:document:1.1"> | 61 <xliff version="1.1" xmlns="urn:oasis:names:tc:xliff:document:1.1"> |
| 62 <file original="filename.po" source-language="en-US" datatype="po"> | 62 <file original="filename.po" source-language="en-US" datatype="po"> |
| 63 <body> | 63 <body> |
| 64 %s | 64 %s |
| 65 </body> | 65 </body> |
| 66 </file> | 66 </file> |
| 67 </xliff>''' | 67 </xliff>''' |
| 68 | 68 |
| 69 def test_parse(self): | 69 def test_parse(self): |
| 70 minixlf = self.xliffskeleton % '''<group restype="x-gettext-plurals"> | 70 minixlf = self.xliffskeleton % '''<group restype="x-gettext-plurals"> |
| 71 <trans-unit id="1[0]" xml:space="preserve"> | 71 <trans-unit id="1[0]" xml:space="preserve"> |
| 72 <source>cow</source> | 72 <source>cow</source> |
| 73 <target>inkomo</target> | 73 <target>inkomo</target> |
| 74 </trans-unit> | 74 </trans-unit> |
| 75 <trans-unit id="1[1]" xml:space="preserve"> | 75 <trans-unit id="1[1]" xml:space="preserve"> |
| 76 <source>cows</source> | 76 <source>cows</source> |
| 77 <target>iinkomo</target> | 77 <target>iinkomo</target> |
| 78 </trans-unit> | 78 </trans-unit> |
| 79 </group>''' | 79 </group>''' |
| 80 xlifffile = self.StoreClass.parsestring(minixlf) | 80 xlifffile = self.StoreClass.parsestring(minixlf) |
| 81 assert len(xlifffile.units) == 1 | 81 assert len(xlifffile.units) == 1 |
| 82 assert xlifffile.translate("cow") == "inkomo" | 82 assert xlifffile.translate("cow") == "inkomo" |
| 83 assert xlifffile.units[0].source == "cow" | 83 assert xlifffile.units[0].source == "cow" |
| 84 assert xlifffile.units[0].source == multistring(["cow", "cows"]) | 84 assert xlifffile.units[0].source == multistring(["cow", "cows"]) |
| 85 | 85 |
| 86 def test_notes(self): | 86 def test_notes(self): |
| 87 minixlf = self.xliffskeleton % '''<group restype="x-gettext-plurals"> | 87 minixlf = self.xliffskeleton % '''<group restype="x-gettext-plurals"> |
| 88 <trans-unit id="1[0]" xml:space="preserve"> | 88 <trans-unit id="1[0]" xml:space="preserve"> |
| 89 <source>cow</source> | 89 <source>cow</source> |
| 90 <target>inkomo</target> | 90 <target>inkomo</target> |
| 91 <note from="po-translator">Zulu translation of program ABC</note> | 91 <note from="po-translator">Zulu translation of program ABC</note> |
| 92 <note from="developer">azoozoo come back!</note> | 92 <note from="developer">azoozoo come back!</note> |
| 93 </trans-unit> | 93 </trans-unit> |
| 94 <trans-unit id="1[1]" xml:space="preserve"> | 94 <trans-unit id="1[1]" xml:space="preserve"> |
| 95 <source>cows</source> | 95 <source>cows</source> |
| 96 <target>iinkomo</target> | 96 <target>iinkomo</target> |
| 97 <note from="po-translator">Zulu translation of program ABC</note> | 97 <note from="po-translator">Zulu translation of program ABC</note> |
| 98 <note from="developer">azoozoo come back!</note> | 98 <note from="developer">azoozoo come back!</note> |
| 99 </trans-unit> | 99 </trans-unit> |
| 100 </group>''' | 100 </group>''' |
| 101 xlifffile = self.StoreClass.parsestring(minixlf) | 101 xlifffile = self.StoreClass.parsestring(minixlf) |
| 102 assert xlifffile.units[0].getnotes() == "Zulu translation of program ABC
\nazoozoo come back!" | 102 assert xlifffile.units[0].getnotes() == "Zulu translation of program ABC
\nazoozoo come back!" |
| 103 assert xlifffile.units[0].getnotes("developer") == "azoozoo come back!" | 103 assert xlifffile.units[0].getnotes("developer") == "azoozoo come back!" |
| 104 assert xlifffile.units[0].getnotes("po-translator") == "Zulu translation
of program ABC" | 104 assert xlifffile.units[0].getnotes("po-translator") == "Zulu translation
of program ABC" |
| LEFT | RIGHT |