-
-
Notifications
You must be signed in to change notification settings - Fork 1.9k
improve docs on loading and applying locales #2683
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -36,25 +36,32 @@ You can grab the relevant MathJax files in `./dist/extras/mathjax/`. | |
### To include localization | ||
|
||
Plotly.js defaults to US English (en-US) and includes British English (en) in the standard bundle. | ||
Many other localizations are available - here is an example using Swiss-German (de-CH), | ||
see the contents of this directory for the full list. | ||
They are also available on our CDN as https://cdn.plot.ly/plotly-locale-de-ch-latest.js OR https://cdn.plot.ly/plotly-locale-de-ch-1.38.1.js | ||
Note that the file names are all lowercase, even though the region is uppercase when you apply a locale. | ||
This example uses Swiss-German (de-CH), but many other localizations are available (see the contents of this directory for the full list). All available locales have working date localizations, but only a subset will localize on-graph text (e.g., modebar controls). See [here](https://github.com/plotly/plotly.js/pulls?q=is%3Apr+label%3A%22type%3A+translation%22+is%3Aclosed) for a list of "fully-supported" locales. | ||
|
||
*After* the plotly.js script tag, add: | ||
#### Loading and registering locales | ||
|
||
Some locales build on other locales (e.g., "de-CH" builds on "de"). In this case, first load the base locale (e.g., "de"), then load the actual locale (e.g., "de-CH"): | ||
|
||
```html | ||
<script src="plotly-locale-de.js"></script> | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think this section is misleading. A priori There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. So, I propose we use a "fully" supported language for this example and invite folks we want to use a non-fully supported localization (e.g. |
||
<script src="plotly-locale-de-ch.js"></script> | ||
``` | ||
|
||
Locale bundles are also available on our CDN (e.g., https://cdn.plot.ly/plotly-locale-de-ch-latest.js OR https://cdn.plot.ly/plotly-locale-de-ch-1.38.1.js). Note that the file names here are all lowercase, but the region is uppercase when you apply a locale. | ||
|
||
#### Apply a locale | ||
|
||
After registering a locale, you can it as the default for all Plotly plots: | ||
|
||
```html | ||
<script>Plotly.setPlotConfig({locale: 'de-CH'})</script> | ||
``` | ||
|
||
The first line loads and registers the locale definition with plotly.js, the second sets it as the default for all Plotly plots. | ||
You can also include multiple locale definitions and apply them to each plot separately as a `config` parameter: | ||
Or, apply the (registered) locale to particular plot(s) as a `config` parameter: | ||
|
||
```js | ||
Plotly.newPlot(graphDiv, data, layout, {locale: 'de-CH'}) | ||
``` | ||
|
||
# Bundle information | ||
|
||
The main plotly.js bundle includes all the official (non-beta) trace modules. | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Perhaps even better, we could ask translation authors to add an entry in a table of "fully" supported localizaion instead of linking to a list of PRs/