| 5 |
|
from transolution.path_mod import path
|
| 6 |
|
from transolution.xmlutils import createNodeAttr,NodeCreator,createDocument,EMPTY_NAMESPACE,XML_NAMESPACE
|
| 7 |
|
from transolution.xliffeditor.document.segments import TuSegment,External
|
| 8 |
|
from transolution.xliffeditor.xliffparser_ng import XliffDocument,XliffException
|
| 9 |
|
|
| |
5 |
from transolution.path_mod import path
|
| |
6 |
from transolution.xmlutils import createNodeAttr,NodeCreator,createDocument,EMPTY_NAMESPACE,XML_NAMESPACE
|
| |
7 |
from transolution.xliffeditor.document.segments import TuSegment,External
|
| |
8 |
from transolution.xliffeditor.xliffparser_ng import XliffDocument,XliffException
|
| |
9 |
|
| 15 |
|
## if len(entry.xlatComment) > 0:
|
| 16 |
|
## note = doc.createElementNS(EMPTY_NAMESPACE,"note")
|
| 17 |
|
## str_note = u"".join(entry.xlatComment).strip()
|
| 18 |
|
## note_txt = doc.createTextNode(str_note)
|
| 19 |
|
## note.appendChild(note_txt)
|
| 20 |
|
## header.appendChild(note)
|
| 21 |
|
## prop = doc.createElementNS(EMPTY_NAMESPACE,"prop")
|
| 22 |
|
## prop.setAttributeNS(EMPTY_NAMESPACE,"type","x-gettext-pi")
|
| 23 |
|
## str_prop = u"".join(entry.procComment).strip()
|
| 24 |
|
## prop_txt = doc.createTextNode(str_prop)
|
| 25 |
|
## prop.appendChild(prop_txt)
|
| 26 |
|
## header.appendChild(prop)
|
| |
15 |
## if len(entry.xlatComment) > 0:
|
| |
16 |
## note = doc.createElementNS(EMPTY_NAMESPACE,"note")
|
| |
17 |
## str_note = u"".join(entry.xlatComment).strip()
|
| |
18 |
## note_txt = doc.createTextNode(str_note)
|
| |
19 |
## note.appendChild(note_txt)
|
| |
20 |
## header.appendChild(note)
|
| |
21 |
## prop = doc.createElementNS(EMPTY_NAMESPACE,"prop")
|
| |
22 |
## prop.setAttributeNS(EMPTY_NAMESPACE,"type","x-gettext-pi")
|
| |
23 |
## str_prop = u"".join(entry.procComment).strip()
|
| |
24 |
## prop_txt = doc.createTextNode(str_prop)
|
| |
25 |
## prop.appendChild(prop_txt)
|
| |
26 |
## header.appendChild(prop)
|
| 34 |
|
## if len(entry.xlatComment) > 0:
|
| 35 |
|
## note = doc.createElementNS(EMPTY_NAMESPACE,"note")
|
| 36 |
|
## str_note = u"".join(entry.xlatComment).strip()
|
| 37 |
|
## note_txt = doc.createTextNode(str_note)
|
| 38 |
|
## note.appendChild(note_txt)
|
| 39 |
|
## tu.appendChild(note)
|
| 40 |
|
## if len(entry.autoComment) > 0:
|
| 41 |
|
## note = doc.createElementNS(EMPTY_NAMESPACE,"note")
|
| 42 |
|
## str_note = u"".join(entry.autoComment).strip()
|
| 43 |
|
## note_txt = doc.createTextNode(str_note)
|
| 44 |
|
## note.appendChild(note_txt)
|
| 45 |
|
## tu.appendChild(note)
|
| 46 |
|
## if len(entry.refComment) > 0:
|
| 47 |
|
## prop = doc.createElementNS(EMPTY_NAMESPACE,"prop")
|
| 48 |
|
## prop.setAttributeNS(EMPTY_NAMESPACE,"type","x-gettext-ref")
|
| 49 |
|
## str_prop = u"".join(entry.refComment).strip()
|
| 50 |
|
## prop_txt = doc.createTextNode(str_prop)
|
| 51 |
|
## prop.appendChild(prop_txt)
|
| 52 |
|
## tu.appendChild(prop)
|
| 53 |
|
## if len(entry.procComment) > 0:
|
| 54 |
|
## prop = doc.createElementNS(EMPTY_NAMESPACE,"prop")
|
| 55 |
|
## prop.setAttributeNS(EMPTY_NAMESPACE,"type","x-gettext-pi")
|
| 56 |
|
## str_prop = u"".join(entry.procComment).strip()
|
| 57 |
|
## prop_txt = doc.createTextNode(str_prop)
|
| 58 |
|
## prop.appendChild(prop_txt)
|
| 59 |
|
## tu.appendChild(prop)
|
| |
34 |
## if len(entry.xlatComment) > 0:
|
| |
35 |
## note = doc.createElementNS(EMPTY_NAMESPACE,"note")
|
| |
36 |
## str_note = u"".join(entry.xlatComment).strip()
|
| |
37 |
## note_txt = doc.createTextNode(str_note)
|
| |
38 |
## note.appendChild(note_txt)
|
| |
39 |
## tu.appendChild(note)
|
| |
40 |
## if len(entry.autoComment) > 0:
|
| |
41 |
## note = doc.createElementNS(EMPTY_NAMESPACE,"note")
|
| |
42 |
## str_note = u"".join(entry.autoComment).strip()
|
| |
43 |
## note_txt = doc.createTextNode(str_note)
|
| |
44 |
## note.appendChild(note_txt)
|
| |
45 |
## tu.appendChild(note)
|
| |
46 |
## if len(entry.refComment) > 0:
|
| |
47 |
## prop = doc.createElementNS(EMPTY_NAMESPACE,"prop")
|
| |
48 |
## prop.setAttributeNS(EMPTY_NAMESPACE,"type","x-gettext-ref")
|
| |
49 |
## str_prop = u"".join(entry.refComment).strip()
|
| |
50 |
## prop_txt = doc.createTextNode(str_prop)
|
| |
51 |
## prop.appendChild(prop_txt)
|
| |
52 |
## tu.appendChild(prop)
|
| |
53 |
## if len(entry.procComment) > 0:
|
| |
54 |
## prop = doc.createElementNS(EMPTY_NAMESPACE,"prop")
|
| |
55 |
## prop.setAttributeNS(EMPTY_NAMESPACE,"type","x-gettext-pi")
|
| |
56 |
## str_prop = u"".join(entry.procComment).strip()
|
| |
57 |
## prop_txt = doc.createTextNode(str_prop)
|
| |
58 |
## prop.appendChild(prop_txt)
|
| |
59 |
## tu.appendChild(prop)
|
| 78 |
|
|
| 79 |
|
|
| 80 |
|
def parseArgs():
|
| 81 |
|
import sys
|
| 82 |
|
from optparse import OptionParser
|
| 83 |
|
|
| 84 |
|
usage = "usage: %prog [options] path out_tmx"
|
| 85 |
|
|
| 86 |
|
op = OptionParser(usage=usage)
|
| 87 |
|
op.add_option('-r', '--recursive',
|
| 88 |
|
action='store_true', dest='recursive',
|
| 89 |
|
help='Process files recursive.')
|
| 90 |
|
op.add_option('-f', '--fmask',
|
| 91 |
|
action='store', type='string', dest='fmask',
|
| 92 |
|
help='File mask to use when running recursive.')
|
| 93 |
|
|
| 94 |
|
|
| 95 |
|
options, args = op.parse_args(sys.argv[1:])
|
| 96 |
|
try:
|
| 97 |
|
pname = path(args[0])
|
| 98 |
|
outfile = path(args[1])
|
| 99 |
|
except IndexError,e:
|
| 100 |
|
op.error("Invalid number if arguments, use -h for help")
|
| 101 |
|
|
| 102 |
|
|
| 103 |
|
if options.recursive:
|
| 104 |
|
if not options.fmask:
|
| 105 |
|
op.error("must give filemask option to when recurse")
|
| 106 |
|
else:
|
| 107 |
|
fnames = pname.walkfiles(options.fmask)
|
| 108 |
|
else:
|
| 109 |
|
if options.fmask:
|
| 110 |
|
if not pname.isdir():
|
| 111 |
|
op.error("must give a directory path when option fmask is given")
|
| 112 |
|
else:
|
| 113 |
|
fnames = pname.listdir(options.fmask)
|
| 114 |
|
else:
|
| 115 |
|
fnames = [pname,]
|
| 116 |
|
|
| 117 |
|
|
| 118 |
|
options.fnames = fnames
|
| 119 |
|
options.outfile = outfile
|
| 120 |
|
return options
|
| 121 |
|
|
| 122 |
|
|
| 123 |
|
def main():
|
| 124 |
|
import sys
|
| 125 |
|
import codecs
|
| 126 |
|
import transolution
|
| 127 |
|
global src_lang,trg_lang
|
| 128 |
|
|
| 129 |
|
options = parseArgs()
|
| 130 |
|
|
| |
78 |
|
| |
79 |
|
| |
80 |
def parseArgs():
|
| |
81 |
import sys
|
| |
82 |
from optparse import OptionParser
|
| |
83 |
|
| |
84 |
usage = "usage: %prog [options] path out_tmx"
|
| |
85 |
|
| |
86 |
op = OptionParser(usage=usage)
|
| |
87 |
op.add_option('-r', '--recursive',
|
| |
88 |
action='store_true', dest='recursive',
|
| |
89 |
help='Process files recursive.')
|
| |
90 |
op.add_option('-f', '--fmask',
|
| |
91 |
action='store', type='string', dest='fmask',
|
| |
92 |
help='File mask to use when running recursive.')
|
| |
93 |
|
| |
94 |
|
| |
95 |
options, args = op.parse_args(sys.argv[1:])
|
| |
96 |
try:
|
| |
97 |
pname = path(args[0])
|
| |
98 |
outfile = path(args[1])
|
| |
99 |
except IndexError,e:
|
| |
100 |
op.error("Invalid number if arguments, use -h for help")
|
| |
101 |
|
| |
102 |
|
| |
103 |
if options.recursive:
|
| |
104 |
if not options.fmask:
|
| |
105 |
op.error("must give filemask option to when recurse")
|
| |
106 |
else:
|
| |
107 |
fnames = pname.walkfiles(options.fmask)
|
| |
108 |
else:
|
| |
109 |
if options.fmask:
|
| |
110 |
if not pname.isdir():
|
| |
111 |
op.error("must give a directory path when option fmask is given")
|
| |
112 |
else:
|
| |
113 |
fnames = pname.listdir(options.fmask)
|
| |
114 |
else:
|
| |
115 |
fnames = [pname,]
|
| |
116 |
|
| |
117 |
|
| |
118 |
options.fnames = fnames
|
| |
119 |
options.outfile = outfile
|
| |
120 |
return options
|
| |
121 |
|
| |
122 |
|
| |
123 |
def main():
|
| |
124 |
import sys
|
| |
125 |
import codecs
|
| |
126 |
import transolution
|
| |
127 |
global src_lang,trg_lang
|
| |
128 |
|
| |
129 |
options = parseArgs()
|
| |
130 |
|
| 134 |
|
body = dom.createElementNS(EMPTY_NAMESPACE,"body")
|
| 135 |
|
doc.appendChild(body)
|
| 136 |
|
print "Parsing Xliff"
|
| 137 |
|
for fname in options.fnames:
|
| 138 |
|
|
| 139 |
|
print 'Processing:%s -->'%(fname,)
|
| 140 |
|
xliff = XliffDocument(fname)
|
| 141 |
|
xliff.parse()
|
| 142 |
|
for filenode in xliff.files:
|
| 143 |
|
src_lang = filenode.getSourceLang()
|
| 144 |
|
trg_lang = filenode.getTargetLang()
|
| 145 |
|
assert src_lang and trg_lang,'Source or Target language not set.'
|
| 146 |
|
|
| 147 |
|
filenode.parseSkeleton()
|
| 148 |
|
for seg in filenode.generateSegments():
|
| 149 |
|
if seg.__class__ is TuSegment and seg.tu.hasTarget():
|
| 150 |
|
addTMXTu(dom,body,seg)
|
| 151 |
|
|
| 152 |
|
print "Writing TMX"
|
| 153 |
|
transolution.xmlutils.toxml(doc,file(options.outfile,'w'))
|
| 154 |
|
print "Done"
|
| 155 |
|
if __name__ == "__main__":
|
| 156 |
|
main()
|
| |
134 |
body = dom.createElementNS(EMPTY_NAMESPACE,"body")
|
| |
135 |
doc.appendChild(body)
|
| |
136 |
print "Parsing Xliff"
|
| |
137 |
for fname in options.fnames:
|
| |
138 |
|
| |
139 |
print 'Processing:%s -->'%(fname,)
|
| |
140 |
xliff = XliffDocument(fname)
|
| |
141 |
xliff.parse()
|
| |
142 |
for filenode in xliff.files:
|
| |
143 |
src_lang = filenode.getSourceLang()
|
| |
144 |
trg_lang = filenode.getTargetLang()
|
| |
145 |
assert src_lang and trg_lang,'Source or Target language not set.'
|
| |
146 |
|
| |
147 |
filenode.parseSkeleton()
|
| |
148 |
for seg in filenode.generateSegments():
|
| |
149 |
if seg.__class__ is TuSegment and seg.tu.hasTarget():
|
| |
150 |
addTMXTu(dom,body,seg)
|
| |
151 |
|
| |
152 |
print "Writing TMX"
|
| |
153 |
transolution.xmlutils.toxml(doc,file(options.outfile,'w'))
|
| |
154 |
print "Done"
|
| |
155 |
if __name__ == "__main__":
|
| |
156 |
main()
|