MCPcopy Index your code
hub / github.com/daviddrysdale/python-phonenumbers / _find_lang

Function _find_lang

python/phonenumbers/prefix.py:29–56  ·  view source on GitHub ↗

Return the entry in the dictionary for the given language information.

(langdict, lang, script, region)

Source from the content-addressed store, hash-verified

27
28
29def _find_lang(langdict, lang, script, region):
30 """Return the entry in the dictionary for the given language information."""
31 # Check if we should map this to a different locale.
32 full_locale = _full_locale(lang, script, region)
33 if (full_locale in _LOCALE_NORMALIZATION_MAP and
34 _LOCALE_NORMALIZATION_MAP[full_locale] in langdict):
35 return langdict[_LOCALE_NORMALIZATION_MAP[full_locale]]
36 # First look for the full locale
37 if full_locale in langdict:
38 return langdict[full_locale]
39 # Then look for lang, script as a combination
40 if script is not None:
41 lang_script = "%s_%s" % (lang, script)
42 if lang_script in langdict:
43 return langdict[lang_script]
44 # Next look for lang, region as a combination
45 if region is not None:
46 lang_region = "%s_%s" % (lang, region)
47 if lang_region in langdict:
48 return langdict[lang_region]
49 # Fall back to bare language code lookup
50 if lang in langdict:
51 return langdict[lang]
52 # Possibly fall back to english
53 if _may_fall_back_to_english(lang):
54 return langdict.get("en", None)
55 else:
56 return None
57
58
59def _prefix_description_for_number(data, longest_prefix, numobj, lang, script=None, region=None):

Callers 1

Calls 3

_full_localeFunction · 0.85
getMethod · 0.45

Tested by

no test coverage detected