Search code examples
pythonpython-3.xplotlyplotly-dash

How to change the language / locale in Dash (Plotly) or the label of the Plotly toolbar?


Plotly Toolbar

I have been able to successfully modify Plotly's toolbar in Dash using a dict (config) passed to dash_core_components.Graph

Now I want to change the "tooltip" or label of the remaining buttons to another language. The documentation states that I can change de locale (language) of the labels using the "locale" parameter. I've seen this both in JavaScript and R docs, being applied to Plotly Graphs or to dash_core_components.Graph:

https://plot.ly/r/locales/

Now I need to do this in Python, but I haven't been able to do this. This is what I've tried:

config_plots = {'modeBarButtonsToRemove':["sendDataToCloud","lasso2d","pan2d","autoScale2d","select2d","zoom2d","zoomIn2d", "zoomOut2d"],
            "locale":"de"}

dcc.Graph(id="plot",config=config_plots,
              figure={"data":plotdata,"layout":layout})

I have added the locale parameter as well to plotly graphs (plotly.graph_objs) and tried with different locales I know that exist, but I've had no luck so far.

The question: How can I customize the text of the labels? Am I missing something using the locale parameter? Is there any way to change the text of the labels so I can translate it without using the locale parameter?

Please note that I know very little of JavaScript so I would prefer to do this in Python if possible


Solution

  • According to this plotly documentation you need to register any new language first.

    In your case this means you need to add

    https://cdn.plot.ly/plotly-locale-de-latest.js
    

    to your dashboard.

    Either by

    app.scripts.append_script({"external_url": "https://cdn.plot.ly/plotly-locale-de-latest.js"})
    

    or by downloading the js file and coping it to the assets folder in your dashboards root folder.

    See https://dash.plot.ly/external-resources for more information.