[Zope3-checkins] SVN: Zope3/trunk/src/zope/tal/tal The TALInterpreter methods called the engine's translate function

Stephan Richter srichter at cosmos.phy.tufts.edu
Wed Nov 2 17:11:11 EST 2005


Log message for revision 39851:
  The TALInterpreter methods called the engine's translate function 
  directly; this is a big no-no; the interpreter's methods should use the 
  interpreter's translate() method.
  
  This fixes a bug in i18nextract, where the file positions were suddenly 
  not available anymore.
  
  

Changed:
  U   Zope3/trunk/src/zope/tal/talgettext.py
  U   Zope3/trunk/src/zope/tal/talinterpreter.py

-=-
Modified: Zope3/trunk/src/zope/tal/talgettext.py
===================================================================
--- Zope3/trunk/src/zope/tal/talgettext.py	2005-11-02 20:17:58 UTC (rev 39850)
+++ Zope3/trunk/src/zope/tal/talgettext.py	2005-11-02 22:11:10 UTC (rev 39851)
@@ -71,7 +71,9 @@
 
 
 class POTALInterpreter(TALInterpreter):
-    def translate(self, msgid, default, i18ndict=None, obj=None):
+    def translate(self, msgid, default=None, i18ndict=None, obj=None):
+        if default is None:
+            default = getattr(msgid, 'default', unicode(msgid))
         # If no i18n dict exists yet, create one.
         if i18ndict is None:
             i18ndict = {}
@@ -83,7 +85,7 @@
             return None
         # TODO: We need to pass in one of context or target_language
         return self.engine.translate(msgid, self.i18nContext.domain, i18ndict,
-                                     position=self.position, default=default)
+                                     default=default, position=self.position)
 
 
 class POEngine(DummyEngine):

Modified: Zope3/trunk/src/zope/tal/talinterpreter.py
===================================================================
--- Zope3/trunk/src/zope/tal/talinterpreter.py	2005-11-02 20:17:58 UTC (rev 39850)
+++ Zope3/trunk/src/zope/tal/talinterpreter.py	2005-11-02 22:11:10 UTC (rev 39851)
@@ -498,7 +498,7 @@
 
         if ok:
             if xlat:
-                translated = self.translate(msgid or value, value, {})
+                translated = self.translate(msgid or value, value)
                 if translated is not None:
                     value = translated
             if value is None:
@@ -631,7 +631,7 @@
             # Translate this now.
             # BBB: Deprecated. Will be removed in 3.3
             self._i18n_deprecate()
-            text = self.engine.translate(text)
+            text = self.translate(text)
         self._writeText(text)
 
     def _i18n_deprecate(self):
@@ -656,9 +656,9 @@
             self.interpret(stuff[1])
             return
         if isinstance(text, I18nMessageTypes):
-            text = self.engine.translate(text)
+            text = self.translate(text)
         elif isinstance(text, (StringType, UnicodeType)):
-            text = self.engine.translate(text, domain=self.i18nContext.domain)
+            text = self.translate(text)
         self._writeText(text)
 
     def do_i18nVariable(self, stuff):
@@ -696,7 +696,7 @@
                 # Translate this now.
                 # BBB: Deprecated. Will be removed in 3.3
                 self._i18n_deprecate()
-                value = self.engine.translate(value)
+                value = self.translate(value)
 
             if not structure:
                 value = cgi.escape(unicode(value))
@@ -788,7 +788,7 @@
             self.interpret(block)
             return
         if isinstance(structure, I18nMessageTypes):
-            text = self.engine.translate(structure)
+            text = self.translate(structure)
         else:
             text = unicode(structure)
         if not (repldict or self.strictinsert):
@@ -845,7 +845,14 @@
             self.interpret(block)
     bytecode_handlers["loop"] = do_loop
 
-    def translate(self, msgid, default, i18ndict, obj=None):
+    def translate(self, msgid, default=None, i18ndict=None,
+                  obj=None, domain=None):
+        if default is None:
+            default = getattr(msgid, 'default', unicode(msgid))
+        if i18ndict is None:
+            i18ndict = {}
+        if domain is None:
+            domain = getattr(msgid, 'domain', self.i18nContext.domain)
         if obj:
             i18ndict.update(obj)
         if not self.i18nInterpolate:



More information about the Zope3-Checkins mailing list