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", keepcomments=False):
46
47 -def converthtml(inputfile, outputfile, templates, includeuntagged=False, pot=False, duplicatestyle="msgctxt", keepcomments=False):
48 """reads in stdin using fromfileclass, converts using convertorclass, writes to stdout"""
49 convertor = html2po()
50 outputfilepos = outputfile.tell()
51 includeheader = outputfilepos == 0
52 outputstore = convertor.convertfile(inputfile, getattr(inputfile, "name", "unknown"), includeheader, includeuntagged, duplicatestyle=duplicatestyle, keepcomments=keepcomments)
53 outputfile.write(str(outputstore))
54 return 1
55
57 from translate.convert import convert
58 from translate.misc import stdiotell
59 import sys
60 sys.stdout = stdiotell.StdIOWrapper(sys.stdout)
61 formats = {"html":("po", converthtml), "htm":("po", converthtml), "xhtml":("po", converthtml), None:("po", converthtml)}
62 parser = convert.ConvertOptionParser(formats, usepots=True, description=__doc__)
63 parser.add_option("-u", "--untagged", dest="includeuntagged", default=False, action="store_true",
64 help="include untagged sections")
65 parser.passthrough.append("includeuntagged")
66 parser.add_option("--keepcomments", dest="keepcomments", default=False, action="store_true",
67 help="preserve html comments as translation notes in the output")
68 parser.passthrough.append("keepcomments")
69 parser.add_duplicates_option()
70 parser.passthrough.append("pot")
71 parser.run(argv)
72
73
74 if __name__ == '__main__':
75 main()
76