From 9dec5306ce5aced2f8f9192d53c0268eb5cfb8d4 Mon Sep 17 00:00:00 2001 From: Umair Khan Date: Mon, 10 Apr 2017 14:19:43 +0500 Subject: [PATCH] makemessages.py: Handle unicode strings. This commit applies to Python 2. It seems that sorted() cannot handle non-ascii character unless the strings are marked as Unicode. --- zerver/management/commands/makemessages.py | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/zerver/management/commands/makemessages.py b/zerver/management/commands/makemessages.py index 24158ff0c1..5f9c3c683b 100644 --- a/zerver/management/commands/makemessages.py +++ b/zerver/management/commands/makemessages.py @@ -46,6 +46,8 @@ from django.utils.translation import trans_real from django.template.base import BLOCK_TAG_START, BLOCK_TAG_END from django.conf import settings +from zerver.lib.str_utils import force_text + strip_whitespace_right = re.compile(u"(%s-?\\s*(trans|pluralize).*?-%s)\\s+" % (BLOCK_TAG_START, BLOCK_TAG_END), re.U) strip_whitespace_left = re.compile(u"\\s+(%s-\\s*(endtrans|pluralize).*?-?%s)" % ( BLOCK_TAG_START, BLOCK_TAG_END), re.U) @@ -246,6 +248,10 @@ class Command(makemessages.Command): except (IOError, ValueError): old_strings = {} - new_strings = self.get_new_strings(old_strings, translation_strings) + new_strings = { + force_text(k): v + for k, v in self.get_new_strings(old_strings, + translation_strings).items() + } with open(output_path, 'w') as writer: json.dump(new_strings, writer, indent=2, sort_keys=True)