[Zope3-checkins] CVS: Zope3/src/zope/app/translation_files -
extract.py:1.9
Stephan Richter
srichter at cosmos.phy.tufts.edu
Wed Aug 20 13:30:25 EDT 2003
Update of /cvs-repository/Zope3/src/zope/app/translation_files
In directory cvs.zope.org:/tmp/cvs-serv14191/translation_files
Modified Files:
extract.py
Log Message:
Added support for _(msgid, default) in the extracting tool and created a
test for it...uhm, we need more tests ;-)
=== Zope3/src/zope/app/translation_files/extract.py 1.8 => 1.9 ===
--- Zope3/src/zope/app/translation_files/extract.py:1.8 Wed Aug 20 01:02:20 2003
+++ Zope3/src/zope/app/translation_files/extract.py Wed Aug 20 12:29:55 2003
@@ -40,6 +40,7 @@
import tokenize
import traceback
from pygettext import safe_eval, normalize, make_escapes
+from zope.i18n.messageid import MessageID
__meta_class__ = type
@@ -199,6 +200,7 @@
def __keywordseen(self, ttype, tstring, lineno):
if ttype == tokenize.OP and tstring == '(':
self.__data = []
+ self.__msgid = ''
self.__lineno = lineno
self.__state = self.__openseen
else:
@@ -210,16 +212,27 @@
# line number of the first line of the strings and update the list
# 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(''.join(self.__data))
+ if self.__data or self.__msgid:
+ if self.__msgid:
+ msgid = self.__msgid
+ default = ''.join(self.__data)
+ else:
+ msgid = ''.join(self.__data)
+ default = None
+ self.__addentry(msgid, default)
self.__state = self.__waiting
+ elif ttype == tokenize.OP and tstring == ',':
+ self.__msgid = ''.join(self.__data)
+ self.__data = []
elif ttype == tokenize.STRING:
self.__data.append(safe_eval(tstring))
- def __addentry(self, msg, lineno=None, isdocstring=0):
+ def __addentry(self, msg, default=None, lineno=None, isdocstring=0):
if lineno is None:
lineno = self.__lineno
+ if default is not None:
+ msg = MessageID(msg, default=default)
entry = (self.__curfile, lineno)
self.__messages.setdefault(msg, {})[entry] = isdocstring
More information about the Zope3-Checkins
mailing list