3 from translate
.storage
import poxliff
4 from translate
.storage
import test_xliff
5 from translate
.misc
.multistring
import multistring
7 class TestPOXLIFFUnit(test_xliff
.TestXLIFFUnit
):
8 UnitClass
= poxliff
.PoXliffUnit
10 def test_plurals(self
):
11 """Tests that plurals are handled correctly."""
12 unit
= self
.UnitClass(multistring(["Cow", "Cows"]))
13 print type(unit
.source
)
14 print repr(unit
.source
)
15 assert isinstance(unit
.source
, multistring
)
16 assert unit
.source
.strings
== ["Cow", "Cows"]
17 assert unit
.source
== "Cow"
19 unit
.target
= ["Koei", "Koeie"]
20 assert isinstance(unit
.target
, multistring
)
21 assert unit
.target
.strings
== ["Koei", "Koeie"]
22 assert unit
.target
== "Koei"
24 unit
.target
= [u
"Sk\u00ear", u
"Sk\u00eare"]
25 assert isinstance(unit
.target
, multistring
)
26 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"
31 """Tests that ids are assigned correctly, especially for plurals"""
32 unit
= self
.UnitClass("gras")
33 assert not unit
.getid()
35 assert unit
.getid() == "4"
37 unit
= self
.UnitClass(multistring(["shoe", "shoes"]))
38 assert not unit
.getid()
40 assert unit
.getid() == "20"
41 assert unit
.units
[1].getid() == "20[1]"
43 unit
.target
= ["utshani", "uutshani", "uuutshani"]
44 assert unit
.getid() == "20"
45 assert unit
.units
[1].getid() == "20[1]"
47 class TestPOXLIFFfile(test_xliff
.TestXLIFFfile
):
48 StoreClass
= poxliff
.PoXliffFile
49 xliffskeleton
= '''<?xml version="1.0" ?>
50 <xliff version="1.1" xmlns="urn:oasis:names:tc:xliff:document:1.1">
51 <file original="filename.po" source-language="en-US" datatype="po">
59 minixlf
= self
.xliffskeleton
% '''<group restype="x-gettext-plurals">
60 <trans-unit id="1[0]" xml:space="preserve">
62 <target>inkomo</target>
64 <trans-unit id="1[1]" xml:space="preserve">
66 <target>iinkomo</target>
69 xlifffile
= self
.StoreClass
.parsestring(minixlf
)
70 assert len(xlifffile
.units
) == 1
71 assert xlifffile
.translate("cow") == "inkomo"
72 assert xlifffile
.units
[0].source
== "cow"
73 assert xlifffile
.units
[0].source
== multistring(["cow", "cows"])
76 minixlf
= self
.xliffskeleton
% '''<group restype="x-gettext-plurals">
77 <trans-unit id="1[0]" xml:space="preserve">
79 <target>inkomo</target>
80 <note from="po-translator">Zulu translation of program ABC</note>
81 <note from="developer">azoozoo come back!</note>
83 <trans-unit id="1[1]" xml:space="preserve">
85 <target>iinkomo</target>
86 <note from="po-translator">Zulu translation of program ABC</note>
87 <note from="developer">azoozoo come back!</note>
90 xlifffile
= self
.StoreClass
.parsestring(minixlf
)
91 assert xlifffile
.units
[0].getnotes() == "Zulu translation of program ABC\nazoozoo come back!"
92 assert xlifffile
.units
[0].getnotes("developer") == "azoozoo come back!"
93 assert xlifffile
.units
[0].getnotes("po-translator") == "Zulu translation of program ABC"