1
2
3
4 from translate.convert import po2prop
5 from translate.convert import test_convert
6 from translate.misc import wStringIO
7 from translate.storage import po
8
11 """helper that converts po source to .properties source without requiring files"""
12 inputfile = wStringIO.StringIO(posource)
13 inputpo = po.pofile(inputfile)
14 convertor = po2prop.po2prop()
15 outputprop = convertor.convertstore(inputpo)
16 return outputprop
17
18 - def merge2prop(self, propsource, posource, personality="java"):
19 """helper that merges po translations to .properties source without requiring files"""
20 inputfile = wStringIO.StringIO(posource)
21 inputpo = po.pofile(inputfile)
22 templatefile = wStringIO.StringIO(propsource)
23
24 convertor = po2prop.reprop(templatefile)
25 outputprop = convertor.convertstore(inputpo, personality=personality)
26 print outputprop
27 return outputprop
28
30 """check the simplest case of merging a translation"""
31 posource = '''#: prop\nmsgid "value"\nmsgstr "waarde"\n'''
32 proptemplate = '''prop=value\n'''
33 propexpected = '''prop=waarde\n'''
34 propfile = self.merge2prop(proptemplate, posource)
35 print propfile
36 assert propfile == [propexpected]
37
39 """check that we preserver hard coded newlines at the start and end of sentence"""
40 posource = '''#: prop\nmsgid "\\nvalue\\n\\n"\nmsgstr "\\nwaarde\\n\\n"\n'''
41 proptemplate = '''prop=\\nvalue\\n\\n\n'''
42 propexpected = '''prop=\\nwaarde\\n\\n\n'''
43 propfile = self.merge2prop(proptemplate, posource)
44 print propfile
45 assert propfile == [propexpected]
46
48 """check that we preserve any spacing in properties files when merging"""
49 posource = '''#: prop\nmsgid "value"\nmsgstr "waarde"\n'''
50 proptemplate = '''prop = value\n'''
51 propexpected = '''prop = waarde\n'''
52 propfile = self.merge2prop(proptemplate, posource)
53 print propfile
54 assert propfile == [propexpected]
55
57 """check that we can correctly merge entries that are blank in the template"""
58 posource = '''#: accesskey-accept
59 msgid ""
60 "_: accesskey-accept\n"
61 ""
62 msgstr ""'''
63 proptemplate = 'accesskey-accept=\n'
64 propexpected = 'accesskey-accept=\n'
65 propfile = self.merge2prop(proptemplate, posource)
66 print propfile
67 assert propfile == [propexpected]
68
70 """check merging a fuzzy translation"""
71 posource = '''#: prop\n#, fuzzy\nmsgid "value"\nmsgstr "waarde"\n'''
72 proptemplate = '''prop=value\n'''
73 propexpected = '''prop=value\n'''
74 propfile = self.merge2prop(proptemplate, posource)
75 print propfile
76 assert propfile == [propexpected]
77
79 """check that when merging with a template with no property values that we copy the template"""
80 posource = ""
81 proptemplate = "# A comment\n"
82 propexpected = proptemplate
83 propfile = self.merge2prop(proptemplate, posource)
84 print propfile
85 assert propfile == [propexpected]
86
88 """test that we output correctly for Java and Mozilla style property files. Mozilla uses Unicode, while Java uses escaped Unicode"""
89 posource = '''#: prop\nmsgid "value"\nmsgstr "ṽḁḽṻḝ"\n'''
90 proptemplate = '''prop = value\n'''
91 propexpectedjava = '''prop = \\u1E7D\\u1E01\\u1E3D\\u1E7B\\u1E1D\n'''
92 propfile = self.merge2prop(proptemplate, posource)
93 print propfile
94 assert propfile == [propexpectedjava]
95 propexpectedmozilla = '''prop = ṽḁḽṻḝ\n'''
96 propfile = self.merge2prop(proptemplate, posource, personality="mozilla")
97 print propfile
98 assert propfile == [propexpectedmozilla]
99
101 """Tests running actual po2prop commands on files"""
102 convertmodule = po2prop
103 defaultoptions = {"progress": "none"}
104
112