[openstack-dev] [oslo] Question on oslo_i18n._message
Okuma, Wayne
wayne.okuma at hp.com
Mon Aug 10 21:22:09 UTC 2015
Hello All,
I have a question on the usage of oslo_i18n._message and hope to get an answer.
Some background first:
I'm working on a portion of Glance - the Glance Metadata Definitions (i.e., metadefs) section.
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.
There are some fields in the .JSON files which need to be internationalized.
I have a program which produces glance-json.pot files for the JSON files.
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).
This seems to work:
import oslo_i18n
# Assumes GLANCE_JSON_LOCALEDIR has been set appropriately.
def translate(message, locale=None):
obj = oslo_i18n._message.Message(message, domain='glance-json')
return oslo_i18n.translate(obj, locale)
...
# then in code...
def _format_namespace_from_db(self, namespace_obj, locale=None):
...
display_name=translate(namespace_obj['display_name'], locale),
The returned display_name will have the correct version based on the locale passed in.
But, is this correct usage of oslo_i18n._message()?
Or is it to remain hidden since it is not part of oslo_i18n.__init__py?
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.
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.
Thanks and Regards,
Wayne Okuma
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.openstack.org/pipermail/openstack-dev/attachments/20150810/3cc36f99/attachment.html>
More information about the OpenStack-dev
mailing list