[openstack-dev] _() consensus??
Mathew R Odden
mrodden at us.ibm.com
Mon Jan 7 20:14:15 UTC 2013
>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 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.
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
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.openstack.org/pipermail/openstack-dev/attachments/20130107/705fe0e9/attachment.html>
More information about the OpenStack-dev
mailing list