[Zope3-checkins] SVN: Zope3/trunk/src/zope/i18n/ Make
SimpleTranslationDomain behave like the regular implementation
Philipp von Weitershausen
philikon at philikon.de
Mon Jul 12 06:07:31 EDT 2004
Log message for revision 26423:
Make SimpleTranslationDomain behave like the regular implementation
with respect to interpolating default values. Added a test for this
and a test for general default behaviour.
-=-
Modified: Zope3/trunk/src/zope/i18n/simpletranslationdomain.py
===================================================================
--- Zope3/trunk/src/zope/i18n/simpletranslationdomain.py 2004-07-12 10:06:33 UTC (rev 26422)
+++ Zope3/trunk/src/zope/i18n/simpletranslationdomain.py 2004-07-12 10:07:31 UTC (rev 26423)
@@ -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/trunk/src/zope/i18n/tests/test_itranslationdomain.py
===================================================================
--- Zope3/trunk/src/zope/i18n/tests/test_itranslationdomain.py 2004-07-12 10:06:33 UTC (rev 26422)
+++ Zope3/trunk/src/zope/i18n/tests/test_itranslationdomain.py 2004-07-12 10:07:31 UTC (rev 26423)
@@ -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