Skip to content

Languages and language packs ​

The texts the grid shows by itself follow the locale option. Korean and English are built in. For any other language you write a language pack and plug it in.

Since 1.2.0

Language packs (registerLocale, localePacks, checkLocalePack) are available since 1.2.0. In 1.1.0 locale accepts only 'ko' and 'en'.

What locale changes ​

  • Texts on screen: the pager, the filter row and filter popup, the column menu, the cell context menu and notes, the empty and loading messages, the total rows, the calendar of the date editor, the cell validation error bubbles and the aria-label of the select-all checkbox.
  • Dates and numbers: the month and weekday names of the calendar, the day a week starts on, and how the pager writes numbers (1,200 or 1.200).
  • Sorting: the order in which text is sorted.

Some things locale does not change.

  • Your data, the column title and the text formatValue returns. Produce those in the right language in your code.
  • Developer-facing messages (option errors, console hints). They come only in Korean or English: a code that starts with ko gives Korean, anything else gives English.
  • Export files and their error messages. Set those separately, as in exportCsv(api, { locale }) (CSV export).

Built-in languages and how a code is resolved ​

Without locale the grid uses Korean. A code is resolved like this.

locale valueTexts used
omitted, 'ko', 'ko-KR'Korean
'en'English
the code of a pack you registered or passed ('ja')that pack
a code that only shares the start with a pack ('ja-JP')that pack (ja). An exact match wins if there is one
any other code ('xx')English. This is not an error
ts
import { createGrid } from 'maxgrid';

createGrid(document.getElementById('grid')!, {
  columns: [{ id: 'name', title: 'Name' }],
  rows,
  rowKey: 'id',
  pagination: { mode: 'client', pageSize: 5 },
  locale: 'en', // with 12 rows the pager reads "1–5 of 12". 'ko' gives "총 12건 중 1–5".
});

Japanese and Simplified Chinese packs ​

Since 1.3.0

Japanese (ja) and Simplified Chinese (zh-CN) language packs are available as separate packages. The texts in these packs are machine translations provided as defaults. If a phrase sounds off, you can change it yourself with the ways below. It also helps to have someone who knows the language read the screen before you ship it.

How to change the texts ​

  1. Change a few phrases: put the phrases in the grid option messages. A phrase you set is shown as is, whatever the language. This is the simplest way.
  2. Replace or extend a pack: copy the pack object, edit it and register it with registerLocale, or give it to a grid with localePacks. A pack given as an option wins over a registered pack with the same code. The steps are in "Using packs" below.
  3. Start from the translation template: build a pack from the template that extractTemplate(builtinPack('en')) returns and check the missing keys with checkLocalePack. The steps are in "Writing a pack" below.
ts
createGrid(el, {
  columns,
  rows,
  rowKey: 'id',
  locale: 'ja',
  messages: { noRows: '該当するデータがありません。' }, // changes only this phrase
});

If you review a pack, check these terms first.

TermWhere it appears
FilterFilter row, filter popup, column menu
SortColumn menu, clear sort
GroupGroup expand, group totals, group panel
PagePager summary, page buttons
SelectionSelected count notice, checkbox name
ColumnColumn menu, hide, pin
RowRow numbers, no-data text, row move notice
Languagenpm packageScript fileSize (gzip)
Japanese@maxgrid/locale-jamaxgrid.locale.ja.min.jsabout 3.3KB
Simplified Chinese@maxgrid/locale-zh-cnmaxgrid.locale.zh-CN.min.jsabout 3.1KB

Change the language in the demo below. The data stays the same; the pager, filter row, column menu and total row texts follow. Strings that stay English in Japanese are the ones not in the pack (see "Missing keys fall back to English" below).

Live demo — drawn by the real renderer

With npm, register a pack once and give its code to locale. Use the registerLocale of the package that creates the grid, as in the table in "Using a pack" below.

bash
npm install maxgrid @maxgrid/locale-ja @maxgrid/locale-zh-cn
ts
import { createGrid, registerLocale } from 'maxgrid';
import { ja } from '@maxgrid/locale-ja';
import { zhCN } from '@maxgrid/locale-zh-cn';

registerLocale(ja);
registerLocale(zhCN);

createGrid(document.getElementById('grid')!, {
  columns: [{ id: 'name', title: '名前' }],
  rows: [],
  rowKey: 'id',
  locale: 'ja', // 'zh-CN' for Chinese
});

With script tags, load the pack file after maxgrid.min.js. It registers itself as soon as it loads.

html
<script src="https://cdn.maxmine.com/maxgrid/1.8.0/maxgrid.min.js"></script>
<script src="https://cdn.maxmine.com/maxgrid/1.8.0/maxgrid.locale.ja.min.js"></script>
<script>
  MaxGrid.createGrid(document.getElementById('grid'), {
    columns: [{ id: 'name', title: '名前' }],
    rows: [],
    rowKey: 'id',
    locale: 'ja',
  });
</script>

The React, Vue and Angular wrappers register with registerLocale from @maxgrid/core. If you pass the pack through the localePacks option, you do not need to register it.

  • Included: the pager, the filter popup and filter row, names and hints for sorting, selection, editing and menus, the date and time pickers, total and subtotal labels, the empty and loading texts, and the date, number and sort rules (formats).
  • Not included: the docs site and the example gallery (Korean and English only), developer-facing error messages, and your table data and column titles.
  • When you export to PDF: PDF export uses the Korean font package (@maxgrid/export-font-ko). That font has Japanese kana and common Han characters, so most Japanese text comes out fine. Characters that exist only in Simplified Chinese come out when you chain the Simplified Chinese font package (@maxgrid/export-font-sc) as in font: [koreanFont, simplifiedChineseFont] (how). Characters that no font has become ? in the PDF and the missing-glyph warning fires (CSV and Excel are not affected).
  • To fix a wording: override it with the messages option. An overridden text stays the same in every language. To replace the whole pack, write your own as in "Writing a pack" below and pass it with localePacks.

Writing a pack: start from the translation template ​

A pack is an object with four sections. Every section has the same keys as the English pack. The count changes between versions, so do not count keys: use the template from extractTemplate(builtinPack('en')) as the reference.

SectionKeysWhat it holds
messages48column menu, group expand, cell context menu, cell notes, empty and loading, announcements
pager17pager button names, the summary, page jump, load failure and retry
filter85labels, operators, value list, hints and errors of the filter row and popup
text41cell validation errors, calendar, total rows, cell error, select all, rating label

Do not write the translation from scratch. Take a template from the English pack. It keeps you from mistyping key names and {placeholder} names.

ts
import { extractTemplate } from '@maxgrid/core';
import { builtinPack } from '@maxgrid/renderer';

const template = extractTemplate(builtinPack('en'));
console.log(Object.keys(template)); // ['messages', 'pager', 'filter', 'text']
console.log(template.pager.summary);
// { en: '{from}–{to} of {total}', placeholders: ['from', 'to', 'total'] }

The template is JSON ordered by section and key. Each entry has the English text (en) and the list of placeholders the text must contain (placeholders). With indentation it is about 17 KB. The number of keys grows a little with each version, so count exactly with something like Object.keys(template.pager).length.

  1. Save JSON.stringify(template, null, 2) to a file and give it to the translator.
  2. The translator adds the text in their language to every entry as a new field (here ja) and sends the file back.
  3. Turn the returned file into a pack object.
ts
import type { LocalePack } from '@maxgrid/core';

// translated: the JSON the translator returned. Every entry is { en, placeholders, ja }.
const section = (items: Record<string, { ja?: string }>) =>
  Object.fromEntries(
    Object.entries(items).flatMap(([key, item]) => (item.ja ? [[key, item.ja]] : [])),
  );

export const ja = {
  code: 'ja',
  messages: section(translated.messages),
  pager: section(translated.pager),
  filter: section(translated.filter),
  text: section(translated.text),
} as LocalePack; // missing keys are caught in "Check that a pack is complete" below

Three rules for translating.

  • Keep {placeholder} names exactly as they are. You may change their order or how often they appear ({total}件中 {from}–{to}件).
  • Do not use HTML. Texts are inserted as plain text. A tag such as <b> is rejected when the pack is registered.
  • Do not leave an empty string. Delete a key you do not translate and English is shown.

Dates, numbers and sorting (formats) ​

Add formats to the pack to set regional rules besides the texts. All fields are optional.

KeyMeaningExample
firstDayOfWeekthe day a calendar week starts on (0 Sunday … 6 Saturday)1 (Monday)
weekendweekday numbers the calendar marks as weekend[5, 6] (Fri, Sat)
collationtext sort rule (BCP 47). Defaults to the pack code'sv' (ä after z)
numberLocalehow numbers are written, for example in the pager. Defaults to code'de-DE' (1.200)

Omitted values follow the Intl information of the browser. With weekend: [5, 6] the calendar marks Friday and Saturday, and with numberLocale: 'de-DE' the summary for 1,200 rows reads 1.200.

Using a pack ​

Register once: registerLocale ​

Register at app start and every grid that uses that code uses the same pack. There is one registry per bundle, so import registerLocale from the package that creates the grid.

Where the grid is createdImport registerLocale from
React, Vue and Angular wrappers@maxgrid/core
the maxgrid package (ESM)maxgrid
maxgrid.min.js (script tag)the global MaxGrid.registerLocale
ts
import { registerLocale } from '@maxgrid/core'; // with a wrapper
import { ja } from './ja';

registerLocale(ja); // registering the same pack again is fine (it is ignored)

// grid options only need the code
const options = { columns, rows, rowKey: 'id', locale: 'ja' };

The maxgrid package exports it from the same place as createGrid, together with checkLocalePack, extractTemplate and builtinPack.

ts
import { createGrid, registerLocale } from 'maxgrid';
import { ja } from './ja';

registerLocale(ja);
createGrid(document.getElementById('grid')!, { columns, rows, rowKey: 'id', locale: 'ja' });

With a script tag it is on the global MaxGrid.

html
<div id="grid" style="height: 320px"></div>

<script src="https://cdn.maxmine.com/maxgrid/1.8.0/maxgrid.min.js"></script>
<script>
  const ja = {
    code: 'ja',
    messages: { noRows: '表示する行がありません。' },
    pager: { summary: '全{total}件中 {from}–{to}件', next: '次のページ' },
    filter: { rowLabel: 'フィルター' },
    text: { summaryTotal: '合計' },
  };

  MaxGrid.registerLocale(ja); // registering the same pack again is fine (it is ignored)
  MaxGrid.createGrid(document.getElementById('grid'), {
    columns: [{ id: 'name', title: 'Name' }],
    rows: [{ id: 1, name: 'Kim' }],
    rowKey: 'id',
    pagination: { mode: 'client', pageSize: 5 },
    locale: 'ja', // picks up the registered pack by its code
  });
</script>

registerLocale throws right away, without registering, when the shape is wrong.

SituationResult
same code, same contentignored
same code, different contentError: locale "ja" is already registered with different content.
ko or enTypeError: built in and cannot be replaced
HTML tag in a text, a non-string value, a missing sectionTypeError with a reason such as locale pack "ja": pager.next must not contain HTML tags.
dir other than 'ltr' or 'rtl'TypeError: the direction must be 'ltr' or 'rtl'

The registry is separate for each bundle

A pack registered with registerLocale from @maxgrid/core is not seen by grids created with the maxgrid package (maxgrid.min.js and the ESM file), and they show English. That package bundles its own copy of @maxgrid/core. The reverse is also true. Import from the package that creates the grid, or, if you must mix them, use the localePacks option right below.

Per grid: localePacks ​

Pass packs in the grid options, with no global registration. This works everywhere, and the option wins over a registered pack with the same code.

ts
import { createGrid } from 'maxgrid';
import { ja } from './ja';

createGrid(document.getElementById('grid')!, {
  columns,
  rows,
  rowKey: 'id',
  locale: 'ja',
  localePacks: [ja],
});

It also works with only a script tag.

html
<div id="grid" style="height: 320px"></div>

<script src="https://cdn.maxmine.com/maxgrid/1.8.0/maxgrid.min.js"></script>
<script>
  const ja = {
    code: 'ja',
    messages: { noRows: '表示する行がありません。' },
    pager: { summary: '全{total}件中 {from}–{to}件', next: '次のページ' },
    filter: { rowLabel: 'フィルター' },
    text: { summaryTotal: '合計' },
  };

  MaxGrid.createGrid(document.getElementById('grid'), {
    columns: [{ id: 'name', title: 'Name' }],
    rows: [/* … */],
    rowKey: 'id',
    pagination: { mode: 'client', pageSize: 5 },
    filterRow: true,
    locale: 'ja',
    localePacks: [ja],
  });
</script>

That pack fills only some keys, so the rest stays English. The next sections explain why.

Switching the language at run time ​

Use setOptions({ locale }). The pager, filter row, column menu and total rows change to the new language on the next redraw, almost at once. With a wrapper, change locale in options.

ts
api.setOptions({ locale: 'en' });

Missing keys fall back to English ​

A key that the pack does not have falls back to English, key by key. A partly translated pack works: what you translated changes and the rest stays English. This also splits inside one section. If you translate only pager.summary, the summary is Japanese and the name of the "next page" button is English.

Texts are chosen in this order. The first one wins.

  1. The grid options messages, filterMessages and pagination.messages
  2. The pack (the localePacks option before the registry)
  3. English
ts
createGrid(el, {
  columns,
  rows,
  rowKey: 'id',
  locale: 'ja',
  localePacks: [ja],
  pagination: { mode: 'client', pageSize: 5, messages: { summary: '{total}行' } }, // wins over the pack
  filterMessages: { rowLabel: '絞り込み' },
  messages: { noRows: '空です' },
});

This order makes it easy to leave the language to the pack and change only a few texts to your own wording.

Check that a pack is complete ​

checkLocalePack(pack, base) compares a pack with the English pack and returns { errors, warnings }. A finished pack has an empty errors.

ts
import { checkLocalePack } from '@maxgrid/core';
import { builtinPack } from '@maxgrid/renderer';
import { ja } from './ja';

const { errors, warnings } = checkLocalePack(ja, builtinPack('en'));

These are the entries you will see most.

ResultMeaning
pager.next: missinga key that the English pack has is missing
filter.extra: unknown keya key the English pack does not have (often a typo)
pager.summary: placeholders differ from Englishthe set of {placeholder} names differs from English
filter.all: contains HTML-like textthe text contains an HTML tag
filter.rowLabel: emptyan empty string
pager.nav: more than twice as long as English(warnings) more than twice the English length. Check that it is not cut

A pack that is small on purpose lists every missing key in errors. Use this check for a finished pack. As a unit test it stops a translation that dropped a key or broke a placeholder before it ships.

ts
import { expect, test } from 'vitest';
import { checkLocalePack } from '@maxgrid/core';
import { builtinPack } from '@maxgrid/renderer';
import { ja } from './ja';

test('the ja pack has the same keys and placeholders as the English pack', () => {
  const { errors } = checkLocalePack(ja, builtinPack('en'));
  expect(errors).toEqual([]);
});

Right-to-left layout (RTL) ​

Since 1.4.0

The direction option and dir: 'rtl' in a locale pack are available since 1.4.0. No Arabic or Hebrew pack is shipped.

direction shows the grid right to left. Omitted, it is left to right and renders exactly as in 1.3.x (no dir attribute is added to the root).

ts
createGrid(el, { columns, rows, rowKey: 'id', direction: 'rtl' });
api.setOptions({ direction: 'ltr' });
ValueMeaning
'ltr'Left to right (default). Puts dir="ltr" on the root so the host page's direction does not leak in
'rtl'Right to left. Puts dir="rtl" on the root
'auto'Follows the CSS direction of the element holding the grid, re-read on gridResized and on option changes. If CSS gives no answer, the locale pack's dir is used

What changes in RTL:

ItemBehavior in RTL
Column placementThe first column sits at the right end; utility columns (row number, check, state, handle) also start on the right
Pinned columnspinned: 'start' sticks to the right, 'end' to the left
Horizontal scrollThe initial position is the right end. The column window (virtualization), header sync and saved scroll position count "distance from the start", so they do not depend on direction
Keys← goes to the next cell and → to the previous one (also in the date picker, cell menu and filter popup tabs). Home and End stay the start and end cell. Alt+← and Alt+→ (column move and resize) swap too
DraggingColumn resize and move, cell range drag, the fill handle (end-side corner) and row drag (handle on the right) all follow the direction
Band bodySlots are a CSS grid, so they mirror on their own
Exportxlsx shows the sheet right to left (with direction: 'rtl'; when 'auto' resolves to rtl pass exportXlsx(api, { rightToLeft: true })). CSV, JSON and XML are unchanged and PDF does not change in this version
  • The theme CSS uses logical properties (inset-inline-*, margin-inline-*) instead of left and right. The left-to-right look is unchanged.
  • To add an Arabic or Hebrew pack, register it with registerLocale({ code: 'ar', dir: 'rtl', ... }) as in Writing a pack and use direction: 'auto'. The pack's dir is read only when the container CSS gives no answer.
  • Number and date shapes in locale texts follow the language (Intl) and are separate from direction.

Good to know ​

  • Only Korean and English are built in. Japanese and Simplified Chinese are available as separate packages (machine translation by default), and for any other language you write a pack with the steps above. The main bundle does not grow.
  • Right-to-left languages are supported with the direction option (see "Right to left (RTL)" below).
  • Have someone who knows the language review a translated pack before you use it. Machine translation alone can leave awkward terms.
  • A pack changes only the texts of the grid. To make the whole screen read as one language, build your data and column titles in that language too. A Japanese grid with Korean data does not feel like a supported language.
  • The texts of the docs site and the example gallery exist only in Korean and English.