﻿id	summary	reporter	owner	description	type	status	component	version	severity	resolution	keywords	cc	stage	has_patch	needs_docs	needs_tests	needs_better_patch	easy	ui_ux
8033	Better error handling for gettext and gettext_lazy issues	Manuel Saelices	Claude Paroz <claude@…>	"It's very common get confused in use of {{{gettext}}} and {{{gettext_lazy}}} functions. An usual error was to use {{{gettext}}} at import time, for example, in any of this cases:
 * In a parameter of {{{settings.py}}} file:
{{{
from django.utils.translation import ugettext as _
...
LANGUAGE_CHOICES = (('es', _('Spanish')),
                    ('en', _('English')),)
}}}
 * In class or field definition of a {{{models.py}}} file:
{{{
from django.db import models
from django.utils.translation import ugettext as _

class Author(models.Model):
    name = models.CharField(_(u'Name'), max_length=100)
}}}

In both cases, if you get an error, the error will be an {{{ImportError}}} usually in another part of code... This is very difficult to debug, because the real error should be ''""Incorrect use of gettext. You can't use gettext at import time""''. 

The error is due to the fact of not all applications has been imported yet, and {{{gettext}}} resolution need to have all possible translation files loaded ({{{django.po}}} files), which implies loading of all applications. This causes a circular import error problem.

In [http://groups.google.com/group/django-developers/browse_frm/thread/fdc392d546fd8da this thread] there is a discussion about this.

We are thinking in check in every call to {{{gettext}}} if django apps has been loaded (using {{{django.db.models.loading.app_cache_ready()}}}) and take one of this options:
 * raise an representative error.
 * return a dummy string.

I personally prefers first one, because {{{gettext}}} should be '''always''' called inside functions (at run time), and '''never''' at import time. I don't imagine a case of we need use {{{gettext}}} before that."	Cleanup/optimization	closed	Internationalization	dev	Normal	fixed			Ready for checkin	1	0	0	0	0	0
