2 # -*- coding: utf-8 -*-
4 from translate
.convert
import ts2po
5 from translate
.convert
import test_convert
6 from translate
.misc
import wStringIO
9 def ts2po(self
, tssource
):
10 converter
= ts2po
.ts2po()
11 tsfile
= wStringIO
.StringIO(tssource
)
12 outputpo
= converter
.convertfile(tsfile
)
13 print "The generated po:"
18 """tests blank conversion"""
19 tssource
= '''<!DOCTYPE TS><TS>
21 <name>MainWindowBase</name>
23 <source>Project:</source>
24 <translation type="unfinished"></translation>
29 pofile
= self
.ts2po(tssource
)
30 assert len(pofile
.units
) == 2
31 assert pofile
.units
[1].source
== "Project:"
32 assert pofile
.units
[1].target
== ""
33 assert pofile
.units
[1].getlocations()[0].startswith("MainWindowBase")
34 assert not pofile
.units
[1].isfuzzy()
37 """tests basic conversion"""
38 tssource
= '''<!DOCTYPE TS><TS>
40 <name>AboutDialog</name>
42 <source>&About</source>
43 <translation>&Giới thiệu</translation>
48 pofile
= self
.ts2po(tssource
)
49 assert len(pofile
.units
) == 2
50 assert pofile
.units
[1].source
== "&About"
51 assert pofile
.units
[1].target
== u
"&Giới thiệu"
52 assert pofile
.units
[1].getlocations()[0].startswith("AboutDialog")
54 def test_unfinished(self
):
55 """tests unfinished conversion"""
56 tssource
= '''<!DOCTYPE TS><TS>
58 <name>MainWindowBase</name>
60 <source>Project:</source>
61 <translation type="unfinished">Projek vergardering</translation>
66 pofile
= self
.ts2po(tssource
)
67 assert len(pofile
.units
) == 2
68 assert pofile
.units
[1].source
== "Project:"
69 assert pofile
.units
[1].target
== "Projek vergardering"
70 assert pofile
.units
[1].getlocations()[0].startswith("MainWindowBase")
71 assert pofile
.units
[1].isfuzzy()
73 def test_multiline(self
):
74 """tests multiline message conversion"""
75 tssource
= '''<!DOCTYPE TS><TS>
81 <translation>Test with
82 new line</translation>
87 pofile
= self
.ts2po(tssource
)
88 assert len(pofile
.units
) == 2
89 assert pofile
.units
[1].source
== "Source with\nnew line"
90 assert pofile
.units
[1].target
== "Test with\nnew line"
91 assert pofile
.units
[1].getlocations()[0].startswith("@default")
93 def test_obsolete(self
):
94 """test the handling of obsolete TS entries"""
95 tssource
= '''<!DOCTYPE TS><TS>
97 <name>Obsoleted</name>
99 <source>Failed</source>
100 <translation type="obsolete">Mislukt</translation>
105 pofile
= self
.ts2po(tssource
)
106 assert pofile
.units
[1].getnotes("developer") == "(obsolete)"
107 # Test that we aren't following the old style
108 assert "_ OBSOLETE" not in pofile
.units
[1].getnotes()
110 class TestTS2POCommand(test_convert
.TestConvertCommand
, TestTS2PO
):
111 """Tests running actual ts2po commands on files"""
112 convertmodule
= ts2po
115 """tests getting help"""
116 options
= test_convert
.TestConvertCommand
.test_help(self
)
117 options
= self
.help_check(options
, "--duplicates=DUPLICATESTYLE")
118 options
= self
.help_check(options
, "-P, --pot", last
=True)