On Sun, 2006-07-02 at 21:16 -0500, Adrian Holovaty wrote:
> On 7/1/06, Malcolm Tredinnick <[EMAIL PROTECTED]> wrote:
> > So you could leave the strings in settings.py, providing you define a
> > function called gettext_noop. All this function does is return the
> > string passed to it (that is all it does for real, anyway). Then the
> > strings are marked with as gettext_noop('Bengali'), etc, and it should
> > all Just Work(tm).
>
> I've made the changes you've suggested (in a local sandbox), but
> there's one problem left: The bottom of django/conf/__init__.py does
> the following:
>
> from django.utils import translation
> translation.install()
>
> This registers the _() function in the __builtins__ namespace.
>
> That code can no longer live there, because the new
> django.utils.translation depends on the USE_I18N setting. But if it
> doesn't live in django/conf/__init__.py, where should it live? What's
> a place where we can put it where we can be sure it'll always be run?
> I'm a bit stumped...
I'm not sure I like what I'm about to suggest, but let's throw it out
and see how it sounds...
How would you feel about making a requirement that settings must be
configured prior to attempting to use translations. By this, I mean,
Django must know that it is either using DJANGO_SETTINGS_MODULE or
manual configuration prior to trying to use _(). In that case, you could
put the import into __builtins__ into LazySettings._import_settings()
and LazySettings.configure(), because you will know the value of
USE_I18N at the end of both of those methods.
The reason I don't really like this (and I think it's a loser if I go
with "trust my gut", but I'm not 100% sure why) is the requirement to
"clarify" which settings are being used first. It might be a bit too
easy to forget to do that and it will be an absolute bear to debug.
The other thing I can think of is to install a function initially that
installs the "real" function over the top of itself the first time it is
called (see attached lazy-install.py for a proof of concept). The first
time the lazy _() is called, it can check settings.USE_I18N, which will
always be accessible at that point (the first access to "settings"
configures it if it has not already been done).
This is all starting to get a bit twisted, but might be unavoidable
unless you go back to the original plan of shipping the strings out of
global_settings and into another file.
I'd probably go for option 2 and a bunch of comments for future
explorers.
Regards,
Malcolm
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups
"Django developers" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at
http://groups.google.com/group/django-developers
-~----------~----~----~----~------~----~------~--~---
#!/usr/bin/env python
import sys
def new_f(*args):
print "Now calling new_f() with", args
def f(*args):
print "Calling f() the first time."
setattr(sys.modules['__builtin__'], '_', new_f)
return new_f(*args)
sys.modules['__builtin__']._ = f
if __name__ == '__main__':
_('fred')
_('barney')
_('wilma')
# vim: se ts=4 sw=4 et: