opental-checkins
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[OpenTAL-checkins] opental/PlacelessTranslationService Negotiator....


From: Fernando Lalo Martins
Subject: [OpenTAL-checkins] opental/PlacelessTranslationService Negotiator....
Date: Sun, 26 Jan 2003 17:59:30 -0500

CVSROOT:        /cvsroot/opental
Module name:    opental
Changes by:     Fernando Lalo Martins <address@hidden>  03/01/26 17:59:30

Modified files:
        PlacelessTranslationService: Negotiator.py 
                                     PlacelessTranslationService.py 

Log message:
        Negotiator caching was not speeding anything up.
        
        Moved check for env==request upper in the call chain, because it was
        already being done in two different functions.
        
        Simplified the code that returns None (this will require a simple
        change to OpenPTi18n).

CVSWeb URLs:
http://savannah.gnu.org/cgi-bin/viewcvs/opental/opental/PlacelessTranslationService/Negotiator.py.diff?tr1=1.5&tr2=1.6&r1=text&r2=text
http://savannah.gnu.org/cgi-bin/viewcvs/opental/opental/PlacelessTranslationService/PlacelessTranslationService.py.diff?tr1=1.5&tr2=1.6&r1=text&r2=text

Patches:
Index: opental/PlacelessTranslationService/Negotiator.py
diff -u opental/PlacelessTranslationService/Negotiator.py:1.5 
opental/PlacelessTranslationService/Negotiator.py:1.6
--- opental/PlacelessTranslationService/Negotiator.py:1.5       Sat Jan 25 
03:56:15 2003
+++ opental/PlacelessTranslationService/Negotiator.py   Sun Jan 26 17:59:30 2003
@@ -17,7 +17,7 @@
 #    Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307, USA
 """
 
-$Id: Negotiator.py,v 1.5 2003/01/25 08:56:15 magnusheino Exp $
+$Id: Negotiator.py,v 1.6 2003/01/26 22:59:30 lalo Exp $
 """
 
 _langPrefsRegistry = []
@@ -44,12 +44,7 @@
 class BrowserLanguages:
     
     def __init__(self, context):
-        try:
-            # ZPT, contrary to the spec, doesn't pass the request
-            # as context arg
-            get = context.REQUEST.get
-        except AttributeError:
-            get = context.get
+        get = context.get
             
         try:
             req_langs = get('user_language', None) or \
@@ -77,11 +72,12 @@
 
 
     def getLanguage(self, langs, env):
-        # Store cache in request object
-        cache = env.REQUEST.other.setdefault('_pts_negotiator_cache', {})
-        langs = tuple(langs)
-
-        return cache.setdefault(langs, self._getLanguage(langs, env))
+        try:
+            return env.other['_pts_negotiator_cache']
+        except KeyError:
+            # Store cache in request object
+            env.set('_pts_negotiator_cache', self._getLanguage(langs, env))
+            return env.other['_pts_negotiator_cache']
 
     def _getLanguage(self, langs, env):
         envprefs = getLangPrefsMethod(env)
Index: opental/PlacelessTranslationService/PlacelessTranslationService.py
diff -u opental/PlacelessTranslationService/PlacelessTranslationService.py:1.5 
opental/PlacelessTranslationService/PlacelessTranslationService.py:1.6
--- opental/PlacelessTranslationService/PlacelessTranslationService.py:1.5      
Sat Jan 25 03:56:59 2003
+++ opental/PlacelessTranslationService/PlacelessTranslationService.py  Sun Jan 
26 17:59:30 2003
@@ -17,7 +17,7 @@
 #    Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307, USA
 """Placeless Translation Service for providing I18n to file-based code.
 
-$Id: PlacelessTranslationService.py,v 1.5 2003/01/25 08:56:59 magnusheino Exp $
+$Id: PlacelessTranslationService.py,v 1.6 2003/01/26 22:59:30 lalo Exp $
 """
 
 from Negotiator import negotiator
@@ -89,7 +89,13 @@
 
         if not msgid:
             # refuse to translate an empty msgid
-            return default or msgid
+            return default
+
+        # ZPT passes the object as context.  That's wrong according to spec.
+        try:
+            context = context.REQUEST
+        except AttributeError:
+            pass
         
         if target_language is None:
             if context is None:
@@ -115,14 +121,11 @@
                 # it's not in this catalog, try the next one
                 pass
         else:
-            # Did the fallback fail?  Sigh, use the default
-            if default is None:
-                # OpenTAL provides a default text.
-                # TAL doesn't but will use the default
-                # if None is returned
-                text = None
-            else:
-                text = default
+            # Did the fallback fail?  Sigh, use the default.
+            # OpenTAL provides a default text.
+            # TAL doesn't but will use the default
+            # if None is returned
+            text = default
 
         # Now we need to do the interpolation
         text = self.interpolate(text, mapping)




reply via email to

[Prev in Thread] Current Thread [Next in Thread]