diff options
| author | Ramiro Morales <ramiro@rmorales.net> | 2013-10-21 00:22:32 -0300 |
|---|---|---|
| committer | Ramiro Morales <ramiro@rmorales.net> | 2013-10-22 06:09:21 -0300 |
| commit | b5f52647fe513ec5f1b3e9b0bf06b7860ea72626 (patch) | |
| tree | 70fc09792def759ac1df9d75bea4a50cb27e3863 /django | |
| parent | a098bee1b9fa4df64f3fd72ff5cbae43bf27e539 (diff) | |
Decode from UTF-8 explicitly when reading a text file in makemessages.
This shows itself with Python 3 under Windows where UTF-8 usually isn't
the default file I/O encoding and caused one failure and three errors
in our test suite under that platform setup.
Diffstat (limited to 'django')
| -rw-r--r-- | django/core/management/commands/makemessages.py | 9 |
1 files changed, 6 insertions, 3 deletions
diff --git a/django/core/management/commands/makemessages.py b/django/core/management/commands/makemessages.py index 8574e7d546..120cff096b 100644 --- a/django/core/management/commands/makemessages.py +++ b/django/core/management/commands/makemessages.py @@ -1,5 +1,6 @@ import fnmatch import glob +import io import os import re import sys @@ -10,6 +11,7 @@ import django from django.core.management.base import CommandError, NoArgsCommand from django.core.management.utils import (handle_extensions, find_command, popen_wrapper) +from django.utils.encoding import force_str from django.utils.functional import total_ordering from django.utils.text import get_text_list from django.utils.jslex import prepare_js_for_gettext @@ -402,16 +404,17 @@ class Command(NoArgsCommand): for domain in domains: django_po = os.path.join(django_dir, 'conf', 'locale', locale, 'LC_MESSAGES', '%s.po' % domain) if os.path.exists(django_po): - with open(django_po, 'rU') as fp: + with io.open(django_po, 'rU', encoding='utf-8') as fp: m = plural_forms_re.search(fp.read()) if m: + plural_form_line = force_str(m.group('value')) if self.verbosity > 1: - self.stdout.write("copying plural forms: %s\n" % m.group('value')) + self.stdout.write("copying plural forms: %s\n" % plural_form_line) lines = [] found = False for line in msgs.split('\n'): if not found and (not line or plural_forms_re.search(line)): - line = '%s\n' % m.group('value') + line = '%s\n' % plural_form_line found = True lines.append(line) msgs = '\n'.join(lines) |
