Commit abe21e5b authored by Guillaume Michon's avatar Guillaume Michon

Make sure Message instances are passed as unicode to Template


git-svn-id: https://svn.erp5.org/repos/public/erp5/trunk@6120 20353a03-c40f-0410-a6d1-a30d3c3de9de
parent 03084582
...@@ -21,7 +21,7 @@ try: ...@@ -21,7 +21,7 @@ try:
except ImportError: except ImportError:
from Products.ERP5Type.patches.string import Template from Products.ERP5Type.patches.string import Template
from Products.ERP5Type.Message import Message
from zLOG import LOG from zLOG import LOG
class LocalizerPatchError(Exception): class LocalizerPatchError(Exception):
...@@ -39,7 +39,6 @@ def Localizer_translate(self, domain, msgid, mapping=None, *args, **kw): ...@@ -39,7 +39,6 @@ def Localizer_translate(self, domain, msgid, mapping=None, *args, **kw):
""" """
This translate() method use Localizer and support catalog aliases. This translate() method use Localizer and support catalog aliases.
""" """
# This dict define the alias between old Translation Service catalog id # This dict define the alias between old Translation Service catalog id
# and new Localizer Message Catalog. # and new Localizer Message Catalog.
message_catalog_aliases = { "Default": "default" message_catalog_aliases = { "Default": "default"
...@@ -70,9 +69,12 @@ def Localizer_translate(self, domain, msgid, mapping=None, *args, **kw): ...@@ -70,9 +69,12 @@ def Localizer_translate(self, domain, msgid, mapping=None, *args, **kw):
translated_str = translated_str.decode('utf8') translated_str = translated_str.decode('utf8')
# make sure all values in the mapping are unicode # make sure all values in the mapping are unicode
for k, v in mapping.items(): for k, v in mapping.items():
if isinstance(v, str) : if isinstance(v, str):
v = v.decode('utf8') v = v.decode('utf8')
elif isinstance(v, Message):
v = str(v).decode('utf8')
unicode_mapping[k] = v unicode_mapping[k] = v
translated_str = Template(translated_str).substitute(unicode_mapping) translated_str = Template(translated_str).substitute(unicode_mapping)
return translated_str return translated_str
......
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