Skip to content
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

Fix #1858 - locale closest match #2833

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions tornado/locale.py
Original file line number Diff line number Diff line change
Expand Up @@ -248,6 +248,10 @@ def get_closest(cls, *locale_codes: str) -> "Locale":
return cls.get(code)
if parts[0].lower() in _supported_locales:
return cls.get(parts[0].lower())
if len(parts) == 1:
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should this be part of the elif len(parts) blocks above?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Using the elif len(parts) would place it higher in the order of operations. There are two returns after the conditional statement, so I wanted it to be the last thing it tries after the others fail.

for supported in _supported_locales:
if parts[0].lower() == supported.split("_")[0]:
return cls.get(supported)
return cls.get(_default_locale)

@classmethod
Expand Down