How to change the locale of Plotly through Dash?

Hello, I’m fairly new to Dash and was trying recently implement bilingualism(eng/fr) into the app I have been working on.

I would like the Plotly Menus and Date Axis to be in french. Essentially, I am trying to have the dash app display this graph found on plotly.com.

Here is the code structure:

- app.py
- assets/
    |-- plotly-locale-fr-latest.js

Here is the dash code for the app.py file:

import dash
import dash_core_components as dcc
import dash_html_components as html
import plotly.graph_objects as go

external_stylesheets = ["https://cdnjs.cloudflare.com/ajax/libs/font-awesome/4.7.0/css/font-awesome.min.css"]

app = dash.Dash(__name__, external_stylesheets=external_stylesheets)

fig = go.Figure(go.Scatter(x=['2018-01-01', '2018-08-31'], y=[10, 5], mode='lines'))
fig.add_trace(go.Scatter(x=['2018-01-01', '2018-08-31'], y=[3, 7], mode='lines'))
app.layout = html.Div(children=[
    html.H1(children='Test for French Locale'),

    dcc.Graph(
        id='example-graph',
        figure=fig
    )
])

# run app
if __name__ == '__main__':
    app.run_server(debug=True)

The code for the plotly-locale-fr-latest.js can be found on Plotly’s cdn here.

Thanks!

Solved! I had missed setting up a config on the dcc.Graph setting the locale to “fr”. Here is the code:

import dash
import dash_core_components as dcc
import dash_html_components as html
import plotly.graph_objects as go

external_stylesheets = ["https://cdnjs.cloudflare.com/ajax/libs/font-awesome/4.7.0/css/font-awesome.min.css"]

app = dash.Dash(__name__, external_stylesheets=external_stylesheets)

fig = go.Figure(go.Scatter(x=['2018-01-01', '2018-08-31'], y=[10, 5], mode='lines'))
fig.add_trace(go.Scatter(x=['2018-01-01', '2018-08-31'], y=[3, 7], mode='lines'))
app.layout = html.Div(children=[
    html.H1(children='Test for French Locale'),

    dcc.Graph(
        id='example-graph',
        figure=fig,
        config=dict(locale="fr")
    )
])

# run app
if __name__ == '__main__':
    app.run_server(debug=True)

Is there a way to force this for all graphs generated or would one have to add the ‘config=dict(locale=“fr”)’ to all dcc.Graph 's created?

Plotly.js allows you to set a global default locale for new graphs (docs here). I’m not sure whether Dash exposes this.

The linked docs give an example of setting the default locale to de-CH. Quoting it here: