[Zope3-checkins] CVS: Zope3/src/zope/i18n - globaltranslationservice.py:1.5 interfaces.py:1.10 simpletranslationservice.py:1.5
Jim Fulton
jim@zope.com
Fri, 28 Mar 2003 19:06:56 -0500
Update of /cvs-repository/Zope3/src/zope/i18n
In directory cvs.zope.org:/tmp/cvs-serv20015/src/zope/i18n
Modified Files:
globaltranslationservice.py interfaces.py
simpletranslationservice.py
Log Message:
Fixed bugs in global translation service:
- Returned message id on failed serach when no message catalogs
were found. Should have returned None.
- Failed lookups with multiple catalogs unless all catalogs had a
translation.
Fixed bug in local translation services:
- Returned message id on failed serach
Added a default argument to translate. This allows the default
text, which could be the message id, to be passed.
=== Zope3/src/zope/i18n/globaltranslationservice.py 1.4 => 1.5 ===
--- Zope3/src/zope/i18n/globaltranslationservice.py:1.4 Tue Mar 25 15:43:35 2003
+++ Zope3/src/zope/i18n/globaltranslationservice.py Fri Mar 28 19:06:25 2003
@@ -66,7 +66,7 @@
self._fallbacks = fallbacks
def translate(self, domain, msgid, mapping=None, context=None,
- target_language=None):
+ target_language=None, default=None):
'''See interface ITranslationService'''
if target_language is None:
if context is None:
@@ -86,14 +86,18 @@
catalog_names = self._catalogs.get((language, domain))
if catalog_names is not None:
break
- # Did the fallback fail? Sigh, use the msgid
+
+ # Did the fallback fail? Sigh, return None
if catalog_names is None:
- catalog_names = []
+ return default
- text = msgid
for name in catalog_names:
catalog = self._data[name]
text = catalog.queryMessage(msgid)
+ if text is not None:
+ break
+ else:
+ return default
# Now we need to do the interpolation
return self.interpolate(text, mapping)
=== Zope3/src/zope/i18n/interfaces.py 1.9 => 1.10 ===
--- Zope3/src/zope/i18n/interfaces.py:1.9 Tue Mar 25 18:25:14 2003
+++ Zope3/src/zope/i18n/interfaces.py Fri Mar 28 19:06:25 2003
@@ -124,10 +124,11 @@
"""
def translate(domain, msgid, mapping=None,
- context=None, target_language=None):
+ context=None, target_language=None,
+ default=None):
"""Return the translation for the message referred to by msgid.
- Return None if no translation is found.
+ Return the default if no translation is found.
However, the method does a little more than a vanilla translation.
The method also looks for a possible language to translate to.
=== Zope3/src/zope/i18n/simpletranslationservice.py 1.4 => 1.5 ===
--- Zope3/src/zope/i18n/simpletranslationservice.py:1.4 Tue Mar 25 18:25:14 2003
+++ Zope3/src/zope/i18n/simpletranslationservice.py Fri Mar 28 19:06:25 2003
@@ -55,7 +55,7 @@
def translate(self, domain, msgid, mapping=None, context=None,
- target_language=None):
+ target_language=None, default=None):
'''See interface ITranslationService'''
# Find out what the target language should be
if target_language is None:
@@ -69,6 +69,8 @@
# Make a raw translation without interpolation
text = self.messages.get((domain, target_language, msgid))
+ if text is None:
+ return default
# Now we need to do the interpolation
return self.interpolate(text, mapping)