[Zope3-checkins] SVN: Zope3/branches/ZopeX3-3.0/src/zope/i18n/ Backport revisions 26420 through 26423 from trunk:

Philipp von Weitershausen philikon at philikon.de
Mon Jul 12 06:11:22 EDT 2004


Log message for revision 26424:
Backport revisions 26420 through 26423 from trunk:

- documentation fixes
- make SimpleTranslationDomain behave like the regular TranslationDomain
  impl wrt default value interpolation



-=-
Modified: Zope3/branches/ZopeX3-3.0/src/zope/i18n/i18nobject.txt
===================================================================
--- Zope3/branches/ZopeX3-3.0/src/zope/i18n/i18nobject.txt	2004-07-12 10:07:31 UTC (rev 26423)
+++ Zope3/branches/ZopeX3-3.0/src/zope/i18n/i18nobject.txt	2004-07-12 10:11:22 UTC (rev 26424)
@@ -54,8 +54,8 @@
 -------------------------
 
 This object will basically provide an internationalized version of
-Zope.App.OFS.AttributeAnnotations. which will be accomplished in a
-similar manner as the `I18nObject`.
+zope.app.annotation.attribute.AttributeAnnotations, which will be
+accomplished in a similar manner as the `I18nObject`.
 
 
 Open Issues

Modified: Zope3/branches/ZopeX3-3.0/src/zope/i18n/locales/provider.py
===================================================================
--- Zope3/branches/ZopeX3-3.0/src/zope/i18n/locales/provider.py	2004-07-12 10:07:31 UTC (rev 26423)
+++ Zope3/branches/ZopeX3-3.0/src/zope/i18n/locales/provider.py	2004-07-12 10:11:22 UTC (rev 26424)
@@ -36,7 +36,7 @@
         self._locale_dir = locale_dir
 
     def loadLocale(self, language=None, country=None, variant=None):
-        "See ZopeProducts.LocaleProvider.interfaces.ILocaleProvider"
+        """See zope.i18n.interfaces.locales.ILocaleProvider"""
         # Creating the filename
         if language == None and country == None and variant == None:
             filename = 'root.xml'
@@ -64,7 +64,7 @@
         self._locales[(language, country, variant)] = locale
 
     def getLocale(self, language=None, country=None, variant=None):
-        "See ZopeProducts.LocaleProvider.interfaces.ILocaleProvider"
+        """See zope.i18n.interfaces.locales.ILocaleProvider"""
         # We want to be liberal in what we accept, but the standard is lower
         # case language codes, upper case country codes, and upper case
         # variants, so coerce case here.

Modified: Zope3/branches/ZopeX3-3.0/src/zope/i18n/negotiator.py
===================================================================
--- Zope3/branches/ZopeX3-3.0/src/zope/i18n/negotiator.py	2004-07-12 10:07:31 UTC (rev 26423)
+++ Zope3/branches/ZopeX3-3.0/src/zope/i18n/negotiator.py	2004-07-12 10:11:22 UTC (rev 26424)
@@ -26,9 +26,8 @@
     return lang
 
 def normalize_langs(langs):
-    # Make a mapping from normalized->original
-    # so we keep can match the normalized lang
-    # and return the original string.
+    # Make a mapping from normalized->original so we keep can match
+    # the normalized lang and return the original string.
     n_langs = {}
     for l in langs:
         n_langs[normalize_lang(l)] = l
@@ -40,18 +39,17 @@
     def getLanguage(self, langs, env):
         envadapter = IUserPreferredLanguages(env)
         userlangs = envadapter.getPreferredLanguages()
-        # Prioritize on the user preferred languages.  Return the first user
-        # preferred language that the object has available.
+        # Prioritize on the user preferred languages.  Return the
+        # first user preferred language that the object has available.
         langs = normalize_langs(langs)
         for lang in userlangs:
             if lang in langs:
                 return langs.get(lang)
-            # If the user asked for a specific
-            # variation, but we don't have it available
-            # we may serve the most generic one, according
-            # to the spec (eg: user asks for ('en-us', 'de'),
-            # but we don't have 'en-us', then 'en' is
-            # preffered to 'de').
+            # If the user asked for a specific variation, but we don't
+            # have it available we may serve the most generic one,
+            # according to the spec (eg: user asks for ('en-us',
+            # 'de'), but we don't have 'en-us', then 'en' is preferred
+            # to 'de').
             parts = lang.split('-')
             if len(parts) > 1 and parts[0] in langs:
                 return langs.get(parts[0])

Modified: Zope3/branches/ZopeX3-3.0/src/zope/i18n/simpletranslationdomain.py
===================================================================
--- Zope3/branches/ZopeX3-3.0/src/zope/i18n/simpletranslationdomain.py	2004-07-12 10:07:31 UTC (rev 26423)
+++ Zope3/branches/ZopeX3-3.0/src/zope/i18n/simpletranslationdomain.py	2004-07-12 10:11:22 UTC (rev 26424)
@@ -57,10 +57,9 @@
             negotiator = getUtility(INegotiator)
             target_language = negotiator.getLanguage(langs, context)
 
-        # Make a raw translation without interpolation
+        # Find a translation; if nothing is found, use the default
+        # value
         text = self.messages.get((target_language, msgid))
         if text is None:
-            return default
-
-        # Now we need to do the interpolation
+	    text = default
         return interpolate(text, mapping)

Modified: Zope3/branches/ZopeX3-3.0/src/zope/i18n/tests/test_itranslationdomain.py
===================================================================
--- Zope3/branches/ZopeX3-3.0/src/zope/i18n/tests/test_itranslationdomain.py	2004-07-12 10:07:31 UTC (rev 26423)
+++ Zope3/branches/ZopeX3-3.0/src/zope/i18n/tests/test_itranslationdomain.py	2004-07-12 10:11:22 UTC (rev 26424)
@@ -27,7 +27,6 @@
 from zope.i18n.interfaces import INegotiator, IUserPreferredLanguages
 from zope.i18n.interfaces import ITranslationDomain
 
-
 class Environment:
 
     implements(IUserPreferredLanguages)
@@ -38,11 +37,9 @@
     def getPreferredLanguages(self):
         return self.langs
 
-
-
 class TestITranslationDomain(PlacelessSetup):
 
-    # This should be overwritten by every clas that inherits this test
+    # This should be overwritten by every class that inherits this test
     def _getTranslationDomain(self):
         pass
 
@@ -72,6 +69,11 @@
         eq(translate('greeting', mapping={'name': 'Stephan'},
                      target_language='de'),
            'Hallo Stephan, wie geht es Dir?')
+        # Testing default value interpolation
+        eq(translate('greeting', mapping={'name': 'Philipp'},
+                     target_language='fr',
+                     default="Hello $name, how are you?"),
+           'Hello Philipp, how are you?')
 
     def testNoTranslation(self):
         translate = self._domain.translate
@@ -79,6 +81,10 @@
         # Test that an unknown message id returns None as a translation
         eq(translate('glorp_smurf_hmpf', target_language='en'),
            None)
+        # Test default value behaviour
+        eq(translate('glorp_smurf_hmpf', target_language='en',
+                     default='Glorp Smurf Hmpf'),
+           'Glorp Smurf Hmpf')
 
     def testNoTargetLanguage(self):
         translate = self._domain.translate



More information about the Zope3-Checkins mailing list