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 re
25 import sys
26 from translate.storage import tiki
27 from translate.storage import po
28
30 - def __init__(self, includeunused=False):
31 """
32 @param includeunused: On conversion, should the "unused" section be preserved? Default: False
33 """
34 self.includeunused = includeunused
35
37 """Converts a given (parsed) tiki file to a po file.
38
39 @param thetikifile: a tikifile pre-loaded with input data
40 """
41 thetargetfile = po.pofile()
42
43
44 targetheader = thetargetfile.makeheader(charset="UTF-8", encoding="8bit")
45 thetargetfile.addunit(targetheader)
46
47
48 for unit in thetikifile.units:
49 if not self.includeunused and "unused" in unit.getlocations():
50 continue
51 newunit = po.pounit()
52 newunit.source = unit.source
53 newunit.settarget(unit.target)
54 locations = unit.getlocations()
55 if locations:
56 newunit.addlocations(locations)
57 thetargetfile.addunit(newunit)
58 return thetargetfile
59
60 -def converttiki(inputfile, outputfile, template=None, includeunused=False):
61 """Converts from tiki file format to po.
62
63 @param inputfile: file handle of the source
64 @param outputfile: file handle to write to
65 @param template: unused
66 @param includeunused: Include the "usused" section of the tiki file? Default: False
67 """
68 convertor = tiki2po(includeunused=includeunused)
69 inputstore = tiki.TikiStore(inputfile)
70 outputstore = convertor.convertstore(inputstore)
71 if outputstore.isempty():
72 return False
73 outputfile.write(str(outputstore))
74 return True
75
77 """Converts tiki .php files to .po."""
78 from translate.convert import convert
79 from translate.misc import stdiotell
80 sys.stdout = stdiotell.StdIOWrapper(sys.stdout)
81
82 formats = {"php":("po",converttiki)}
83
84 parser = convert.ConvertOptionParser(formats, description=__doc__)
85 parser.add_option("", "--include-unused", dest="includeunused", action="store_true", default=False, help="Include strings in the unused section")
86 parser.passthrough.append("includeunused")
87 parser.run(argv)
88
89 if __name__ == '__main__':
90 main()
91