[1.7.x] Revert "Applied unicode_literals to makemessages command"
This reverts commit cdfefbec7
as it caused a regression (#23271).
This commit is contained in:
parent
72fdd62e93
commit
e705d8c4b4
|
@ -1,5 +1,3 @@
|
||||||
from __future__ import unicode_literals
|
|
||||||
|
|
||||||
import fnmatch
|
import fnmatch
|
||||||
import glob
|
import glob
|
||||||
import io
|
import io
|
||||||
|
@ -66,12 +64,12 @@ class TranslatableFile(object):
|
||||||
if domain == 'djangojs' and file_ext in command.extensions:
|
if domain == 'djangojs' and file_ext in command.extensions:
|
||||||
is_templatized = True
|
is_templatized = True
|
||||||
orig_file = os.path.join(self.dirpath, self.file)
|
orig_file = os.path.join(self.dirpath, self.file)
|
||||||
with io.open(orig_file, encoding=settings.FILE_CHARSET) as fp:
|
with open(orig_file) as fp:
|
||||||
src_data = fp.read()
|
src_data = fp.read()
|
||||||
src_data = prepare_js_for_gettext(src_data)
|
src_data = prepare_js_for_gettext(src_data)
|
||||||
thefile = '%s.c' % self.file
|
thefile = '%s.c' % self.file
|
||||||
work_file = os.path.join(self.dirpath, thefile)
|
work_file = os.path.join(self.dirpath, thefile)
|
||||||
with io.open(work_file, "w", encoding='utf-8') as fp:
|
with open(work_file, "w") as fp:
|
||||||
fp.write(src_data)
|
fp.write(src_data)
|
||||||
args = [
|
args = [
|
||||||
'xgettext',
|
'xgettext',
|
||||||
|
@ -90,11 +88,11 @@ class TranslatableFile(object):
|
||||||
orig_file = os.path.join(self.dirpath, self.file)
|
orig_file = os.path.join(self.dirpath, self.file)
|
||||||
is_templatized = file_ext in command.extensions
|
is_templatized = file_ext in command.extensions
|
||||||
if is_templatized:
|
if is_templatized:
|
||||||
with io.open(orig_file, 'r', encoding=settings.FILE_CHARSET) as fp:
|
with open(orig_file, 'r' if six.PY3 else 'rU') as fp:
|
||||||
src_data = fp.read()
|
src_data = fp.read()
|
||||||
thefile = '%s.py' % self.file
|
thefile = '%s.py' % self.file
|
||||||
content = templatize(src_data, orig_file[2:])
|
content = templatize(src_data, orig_file[2:])
|
||||||
with io.open(os.path.join(self.dirpath, thefile), "w", encoding='utf-8') as fp:
|
with open(os.path.join(self.dirpath, thefile), "w") as fp:
|
||||||
fp.write(content)
|
fp.write(content)
|
||||||
work_file = os.path.join(self.dirpath, thefile)
|
work_file = os.path.join(self.dirpath, thefile)
|
||||||
args = [
|
args = [
|
||||||
|
@ -128,8 +126,6 @@ class TranslatableFile(object):
|
||||||
# Print warnings
|
# Print warnings
|
||||||
command.stdout.write(errors)
|
command.stdout.write(errors)
|
||||||
if msgs:
|
if msgs:
|
||||||
if six.PY2:
|
|
||||||
msgs = msgs.decode('utf-8')
|
|
||||||
# Write/append messages to pot file
|
# Write/append messages to pot file
|
||||||
potfile = os.path.join(self.locale_dir, '%s.pot' % str(domain))
|
potfile = os.path.join(self.locale_dir, '%s.pot' % str(domain))
|
||||||
if is_templatized:
|
if is_templatized:
|
||||||
|
@ -158,7 +154,7 @@ def write_pot_file(potfile, msgs):
|
||||||
msgs = '\n'.join(dropwhile(len, msgs.split('\n')))
|
msgs = '\n'.join(dropwhile(len, msgs.split('\n')))
|
||||||
else:
|
else:
|
||||||
msgs = msgs.replace('charset=CHARSET', 'charset=UTF-8')
|
msgs = msgs.replace('charset=CHARSET', 'charset=UTF-8')
|
||||||
with io.open(potfile, 'a', encoding='utf-8') as fp:
|
with open(potfile, 'a') as fp:
|
||||||
fp.write(msgs)
|
fp.write(msgs)
|
||||||
|
|
||||||
|
|
||||||
|
@ -319,15 +315,13 @@ class Command(NoArgsCommand):
|
||||||
continue
|
continue
|
||||||
args = ['msguniq'] + self.msguniq_options + [potfile]
|
args = ['msguniq'] + self.msguniq_options + [potfile]
|
||||||
msgs, errors, status = popen_wrapper(args)
|
msgs, errors, status = popen_wrapper(args)
|
||||||
if six.PY2:
|
|
||||||
msgs = msgs.decode('utf-8')
|
|
||||||
if errors:
|
if errors:
|
||||||
if status != STATUS_OK:
|
if status != STATUS_OK:
|
||||||
raise CommandError(
|
raise CommandError(
|
||||||
"errors happened while running msguniq\n%s" % errors)
|
"errors happened while running msguniq\n%s" % errors)
|
||||||
elif self.verbosity > 0:
|
elif self.verbosity > 0:
|
||||||
self.stdout.write(errors)
|
self.stdout.write(errors)
|
||||||
with io.open(potfile, 'w', encoding='utf-8') as fp:
|
with open(potfile, 'w') as fp:
|
||||||
fp.write(msgs)
|
fp.write(msgs)
|
||||||
potfiles.append(potfile)
|
potfiles.append(potfile)
|
||||||
return potfiles
|
return potfiles
|
||||||
|
@ -399,8 +393,6 @@ class Command(NoArgsCommand):
|
||||||
if os.path.exists(pofile):
|
if os.path.exists(pofile):
|
||||||
args = ['msgmerge'] + self.msgmerge_options + [pofile, potfile]
|
args = ['msgmerge'] + self.msgmerge_options + [pofile, potfile]
|
||||||
msgs, errors, status = popen_wrapper(args)
|
msgs, errors, status = popen_wrapper(args)
|
||||||
if six.PY2:
|
|
||||||
msgs = msgs.decode('utf-8')
|
|
||||||
if errors:
|
if errors:
|
||||||
if status != STATUS_OK:
|
if status != STATUS_OK:
|
||||||
raise CommandError(
|
raise CommandError(
|
||||||
|
@ -408,13 +400,13 @@ class Command(NoArgsCommand):
|
||||||
elif self.verbosity > 0:
|
elif self.verbosity > 0:
|
||||||
self.stdout.write(errors)
|
self.stdout.write(errors)
|
||||||
else:
|
else:
|
||||||
with io.open(potfile, 'r', encoding='utf-8') as fp:
|
with open(potfile, 'r') as fp:
|
||||||
msgs = fp.read()
|
msgs = fp.read()
|
||||||
if not self.invoked_for_django:
|
if not self.invoked_for_django:
|
||||||
msgs = self.copy_plural_forms(msgs, locale)
|
msgs = self.copy_plural_forms(msgs, locale)
|
||||||
msgs = msgs.replace(
|
msgs = msgs.replace(
|
||||||
"#. #-#-#-#-# %s.pot (PACKAGE VERSION) #-#-#-#-#\n" % self.domain, "")
|
"#. #-#-#-#-# %s.pot (PACKAGE VERSION) #-#-#-#-#\n" % self.domain, "")
|
||||||
with io.open(pofile, 'w', encoding='utf-8') as fp:
|
with open(pofile, 'w') as fp:
|
||||||
fp.write(msgs)
|
fp.write(msgs)
|
||||||
|
|
||||||
if self.no_obsolete:
|
if self.no_obsolete:
|
||||||
|
@ -441,7 +433,7 @@ class Command(NoArgsCommand):
|
||||||
for domain in domains:
|
for domain in domains:
|
||||||
django_po = os.path.join(django_dir, 'conf', 'locale', locale, 'LC_MESSAGES', '%s.po' % domain)
|
django_po = os.path.join(django_dir, 'conf', 'locale', locale, 'LC_MESSAGES', '%s.po' % domain)
|
||||||
if os.path.exists(django_po):
|
if os.path.exists(django_po):
|
||||||
with io.open(django_po, 'r', encoding='utf-8') as fp:
|
with io.open(django_po, 'r' if six.PY3 else 'rU', encoding='utf-8') as fp:
|
||||||
m = plural_forms_re.search(fp.read())
|
m = plural_forms_re.search(fp.read())
|
||||||
if m:
|
if m:
|
||||||
plural_form_line = force_str(m.group('value'))
|
plural_form_line = force_str(m.group('value'))
|
||||||
|
|
|
@ -14,7 +14,7 @@ from django.core.exceptions import AppRegistryNotReady
|
||||||
from django.dispatch import receiver
|
from django.dispatch import receiver
|
||||||
from django.test.signals import setting_changed
|
from django.test.signals import setting_changed
|
||||||
from django.utils.deprecation import RemovedInDjango19Warning
|
from django.utils.deprecation import RemovedInDjango19Warning
|
||||||
from django.utils.encoding import force_text
|
from django.utils.encoding import force_str, force_text
|
||||||
from django.utils._os import upath
|
from django.utils._os import upath
|
||||||
from django.utils.safestring import mark_safe, SafeData
|
from django.utils.safestring import mark_safe, SafeData
|
||||||
from django.utils import six, lru_cache
|
from django.utils import six, lru_cache
|
||||||
|
@ -723,7 +723,7 @@ def templatize(src, origin=None):
|
||||||
comment_lineno_cache = t.lineno
|
comment_lineno_cache = t.lineno
|
||||||
else:
|
else:
|
||||||
out.write(blankout(t.contents, 'X'))
|
out.write(blankout(t.contents, 'X'))
|
||||||
return out.getvalue()
|
return force_str(out.getvalue())
|
||||||
|
|
||||||
|
|
||||||
def parse_accept_lang_header(lang_string):
|
def parse_accept_lang_header(lang_string):
|
||||||
|
|
Loading…
Reference in New Issue