Commit 1edd461b authored by Jérome Perrin's avatar Jérome Perrin

Localizer: py3

parent 1f1faa4b
...@@ -106,15 +106,11 @@ def message_decode(message): ...@@ -106,15 +106,11 @@ def message_decode(message):
To be used in the user interface, to avoid problems with the To be used in the user interface, to avoid problems with the
encodings, HTML entities, etc.. encodings, HTML entities, etc..
""" """
message = decodebytes(message) message = decodebytes(message.encode())
encoding = HTTPRequest.default_encoding encoding = HTTPRequest.default_encoding
return six.text_type(message, encoding) return six.text_type(message, encoding)
def filter_sort(x, y):
return cmp(to_unicode(x), to_unicode(y))
def get_url(url, batch_start, batch_size, regex, lang, empty, **kw): def get_url(url, batch_start, batch_size, regex, lang, empty, **kw):
params = [] params = []
for key, value in six.iteritems(kw): for key, value in six.iteritems(kw):
...@@ -396,7 +392,7 @@ class MessageCatalog(LanguageManager, ObjectManager, SimpleItem): ...@@ -396,7 +392,7 @@ class MessageCatalog(LanguageManager, ObjectManager, SimpleItem):
for m, t in six.iteritems(self._messages): for m, t in six.iteritems(self._messages):
if query.search(m) and (not empty or not t.get(lang, '').strip()): if query.search(m) and (not empty or not t.get(lang, '').strip()):
messages.append(m) messages.append(m)
messages.sort(filter_sort) messages.sort(key=lambda m: to_unicode(m))
# How many messages # How many messages
n = len(messages) n = len(messages)
namespace['n_messages'] = n namespace['n_messages'] = n
...@@ -664,6 +660,10 @@ class MessageCatalog(LanguageManager, ObjectManager, SimpleItem): ...@@ -664,6 +660,10 @@ class MessageCatalog(LanguageManager, ObjectManager, SimpleItem):
messages = self._messages messages = self._messages
# Load the data # Load the data
if isinstance(data, bytes): # six.PY2
pass
elif isinstance(data, bytes): # six.PY3
data = data.decode()
po = polib.pofile(data) po = polib.pofile(data)
encoding = to_str(po.encoding) encoding = to_str(po.encoding)
for entry in po: for entry in po:
......
...@@ -23,9 +23,7 @@ from App.ImageFile import ImageFile ...@@ -23,9 +23,7 @@ from App.ImageFile import ImageFile
from DocumentTemplate.DT_String import String from DocumentTemplate.DT_String import String
# Import from Localizer # Import from Localizer
import six from . import patches as _
if six.PY2:
from . import patches as _
from . import Localizer, MessageCatalog from . import Localizer, MessageCatalog
from .LocalFiles import LocalDTMLFile from .LocalFiles import LocalDTMLFile
......
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