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 from translate.storage import po
27
31
38
40
41 targetheader = self.mypofile.init_headers(charset="UTF-8", encoding="8bit")
42 targetheader.addnote("extracted from web2py", "developer")
43
44 for source_str in mydict.keys():
45 target_str = mydict[source_str]
46 if target_str.startswith('*** '):
47 target_str = ''
48 pounit = self.convertunit(source_str, target_str)
49 self.mypofile.addunit(pounit)
50
51 return self.mypofile
52
53 -def convertpy(inputfile, outputfile, encoding="UTF-8"):
54
55 new_pofile = po.pofile()
56 convertor = web2py2po(new_pofile)
57
58 mydict = eval(inputfile.read())
59 if not isinstance(mydict, dict):
60 return 0
61
62 outputstore = convertor.convertstore(mydict)
63
64 if outputstore.isempty():
65 return 0
66
67 outputfile.write(str(outputstore))
68 return 1
69
71 from translate.convert import convert
72 formats = {("py", "po"): ("po", convertpy), ("py", None): ("po", convertpy)}
73 parser = convert.ConvertOptionParser(formats, usetemplates=False, description=__doc__)
74 parser.run(argv)
75
76 if __name__ == '__main__':
77 main()
78