YuriyKrasilnikov commented on PR #37790:
URL: https://github.com/apache/superset/pull/37790#issuecomment-3872851488
### Update: AdhocMetric/AdhocColumn label translations
Adds inline translation support for custom metric and column labels visible
on dashboards (tooltips, legends, axes, table headers).
**Architecture:** Identical to native filters — `translations` stored
directly in the metric/column object within `Slice.params`. No DB migration
needed.
```json
{
"label": "Total Revenue",
"hasCustomLabel": true,
"translations": {"label": {"de": "Gesamtumsatz", "fr": "Revenu total"}}
}
```
**Backend:**
- `localize_metric_labels()` utility in
`superset/localization/metric_label_utils.py` — processes `form_data.metrics[]`
and `form_data.columns[]`, replaces labels for user locale
- Integrated in `ChartEntityResponseSchema.post_dump()` (dashboard charts
endpoint)
- `translations` field added to `ChartDataAdhocMetricSchema` for validation
- Only objects with `hasCustomLabel=true` + `translations.label` are
processed; string refs (SavedMetric/PhysicalColumn) pass through
**Frontend:**
- `translations` field added to `AdhocMetricBase`, `AdhocColumn` types, and
`AdhocMetric` class
- `AdhocMetricEditPopoverTitle` renders `LocaleSwitcher` when feature flag
is on and metric has custom label
- `AdhocMetricPopoverTrigger` manages translations state, includes in saved
metric object
**Tests:**
- 20 backend unit tests (`metric_label_localization_test.py`): translation,
no-translation, hasCustomLabel=false, columns, string refs, mixed types, locale
fallback, no-mutation, edge cases
- 4 schema integration tests (`chart_schema_localization_test.py`):
metric/column labels in form_data, feature flag off, mixed string/dict metrics
- 5 existing frontend tests pass with updated mocks
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]