Commit 402d9c02 authored by Yoshinori Okuji's avatar Yoshinori Okuji

Small optimization.

git-svn-id: https://svn.erp5.org/repos/public/erp5/trunk@18373 20353a03-c40f-0410-a6d1-a30d3c3de9de
parent d0c4124d
...@@ -48,29 +48,34 @@ def Localizer_translate(self, domain, msgid, lang=None, mapping=None, *args, **k ...@@ -48,29 +48,34 @@ def Localizer_translate(self, domain, msgid, lang=None, mapping=None, *args, **k
# Get the Localizer catalog id # Get the Localizer catalog id
catalog_id = message_catalog_aliases.get(domain, domain) catalog_id = message_catalog_aliases.get(domain, domain)
if catalog_id not in self.objectIds(): catalog_obj = self._getOb(catalog_id, None)
if catalog_obj is None:
# No catalog found: use the default one # No catalog found: use the default one
catalog_id = 'default' catalog_obj = self['default']
catalog_obj = self[catalog_id]
# Call the Message Catalog gettext method # Call the Message Catalog gettext method
params = {} params = {}
for key in ('lang', 'add', 'default'): for key in ('add', 'default'):
if key in kw: try:
params[key] = kw[key] params[key] = kw[key]
except KeyError:
pass
if lang is not None: if lang is not None:
params['lang'] = lang params['lang'] = lang
if 'target_language' in kw: else:
try:
params['lang'] = kw['target_language'] params['lang'] = kw['target_language']
except KeyError:
pass
translated_str = catalog_obj.gettext(msgid, **params) translated_str = catalog_obj.gettext(msgid, **params)
# Map the translated string with given parameters # Map the translated string with given parameters
if type(mapping) is type({}) and len(mapping): if isinstance(mapping, dict) and mapping:
unicode_mapping = {} unicode_mapping = {}
if not isinstance(translated_str, unicode): if not isinstance(translated_str, unicode):
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.iteritems():
if isinstance(v, str): if isinstance(v, str):
v = v.decode('utf8') v = v.decode('utf8')
elif isinstance(v, Message): elif isinstance(v, 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