1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23 """convert HTML files to Gettext PO localization files
24
25 See: http://translate.sourceforge.net/wiki/toolkit/html2po for examples and
26 usage instructions
27 """
28
29 from translate.storage import po
30 from translate.storage import html
31
33 - def convertfile(self, inputfile, filename, includeheader, includeuntagged=False, duplicatestyle="msgctxt"):
45
46 -def converthtml(inputfile, outputfile, templates, includeuntagged=False, pot=False, duplicatestyle="msgctxt"):
47 """reads in stdin using fromfileclass, converts using convertorclass, writes to stdout"""
48 convertor = html2po()
49 outputfilepos = outputfile.tell()
50 includeheader = outputfilepos == 0
51 outputstore = convertor.convertfile(inputfile, getattr(inputfile, "name", "unknown"), includeheader, includeuntagged, duplicatestyle=duplicatestyle)
52 outputfile.write(str(outputstore))
53 return 1
54
56 from translate.convert import convert
57 from translate.misc import stdiotell
58 import sys
59 sys.stdout = stdiotell.StdIOWrapper(sys.stdout)
60 formats = {"html":("po", converthtml), "htm":("po", converthtml), "xhtml":("po", converthtml), None:("po", converthtml)}
61 parser = convert.ConvertOptionParser(formats, usepots=True, description=__doc__)
62 parser.add_option("-u", "--untagged", dest="includeuntagged", default=False, action="store_true",
63 help="include untagged sections")
64 parser.passthrough.append("includeuntagged")
65 parser.add_duplicates_option()
66 parser.passthrough.append("pot")
67 parser.run(argv)
68
69
70 if __name__ == '__main__':
71 main()
72