Can I change language code <html lang=“en”> to other?

This question was already asked but with no answer .

My app deploys as an english app and user brower partialy translates some words to french giving funny results

How to I set lang to french ?.

2 Likes

Hi @Boubil_Nat

To work with HTML codes, you’ll need to activate unsafe_allow_html=True parameter in st.markdown.

As for translation, it seems to be a browser translation. Other options could be actual translation of the underlying text. Or the use of a language translation library that translates text used in-app.

Then lang attribute has to be set on the tag which cannot be done with st.markdown .

Hi @Boubil_Nat

Perhaps you can look into CSS customization which uses st.markdown().

input_css = """
... css code goes here ...
"""
st.markdown(f'<style>{input_css}</style>', unsafe_allow_html=True)

I’m having the same problem on my app, using Spanish language, the browsers keep trying to translate to english. Is there any way to change headers or only the lang of the app?

1 Like

Same problem here.

I found a solution, but it’s not exactly user friendly.

You can directly change HTML code in streamlit library.
If it is installed in the venv (virtual environment), the file you need is located at the path:
Windows: “venv\Lib\site-packages\streamlit\static\index.html”.
Linux with python3.11: “venv/lib/python3.11/site-packages/streamlit/static/index.html”.

This file has all the content wrapping of the page. html, head, and body tags.

There you can specify the necessary parameters for these tags or add your own tags.

Please note that this is not the best solution, because when you update streamlit library - you will have to change all these HTML parameters in venv again.

But this is the only working solution that I could find.

P.S. For Streamlit developers: Please add an option to specify page language. Visitors of my site complain that the site is displayed incorrectly and shows errors. Because their browser automatically translates the page, including material icons.