import streamlit as st import langcodes # https://huggingface.co/blog/streamlit-spaces langtext = st.text_input("language code", "en") lang = langcodes.Language.get(langtext) if langcodes.tag_is_valid('langtext'): st.write(f"'{langtext}' is a valid BCP-47 language code") else: st.write(f"'{langtext}' is not a valid BCP-47 language code") if lang.is_valid() == False: 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}")