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