oslo_i18n.translate does not honor locale in non-lazy mode

Bug #1629569 reported by Akihiro Motoki
6
This bug affects 1 person
Affects Status Importance Assigned to Milestone
oslo.i18n
Won't Fix
Undecided
Unassigned

Bug Description

When non-lazy mode is used, oslo_i18n.translate does not honor 'desired_locale' argument.
The test result is shown below.

Non-lazy mode is currently used in most server projects like nova and neutron.
(I grepped enable_lazy for nova and neutron code but no match is found.)
Thus, translations in API responses does not work expectedly.

If lazy mode is used, it works expectedly.
Do all server projects have to use the lazy mode? Or is this a bug of oslo.i18n?

If it is the intended behavior, we should document it and send a patch to server projects.

----

http://paste.openstack.org/show/583760/ is my test result.
The script I used to test is http://paste.openstack.org/show/583759/.

L.4-23 is the result when lazy mode is used. I got the expected result.
The expected Japanese string is displayed at L.8-9 and L.18-19.

L.24-43 is when non-lazy mode. This is unexpected.
Even though 'ja' is passed to desired_locale when oslo_i18n.translate is called,
L.31-32 and L.38-39 contains messages in a language specified in LANG env var.
No LANG is specified for L.31-32, so English is shown.
ko_KR.UTF-8 is specified as LANG, so Korean is shown in L.38-39.

Revision history for this message
Akihiro Motoki (amotoki) wrote :

The reason of this bug is that ugettext or gettext in Py3 is used to translate strings in non-lazy mode [1].
ugettext from python gettext does not take desired_locale argument [2] and the locale to be used is determined based on environment variables like LANG.

[1] http://git.openstack.org/cgit/openstack/oslo.i18n/tree/oslo_i18n/_factory.py#n55
[2] https://docs.python.org/2.7/library/gettext.html#the-gnutranslations-class

Revision history for this message
Akihiro Motoki (amotoki) wrote :

I would like to hear opinions from oslo.i18n maintainers about this is the intended behavior or a bug.

Revision history for this message
Doug Hellmann (doug-hellmann) wrote :

The desired_locale parameter is only used in lazy mode by design.

Changed in oslo.i18n:
status: New → Won't Fix
To post a comment you must log in.
This report contains Public information  
Everyone can see this information.

Other bug subscribers

Remote bug watches

Bug watches keep track of this bug in other bug trackers.