1
2
3 import StringIO
4 import subprocess
5 import os.path
6
7 from translate.storage import test_base
8 from translate.storage import mo
9 from translate.storage import factory
10
13
14 posources = [
15 r'''
16 msgid ""
17 msgstr ""
18 "PO-Revision-Date: 2006-02-09 23:33+0200\n"
19 "MIME-Version: 1.0\n"
20 "Content-Type: text/plain; charset=UTF-8\n"
21 "Content-Transfer-Encoding: 8-bit\n"
22 ''',
23 r'''
24 msgid ""
25 msgstr ""
26 "PO-Revision-Date: 2006-02-09 23:33+0200\n"
27 "MIME-Version: 1.0\n"
28 "Content-Type: text/plain; charset=UTF-8\n"
29 "Content-Transfer-Encoding: 8-bit\n"
30
31 msgid "plant"
32 msgstr ""
33 ''',
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52 r'''
53 msgid ""
54 msgstr ""
55 "PO-Revision-Date: 2006-02-09 23:33+0200\n"
56 "MIME-Version: 1.0\n"
57 "Content-Type: text/plain; charset=UTF-8\n"
58 "Content-Transfer-Encoding: 8-bit\n"
59
60 msgid "plant"
61 msgstr ""
62
63 msgid ""
64 "_: Noun\n"
65 "convert"
66 msgstr "bekeerling"
67
68 msgctxt "verb"
69 msgid ""
70 "convert"
71 msgstr "omskakel"
72 ''',
73 r'''
74 msgid ""
75 msgstr ""
76 "PO-Revision-Date: 2006-02-09 23:33+0200\n"
77 "MIME-Version: 1.0\n"
78 "Content-Type: text/plain; charset=UTF-8\n"
79 "Content-Transfer-Encoding: 8-bit\n"
80
81 msgid "plant"
82 msgstr ""
83
84 msgid ""
85 "_: Noun\n"
86 "convert"
87 msgstr "bekeerling"
88
89 msgctxt "verb"
90 msgid ""
91 "convert"
92 msgstr "omskakel"
93
94 msgid "tree"
95 msgid_plural "trees"
96 msgstr[0] ""
97 ''']
98
100 StoreClass = mo.mofile
101
103 return (os.path.abspath(self.filename + '.po'),
104 os.path.abspath(self.filename + '.msgfmt.mo'),
105 os.path.abspath(self.filename + '.pocompile.mo'))
106
108 for file in self.get_mo_and_po():
109 if os.path.exists(file):
110 os.remove(file)
111
115
119
121 for posource in posources:
122 print "PO source file"
123 print posource
124 PO_FILE, MO_MSGFMT, MO_POCOMPILE = self.get_mo_and_po()
125
126 out_file = open(PO_FILE, 'w')
127 out_file.write(posource)
128 out_file.close()
129
130 subprocess.call(['msgfmt', PO_FILE, '-o', MO_MSGFMT])
131 subprocess.call(['pocompile', PO_FILE, MO_POCOMPILE])
132
133 store = factory.getobject(StringIO.StringIO(posource))
134 if store.isempty() and not os.path.exists(MO_POCOMPILE):
135
136
137 continue
138
139 mo_msgfmt_f = open(MO_MSGFMT)
140 mo_pocompile_f = open(MO_POCOMPILE)
141
142 try:
143 mo_msgfmt = mo_msgfmt_f.read()
144 print "msgfmt output:"
145 print repr(mo_msgfmt)
146 mo_pocompile = mo_pocompile_f.read()
147 print "pocompile output:"
148 print repr(mo_pocompile)
149 assert mo_msgfmt == mo_pocompile
150 finally:
151 mo_msgfmt_f.close()
152 mo_pocompile_f.close()
153