Opened 9 years ago

Closed 9 years ago

Last modified 9 years ago

#24842 closed Bug (needsinfo)

Resets settings if before defining DATABASES use ugettext or ugettext_lazy

Reported by: Lagovas Owned by: nobody
Component: Internationalization Version: 1.6
Severity: Normal Keywords: settings translations ugettext
Cc: Triage Stage: Unreviewed
Has patch: no Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: no UI/UX: no

Description

Code like:

from django.utils.translation import ugettext_lazy as _
class SOME_SETTINGS_CONSTANT:
    A=1_(u'a')
    B=2
    CHOICES = (
        A,  _(u'a')
        B,  _(u'b')
    )
    TEXT_CHOICES = {k:v for k, v in CHOICES}

After that expression TEXT_CHOICES ... fetch translated value and resets settings like if u used ugettext in settings.py. But if place this expression at the end of settings then all is ok.

Change History (3)

comment:1 by Tim Graham, 9 years ago

Could you edit the description to fix the syntax errors in your example and also elaborate on the problem a bit? I'm having trouble understanding what the problem/expected behavior is. Maybe an example shell session would help.

comment:2 by Claude Paroz, 9 years ago

Resolution: invalid
Status: newclosed

You should never call any django.utils.translation method inside a settings.py file, as it will most probably lead to circular imports.
Use some noop method like gettext_noop = lambda s: s in the settings file so as the string is extracted in po files, then call ugettext or ugettext_lazy later in your code when you use that value to translate it.

comment:3 by Claude Paroz, 9 years ago

Resolution: invalidneedsinfo

I may be wrong with ugettext_lazy not being usable in settings files (thanks Baptiste for correcting me). Sorry.
However, as Tim said, we still need some more code/explanations to understand what your issue really is.

Note: See TracTickets for help on using tickets.
Back to Top