On Fri, 2007-05-11 at 02:13 -0700, sandro dentella wrote:
> Hi,
> 
>   here again...
> 
>   I think that this is an error, at least again a different behaviour
>   compared to version of some weeks ago (r4871)
> 
> 
> ## english version gives no problem
> (Pdb) print "New Ticket #%(id)s '%(title)s' for project %(project)s" %
> (Item(instance))
> New Ticket #3 'test 3' for project jungle
> 
> ## translated version raise TypeError
> (Pdb) _("New Ticket #%(id)s '%(title)s' for project %(project)s")
> *** TypeError: 'Item' object is not callable
> 
> 
> ## let's take the gettext, not the builtin one
> (Pdb) from django.utils.translation import gettext
> (Pdb) gettext("New Ticket #%(id)s '%(title)s' for project %
> (project)s")
> "Nuovo Ticket #%(id)s '%(title)s' per il progetto %(project)s"
> 
> it works!
> 
> just for completeness Item is defined as:
> 
> class Item(object):
>     """ a simple way to turn an instance into a subscriptable obj
>     return an object encoded into settings.DEFAULT_CARSET
>     """
> 
>     def __init__(self, obj, enc=settings.DEFAULT_CHARSET):
>         self.obj = obj
>         self.ENC = enc
> 
>     def __getitem__(self, name):
>         try:
>             return getattr(self.obj, name).encode(self.ENC)
>         except:
>             ## integers and other do not have 'encode' attribute
>             return getattr(self.obj, name)
> 
> Of course the solution for me is just to import gettext explicitely.
> Should
> I file a ticket for this?

No. Prior to 1.0 we are going to remove the implicit and automatic
aliasing of gettext() to _() throughout the code anyway. It's a bit of a
Python design wart -- i.e. they *really* didn't think it through. The
problem is that if you rely on the it always being in builtins, doctests
(and interactive shell work) break. In fact, I'm pretty sure that's
somewhat the cause of the problem you're seeing. Remember that _ is used
as "the last result" in the Python interactive prompt.

So we have an open ticket (#2920) to remove it everywhere in our
internal code and not install it in builtins. People will need to import
it explicitly, which will also force them to think about whether they
really mean gettext() or gettext_lazy().

Regards,
Malcolm



--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to