[Zope3-checkins] CVS: Zope3/src/zope/i18n - translate.py:1.5

Marius Gedminas mgedmin@codeworks.lt
Fri, 11 Apr 2003 09:43:07 -0400


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

Modified Files:
	translate.py 
Log Message:
Fixed the ComponentLookupError when the browser does not send a list of
accepted languages.

Added an extensive XXX comment about a possibly problematic situation with
translations to a language for which there is no Zope 3 locale found.



=== Zope3/src/zope/i18n/translate.py 1.4 => 1.5 ===
--- Zope3/src/zope/i18n/translate.py:1.4	Thu Apr  3 14:55:20 2003
+++ Zope3/src/zope/i18n/translate.py	Fri Apr 11 09:42:36 2003
@@ -37,13 +37,32 @@
         self._domain = domain
         self._context = context
         self._translation_service = getService(context, 'Translation')
-        
+
     def translate(self, msgid, mapping=None, default=None):
         """Translate the source msgid using the given mapping.
 
         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(
-            self._domain, msgid, mapping, self._context,
-            self._locale.id.language,
+            self._domain, msgid, mapping=mapping,
+            target_language=self._locale.id.language,
             default=default)