-
Notifications
You must be signed in to change notification settings - Fork 0
/
extopts.py
46 lines (36 loc) · 1009 Bytes
/
extopts.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
"""Grab the tips from Options.xml
$Id: extopts.py,v 1.1 2007/01/14 14:07:31 stephen Exp $
Originally ROX-Filer/src/po/tips.py by Thomas Leonard.
"""
from xml.sax import *
from xml.sax.handler import ContentHandler
import os, sys
class Handler(ContentHandler):
data = ""
def startElement(self, tag, attrs):
for x in ['title', 'label', 'end', 'unit']:
if attrs.has_key(x):
self.trans(attrs[x])
self.data = ""
def characters(self, data):
self.data = self.data + data
def endElement(self, tag):
data = self.data.strip()
if data:
self.trans(data)
self.data = ""
def trans(self, data):
data = '\\n'.join(data.split('\n'))
if data:
out.write('_("%s")\n' % data.replace('"', '\\"'))
ifname='Options.xml'
ofname='Options_strings'
if len(sys.argv)>2:
ifname=sys.argv[1]
ofname=sys.argv[2]
elif len(sys.argv)==2:
ifname=sys.argv[1]
print "Extracting translatable bits from %s..." % os.path.basename(ifname)
out = open(ofname, 'wb')
parse(ifname, Handler())
out.close()