[openstack-dev] [oslo] Question on oslo_i18n._message

2015-08-10 Thread Okuma, Wayne
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


Re: [openstack-dev] [oslo] Question on oslo_i18n._message

2015-08-10 Thread Okuma, Wayne


-Original Message-
From: Doug Hellmann [mailto:d...@doughellmann.com] 
Sent: Monday, August 10, 2015 4:00 PM
To: openstack-dev
Subject: Re: [openstack-dev] [oslo] Question on oslo_i18n._message

Excerpts from Okuma, Wayne's message of 2015-08-10 21:22:09 +:
 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).

The API layer can also set a language based on the browser settings. Are the 
JSON files being served by the glance API? Or are they in some other way coming 
through from glance?

WO: The JSON data is being served by the REST API as far as I know. The current 
API doesn't support being passed a locale flag yet though.
 
 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

As you surmise, the _message module is marked private (note the _ prefix on 
the name), so you shouldn't use it directly. The fact that Message objects 
exists is an implementation detail of the lazy translation machinery, and isn't 
meant to be something that applications rely on.

You could use oslo_i18n.TranslatorFactory to get a function to wrap your 
strings instead [1].  The primary attribute should be what you want. Passing 
the return value to translate() would then give you the translated value.

Something like:

  factory = oslo_i18n.TranslatorFactory('glance-json')
  trans = factory.primary

  def translate(message, locale=None):
  return oslo_i18n.translate(trans(message), locale)

This ought to work whether lazy translation is enabled or not, as long as the 
catalog files are installed properly.

Doug

WO: The above works for me...Thanks. I'm curious if there will be a version in 
which a global set of already opened catalogues will be kept for the sake of 
efficiency?

[1] 
http://docs.openstack.org/developer/oslo.i18n/api.html#oslo_i18n.TranslatorFactory

__
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

__
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


Re: [openstack-dev] [Glance] Proposal to change Glance meeting time.

2015-03-12 Thread Okuma, Wayne
My vote is for 1500.

-Original Message-
From: Hemanth Makkapati [mailto:hemanth.makkap...@rackspace.com] 
Sent: Thursday, March 12, 2015 8:32 AM
To: OpenStack Development Mailing List (not for usage questions)
Subject: Re: [openstack-dev] [Glance] Proposal to change Glance meeting time.

+1 to consistent time. 
Both 1400 and 1500 work me.

-Hemanth

From: Ian Cordasco ian.corda...@rackspace.com
Sent: Wednesday, March 11, 2015 10:25 AM
To: OpenStack Development Mailing List (not for usage questions)
Subject: Re: [openstack-dev] [Glance] Proposal to change Glance meeting time.

I have no opinions on the matter. Either 1400 or 1500 work for me. I think 
there are a lot of people asking for it to be at 1500 instead though.
Would anyone object to changing it to 1500 instead (as long as it is one 
consistent time for the meeting)?

On 3/11/15, 01:53, Inessa Vasilevskaya ivasilevsk...@mirantis.com
wrote:

+1


On Mon, Mar 9, 2015 at 2:43 AM, Alexander Tivelkov 
ativel...@mirantis.com wrote:

Works for me, but the previous one worked as well. So, consider my vote 
as +1 unless the majority is against this :)


--
Regards,
Alexander Tivelkov




On Mon, Mar 9, 2015 at 12:36 AM, Fei Long Wang 
feil...@catalyst.net.nz wrote:

Oh, it means 3:00AM for me :-(


On 09/03/15 09:07, Nikhil Komawar wrote:






Hi all,


Currently, we've alternating time for Glance meetings. Now, with the 
Daylight savings being implemented in some parts of the world, we're 
thinking of moving the meeting time to just one slot i.e. earlier in 
the day(night). This solves the original conflicting  times issue that 
a subset of the individuals had; to add to that the schedule is less 
confusing and unified.



So, the new proposal is:
Glance meetings [1] to be conducted
weekly on
Thursdays at 1400UTC [2] on
#openstack-meeting-4



This would be implemented on Mar 19th, given there are no major 
objections.


Please vote with +1/-1 here.



[1]
https://wiki.openstack.org/wiki/Meetings#Glance_Team_meeting
https://wiki.openstack.org/wiki/Meetings#Glance_Team_meeting
[2]
http://www.timeanddate.com/worldclock/fixedtime.html?hour=14min=0sec=
0 
http://www.timeanddate.com/worldclock/fixedtime.html?hour=14min=0sec
=0


Thanks,
-Nikhil






___
___ OpenStack Development Mailing List (not for usage questions)
Unsubscribe:
openstack-dev-requ...@lists.openstack.org?subject:unsubscribehttp://lists.
openstack.org/cgi-bin/mailman/listinfo/openstack-dev


--
Cheers  Best regards,
Fei Long Wang (王飞龙)
---
---
Senior Cloud Software Engineer
Tel: +64-48032246 tel:%2B64-48032246
Email: flw...@catalyst.net.nz
Catalyst IT Limited
Level 6, Catalyst House, 150 Willis Street, Wellington
---
---


___
___ OpenStack Development Mailing List (not for usage questions)
Unsubscribe:
openstack-dev-requ...@lists.openstack.org?subject:unsubscribe
http://openstack-dev-requ...@lists.openstack.org?subject:unsubscribe
http://lists.openstack.org/cgi-bin/mailman/listinfo/openstack-dev









___
___ OpenStack Development Mailing List (not for usage questions)
Unsubscribe:
openstack-dev-requ...@lists.openstack.org?subject:unsubscribe
http://openstack-dev-requ...@lists.openstack.org?subject:unsubscribe
http://lists.openstack.org/cgi-bin/mailman/listinfo/openstack-dev







__
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
__
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
__
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


Re: [openstack-dev] [glance] Metadef-tags create api change request.

2015-02-11 Thread Okuma, Wayne
Hello,

I would like to change the metadef-tags create API which was checked into Kilo 
(cycle 1).
The python-glanceclient that would support metadef-tags has not been released 
yet and I would like to make this change before doing so.
The details are here: https://review.openstack.org/#/c/154229/

Thanks and Regards,
Wayne

__
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