1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23 """convert OpenDocument (ODF) files to Gettext PO localization files"""
24
25 from translate.storage import po
26 from translate.storage import odf
27
30 """converts a file to .po format"""
31 thetargetfile = po.pofile()
32 filename = getattr(inputfile, "name", "unkown")
33 targetheader = thetargetfile.makeheader(charset="UTF-8", encoding="8bit")
34 targetheader.addnote("extracted from %s\n" % filename, "developer")
35 thetargetfile.addunit(targetheader)
36 odfdoc = odf.ODFFile(inputfile)
37 blocknum = 0
38 for unit in odfdoc.getunits():
39 if not unit: continue
40 blocknum += 1
41 newunit = thetargetfile.addsourceunit(unit.source)
42 newunit.addlocations("%s:%d" % (filename, blocknum))
43 return thetargetfile
44
46 """reads in stdin using fromfileclass, converts using convertorclass, writes to stdout"""
47 convertor = odf2po()
48 outputstore = convertor.convertstore(inputfile)
49 if outputstore.isempty():
50 return 0
51 outputfile.write(str(outputstore))
52 return 1
53
55 from translate.convert import convert
56 formats = {"sxw":("po", convertodf), "odt":("po", convertodf), "ods":("po", convertodf), "odp":("po", convertodf)}
57 parser = convert.ConvertOptionParser(formats, description=__doc__)
58 parser.run(argv)
59
60
61 if __name__ == '__main__':
62 main()
63