✊🏿 Black Lives Matter. Please consider donating to Black Girls Code today.
⚡️ Concerned about the grid? Kyle Baranko teaches how to predicting peak loads using XGBoost. Register for the August webinar!

Supporting differnt languages (aka, i18n)


I’m creating a dashboard using Dash that needs to display text (headers, paragraphs, etc.) in different languages. I have been looking for a way to do this directly in Dash, as well as using a third library that works well with Flask (for example, flask-babel)

What is the right approach for this problem?

Suppose that I have a simple application like the following one:

import dash
import dash_core_components as dcc
import dash_html_components as html
import plotly.express as px

app = dash.Dash()

content = [
    dcc.Graph(figure=px.bar(x=['a', 'b'], y=[3, 2], title='Graph title'))

app.layout = html.Div(content)

if __name__ ==  '__main__':
    app.run_server(port=5000, debug=True)

My goal is to have the strings Header, Paragraph and Graph title translated to the language of the user’s web browser (I’m also fine if I need to add a toolbar that allows the user to select the language).