Internationalization (i18n)¶
grid-view-spec is host-agnostic: UI chrome uses dotted msgids (column_settings.title, export.pdf, …) in Django templates and the JS catalog.
Requirements¶
- Add
grid_view_spec.backends.djangotoINSTALLED_APPS(loadsgrid_view_spec/locale/). - Set
LANGUAGE_CODEand enableLocaleMiddlewarein the host project. - Include
{% grid_view_spec_assets part='js' force_core=True %}once per page (injectsGridViewI18nbefore bundle scripts).
Optional host overrides: add the same msgids under the host LOCALE_PATHS.
Two surfaces, one catalog¶
| Surface | Pattern | Example |
|---|---|---|
| Django templates | {% translate "column_settings.title" %} |
Modal shell, export buttons, filter bar |
| JavaScript | window.GridViewI18n via GridView.i18n.t(key, fallback) |
Dynamic modal groups, multiselect labels |
All JS keys are listed in grid_view_spec.backends.django.i18n.JS_I18N_KEYS (canonical list in grid_view_spec.i18n) and compiled into locale/*/LC_MESSAGES/django.po.
After editing .po files:
Host-owned labels¶
Table/chart/KPI column labels and filter option text come from the host app (GridViewSpec blocks, filter schemas). Use plain str for export column labels in builders.
Package i18n covers grid chrome only (toolbars, modals, export buttons, empty states).
Column settings + export¶
Column settings UI uses the same msgids as the modal. Export column order/visibility uses the export_cols URL param — Server filtering.
Do not¶
- Hardcode locale-specific strings in package templates or JS.
- Use English sentence msgids for new strings — prefer dotted keys in
grid_view_spec/i18n.py. - Use
gettext_lazyon exported table column labels in XLSX/PDF builders.