oslo_i18n.translate does not honor locale in non-lazy mode
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://
The script I used to test is http://
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.
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 /docs.python. org/2.7/ library/ gettext. html#the- gnutranslations -class
[2] https:/