Loading django/core/management/commands/makemessages.py +9 −17 Original line number Diff line number Diff line from __future__ import unicode_literals import fnmatch import glob import io Loading Loading @@ -66,12 +64,12 @@ class TranslatableFile(object): if domain == 'djangojs' and file_ext in command.extensions: is_templatized = True 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 = prepare_js_for_gettext(src_data) thefile = '%s.c' % self.file 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) args = [ 'xgettext', Loading @@ -90,11 +88,11 @@ class TranslatableFile(object): orig_file = os.path.join(self.dirpath, self.file) is_templatized = file_ext in command.extensions 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() thefile = '%s.py' % self.file 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) work_file = os.path.join(self.dirpath, thefile) args = [ Loading Loading @@ -128,8 +126,6 @@ class TranslatableFile(object): # Print warnings command.stdout.write(errors) if msgs: if six.PY2: msgs = msgs.decode('utf-8') # Write/append messages to pot file potfile = os.path.join(self.locale_dir, '%s.pot' % str(domain)) if is_templatized: Loading Loading @@ -158,7 +154,7 @@ def write_pot_file(potfile, msgs): msgs = '\n'.join(dropwhile(len, msgs.split('\n'))) else: 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) Loading Loading @@ -319,15 +315,13 @@ class Command(NoArgsCommand): continue args = ['msguniq'] + self.msguniq_options + [potfile] msgs, errors, status = popen_wrapper(args) if six.PY2: msgs = msgs.decode('utf-8') if errors: if status != STATUS_OK: raise CommandError( "errors happened while running msguniq\n%s" % errors) elif self.verbosity > 0: self.stdout.write(errors) with io.open(potfile, 'w', encoding='utf-8') as fp: with open(potfile, 'w') as fp: fp.write(msgs) potfiles.append(potfile) return potfiles Loading Loading @@ -399,8 +393,6 @@ class Command(NoArgsCommand): if os.path.exists(pofile): args = ['msgmerge'] + self.msgmerge_options + [pofile, potfile] msgs, errors, status = popen_wrapper(args) if six.PY2: msgs = msgs.decode('utf-8') if errors: if status != STATUS_OK: raise CommandError( Loading @@ -408,13 +400,13 @@ class Command(NoArgsCommand): elif self.verbosity > 0: self.stdout.write(errors) else: with io.open(potfile, 'r', encoding='utf-8') as fp: with open(potfile, 'r') as fp: msgs = fp.read() if not self.invoked_for_django: msgs = self.copy_plural_forms(msgs, locale) msgs = msgs.replace( "#. #-#-#-#-# %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) if self.no_obsolete: Loading @@ -441,7 +433,7 @@ 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 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()) if m: plural_form_line = force_str(m.group('value')) Loading django/utils/translation/trans_real.py +2 −2 Original line number Diff line number Diff line Loading @@ -14,7 +14,7 @@ from django.core.exceptions import AppRegistryNotReady from django.dispatch import receiver from django.test.signals import setting_changed 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.safestring import mark_safe, SafeData from django.utils import six, lru_cache Loading Loading @@ -723,7 +723,7 @@ def templatize(src, origin=None): comment_lineno_cache = t.lineno else: out.write(blankout(t.contents, 'X')) return out.getvalue() return force_str(out.getvalue()) def parse_accept_lang_header(lang_string): Loading Loading
django/core/management/commands/makemessages.py +9 −17 Original line number Diff line number Diff line from __future__ import unicode_literals import fnmatch import glob import io Loading Loading @@ -66,12 +64,12 @@ class TranslatableFile(object): if domain == 'djangojs' and file_ext in command.extensions: is_templatized = True 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 = prepare_js_for_gettext(src_data) thefile = '%s.c' % self.file 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) args = [ 'xgettext', Loading @@ -90,11 +88,11 @@ class TranslatableFile(object): orig_file = os.path.join(self.dirpath, self.file) is_templatized = file_ext in command.extensions 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() thefile = '%s.py' % self.file 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) work_file = os.path.join(self.dirpath, thefile) args = [ Loading Loading @@ -128,8 +126,6 @@ class TranslatableFile(object): # Print warnings command.stdout.write(errors) if msgs: if six.PY2: msgs = msgs.decode('utf-8') # Write/append messages to pot file potfile = os.path.join(self.locale_dir, '%s.pot' % str(domain)) if is_templatized: Loading Loading @@ -158,7 +154,7 @@ def write_pot_file(potfile, msgs): msgs = '\n'.join(dropwhile(len, msgs.split('\n'))) else: 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) Loading Loading @@ -319,15 +315,13 @@ class Command(NoArgsCommand): continue args = ['msguniq'] + self.msguniq_options + [potfile] msgs, errors, status = popen_wrapper(args) if six.PY2: msgs = msgs.decode('utf-8') if errors: if status != STATUS_OK: raise CommandError( "errors happened while running msguniq\n%s" % errors) elif self.verbosity > 0: self.stdout.write(errors) with io.open(potfile, 'w', encoding='utf-8') as fp: with open(potfile, 'w') as fp: fp.write(msgs) potfiles.append(potfile) return potfiles Loading Loading @@ -399,8 +393,6 @@ class Command(NoArgsCommand): if os.path.exists(pofile): args = ['msgmerge'] + self.msgmerge_options + [pofile, potfile] msgs, errors, status = popen_wrapper(args) if six.PY2: msgs = msgs.decode('utf-8') if errors: if status != STATUS_OK: raise CommandError( Loading @@ -408,13 +400,13 @@ class Command(NoArgsCommand): elif self.verbosity > 0: self.stdout.write(errors) else: with io.open(potfile, 'r', encoding='utf-8') as fp: with open(potfile, 'r') as fp: msgs = fp.read() if not self.invoked_for_django: msgs = self.copy_plural_forms(msgs, locale) msgs = msgs.replace( "#. #-#-#-#-# %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) if self.no_obsolete: Loading @@ -441,7 +433,7 @@ 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 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()) if m: plural_form_line = force_str(m.group('value')) Loading
django/utils/translation/trans_real.py +2 −2 Original line number Diff line number Diff line Loading @@ -14,7 +14,7 @@ from django.core.exceptions import AppRegistryNotReady from django.dispatch import receiver from django.test.signals import setting_changed 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.safestring import mark_safe, SafeData from django.utils import six, lru_cache Loading Loading @@ -723,7 +723,7 @@ def templatize(src, origin=None): comment_lineno_cache = t.lineno else: out.write(blankout(t.contents, 'X')) return out.getvalue() return force_str(out.getvalue()) def parse_accept_lang_header(lang_string): Loading