Wanted: Best practices for setting "_" (to ugettext/ugettext_lazy)

48 views
Skip to first unread message

Torsten Bronger

unread,
Jan 24, 2015, 3:46:31 AM1/24/15
to django...@googlegroups.com
Hallöchen!

This is not about where to use ugettext/ugettext_lazy. I know
that. :-)

But I was fed up with all those "_ = ugettext" scattered in my code
and tried to find a more systematic approach. The following test
program runs through:

ugettext = lambda x: x
ugettext_lazy = lambda x: x

_ = ugettext_lazy

def function():
assert _ == ugettext

class A(object):
assert _ == ugettext_lazy

def method(self):
assert _ == ugettext

assert _ == ugettext_lazy

assert _ == ugettext_lazy

def function_b():
assert _ == ugettext

_ = ugettext


function()
function_b()
a = A()
a.method()

Do you think this is a good idea? Simply setting _ to
ugetttext_lazy at the beginning of a module and to ugettext at the
end (and dealing with the very few remaining exceptions)? How do
you do that?

Tschö,
Torsten.

--
Torsten Bronger Jabber ID: torsten...@jabber.rwth-aachen.de
or http://bronger-jmp.appspot.com

Collin Anderson

unread,
Jan 27, 2015, 4:07:35 PM1/27/15
to django...@googlegroups.com
Hi,

Why reset it at the end of your module?

Why not use ugettext_lazy everywhere?
from django.utils.translation import ugettext_lazy as _

(Disclaimer: I've never used translations before :)

Collin
Reply all
Reply to author
Forward
0 new messages