Return the entry in the dictionary for the given language information.
(langdict, lang, script, region)
| 27 | |
| 28 | |
| 29 | def _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 | |
| 59 | def _prefix_description_for_number(data, longest_prefix, numobj, lang, script=None, region=None): |
no test coverage detected