Refactor get_language_name function to handle missing language names
This commit is contained in:
parent
becb84a73d
commit
cfe61a26d0
|
@ -49,15 +49,24 @@ except ImportError:
|
||||||
|
|
||||||
|
|
||||||
def get_language_names(locale):
|
def get_language_names(locale):
|
||||||
return _LANGUAGE_NAMES.get(str(locale))
|
names = _LANGUAGE_NAMES.get(str(locale))
|
||||||
|
if names is None:
|
||||||
|
names = _LANGUAGE_NAMES.get(locale.language)
|
||||||
|
return names
|
||||||
|
|
||||||
|
|
||||||
def get_language_name(locale, lang_code):
|
def get_language_name(locale, lang_code):
|
||||||
try:
|
UNKNOWN_TRANSLATION = "Unknown"
|
||||||
return get_language_names(locale)[lang_code]
|
names = get_language_names(locale)
|
||||||
except KeyError:
|
if names is None:
|
||||||
log.error('Missing translation for language name: {}'.format(lang_code))
|
log.error(f"Missing language names for locale: {str(locale)}/{locale.language}")
|
||||||
return "Unknown"
|
return UNKNOWN_TRANSLATION
|
||||||
|
|
||||||
|
name = names.get(lang_code, UNKNOWN_TRANSLATION)
|
||||||
|
if name == UNKNOWN_TRANSLATION:
|
||||||
|
log.error("Missing translation for language name: {}".format(lang_code))
|
||||||
|
|
||||||
|
return name
|
||||||
|
|
||||||
|
|
||||||
def get_language_codes(locale, language_names, remainder=None):
|
def get_language_codes(locale, language_names, remainder=None):
|
||||||
|
|
Loading…
Reference in New Issue
Block a user