diff --git a/src/scribe_data/utils.py b/src/scribe_data/utils.py index 7cec1b7eb..4c067ee50 100644 --- a/src/scribe_data/utils.py +++ b/src/scribe_data/utils.py @@ -158,11 +158,9 @@ def get_language_iso(language: str) -> str: """ try: iso_code = str(langcodes.find(language).language) - return iso_code - except langcodes.LanguageTagError: + except LookupError: raise ValueError(f"{language.capitalize()} is currently not a supported language for ISO conversion.") - - + return iso_code def get_language_from_iso(iso: str) -> str: """ @@ -178,11 +176,12 @@ def get_language_from_iso(iso: str) -> str: str The name for the language which has an ISO value of iso. """ - try: - language_name = str(Language.make(language=iso).display_name()) - return language_name - except langcodes.LanguageTagError: - raise ValueError(f"{iso} is currently not a supported ISO language.") + + language_name = str(Language.make(language=iso).display_name()) + if "Unknown language" in str(language_name): + raise ValueError(f"{iso.upper()} is currently not a supported ISO language.") + return language_name + def get_language_words_to_remove(language: str) -> list[str]: """