1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22 """ Convert TikiWiki's language.php files to GetText PO files. """
23
24 import sys
25
26 from translate.storage import tiki
27 from translate.storage import po
28
29
31
32 - def __init__(self, includeunused=False):
33 """
34 @param includeunused: On conversion, should the "unused" section be preserved? Default: False
35 """
36 self.includeunused = includeunused
37
39 """Converts a given (parsed) tiki file to a po file.
40
41 @param thetikifile: a tikifile pre-loaded with input data
42 """
43 thetargetfile = po.pofile()
44
45
46 targetheader = thetargetfile.init_headers(charset="UTF-8", encoding="8bit")
47
48
49 for unit in thetikifile.units:
50 if not self.includeunused and "unused" in unit.getlocations():
51 continue
52 newunit = po.pounit()
53 newunit.source = unit.source
54 newunit.settarget(unit.target)
55 locations = unit.getlocations()
56 if locations:
57 newunit.addlocations(locations)
58 thetargetfile.addunit(newunit)
59 return thetargetfile
60
61
62 -def converttiki(inputfile, outputfile, template=None, includeunused=False):
63 """Converts from tiki file format to po.
64
65 @param inputfile: file handle of the source
66 @param outputfile: file handle to write to
67 @param template: unused
68 @param includeunused: Include the "usused" section of the tiki file? Default: False
69 """
70 convertor = tiki2po(includeunused=includeunused)
71 inputstore = tiki.TikiStore(inputfile)
72 outputstore = convertor.convertstore(inputstore)
73 if outputstore.isempty():
74 return False
75 outputfile.write(str(outputstore))
76 return True
77
78
80 """Converts tiki .php files to .po."""
81 from translate.convert import convert
82 from translate.misc import stdiotell
83 sys.stdout = stdiotell.StdIOWrapper(sys.stdout)
84
85 formats = {"php": ("po", converttiki)}
86
87 parser = convert.ConvertOptionParser(formats, description=__doc__)
88 parser.add_option("", "--include-unused", dest="includeunused", action="store_true", default=False, help="Include strings in the unused section")
89 parser.passthrough.append("includeunused")
90 parser.run(argv)
91
92
93 if __name__ == '__main__':
94 main()
95