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