[Zope3-checkins] CVS: Zope3/src/zope/i18n - negotiator.py:1.8 translate.py:1.10

Stephan Richter srichter at cosmos.phy.tufts.edu
Fri Feb 27 17:25:53 EST 2004


Update of /cvs-repository/Zope3/src/zope/i18n
In directory cvs.zope.org:/tmp/cvs-serv19338/src/zope/i18n

Modified Files:
	negotiator.py translate.py 
Log Message:
I must have been on sleep-derivation when originally writing the Translator 
code, which was horribly broken.

Fixed everything and updated the engine to do the right thing too.


=== Zope3/src/zope/i18n/negotiator.py 1.7 => 1.8 ===
--- Zope3/src/zope/i18n/negotiator.py:1.7	Fri Feb 27 12:48:42 2004
+++ Zope3/src/zope/i18n/negotiator.py	Fri Feb 27 17:25:22 2004
@@ -11,11 +11,10 @@
 # FOR A PARTICULAR PURPOSE.
 #
 ##############################################################################
-"""
+"""Language Negotiator
 
 $Id$
 """
-
 from zope.i18n.interfaces import INegotiator
 from zope.i18n.interfaces import IUserPreferredLanguages
 from zope.component import getAdapter
@@ -37,7 +36,6 @@
     return n_langs
 
 class Negotiator:
-
     implements(INegotiator)
 
     def getLanguage(self, langs, env):


=== Zope3/src/zope/i18n/translate.py 1.9 => 1.10 ===
--- Zope3/src/zope/i18n/translate.py:1.9	Thu Feb  5 17:52:21 2004
+++ Zope3/src/zope/i18n/translate.py	Fri Feb 27 17:25:22 2004
@@ -26,46 +26,18 @@
     It is expected that object be constructed with enough information to find
     the domain, context, and target language.
     """
-
     implements(ITranslator)
 
-    def __init__(self, locale, domain, context=None):
-        """locale comes from the request, domain specifies the application,
-        and context specifies the place (it may be none for global contexts).
-        """
-        self._locale = locale
+    def __init__(self, domain, context, location=None):
+        """Initialize the object."""
         self._domain = domain
         self._context = context
-        self._translation_service = getService(context, 'Translation')
+        self._translation_service = getService(location, 'Translation')
+
 
     def translate(self, msgid, mapping=None, default=None):
-        """Translate the source msgid using the given mapping.
+        """See zope.i18n.interfaces.ITranslator."""
 
-        See ITranslationService for details.
-        """
-        # XXX Note that we cannot pass `context` to translation service as it
-        #     is most likely a Zope container that is not adaptable to
-        #     IUserPreferredLanguages.  It would be possible to pass the
-        #     request if we had it (ZopeContext, which is currently the only
-        #     user of Translator, has the request and could pass it to us
-        #     here).
-        #
-        #     OTOH if the request had information about user's preferred
-        #     languages, self._locale.id.language would most likely be not
-        #     None.  Therefore passing request is only useful in one case:
-        #     when the user asked for an exotic language for which we have no
-        #     locale, and there were no fallback languages with a supported
-        #     locale.
-        #
-        #     Note that this also uncovers an interesting situation.  Suppose
-        #     the user sets HTTP_ACCEPT_LANGUAGES to lg, en;q=0.5.
-        #     BrowserRequest looks for a locale matching 'lg', does not find
-        #     it and settles on a locale for 'en'.  When we get here,
-        #     self._locale.id.language is 'en', so 'lg' translations will not
-        #     be used even if available.  Perhaps the fix would be to only
-        #     specify context=self.request and just ignore
-        #     self._locale.id.language.
         return self._translation_service.translate(
-            msgid, self._domain, mapping=mapping,
-            target_language=self._locale.id.language,
+            msgid, self._domain, mapping=mapping, context=self._context,
             default=default)




More information about the Zope3-Checkins mailing list