Skip to content

Localization

All UI strings, ARIA labels, and synthetic cell labels (Grand total, (Blank), Total, Group, Row selection) come from a single dictionary configured at construction via localeText.

English vs Russian (next-grid-js/locale/ru)
import { Grid } from 'next-grid-js';
import { ru } from 'next-grid-js/locale/ru';
import { createOrders, type OrderRow } from './data/orders';
import { syncGridTheme } from './theme';
import type { DemoMountContext } from './types';
import { addButton } from './ui';
export function mount({
stage,
controls,
meta,
}: DemoMountContext): () => void {
let lang: 'en' | 'ru' = 'en';
let grid: Grid<OrderRow> | null = null;
let stopTheme: (() => void) | null = null;
const rows = createOrders(30);
const mountGrid = () => {
grid?.destroy();
stopTheme?.();
grid = new Grid<OrderRow>({
container: stage,
columnDefs: [
{
key: 'id',
name: lang === 'ru' ? 'Код' : 'ID',
width: 96,
isSortable: true,
},
{
key: 'customer',
name: lang === 'ru' ? 'Клиент' : 'Customer',
width: 175,
flex: 1,
isSortable: true,
},
{
key: 'region',
name: lang === 'ru' ? 'Регион' : 'Region',
width: 105,
},
{
key: 'amount',
name: lang === 'ru' ? 'Сумма' : 'Amount',
width: 115,
cellDataType: 'number',
formatter: ({ value }) =>
`$${Number(value).toLocaleString('en-US')}`,
},
],
rowData: rows,
getRowId: (row) => row.id,
localeText: lang === 'ru' ? ru : undefined,
dataExport: { formats: ['csv', 'xlsx'] },
initialState: {
version: 5,
pagination: {
enabled: true,
page: 0,
pageSize: 8,
},
},
});
stopTheme = syncGridTheme(stage);
meta.textContent = `Locale: ${lang.toUpperCase()} (recreates grid on change)`;
};
mountGrid();
addButton(controls, 'English (default)', () => {
lang = 'en';
mountGrid();
});
addButton(controls, 'Русский (ru)', () => {
lang = 'ru';
mountGrid();
});
return () => {
grid?.destroy();
stopTheme?.();
};
}
import { Grid, en, type GridLocaleText } from 'next-grid-js';
import { ru } from 'next-grid-js/locale/ru';
// 1. Built-in Russian dictionary (separate ~2 KB gzip entry)
new Grid({ container, columnDefs, rowData, localeText: ru });
// 2. Partial dictionary (missing keys fall back to English)
new Grid({
container,
columnDefs,
rowData,
localeText: {
overlayLoading: 'Laden...',
footerPageOf: 'Seite {page} von {pageCount}',
clipboardCopiedCells: ({ count }) => `${count} Zellen kopiert`,
},
});
// 3. Complete custom dictionary verified by TypeScript
const custom: GridLocaleText = { ...en, overlayLoading: 'Loading...' };
// 4. Deterministic i18n resolver (undefined falls back to English)
new Grid({
container,
columnDefs,
rowData,
localeText: (key, params) => i18n.t(`grid.${key}`, params),
});
  • Construction-Only: localeText is read at construction; changing language requires creating a new grid instance. A resolver function must return deterministic text for the same (key, params) over the grid’s lifetime.
  • Validation: Unknown keys, unknown {placeholder} names in template strings, or non-string/non-function values throw at construction.
  • Pluralization: Count parameters arrive as numbers; apply plural rules in dictionary functions (for example Intl.PluralRules).
  • Programmatic vs. User Strings: Programmatic refusal messages (CellMutationResult.message, developer Error/TypeError) stay English while UI announcements (editor errors, clipboard live status) use localeText. Value formatting remains the responsibility of column formatter callbacks.