New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
locale fails if LANGUAGE has multiple locales #41664
Comments
The locale module does not correctly handle the LANGUAGE="en_DK:en_GB:en_US:en" Note, en_DK does not exist in locale_alias In normalize, the colons are replaced with dots, which GLIBC documentation: "While for the LC_xxx variables the value should Testing this is simple, just set your LANGUAGE > export LANGUAGE="en_DK:en_GB:en_US:en"
> python
ActivePython 2.4 Build 244 (ActiveState Corp.) based on
Python 2.4 (#1, Feb 9 2005, 19:33:15)
[GCC 3.3.1 (SuSE Linux)] on linux2
Type "help", "copyright", "credits" or "license" for
more information.
>>> import locale
>>> locale.getdefaultlocale()
Traceback (most recent call last):
File "<stdin>", line 1, in ?
File "/opt/ActivePython-2.4/lib/python2.4/locale.py",
line 344, in getdefaultlocale
return _parse_localename(localename)
File "/opt/ActivePython-2.4/lib/python2.4/locale.py",
line 278, in _parse_localename
raise ValueError, 'unknown locale: %s' % localename
ValueError: unknown locale: en_DK:en_GB:en_US:en
>>> |
Logged In: YES The URL you gave does state that LANGUAGE can take mulitple |
Logged In: YES The docs for getdefaultlocale state that it follows the GNU |
Logged In: YES IMHO the proper behaviour is to split on the colon, then try |
Logged In: YES Another consequence of this bug is that even if LANGUAGE=pt_BR:pt_PT:pt getdefaultlocale did not raise an exception, but return |
Logged In: YES The current CVS version returns this value: >>> import locale
>>> locale.getdefaultlocale()
(None, None) Given all the problems with the LANGUAGE environment variable |
Logged In: YES Hi Marc-Andre, do you mean that the current CVS version will return (None, None) I do not have an overview about other problems with the Anyway, Bernhard R. |
Logged In: YES Hi Bernhard, sorry my last comment wasn't clear: you get this output if The parsing order was changed, so that LANGUAGE is no longer |
Logged In: YES Hi, using other information first seems to be a step forward to me. But if LANGUAGE will be evaluated, will the colon be parsed correctly Bernhard R. |
I first verified that the relevant parts of I'm adding a patch to remove default support for the LANGUAGE variable and tests to assert that values like 'en_DK:en_GB:en_US' raise ValueError (plus asserting that getting value from LC_ALL, LC_CTYPE, and LANG are all supported.) None of the logic for normalizing candidate env vars has been changed, so the questions about how values like 'en_DK:en_GB:en_US' are handled all still apply -- I've just operated under the assumption that such values will continue to raise ValueError. |
The initial problem (":" in the LANGUAGE variable) was fixed in an independent (?) issue (bpo-1166938) by r39572. If I understood correctly, locale.getdefaultlocale() is supposed to give the locale settings that we will be active after the first call to locale.setlocale(locale.LC_ALL, ''). In this case, LANGUAGE should be ignored because it has no effect on the active locale. The variable is specific to the gettext library, it is not used by the locale machinery. About remove-support-for-LANGUAGE--in-locale.patch: you should also update the documentation. |
The words here https://docs.python.org/3/library/locale.html#locale.getdefaultlocale read in part "envvars defaults to the search path used in GNU gettext; it must always contain the variable name 'LANG'.". I think this means that envvars should always contain 'LANG', even if the default is not used, but the code doesn't seem to need that. If somebody can clarify this for me I'll submit a new patch. |
It looks to me that this issue is already gone. >>> import os, locale
>>> os.environ['LANGUAGE'] = 'en_DK:en_GB:en_US:en'
>>> locale.getdefaultlocale(['LANGUAGE'])
('en_DK', 'ISO8859-1') 'en_DK' was added in bpo-20079. |
Note: these values reflect the state of the issue at the time it was migrated and might not reflect the current state.
Show more details
GitHub fields:
bugs.python.org fields:
The text was updated successfully, but these errors were encountered: