diff options
| author | Claude Paroz <claude@2xlibre.net> | 2016-09-29 16:13:10 +0200 |
|---|---|---|
| committer | Claude Paroz <claude@2xlibre.net> | 2016-10-01 14:57:16 +0200 |
| commit | fa2f55cfd554c6f99653ffe0d40fd7ca74cb680e (patch) | |
| tree | 9fcc03004ae628a176dca0a98accc9ead4910021 /django/core | |
| parent | 63bf615d5e5566e23ba698f95e64acfa9f2651ff (diff) | |
Refs #26940 -- Re-allowed makemessages without settings
Thanks Tim Graham for the review.
Diffstat (limited to 'django/core')
| -rw-r--r-- | django/core/management/commands/makemessages.py | 23 |
1 files changed, 19 insertions, 4 deletions
diff --git a/django/core/management/commands/makemessages.py b/django/core/management/commands/makemessages.py index 93039ac096..72390e4a75 100644 --- a/django/core/management/commands/makemessages.py +++ b/django/core/management/commands/makemessages.py @@ -11,6 +11,7 @@ from itertools import dropwhile import django from django.conf import settings +from django.core.exceptions import ImproperlyConfigured from django.core.files.temp import NamedTemporaryFile from django.core.management.base import BaseCommand, CommandError from django.core.management.utils import ( @@ -103,13 +104,14 @@ class BuildFile(object): if not self.is_templatized: return - with io.open(self.path, 'r', encoding=settings.FILE_CHARSET) as fp: + encoding = settings.FILE_CHARSET if self.command.settings_available else 'utf-8' + with io.open(self.path, 'r', encoding=encoding) as fp: src_data = fp.read() if self.domain == 'djangojs': content = prepare_js_for_gettext(src_data) elif self.domain == 'django': - content = templatize(src_data, self.path[2:]) + content = templatize(src_data, origin=self.path[2:], charset=encoding) with io.open(self.work_path, 'w', encoding='utf-8') as fp: fp.write(content) @@ -325,7 +327,8 @@ class Command(BaseCommand): self.default_locale_path = self.locale_paths[0] self.invoked_for_django = True else: - self.locale_paths.extend(settings.LOCALE_PATHS) + if self.settings_available: + self.locale_paths.extend(settings.LOCALE_PATHS) # Allow to run makemessages inside an app dir if os.path.isdir('locale'): self.locale_paths.append(os.path.abspath('locale')) @@ -377,6 +380,16 @@ class Command(BaseCommand): else: raise CommandError("Unable to get gettext version. Is it installed?") + @cached_property + def settings_available(self): + try: + settings.LOCALE_PATHS + except ImproperlyConfigured: + if self.verbosity > 1: + self.stderr.write("Running without configured settings.") + return False + return True + def build_potfiles(self): """ Build pot files and apply msguniq to them. @@ -438,7 +451,9 @@ class Command(BaseCommand): norm_patterns.append(p) all_files = [] - ignored_roots = [os.path.normpath(p) for p in (settings.MEDIA_ROOT, settings.STATIC_ROOT) if p] + ignored_roots = [] + if self.settings_available: + ignored_roots = [os.path.normpath(p) for p in (settings.MEDIA_ROOT, settings.STATIC_ROOT) if p] for dirpath, dirnames, filenames in os.walk(root, topdown=True, followlinks=self.symlinks): for dirname in dirnames[:]: if (is_ignored(os.path.normpath(os.path.join(dirpath, dirname)), norm_patterns) or |
