* src/get_strings: Support extracting strings from tips.xml file.
* src/build_po: Process tips.xml file. * src/TipOfDay.py (TipOfDay.__init__): Use translated tips. * src/template.po: new translatable strings. svn: r4586
This commit is contained in:
parent
586ab531a1
commit
bb00d70d21
@ -1,6 +1,11 @@
|
||||
2005-05-13 Alex Roitman <shura@gramps-project.org>
|
||||
* src/DateDisplay.py (DateDisplayEn): Localize format names.
|
||||
|
||||
* src/get_strings: Support extracting strings from tips.xml file.
|
||||
* src/build_po: Process tips.xml file.
|
||||
* src/TipOfDay.py (TipOfDay.__init__): Use translated tips.
|
||||
* src/po/template.po: new translatable strings.
|
||||
|
||||
2005-05-13 Martin Hawlisch <Martin.Hawlisch@gmx.de>
|
||||
* src/SelectChild.py (on_save_child_clicked) Commit new parent family
|
||||
of child properly; correct handle/object mismatch; exec parent callback
|
||||
|
@ -27,6 +27,7 @@
|
||||
#-------------------------------------------------------------------------
|
||||
from xml.parsers.expat import ParserCreate
|
||||
from random import Random
|
||||
from gettext import gettext as _
|
||||
|
||||
#-------------------------------------------------------------------------
|
||||
#
|
||||
@ -68,7 +69,7 @@ class TipOfDay:
|
||||
index = 0
|
||||
rval = 0
|
||||
while rval == 0:
|
||||
tip.set_text(tip_list[new_index[index]])
|
||||
tip.set_text(_(tip_list[new_index[index]]))
|
||||
tip.set_use_markup(1)
|
||||
rval = top.run()
|
||||
if index >= len(tip_list)-1:
|
||||
|
@ -4,5 +4,5 @@ then
|
||||
mv po/template.po po/template.po.bak
|
||||
fi
|
||||
|
||||
./get_strings -o po/template.po *.py */*.py *.glade */*.glade
|
||||
./get_strings -o po/template.po *.py */*.py *.glade */*.glade data/tips.xml
|
||||
|
||||
|
@ -9,6 +9,7 @@
|
||||
# Completely butchered to add glade support for the GRAMPS
|
||||
# project by Don Allingham (dallingham@users.sourceforge.net)
|
||||
#
|
||||
# Further bastardized by Alex
|
||||
|
||||
# $Id$
|
||||
|
||||
@ -120,7 +121,6 @@ import getopt
|
||||
import tokenize
|
||||
import operator
|
||||
import re
|
||||
import string
|
||||
import os
|
||||
|
||||
from xml.sax import make_parser,handler,SAXParseException
|
||||
@ -213,6 +213,87 @@ class GladeParser(handler.ContentHandler):
|
||||
def characters(self, data):
|
||||
self.text = self.text + data
|
||||
|
||||
class TipExtractor:
|
||||
|
||||
def __init__(self,msgs):
|
||||
self.strings = msgs
|
||||
|
||||
def add_string(self, str, lineno):
|
||||
if str.strip() == "":
|
||||
return
|
||||
if _ignore.has_key(str):
|
||||
return
|
||||
entry = (self.file, lineno)
|
||||
if self.strings.has_key(str):
|
||||
self.strings[str][entry] = 0
|
||||
else:
|
||||
self.strings[str] = {entry: 0}
|
||||
|
||||
def parse(self,file):
|
||||
self.p = make_parser()
|
||||
self.p.setContentHandler(TipParser(self,file))
|
||||
filename = "file://" + os.path.abspath(file)
|
||||
self.file = file
|
||||
self.p.parse(filename)
|
||||
|
||||
class TipParser(handler.ContentHandler):
|
||||
"""
|
||||
SAX parsing class for the Tips XML file.
|
||||
|
||||
This parser needs to extract strings in *exactly* the same way
|
||||
as the TipOfDay.TipParser does. Otherwise, msgid's won't be correctly
|
||||
matched.
|
||||
"""
|
||||
|
||||
def __init__(self,parent,filename):
|
||||
"""
|
||||
Creates a SheetParser class that populates the passed StyleSheetList
|
||||
class.
|
||||
|
||||
sheetlist - StyleSheetList instance to be loaded from the file.
|
||||
"""
|
||||
handler.ContentHandler.__init__(self)
|
||||
self.parent = parent
|
||||
self.translate = 0
|
||||
self.text = ""
|
||||
self.filename = filename
|
||||
self.lineno = 0
|
||||
|
||||
def startElement(self,tag,attrs):
|
||||
"""
|
||||
Overridden class that handles the start of a XML element
|
||||
"""
|
||||
if tag == "tip":
|
||||
self.text = ""
|
||||
elif tag != "tips":
|
||||
# let all the other tags through, except for the "tips" tag
|
||||
self.text = self.text + "<%s>" % tag
|
||||
|
||||
def endElement(self,tag):
|
||||
"Overridden class that handles the start of a XML element"
|
||||
if tag == "tip":
|
||||
if not _int_re.match(self.text):
|
||||
text = self.escape(self.text)
|
||||
self.parent.add_string(' '.join(text.split()),
|
||||
self.locator.getLineNumber())
|
||||
elif tag != "tips":
|
||||
# let all the other tags through, except for the "tips" tag
|
||||
self.text = self.text + "</%s>" % tag
|
||||
|
||||
def setDocumentLocator(self,locator):
|
||||
self.locator = locator
|
||||
|
||||
def characters(self, data):
|
||||
self.text = self.text + data
|
||||
|
||||
def escape(self,text):
|
||||
"""
|
||||
The tip's text will be interpreted as a markup, so we need to escape
|
||||
some special chars.
|
||||
"""
|
||||
text = text.replace('&','&'); # Must be first
|
||||
return text
|
||||
|
||||
# The normal pot-file header. msgmerge and Emacs's po-mode work better if it's
|
||||
# there.
|
||||
pot_header = _('''\
|
||||
@ -270,7 +351,7 @@ def escape(s):
|
||||
s = list(s)
|
||||
for i in range(len(s)):
|
||||
s[i] = escapes[ord(s[i])]
|
||||
return string.join(s,'')
|
||||
return ''.join(s)
|
||||
|
||||
|
||||
def safe_eval(s):
|
||||
@ -281,7 +362,7 @@ def safe_eval(s):
|
||||
def normalize(s):
|
||||
# This converts the various Python string types into a format that is
|
||||
# appropriate for .po files, namely much closer to C style.
|
||||
lines = string.split(s,'\n')
|
||||
lines = s.split('\n')
|
||||
if len(lines) == 1:
|
||||
s = '"' + escape(s) + '"'
|
||||
else:
|
||||
@ -291,7 +372,7 @@ def normalize(s):
|
||||
for i in range(len(lines)):
|
||||
lines[i] = escape(lines[i])
|
||||
lineterm = '\\n"\n"'
|
||||
s = '""\n"' + string.join(lines,lineterm) + '"'
|
||||
s = '""\n"' + lineterm.join(lines) + '"'
|
||||
return s
|
||||
|
||||
class TokenEater:
|
||||
@ -342,7 +423,7 @@ class TokenEater:
|
||||
# of messages seen. Reset state for the next batch. If there
|
||||
# were no strings inside _(), then just ignore this entry.
|
||||
if self.__data:
|
||||
self.__addentry(string.join(self.__data,''))
|
||||
self.__addentry(''.join(self.__data))
|
||||
self.__state = self.__waiting
|
||||
elif ttype == tokenize.STRING:
|
||||
self.__data.append(safe_eval(tstring))
|
||||
@ -499,13 +580,18 @@ def main():
|
||||
# slurp through all the files
|
||||
eater = TokenEater(options)
|
||||
p = GladeExtractor(eater.get_messages())
|
||||
tp = TipExtractor(eater.get_messages())
|
||||
|
||||
for filename in args:
|
||||
if filename[-5:] == 'glade':
|
||||
print 'Working on %s' % filename
|
||||
p.parse(filename)
|
||||
elif filename[-3:] == 'xml':
|
||||
elif filename[-8:] == 'tips.xml':
|
||||
# Using our own custom Tips parser for tips.xml
|
||||
print 'Working on %s' % filename
|
||||
tp.parse(filename)
|
||||
elif filename[-3:] == 'xml':
|
||||
# THIS IS NOT WORKING -- something has changed in SAX/Expat
|
||||
try:
|
||||
parser = make_parser()
|
||||
pxml = XMLParser(filename,eater.get_messages())
|
||||
|
File diff suppressed because it is too large
Load Diff
Loading…
x
Reference in New Issue
Block a user