[Freeipa-devel] localized strings

Jason Gerard DeRose jderose at redhat.com
Wed Nov 11 20:45:09 UTC 2009


On Tue, 2009-11-10 at 20:42 -0500, John Dennis wrote:
> I was writing some new code and wanted to return an error message. Error 
> messages need to be localized. Typically this is done via the _() 
> method. But _() has to be defined and there are several ways that can 
> happen. So I went looking for existing usage in our code base. I was 
> surprised at how little I found which makes me wonder if I'm not 
> understanding how we're handling messages. errors.py does define _() 
> which makes sense, but a lot of the usage of the error classes in 
> errors.py involves providing a customized error detail message, usually 
> via the 'reason' keyword, for example:
> 
> raise errors.NotFound(reason="Group '%s' does not exist" % kw['group'])

This is a practice I've tried to discourage, but we still use it a lot.

> but it seems to me this should be:
> 
> raise errors.NotFound(reason=_("Group '%s' does not exist") % kw['group'])
> 
> 
> Virtually all of the examples I found of returning a detailed error 
> message omitted the _() localization method. Why? Am I missing something 
> about how we're supposed to be coding this? This also raised the 
> question in my mind about how we're binding _(), the only example I 
> could find was this:
> 
> from request import ugettext as _

Yes, this is the current mechanism.  The next UI patch adds a more
generalized mechanism so we can have translation from multiple gettext
domains.

> Is this what all the modules are supposed to be doing to bind _()?

Yes.




More information about the Freeipa-devel mailing list