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
__________________________________________________________________________ OpenStack Development Mailing List (not for usage questions) Unsubscribe: openstack-dev-requ...@lists.openstack.org?subject:unsubscribe http://lists.openstack.org/cgi-bin/mailman/listinfo/openstack-dev