plotly / plotly/plotly.py

write_html: locale config does not work

Open
#2,302 2 comments 3 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

bug P3
Dominant language
Python
Stars
18.8k
Forks
2.8k
Avg merge
16h 26m
Merged PRs (30d)
21

Description

Hi!

I'm using plotly to generate a standalone HTML-file that contains only my plot. I do want the axes to be localized in German (one axis has Dates).

This code does not work:

fig.write_html("index.html",
  include_plotlyjs="cdn",
  config={"locale": "de"}
)

The reason is that the following line is missing in the generated HTML-file (cf. plotly.js documentation)

<script src="https://cdn.plot.ly/plotly-locale-de-latest.js"></script>

I suggest to add a locale argument to the write_html function that does two things (think of de as exchangeable):

  • it adds the missing localization file somewhere here
  • it adds "locale": "de" to the plotconfig

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start in packages/python/plotly/plotly/io/_html.py around line 345 and trace how write_html builds the standalone HTML and plot configuration. Verify the example with a German locale, then ensure the generated document loads the locale script and applies the requested locale to the plot configuration.

Written by the indexing model from the issue text.

Assessment

Tech stack
javascript, python
Domain
data-visualization, web-dev
Issue type
Feature
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
42/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.