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