[Chartjs]-Automatic legend translation on chart.js

1👍

Chart.js’s settings are very flexible. Instead of a static text labels like,

...
labels: 'Top Sellers (quantity sold/week)',
...

You can use a function like

...
labels: i18nLabels("eng"),
...

And then of course you need to create that function that will extract the language from the <html> tag or from the browser settings.

Here is a demo: https://codepen.io/adelriosantiago/pen/rNOEBmY?editors=0010, try switching from labels: i18nLabels("spa") to labels: i18nLabels("eng") around line 19.

Leave a comment