Commit ba435293 authored by Kazuhiko Shiozaki's avatar Kazuhiko Shiozaki

support non-ascii msgid and add a backward compatibility for the existing...

support non-ascii msgid and add a backward compatibility for the existing catalog that stores non-ascii msgid as str not unicode.
parent c07f39fd
...@@ -31,7 +31,7 @@ from ZPublisher.BeforeTraverse import registerBeforeTraverse, \ ...@@ -31,7 +31,7 @@ from ZPublisher.BeforeTraverse import registerBeforeTraverse, \
# Import Localizer modules # Import Localizer modules
from interfaces import ILocalizer from interfaces import ILocalizer
from LocalFiles import LocalDTMLFile from LocalFiles import LocalDTMLFile
from MessageCatalog import MessageCatalog from MessageCatalog import MessageCatalog, to_unicode
from utils import lang_negotiator from utils import lang_negotiator
from LanguageManager import LanguageManager from LanguageManager import LanguageManager
...@@ -243,7 +243,7 @@ class Localizer(LanguageManager, Folder): ...@@ -243,7 +243,7 @@ class Localizer(LanguageManager, Folder):
assert not args assert not args
if lang is not None: if lang is not None:
kw['target_language'] = lang kw['target_language'] = lang
return translate(msgid, domain=domain, **kw) return translate(to_unicode(msgid), domain=domain, **kw)
InitializeClass(Localizer) InitializeClass(Localizer)
......
...@@ -230,12 +230,17 @@ class MessageCatalog(LanguageManager, ObjectManager, SimpleItem): ...@@ -230,12 +230,17 @@ class MessageCatalog(LanguageManager, ObjectManager, SimpleItem):
security.declarePublic('message_exists') security.declarePublic('message_exists')
def message_exists(self, message): def message_exists(self, message):
""" """ """ """
return self._messages.has_key(message) # BBB call get_message_key to support both (old) str key and
# (new) unicode key.
return bool(self.get_message_key(message))
security.declareProtected('Manage messages', 'message_edit') security.declareProtected('Manage messages', 'message_edit')
def message_edit(self, message, language, translation, note): def message_edit(self, message, language, translation, note):
""" """ """ """
# BBB call get_message_key to support both (old) str key and
# (new) unicode key.
message = self.get_message_key(message) or message
self._messages[message][language] = translation self._messages[message][language] = translation
self._messages[message]['note'] = note self._messages[message]['note'] = note
...@@ -243,6 +248,9 @@ class MessageCatalog(LanguageManager, ObjectManager, SimpleItem): ...@@ -243,6 +248,9 @@ class MessageCatalog(LanguageManager, ObjectManager, SimpleItem):
security.declareProtected('Manage messages', 'message_del') security.declareProtected('Manage messages', 'message_del')
def message_del(self, message): def message_del(self, message):
""" """ """ """
# BBB call get_message_key to support both (old) str key and
# (new) unicode key.
message = self.get_message_key(message) or message
del self._messages[message] del self._messages[message]
...@@ -258,6 +266,9 @@ class MessageCatalog(LanguageManager, ObjectManager, SimpleItem): ...@@ -258,6 +266,9 @@ class MessageCatalog(LanguageManager, ObjectManager, SimpleItem):
raise TypeError, 'only strings can be translated.' raise TypeError, 'only strings can be translated.'
message = message.strip() 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 message
if default is None: if default is None:
default = message default = 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