<html xmlns:v="urn:schemas-microsoft-com:vml" xmlns:o="urn:schemas-microsoft-com:office:office" xmlns:w="urn:schemas-microsoft-com:office:word" xmlns:m="http://schemas.microsoft.com/office/2004/12/omml" xmlns="http://www.w3.org/TR/REC-html40">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=us-ascii">
<meta name="Generator" content="Microsoft Word 15 (filtered medium)">
<style><!--
/* Font Definitions */
@font-face
        {font-family:"Cambria Math";
        panose-1:2 4 5 3 5 4 6 3 2 4;}
@font-face
        {font-family:Calibri;
        panose-1:2 15 5 2 2 2 4 3 2 4;}
/* Style Definitions */
p.MsoNormal, li.MsoNormal, div.MsoNormal
        {margin:0in;
        margin-bottom:.0001pt;
        font-size:11.0pt;
        font-family:"Calibri",sans-serif;}
a:link, span.MsoHyperlink
        {mso-style-priority:99;
        color:#0563C1;
        text-decoration:underline;}
a:visited, span.MsoHyperlinkFollowed
        {mso-style-priority:99;
        color:#954F72;
        text-decoration:underline;}
span.EmailStyle17
        {mso-style-type:personal-compose;
        font-family:"Calibri",sans-serif;
        color:windowtext;}
.MsoChpDefault
        {mso-style-type:export-only;
        font-family:"Calibri",sans-serif;}
@page WordSection1
        {size:8.5in 11.0in;
        margin:1.0in 1.0in 1.0in 1.0in;}
div.WordSection1
        {page:WordSection1;}
--></style><!--[if gte mso 9]><xml>
<o:shapedefaults v:ext="edit" spidmax="1026" />
</xml><![endif]--><!--[if gte mso 9]><xml>
<o:shapelayout v:ext="edit">
<o:idmap v:ext="edit" data="1" />
</o:shapelayout></xml><![endif]-->
</head>
<body lang="EN-US" link="#0563C1" vlink="#954F72">
<div class="WordSection1">
<p class="MsoNormal">Hello All,<o:p></o:p></p>
<p class="MsoNormal"><o:p> </o:p></p>
<p class="MsoNormal">I have a question on the usage of oslo_i18n._message and hope to get an answer.<o:p></o:p></p>
<p class="MsoNormal"><o:p> </o:p></p>
<p class="MsoNormal">Some background first:<o:p></o:p></p>
<p class="MsoNormal">I’m working on a portion of Glance – the Glance Metadata Definitions (i.e., metadefs) section.<o:p></o:p></p>
<p class="MsoNormal">We have about ~20 .JSON files which hold data. The .JSON files get loaded into the Glance.metadef_xxx related tables which in turn gets displayed in Horizon via the glance REST API code.<o:p></o:p></p>
<p class="MsoNormal">There are some fields in the .JSON files which need to be internationalized.<o:p></o:p></p>
<p class="MsoNormal">I have a program which produces glance-json.pot files for the JSON files.<o:p></o:p></p>
<p class="MsoNormal"><o:p> </o:p></p>
<p class="MsoNormal">In Horizon, when they are viewing the data, the end-user may change the language they wish to see by going into the profile section (upper right hand corner of Horizon) and selecting the language. So,  I need a more dynamic version of i18n
 than just the version of i18n that gets started up when the Glance service is started (i.e., based on GLANCE_LOCALEDIR and LANGUAGE, LANG, etc., settings).<o:p></o:p></p>
<p class="MsoNormal"><o:p> </o:p></p>
<p class="MsoNormal">This seems to work:<o:p></o:p></p>
<p class="MsoNormal"><o:p> </o:p></p>
<p class="MsoNormal">import oslo_i18n<o:p></o:p></p>
<p class="MsoNormal"><o:p> </o:p></p>
<p class="MsoNormal"># Assumes GLANCE_JSON_LOCALEDIR has been set appropriately.<o:p></o:p></p>
<p class="MsoNormal">def translate(message, locale=None):<o:p></o:p></p>
<p class="MsoNormal">    obj = oslo_i18n._message.Message(message, domain='glance-json')<o:p></o:p></p>
<p class="MsoNormal">    return oslo_i18n.translate(obj, locale)<o:p></o:p></p>
<p class="MsoNormal">…<o:p></o:p></p>
<p class="MsoNormal"># then in code…<o:p></o:p></p>
<p class="MsoNormal">    def _format_namespace_from_db(self, namespace_obj, locale=None):<o:p></o:p></p>
<p class="MsoNormal">    …<o:p></o:p></p>
<p class="MsoNormal">        display_name=translate(namespace_obj['display_name'], locale),<o:p></o:p></p>
<p class="MsoNormal"><o:p> </o:p></p>
<p class="MsoNormal">The returned display_name will have the correct version based on the locale passed in.<o:p></o:p></p>
<p class="MsoNormal"><o:p> </o:p></p>
<p class="MsoNormal">But, is this correct usage of oslo_i18n._message()?<o:p></o:p></p>
<p class="MsoNormal">Or is it to remain hidden since it is not part of oslo_i18n.__init__py?<o:p></o:p></p>
<p class="MsoNormal">If it is to remain hidden, then, what would be the better way of getting a “dynamic” translation based on some arbitrary locale that is passed in.<o:p></o:p></p>
<p class="MsoNormal"><o:p> </o:p></p>
<p class="MsoNormal">If you don’t know the answer, but, know someone that might - please pass on their name(s) and I can try to contact them directly.<o:p></o:p></p>
<p class="MsoNormal"><o:p> </o:p></p>
<p class="MsoNormal">Thanks and Regards,<o:p></o:p></p>
<p class="MsoNormal">Wayne Okuma<o:p></o:p></p>
<p class="MsoNormal"><o:p> </o:p></p>
</div>
</body>
</html>