MCPcopy
hub / github.com/tornadoweb/tornado / get_closest

Method get_closest

tornado/locale.py:234–249  ·  view source on GitHub ↗

Returns the closest match for the given locale code.

(cls, *locale_codes: str)

Source from the content-addressed store, hash-verified

232
233 @classmethod
234 def get_closest(cls, *locale_codes: str) -> "Locale":
235 """Returns the closest match for the given locale code."""
236 for code in locale_codes:
237 if not code:
238 continue
239 code = code.replace("-", "_")
240 parts = code.split("_")
241 if len(parts) > 2:
242 continue
243 elif len(parts) == 2:
244 code = parts[0].lower() + "_" + parts[1].upper()
245 if code in _supported_locales:
246 return cls.get(code)
247 if parts[0].lower() in _supported_locales:
248 return cls.get(parts[0].lower())
249 return cls.get(_default_locale)
250
251 @classmethod
252 def get(cls, code: str) -> "Locale":

Callers 1

getFunction · 0.80

Calls 4

replaceMethod · 0.80
splitMethod · 0.80
upperMethod · 0.80
getMethod · 0.45

Tested by

no test coverage detected