Skip to content


Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

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.
  • Loading branch information...
commit b5f52647fe513ec5f1b3e9b0bf06b7860ea72626 1 parent a098bee
Ramiro Morales authored
9 django/core/management/commands/
@@ -1,5 +1,6 @@
import fnmatch
import glob
+import io
import os
import re
import sys
@@ -10,6 +11,7 @@
from import CommandError, NoArgsCommand
from import (handle_extensions, find_command,
+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 @@ def copy_plural_forms(self, msgs, locale):
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, 'rU', encoding='utf-8') as fp:
m =
if m:
+ plural_form_line = force_str('value'))
if self.verbosity > 1:
- self.stdout.write("copying plural forms: %s\n" %'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
- line = '%s\n' %'value')
+ line = '%s\n' % plural_form_line
found = True
msgs = '\n'.join(lines)
9 tests/i18n/commands/
@@ -1,6 +1,7 @@
# -*- encoding: utf-8 -*-
from __future__ import unicode_literals
+import io
import os
import re
import shutil
@@ -65,8 +66,8 @@ def test_comments_extractor(self):
management.call_command('makemessages', locale=LOCALE, verbosity=0)
- with open(self.PO_FILE, 'r') as fp:
- po_contents = force_text(
+ with, 'r', encoding='utf-8') as fp:
+ po_contents =
self.assertTrue('#. Translators: This comment should be extracted' in po_contents)
self.assertTrue('This comment should not be extracted' not in po_contents)
# Comments in templates
@@ -363,8 +364,8 @@ def test_override_plural_forms(self):
management.call_command('makemessages', locale='es', extensions=['djtpl'], verbosity=0)
- with open(self.PO_FILE_ES, 'r') as fp:
- po_contents = force_text(
+ with, 'r', encoding='utf-8') as fp:
+ po_contents =
found = re.findall(r'^(?P<value>"Plural-Forms.+?\\n")\s*$', po_contents, re.MULTILINE | re.DOTALL)
self.assertEqual(1, len(found))
Please sign in to comment.
Something went wrong with that request. Please try again.