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.
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?.(); };}Providing Translations
Section titled “Providing Translations”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 TypeScriptconst 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),});Rules & Scope
Section titled “Rules & Scope”- Construction-Only:
localeTextis 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, developerError/TypeError) stay English while UI announcements (editor errors, clipboard live status) uselocaleText. Value formatting remains the responsibility of columnformattercallbacks.