Localization (i18n) in Apex Grid
Every built-in string in Apex Grid (filter operands, menu items, toolbar labels, paginator text, and the enterprise feature strings) is localizable through the localeText override map. You can supply a bundled dictionary such as Spanish (esLocale), your own partial overrides, or both. Available on both <apex-grid> and <apex-grid-enterprise> since v3.3.
Using a bundled locale
import { esLocale } from 'apex-grid';
grid.localeText = esLocale;
The grid re-renders its chrome in the chosen language. Bundled dictionaries cover the core strings and the enterprise features.
Overriding individual strings
localeText is a plain override map, so you can translate (or reword) just the strings you care about and leave the rest as the built-in defaults:
grid.localeText = {
...esLocale,
// reword a few entries on top of the base dictionary
'toolbar.searchPlaceholder': 'Buscar…',
'toolbar.exportCsv': 'Descargar CSV',
};
Any key you omit falls back to the built-in English default, so a partial map is always safe.
Resolving a string yourself
If you build custom UI around the grid (a toolbar button, a companion element), resolve a locale string through the grid's localize method so your UI matches the grid's language:
const label = grid.localize('toolbar.exportCsv'); // resolve a key
const withFallback = grid.localize('my.key', {}, 'Fallback');
Validator and accessible-name keys
The text below has its own locale keys, so localeText translates it like the rest of the chrome. Each English default is the text the grid shows without an override, and esLocale translates them all.
| Key | English default | Where it shows |
|---|---|---|
toolbar.exportCsv | Export CSV | The CSV item of the export menu |
filter.and / filter.or | and / or | The filter panel's join toggles |
cell.rating | {value} of {max} | A rating cell's accessible name |
cell.true / cell.false | true / false | A boolean cell's accessible name |
validation.required | This field is required | The default message of required() |
validation.min | Must be at least {limit} | The default message of min() |
validation.max | Must be at most {limit} | The default message of max() |
validation.pattern | Invalid format | The default message of pattern() |
filterBuilder.true / filterBuilder.false | true / false | The enterprise filter builder's boolean values |
contextMenu.groupBy, contextMenu.ungroupAll, contextMenu.expandGroups, contextMenu.collapseGroups | Group by this column, Un-group all, Expand all groups, Collapse all groups | The enterprise header menu's grouping items |
A custom validator can resolve keys the same way the built-ins do, through the localize function on its context:
const atLeastOne = (value, ctx) =>
value >= 1 ? null : (ctx.localize?.('validation.min', { limit: 1 }) ?? 'Must be at least 1');
ctx.localize is absent when a validator is called outside a grid, where the built-ins use the English defaults.
React example
import { useEffect, useRef } from 'react'
import 'apex-grid/define'
import { esLocale } from 'apex-grid'
export default function LocalizedGrid() {
const ref = useRef<any>(null)
useEffect(() => {
const grid = ref.current
grid.columns = columns
grid.data = data
grid.localeText = esLocale
}, [])
return <apex-grid ref={ref} style={{ height: 480 }} />
}