[Zope3-checkins] CVS: Zope3/src/zope/app/services/translation - translationservice.py:1.7
Jim Fulton
jim@zope.com
Fri, 28 Mar 2003 19:06:55 -0500
Update of /cvs-repository/Zope3/src/zope/app/services/translation
In directory cvs.zope.org:/tmp/cvs-serv20015/src/zope/app/services/translation
Modified Files:
translationservice.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/app/services/translation/translationservice.py 1.6 => 1.7 ===
--- Zope3/src/zope/app/services/translation/translationservice.py:1.6 Tue Mar 25 18:25:12 2003
+++ Zope3/src/zope/app/services/translation/translationservice.py Fri Mar 28 19:06:24 2003
@@ -72,7 +72,7 @@
object.getDomain(), name)
def translate(self, domain, msgid, mapping=None, context=None,
- target_language=None):
+ target_language=None, default=None):
"""See interface ITranslationService"""
if domain is None:
domain = self.default_domain
@@ -89,20 +89,20 @@
# Get the translation. Default is the source text itself.
catalog_names = self._catalogs.get((target_language, domain), [])
- text = msgid
for name in catalog_names:
catalog = super(TranslationService, self).__getitem__(name)
text = catalog.queryMessage(msgid)
-
- # If the message id equals the returned text, then we should look up
- # a translation server higher up the tree.
- if text == msgid:
+ if text is not None:
+ break
+ else:
+ # If nothing found, delegate to
+ # a translation server higher up the tree.
ts = queryNextService(self, 'Translation')
if ts is not None:
return ts.translate(domain, msgid, mapping, context,
- target_language)
+ target_language, default=default)
else:
- return text
+ return default
# Now we need to do the interpolation
return self.interpolate(text, mapping)