[openstack-dev] _() consensus??

Xu He Jie xuhj at linux.vnet.ibm.com
Tue Jan 8 07:27:12 UTC 2013


On 2013?01?08? 04:14, Mathew R Odden wrote:
>
> >And I guess all the user-visible message was exception message in 
> REST API
> >So as example, the code probably looks like:
> >in Controller:
> >def index(self, req):
> >      try:
> >           res = self._get_(resources)(...)
> >      except Exception as e:
> >          LOG.exception(e.message)
> >          user_locale = get_user_locale_from_request(req)
> >          t = gettext.tranlsation('xxx-usermsg', languages=user_locale)
> >          res = {'Error': t.ugettext(e.message.orignal)}
> >      return res
> >
> >The exception message can log at server side:
> >LOG.exception(e.message)
> >
> >And the exception message also can return to user as user-visible
> >message too:
> >t = gettext.tranlsation('xxx-usermsg', languages=user_locale)
> >          res = {'Error': t.ugettext(e.message.orignal)}
> >
> >We can wrapper the user-visible message by 'L_()'. And 'L_' should be an
> >object. It can return
> >server side translation and also can return orignal message that need be
> >translated as user request.
>
> I have actually been looking into the same issues here independently I 
> guess. My solution is roughly the same as the one mentioned above. 
> i.e. override _() (or L_()) to return a message object with __mod__() 
> overriden as well to save the original message and parameters until it 
> needs to be serialized to a string on write out. Then the message can 
> be localized at print time.
>
I know a way called lazy gettext. I guess that is same as you said. But 
we can't pass user's locale to '__mod__()'.
>
>
> I am not sure if this is the best solution however, as the consequence 
> is dealing with python objects instead of strings, which might have 
> issues when passed through AMQP and such.
>
I missed this problem too. :)  We need investigate this problem.
>
>
> Blueprint I was working on drafting is here:
>
> https://blueprints.launchpad.net/nova/+spec/user-locale-api
>
> Mathew Odden, Software Engineer
> IBM STG Emerging Solutions Development
> mrodden at us.ibm.com
>
>
> _______________________________________________
> OpenStack-dev mailing list
> OpenStack-dev at lists.openstack.org
> http://lists.openstack.org/cgi-bin/mailman/listinfo/openstack-dev

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.openstack.org/pipermail/openstack-dev/attachments/20130108/27911e73/attachment.html>


More information about the OpenStack-dev mailing list