2 # -*- coding: utf-8 -*-
4 # Copyright 2004-2006 Zuza Software Foundation
6 # This file is part of translate.
8 # translate is free software; you can redistribute it and/or modify
9 # it under the terms of the GNU General Public License as published by
10 # the Free Software Foundation; either version 2 of the License, or
11 # (at your option) any later version.
13 # translate is distributed in the hope that it will be useful,
14 # but WITHOUT ANY WARRANTY; without even the implied warranty of
15 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 # GNU General Public License for more details.
18 # You should have received a copy of the GNU General Public License
19 # along with translate; if not, write to the Free Software
20 # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
23 """convert OpenDocument (ODF) files to Gettext PO localization files"""
25 from translate
.storage
import po
26 from translate
.storage
import odf
29 def convertstore(self
, inputfile
):
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
)
38 for unit
in odfdoc
.getunits():
41 newunit
= thetargetfile
.addsourceunit(unit
.source
)
42 newunit
.addlocations("%s:%d" % (filename
, blocknum
))
45 def convertodf(inputfile
, outputfile
, templates
):
46 """reads in stdin using fromfileclass, converts using convertorclass, writes to stdout"""
48 outputstore
= convertor
.convertstore(inputfile
)
49 if outputstore
.isempty():
51 outputfile
.write(str(outputstore
))
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__
)
61 if __name__
== '__main__':