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.
This commit is contained in:
Umair Khan 2017-04-10 14:19:43 +05:00 committed by Tim Abbott
parent b39006655e
commit 9dec5306ce
1 changed files with 7 additions and 1 deletions

View File

@ -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)