Asset Metadata Translation
Superset's built-in internationalization (Flask-Babel / gettext) translates the application's UI chrome — buttons, menus, labels, error messages. It does not translate user-authored content such as chart names, dashboard titles, or axis/metric labels, because those are stored as data rather than as translatable source strings.
This feature lets a deployment localize that user-authored metadata, so a chart named "Sales" can display as "Ventes" to a French viewer and "Hokohoko" to a Māori viewer — while the canonical stored name stays unchanged.
This implements the read path discussed in
SIP-161. Superset core does
not store these translations. It calls a deployment-provided
TRANSLATION_HOOK at render time; where the translations live and how they are
authored is entirely up to the deployment (a static map, an external machine
translation service, a database table, gettext .po catalogs, …). This keeps
core minimal and the storage/authoring strategy pluggable.
Enabling
Two conditions must both be true, otherwise translation is skipped entirely (single-language deployments pay zero cost):
- The
ENABLE_I18N_ASSET_TRANSLATIONSfeature flag is enabled. - More than one language is configured in
LANGUAGES.
# superset_config.py
FEATURE_FLAGS = {
"ENABLE_I18N_ASSET_TRANSLATIONS": True,
}
BABEL_DEFAULT_LOCALE = "en"
LANGUAGES = {
"en": {"flag": "us", "name": "English"},
"fr": {"flag": "fr", "name": "French"},
}
When enabled, the canonical text is always returned unchanged if:
- the active locale is the default locale (
BABEL_DEFAULT_LOCALE), or - neither
TRANSLATION_HOOKnorTRANSLATION_BATCH_HOOKis configured, or - the hook returns a falsy value (no translation found), or
- the hook raises (the error is logged; the original text is preserved).
The canonical text is always a safe fallback, so a missing or broken translation never blanks out a chart or dashboard name.
The TRANSLATION_HOOK
Define a callable in superset_config.py. It receives the default (canonical)
text and the target locale, plus keyword context to disambiguate identical
strings, and returns the translated text — or a falsy value to fall back.
def TRANSLATION_HOOK(
default_text: str,
locale: str,
**kwargs, # e.g. model_name="Dashboard", field_name="dashboard_title"
) -> str | None:
...
Keep **kwargs last so future context can be added without breaking your
implementation. Treat the hook as a pure, deterministic lookup where possible.
The TRANSLATION_BATCH_HOOK
TRANSLATION_HOOK is called once per string, which is fine for an in-memory
lookup but costly if every call is a query or a network round trip. Rendering a
dashboard resolves every chart name on it; a page of recent activity resolves
every entry.
For those stores, define TRANSLATION_BATCH_HOOK instead. Superset hands it
every string it is about to render for one context and expects a mapping back:
def TRANSLATION_BATCH_HOOK(
default_texts: list[str],
locale: str,
**kwargs, # e.g. model_name="Slice", field_name="slice_name"
) -> dict[str, str | None]:
...
Keys that are missing from the returned mapping — or that map to a falsy value — fall back to the canonical text, so returning only the strings you actually have a translation for is fine.
When set, this fully replaces TRANSLATION_HOOK: individual lookups are
routed through it as a one-element batch, so there is no need to configure
both. Superset also memoizes resolutions for the duration of a request, so a
repeated string costs one lookup no matter how many times it is rendered.
Batching applies where Superset holds a whole collection before rendering it — the charts on a dashboard and the "Recents" list. On the chart and dashboard list pages each row is serialized independently, so those still resolve per row; back your hook with a cache or an in-process map if that path matters to you.
The i18n Jinja macro
Content that passes through SQL templating — virtual dataset SQL, calculated columns, metric expressions, SQL Lab queries — can opt into translation explicitly:
{{ i18n('Sales') }}
This resolves through the configured translation hook -- batch or single -- and the same enable gate; when the feature is off it simply returns the original text.
The macro is bound only in the SQL template processor, so it reaches strings
Superset renders server-side as part of a query. It does not reach labels
the frontend renders from stored metadata -- chart axis labels and native
filter names among them -- where {{ i18n('Sales') }} would display literally.
Reference hook implementations
These are starting points — copy one into superset_config.py and adapt it.
1. Static dictionary
Best for a small, fixed set of strings managed by an administrator.
_TRANSLATIONS = {
("fr", "Sales"): "Ventes",
("fr", "Sales Dashboard"): "Tableau de bord des ventes",
("mi", "Sales"): "Hokohoko",
}
def TRANSLATION_HOOK(default_text, locale, **kwargs):
return _TRANSLATIONS.get((locale, default_text))
2. External machine-translation service
No human authoring; strings are translated on demand. Cache aggressively, since the hook is called per field per render.
from functools import lru_cache
# from google.cloud import translate_v2 as translate
# _client = translate.Client()
@lru_cache(maxsize=10_000)
def _translate(text, locale):
# return _client.translate(text, target_language=locale)["translatedText"]
...
def TRANSLATION_HOOK(default_text, locale, **kwargs):
try:
return _translate(default_text, locale)
except Exception:
return None # fall back to canonical text
3. gettext .po catalogs
Reuse the standard translation toolchain (Poedit, Transifex, Weblate) that
Superset already uses for UI chrome, keyed by the source string. Maintain a
separate catalog domain (e.g. assets) so content strings don't collide with
UI strings.
import gettext
_CATALOGS = {
locale: gettext.translation(
"assets", localedir="/app/asset_translations", languages=[locale]
)
for locale in ("fr", "mi")
}
def TRANSLATION_HOOK(default_text, locale, **kwargs):
catalog = _CATALOGS.get(locale)
if not catalog:
return None
translated = catalog.gettext(default_text)
return translated if translated != default_text else None
4. Database-backed (with authoring)
For deployments that need editors to enter translations in-app, back the hook with a table and build (or generate) a small admin surface that writes to it. A self-contained reference for this pattern — table model, hook, and a minimal seeding/admin flow — is provided as an example rather than shipped in core; see the example referenced from the project repository.
Prefer the batch form here — one IN query per collection instead of one query
per string:
def TRANSLATION_BATCH_HOOK(default_texts, locale, **kwargs):
return my_translation_store.lookup_many(
locale=locale,
texts=default_texts,
model_name=kwargs.get("model_name"),
field_name=kwargs.get("field_name"),
)
What gets translated
| Surface | Field |
|---|---|
| Chart / dashboard list & cards | slice_name / dashboard_title |
| Dashboard view header & chart panel titles | dashboard_title / slice_name |
| Home page "Recents" cards | recent-activity item titles |
SQL-templated content via {{ i18n(...) }} | any wrapped string |
Editing flows (the chart/dashboard Properties modals, inline title editing) always operate on the canonical name, so a save can never overwrite the stored name with a translation.