You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
gettext.install() ignores previous call to locale.setlocale() #64243
I think it makes sense to align our gettext implementation with C, that is, let the result of locale.getlocale override all the environment variables except for LANGUAGE.
In any case, this part of gettext has no dedicated tests. I have a patch ready which tests gettext._expand_lang but more tests will be needed also for gettext.find. Once there is sufficient coverage we can look into fixing this
Activity
fmoreau commentedon Dec 21, 2013
It seems that gettext.install() uses environment variables such as LANGUAGE, to find out which language it should use to find the translation file.
This means that any local settings done by setlocale() previoulsy are ignored.
I don't think it's the case with the C implementation.
abadger commentedon May 12, 2019
I tested a small C program and found that setlocale takes precedence for LC_ALL, LC_MESSAGES, and LANG but not for LANGUAGE.
So this could be considered a bug in the stdlib's gettext. If we fix it, we'll need to make sure that we continue to honor LANGUAGE, though.
StanFromIreland commentedon Feb 23, 2025
locale.setlocalecalls_setlocalewhich sets the variable for the processgettext.findchecks the environment variables: LANG, LANGUAGES, LC_ALL, LC_MESSAGES byos.environ.get()gettext.findshould be modified to fallback tolocale.getlocale()which checks the variable for the python process.picnixz commentedon Feb 25, 2025
cc @tomasr8
tomasr8 commentedon Feb 25, 2025
I think it makes sense to align our gettext implementation with C, that is, let the result of
locale.getlocaleoverride all the environment variables except forLANGUAGE.In any case, this part of gettext has no dedicated tests. I have a patch ready which tests
gettext._expand_langbut more tests will be needed also forgettext.find. Once there is sufficient coverage we can look into fixing thisStanFromIreland commentedon Feb 25, 2025
Testing will not be too simple, environment variables are not something we can really control.
tomasr8 commentedon Feb 25, 2025
I don't think it'll be that bad, we have
EnvironmentVarGuardfor that :)StanFromIreland commentedon Feb 27, 2025
Can I write some tests for find() or do you already have some ready?
tomasr8 commentedon Feb 27, 2025
Feel free! I will open a PR for
_expand_langbut I haven't started onfindyet. I opened #130655 for it