4

I am following Django Doc, but I get the following error message when I do as it says.

"The translation infrastructure cannot be initialized before the "
django.core.exceptions.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.

Settings.py

LANGUAGE_CODE = 'en'

LOCALE_PATHS = (
    os.path.join(BASE_DIR, 'locale/'),
)

USE_I18N = True

USE_L10N = True

USE_TZ = True

TIME_ZONE = 'Europe/Copenhagen'

from django.utils.translation import ugettext as _

LANGUAGES = [
  ('da', _('Danish')),
  ('en', _('English')),
]

I understand this is because translation is being called before the necessary lib is loaded, but how can I change it if the documentation says this way?

WSGI.py

import os

from django.core.wsgi import get_wsgi_application

os.environ.setdefault("DJANGO_SETTINGS_MODULE", "my_app.settings")

application = get_wsgi_application()
Ev.
  • 1,537
  • 1
  • 24
  • 49
  • You need to use `ugettext_lazy` – Sayse Feb 02 '16 at 15:55
  • Possible duplicate of [When should I use ugettext\_lazy?](http://stackoverflow.com/questions/4160770/when-should-i-use-ugettext-lazy) – Sayse Feb 02 '16 at 15:55
  • @Sayse Wow. It would have a huge performance impact if the wrong one is used, I assume. Thanks for the heads up. Can you answer the post? It worked. I will mark as the solution. I bet it will help people in the future. :) – Ev. Feb 02 '16 at 16:01
  • 3
    Ev. Thanks, but its normally discouraged to answer questions you believe to be a duplicate of another post (which I partially do here) since it actually makes tracking down the correct answer harder for future readers. Glad it helped though! – Sayse Feb 02 '16 at 16:04

0 Answers0