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 langcodes.LanguageTagError as e: st.write(f"Could not simply instantiate, trying to look up instead.") lang = None if lang is None: try: found = langcodes.find(langtext) lang = found except LookupError as e: st.write(f"Unable to look up language code.") lang = None #st.write(f"langcodes found the following tag: {type(found)}") # a Language object if lang is not None: display = lang.display_name() st.write(f"langcodes found the following tag: {lang}") st.write(f"Display name for {lang}: {lang.display_name()}") st.write(f"Autonym for {lang}: {lang.autonym()}")