Merge pull request #37714 from fix-graphic-label-translation-issue

fix: graphic label translation issue completely
This commit is contained in:
dataCenter430 2026-03-02 14:25:58 -05:00 committed by GitHub
commit 4e7b19a00e
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -568,6 +568,7 @@ export default class ChartWidget extends Widget {
async render() {
let setup_dashboard_chart = () => {
this.translate_chart_labels();
const chart_args = this.get_chart_args();
const is_circular_chart = ["Pie", "Donut", "Percentage"].includes(this.chart_doc.type);
@ -702,6 +703,26 @@ export default class ChartWidget extends Widget {
return chart_args;
}
translate_chart_labels() {
if (this.data && Array.isArray(this.data.labels)) {
this.data.labels = this.data.labels.map((label) => {
if (label === null || label === undefined) {
return label;
}
return typeof label === "string" ? __(label) : label;
});
}
if (this.data && Array.isArray(this.data.datasets)) {
this.data.datasets = this.data.datasets.map((dataset) => {
if (dataset && typeof dataset.name === "string") {
dataset.name = __(dataset.name);
}
return dataset;
});
}
}
get_chart_colors() {
let colors = [];
if (this.chart_doc.y_axis.length) {