summaryrefslogtreecommitdiff
path: root/django
diff options
context:
space:
mode:
authorClaude Paroz <claude@2xlibre.net>2014-06-21 15:00:35 +0200
committerClaude Paroz <claude@2xlibre.net>2014-06-23 09:31:45 +0200
commit9618d68b345fe69c787f8426b07e920e647e05f3 (patch)
tree4ae5388f3da46b38d729f9f931448c58a18ddaec /django
parent21c496ea52b8bdf0d97507c00a87286425dac087 (diff)
Fixed #8033 -- Explained app registry error during translation setup
Thanks Tim Graham and Aymeric Augustin for the review.
Diffstat (limited to 'django')
-rw-r--r--django/apps/registry.py4
-rw-r--r--django/core/exceptions.py5
-rw-r--r--django/utils/translation/trans_real.py10
3 files changed, 16 insertions, 3 deletions
diff --git a/django/apps/registry.py b/django/apps/registry.py
index 41095bd41e..492a97f603 100644
--- a/django/apps/registry.py
+++ b/django/apps/registry.py
@@ -4,7 +4,7 @@ import sys
import threading
import warnings
-from django.core.exceptions import ImproperlyConfigured
+from django.core.exceptions import AppRegistryNotReady, ImproperlyConfigured
from django.utils import lru_cache
from django.utils.deprecation import RemovedInDjango19Warning
from django.utils._os import upath
@@ -116,7 +116,7 @@ class Apps(object):
Raises an exception if the registry isn't ready.
"""
if not self.ready:
- raise RuntimeError("App registry isn't ready yet.")
+ raise AppRegistryNotReady()
def get_app_configs(self):
"""
diff --git a/django/core/exceptions.py b/django/core/exceptions.py
index cf4aea0f36..552b0067c3 100644
--- a/django/core/exceptions.py
+++ b/django/core/exceptions.py
@@ -12,6 +12,11 @@ class DjangoRuntimeWarning(RuntimeWarning):
pass
+class AppRegistryNotReady(Exception):
+ """The django.apps registry is not populated yet"""
+ pass
+
+
class ObjectDoesNotExist(Exception):
"""The requested object does not exist"""
silent_variable_failure = True
diff --git a/django/utils/translation/trans_real.py b/django/utils/translation/trans_real.py
index 71445cb365..56a0da2639 100644
--- a/django/utils/translation/trans_real.py
+++ b/django/utils/translation/trans_real.py
@@ -11,6 +11,7 @@ import warnings
from django.apps import apps
from django.conf import settings
+from django.core.exceptions import AppRegistryNotReady
from django.dispatch import receiver
from django.test.signals import setting_changed
from django.utils.deprecation import RemovedInDjango19Warning
@@ -160,7 +161,14 @@ class DjangoTranslation(gettext_module.GNUTranslations):
def _add_installed_apps_translations(self):
"""Merges translations from each installed app."""
- for app_config in reversed(list(apps.get_app_configs())):
+ try:
+ app_configs = reversed(list(apps.get_app_configs()))
+ except AppRegistryNotReady:
+ raise AppRegistryNotReady(
+ "The translation infrastructure cannot be initialized before the "
+ "apps registry is ready. Check that you don't make non-lazy "
+ "gettext calls at import time.")
+ for app_config in app_configs:
localedir = os.path.join(app_config.path, 'locale')
translation = self._new_gnu_trans(localedir)
self.merge(translation)