Commit bbf79a2e authored by Arnaud Fontaine's avatar Arnaud Fontaine

Fix inconsistency in Localizer and MessageCatalog translate method for message with no translation.

The former calls zope.i18n.translate() which calls MessageCatalog.translate()
by passing 'default' argument to the original message, thus returning the
original message when there is no translation. But, when the latter is called
without 'default' argument, it is set to message.strip(), thus returning the
strip'ed original message.
parent b140df9f
......@@ -185,6 +185,25 @@ assertEquals("This is 1€.", context.Base_translateString("This is 1€."))
from Products.Localizer.utils import get_request
self.assertEquals(get_request(), self.portal.REQUEST)
def test_default_not_changed(self):
"""
When there is no translation available for a given message, the default
value (e.g. the original message) must be returned
"""
message = " This is 1€ non-translated "
localizer = self.portal.Localizer
# Base_translateString == Localizer.translate() currently, which calls
# zope.i18n.translate and sets 'default' to 'message' before passing it to
# MessageCatalog (Localizer.erp5_ui.translate)
self.assertEquals(message, self.portal.Base_translateString(message))
self.assertEquals(message,
self.portal.Localizer.translate('ui', message).encode('utf-8'))
# default=None, thus 'message' was previously stripped before being set as
# 'default' value (MessageCatalog.gettext)
self.assertEquals(message, self.portal.Localizer.erp5_ui.translate(message))
def test_suite():
suite = unittest.TestSuite()
suite.addTest(unittest.makeSuite(TestLocalizer))
......
......@@ -278,11 +278,11 @@ class MessageCatalog(LanguageManager, ObjectManager, SimpleItem):
if not isinstance(message, basestring):
raise TypeError, 'only strings can be translated.'
message = message.strip()
if default is None:
default = message
message = message.strip()
# BBB call get_message_key to support both (old) str key and
# (new) unicode key.
message = self.get_message_key(message) or to_unicode(message)
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment