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