1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24 """convert web2py translation dictionaries (.py) to GNU/gettext PO files"""
25
26 import sys
27 from translate.storage import po
28
32
39
41
42 targetheader = self.mypofile.makeheader(charset="UTF-8", encoding="8bit")
43 targetheader.addnote("extracted from web2py", "developer")
44
45 self.mypofile.addunit(targetheader)
46
47 for source_str in mydict.keys():
48 target_str = mydict[source_str]
49 if target_str.startswith('*** '):
50 target_str = ''
51 pounit = self.convertunit(source_str, target_str)
52 self.mypofile.addunit(pounit)
53
54 return self.mypofile
55
56 -def convertpy(inputfile, outputfile, encoding="UTF-8"):
57
58 new_pofile = po.pofile()
59 convertor = web2py2po(new_pofile)
60
61 mydict = eval(inputfile.read())
62 if not isinstance(mydict, dict):
63 return 0
64
65 outputstore = convertor.convertstore(mydict)
66
67 if outputstore.isempty():
68 return 0
69
70 outputfile.write(str(outputstore))
71 return 1
72
74 from translate.convert import convert
75 formats = {("py", "po"): ("po", convertpy), ("py", None): ("po", convertpy)}
76 parser = convert.ConvertOptionParser(formats, usetemplates=False, description=__doc__)
77 parser.run(argv)
78
79 if __name__ == '__main__':
80 main()
81