import streamlit as st import langcodes # https://huggingface.co/blog/streamlit-spaces langtext = st.text_input("language code", "en") if langcodes.tag_is_valid(langtext): st.write(f"{langtext} is already a valid BCP-47 language tag") else: st.write(f"{langtext} is not already a valid BCP-47 language tag") try: lang = langcodes.Language.get(langtext) except LanguageTagError as e: st.write(f"Could not simiply instantiate, try looking up instead.") lang = None try: found = langcodes.find(langtext) lang = found except LookupError as e: st.write(f"Couldn't look up langtext, sorry: {e}") lang = None #st.write(f"langcodes found the following tag: {type(found)}") # a Language object display = lang.display_name() st.write(f"langcodes found the following tag: {lang}") st.write(f"Display name for {lang}: {display}")