[openstack-dev] _() consensus??

Xu He Jie xuhj at linux.vnet.ibm.com
Sat Jan 5 08:59:00 UTC 2013

On 2013?01?05? 16:43, Zhongyue Luo wrote:
> Hi all,
> I understand that i18n is an important feature to customers and that 
> having gettextutils wrapped on all log messages will benefit
> in packing custom .pot files to ship with a product.
> However seeing the number of _()'s increasing in source code, its now 
> kind of bothering me now to see all the messages go through
> the heavy process of gettext.translation() even when I don't need i18n.
> Therefore I propose a flag, e.g i18n=true|false, so that a developer 
> can choose the behavior of the _().
> in openstack.common.gettextutils.py...
> def _(msg):
>    if cfg.CONF.i18n:
>        return t.ugettext(msg)
>    else:
>        return msg
> Well you can have the if/else outside of the function to prevent 
> looking up the conf every time it gets called but you get the idea.
> Any thoughts?
> _______________________________________________
> OpenStack-dev mailing list
> OpenStack-dev at lists.openstack.org
> http://lists.openstack.org/cgi-bin/mailman/listinfo/openstack-dev
When gettext.install can't find the right translation domain, it will 
return NullTranslation object.
The 'ugettext' implement of NullTranslation as below:
     def ugettext(self, message):
         if self._fallback:
             return self._fallback.ugettext(message)
         return unicode(message)

It looks like it's not too heavy. So I think it's ok.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.openstack.org/pipermail/openstack-dev/attachments/20130105/44f33d0d/attachment.html>

More information about the OpenStack-dev mailing list