1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23 """convert Gettext PO localization files to HTML files
24
25 see: http://translate.sourceforge.net/wiki/toolkit/po2html for examples and
26 usage instructions
27 """
28
29 from translate.storage import html
30 from translate.storage import po
31
32
34 """po2html can take a po file and generate html. best to give it a
35 template file otherwise will just concat msgstrs"""
36
38 unit = self.inputstore.sourceindex.get(string, None)
39 if unit is None:
40 return string
41 unit = unit[0]
42 if self.includefuzzy or not unit.isfuzzy():
43 return unit.target
44 else:
45 return None
46
47 - def mergestore(self, inputstore, templatetext, includefuzzy):
54
55
56 -def converthtml(inputfile, outputfile, templatefile, includefuzzy=False):
57 """reads in stdin using fromfileclass, converts using convertorclass,
58 writes to stdout"""
59 inputstore = po.pofile(inputfile)
60 convertor = po2html()
61 if templatefile is None:
62 raise ValueError("must have template file for HTML files")
63 else:
64 outputstring = convertor.mergestore(inputstore, templatefile,
65 includefuzzy)
66 outputfilepos = outputfile.tell()
67 outputfile.write(outputstring.encode('utf-8'))
68 return 1
69
70
72 from translate.convert import convert
73 from translate.misc import stdiotell
74 import sys
75 sys.stdout = stdiotell.StdIOWrapper(sys.stdout)
76 formats = {("po", "htm"): ("htm", converthtml),
77 ("po", "html"): ("html", converthtml),
78 ("po", "xhtml"): ("xhtml", converthtml),
79 ("po"): ("html", converthtml),
80 }
81 parser = convert.ConvertOptionParser(formats, usetemplates=True,
82 description=__doc__)
83 parser.add_fuzzy_option()
84 parser.run(argv)
85
86
87 if __name__ == '__main__':
88 main()
89