feat(i18n): translate asset metadata via configurable hook (SIP-161)#40679
Draft
alex-poor wants to merge 7 commits into
Draft
feat(i18n): translate asset metadata via configurable hook (SIP-161)#40679alex-poor wants to merge 7 commits into
alex-poor wants to merge 7 commits into
Conversation
Add a read path for localizing user-authored asset metadata (chart names,
dashboard titles, axis/metric labels) into the viewer's locale, gated by the
ENABLE_I18N_ASSET_TRANSLATIONS feature flag and a multi-language LANGUAGES
config.
Superset core does not store translations; resolution is delegated to a
deployment-provided TRANSLATION_HOOK, keeping core minimal and the storage
strategy pluggable (per the SIP-161 maintainer direction). The canonical text
is always a safe fallback, so a missing or failing translation never blanks a
name.
- superset/utils/i18n.py: translate() resolver + enable gate
- config: ENABLE_I18N_ASSET_TRANSLATIONS flag + TRANSLATION_HOOK
- models: read-only localized_name / localized_title properties
- charts/dashboards schemas + list_columns: expose localized_* (dump-only)
- jinja_context: {{ i18n('...') }} macro for templated fields
- daos/log: localize recent-activity item titles
Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
Display the localized_name / localized_title fields across all surfaces that show user-authored names, falling back to the canonical value: - chart & dashboard list pages and cards - dashboard view header and chart panel titles Editing flows (Properties modals, inline title editing) keep operating on the canonical slice_name / dashboard_title, so a save can never overwrite the stored name with a translation. The localized title for the dashboard view is carried as display-only state, never into persisted layout meta. Also threads localized_title through the column allowlists the dashboard view (DASHBOARD_GET_COLUMNS) and list (DASHBOARD_COLUMNS_TO_FETCH) request, which otherwise silently drop unlisted fields. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
- unit tests for translate(): enable gate, default-locale/hook/raise fallbacks, context forwarding, empty-text passthrough - SliceHeader tests: localized name shown when viewing, canonical name shown in edit mode (so edits target the real value) - integration test for recent-activity title localization Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
- admin docs for the hook contract, the i18n Jinja macro, the enable gate, and three reference hook implementations (static dict, MT service, .po catalogs) - a self-contained database-backed example (table + hook + seeding) under examples/, kept out of core to demonstrate end-to-end authoring Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
✅ Deploy Preview for superset-docs-preview ready!
To edit notification comments on pull requests, go to your Netlify project configuration. |
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## master #40679 +/- ##
==========================================
- Coverage 63.94% 55.92% -8.03%
==========================================
Files 2658 2659 +1
Lines 143011 143075 +64
Branches 32866 32880 +14
==========================================
- Hits 91454 80015 -11439
- Misses 49994 62372 +12378
+ Partials 1563 688 -875
Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
The dashboard list now requests localized_title in select_columns; update the inline snapshot of the fetch URL to match. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
The shared integration-test database may contain unrelated recent activity, so locate the seeded dashboard's entry by item_url rather than assuming it is first in the result. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
- add unit tests for the i18n_macro (translates via hook; no-op when disabled) - ignore examples/ in codecov: the reference implementation is documentation, not shipped application code Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
SUMMARY
Revives SIP-161 (Translating Superset asset metadata) with a focused, minimal-core implementation of the read path.
Superset's built-in i18n (Flask-Babel/gettext) translates UI chrome but not user-authored content — chart names, dashboard titles, axis/metric labels. This PR lets a deployment localize that metadata so a chart named "Sales" can display as "Ventes" / "Hokohoko" per the viewer's locale, while the canonical stored name is never changed.
Design — aligned with the maintainer direction on the SIP (mistercrunch/rusackas, Apr 2025): keep core minimal and push storage/authoring to deployments.
TRANSLATION_HOOK(default_text, locale, **context) -> str | Noneis the only integration point. Superset core does not store translations — the hook decides where they live (static map, external MT service, a table,.pocatalogs, …).{{ i18n('...') }}Jinja macro lets templated fields opt in.ENABLE_I18N_ASSET_TRANSLATIONSfeature flag and a multi-languageLANGUAGESconfig, so single-language deployments pay zero cost.This is the read path only. Storage and an authoring UI are intentionally left out of core; a self-contained database-backed reference (table + hook + seeding) is provided under
examples/to show end-to-end authoring without shipping it as a supported component.Surfaces localized: chart/dashboard lists & cards, dashboard view header, chart panel titles, home "Recents" cards, and
{{ i18n() }}-wrapped templated fields.BEFORE/AFTER SCREENSHOTS OR ANIMATED GIF
Verified locally end-to-end with a demo hook (en + Māori): list pages, cards, dashboard header, and chart panels display the localized name; edit modals/inline title editing show the canonical English name. (Screenshots to be added.)
TESTING INSTRUCTIONS
superset_config.py:Automated:
pytest tests/unit_tests/utils/i18n_test.pyand the newrecent_activitylocalization integration test intests/integration_tests/log_api_tests.py; SliceHeader render tests cover the view-vs-edit behavior.ADDITIONAL INFORMATION
ENABLE_I18N_ASSET_TRANSLATIONSOpened as a draft to restart the SIP-161 discussion with a concrete, reviewable read-path implementation. Storage/authoring deliberately deferred — feedback welcome on whether the hook contract is the right minimal-core surface.