[Freeipa-devel] localized strings

John Dennis jdennis at redhat.com
Wed Nov 11 21:16:43 UTC 2009


On 11/11/2009 03:45 PM, Jason Gerard DeRose wrote:
> 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.

Could you provide a bit more explanation for why you would like to 
discourage this practice?

Do you want to see an exception class for each possible error and no 
customization of the error strings?

>> 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.
>


-- 
John Dennis <jdennis at redhat.com>

Looking to carve out IT costs?
www.redhat.com/carveoutcosts/




More information about the Freeipa-devel mailing list