1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23 """convert XLIFF localization files to Gettext PO localization files
24
25 see: http://translate.sourceforge.net/wiki/toolkit/xliff2po for examples and
26 usage instructions
27 """
28
29 from translate.storage import po
30 from translate.storage import xliff
31 from translate.misc import wStringIO
32
35 """makes a pounit from the given transunit"""
36 thepo = po.pounit()
37
38
39 if transunit.getrestype() == "x-gettext-domain-header":
40 thepo.source = ""
41 else:
42 thepo.source = transunit.source
43 thepo.target = transunit.target
44
45
46 locations = transunit.getlocations()
47 if locations:
48 thepo.addlocation("%s" % " ".join(locations))
49
50
51
52 trancomments = transunit.getnotes("translator")
53 if trancomments:
54 thepo.addnote(trancomments, origin="translator")
55
56
57 autocomments = transunit.getnotes("developer")
58 if autocomments:
59 thepo.addnote(autocomments, origin="developer")
60
61
62 if transunit.isfuzzy():
63 thepo.markfuzzy(True)
64
65 return thepo
66
68 """converts a .xliff file to .po format"""
69
70
71
72 if not isinstance(inputfile, (file, wStringIO.StringIO)):
73 inputfile = str(inputfile)
74 XliffFile = xliff.xlifffile.parsestring(inputfile)
75 thetargetfile = po.pofile()
76 targetheader = thetargetfile.makeheader(charset="UTF-8", encoding="8bit")
77
78 for transunit in XliffFile.units:
79 thepo = self.converttransunit(transunit)
80 thetargetfile.addunit(thepo)
81 return thetargetfile
82
84 """reads in stdin using fromfileclass, converts using convertorclass, writes to stdout"""
85 convertor = xliff2po()
86 outputstore = convertor.convertstore(inputfile)
87 if outputstore.isempty():
88 return 0
89 outputfile.write(str(outputstore))
90 return 1
91
93 from translate.convert import convert
94 formats = {"xlf":("po", convertxliff)}
95 parser = convert.ConvertOptionParser(formats, usepots=True, description=__doc__)
96 parser.run(argv)
97