<html>
<head>
<meta content="text/html; charset=ISO-8859-1"
http-equiv="Content-Type">
</head>
<body text="#000000" bgcolor="#FFFFFF">
<div class="moz-cite-prefix">On 2013年01月08日 04:14, Mathew R Odden
wrote:<br>
</div>
<blockquote
cite="mid:OF958C94B9.40B9E95D-ON86257AEC.006E478E-86257AEC.006F2B06@us.ibm.com"
type="cite">
<p><font size="1" face="Lucida Console" color="#535353">>And I
guess all the user-visible message was exception message in
REST API<br>
>So as example, the code probably looks like:<br>
>in Controller:<br>
>def index(self, req):<br>
> try:<br>
> res = self._get_(resources)(...)<br>
> except Exception as e:<br>
> LOG.exception(e.message)<br>
> user_locale = get_user_locale_from_request(req)<br>
> t = gettext.tranlsation('xxx-usermsg',
languages=user_locale)<br>
> res = {'Error': t.ugettext(e.message.orignal)}<br>
> return res<br>
><br>
>The exception message can log at server side:<br>
>LOG.exception(e.message)<br>
><br>
>And the exception message also can return to user as
user-visible <br>
>message too:<br>
>t = gettext.tranlsation('xxx-usermsg',
languages=user_locale)<br>
> res = {'Error': t.ugettext(e.message.orignal)}<br>
><br>
>We can wrapper the user-visible message by 'L_()'. And
'L_' should be an <br>
>object. It can return<br>
>server side translation and also can return orignal
message that need be <br>
>translated as user request.</font><br>
<br>
<font size="2" face="sans-serif">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.</font><br>
</p>
</blockquote>
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__()'.<br>
<blockquote
cite="mid:OF958C94B9.40B9E95D-ON86257AEC.006E478E-86257AEC.006F2B06@us.ibm.com"
type="cite">
<p>
<br>
<font size="2" face="sans-serif">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.</font><br>
</p>
</blockquote>
I missed this problem too. :) We need investigate this problem.<br>
<blockquote
cite="mid:OF958C94B9.40B9E95D-ON86257AEC.006E478E-86257AEC.006F2B06@us.ibm.com"
type="cite">
<p>
<br>
<font size="2" face="sans-serif">Blueprint I was working on
drafting is here:</font><br>
<br>
<font size="2" face="sans-serif"><a moz-do-not-send="true"
href="https://blueprints.launchpad.net/nova/+spec/user-locale-api">https://blueprints.launchpad.net/nova/+spec/user-locale-api</a></font><br>
<br>
<font size="2" face="sans-serif">Mathew Odden, Software Engineer
<br>
IBM STG Emerging Solutions Development <br>
<a class="moz-txt-link-abbreviated" href="mailto:mrodden@us.ibm.com">mrodden@us.ibm.com</a></font>
<br>
</p>
<fieldset class="mimeAttachmentHeader"></fieldset>
<br>
<pre wrap="">_______________________________________________
OpenStack-dev mailing list
<a class="moz-txt-link-abbreviated" href="mailto:OpenStack-dev@lists.openstack.org">OpenStack-dev@lists.openstack.org</a>
<a class="moz-txt-link-freetext" href="http://lists.openstack.org/cgi-bin/mailman/listinfo/openstack-dev">http://lists.openstack.org/cgi-bin/mailman/listinfo/openstack-dev</a>
</pre>
</blockquote>
<br>
</body>
</html>