Skip to content

gh-64243: Implement locale.getlocale fall back in gettext.find #131477

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

Open
wants to merge 12 commits into
base: main
Choose a base branch
from
Prev Previous commit
Next Next commit
Tomas's feedback
  • Loading branch information
StanFromIreland committed Mar 31, 2025
commit f9851e12a99d29bfbc21ab2a0bba0b413afbfe35
8 changes: 4 additions & 4 deletions Lib/gettext.py
Original file line number Diff line number Diff line change
Expand Up @@ -492,10 +492,10 @@ def find(domain, localedir=None, languages=None, all=False):
localedir = _default_localedir
if languages is None:
languages = []
if os.environ.get('LANGUAGE'):
languages = os.environ.get('LANGUAGE').split(',')
elif locale.getlocale() != (None, None):
languages.append(".".join(filter(None, locale.getlocale())))
if val := os.environ.get('LANGUAGE'):
languages = val.split(':')
elif (loc := locale.getlocale()) != (None, None):
languages.append(".".join(filter(None, loc)))
else:
for envar in ('LC_ALL', 'LC_MESSAGES', 'LANG'):
val = os.environ.get(envar)
Expand Down
7 changes: 7 additions & 0 deletions Lib/test/test_gettext.py
Original file line number Diff line number Diff line change
Expand Up @@ -748,6 +748,13 @@ def test_find_with_env_vars(self, patch_getlocale):
localedir=os.path.join(self.tempdir, "locale"))
self.assertEqual(result, mo_file)
self.env.unset(var)
# test fallbacks
for var in ('LANGUAGE', 'LC_ALL', 'LC_MESSAGES', 'LANG'):
self.env.set(var, 'es_ES:ga_IE:fr_FR')
result = gettext.find("mofile",
localedir=os.path.join(self.tempdir, "locale"))
self.assertEqual(result, mo_file)
self.env.unset(var)

@unittest.mock.patch("locale.getlocale", return_value=('ga_IE', 'UTF-8'))
def test_process_vars_override(self, patch_getlocale):
Expand Down
Loading
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy