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-labelof 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,200or1.200). - Sorting: the order in which text is sorted.
Some things locale does not change.
- Your data, the column
titleand the textformatValuereturns. 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
kogives 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 value | Texts 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 |
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
- 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. - Replace or extend a pack: copy the pack object, edit it and register it with
registerLocale, or give it to a grid withlocalePacks. A pack given as an option wins over a registered pack with the same code. The steps are in "Using packs" below. - Start from the translation template: build a pack from the template that
extractTemplate(builtinPack('en'))returns and check the missing keys withcheckLocalePack. The steps are in "Writing a pack" below.
createGrid(el, {
columns,
rows,
rowKey: 'id',
locale: 'ja',
messages: { noRows: '該当するデータがありません。' }, // changes only this phrase
});If you review a pack, check these terms first.
| Term | Where it appears |
|---|---|
| Filter | Filter row, filter popup, column menu |
| Sort | Column menu, clear sort |
| Group | Group expand, group totals, group panel |
| Page | Pager summary, page buttons |
| Selection | Selected count notice, checkbox name |
| Column | Column menu, hide, pin |
| Row | Row numbers, no-data text, row move notice |
| Language | npm package | Script file | Size (gzip) |
|---|---|---|---|
| Japanese | @maxgrid/locale-ja | maxgrid.locale.ja.min.js | about 3.3KB |
| Simplified Chinese | @maxgrid/locale-zh-cn | maxgrid.locale.zh-CN.min.js | about 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).
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.
npm install maxgrid @maxgrid/locale-ja @maxgrid/locale-zh-cnimport { 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.
<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 infont: [koreanFont, simplifiedChineseFont](how). Characters that no font has become?in the PDF and themissing-glyphwarning fires (CSV and Excel are not affected). - To fix a wording: override it with the
messagesoption. 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 withlocalePacks.
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.
| Section | Keys | What it holds |
|---|---|---|
messages | 48 | column menu, group expand, cell context menu, cell notes, empty and loading, announcements |
pager | 17 | pager button names, the summary, page jump, load failure and retry |
filter | 85 | labels, operators, value list, hints and errors of the filter row and popup |
text | 41 | cell 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.
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.
- Save
JSON.stringify(template, null, 2)to a file and give it to the translator. - The translator adds the text in their language to every entry as a new field (here
ja) and sends the file back. - Turn the returned file into a pack object.
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" belowThree 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.
| Key | Meaning | Example |
|---|---|---|
firstDayOfWeek | the day a calendar week starts on (0 Sunday … 6 Saturday) | 1 (Monday) |
weekend | weekday numbers the calendar marks as weekend | [5, 6] (Fri, Sat) |
collation | text sort rule (BCP 47). Defaults to the pack code | 'sv' (ä after z) |
numberLocale | how 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 created | Import registerLocale from |
|---|---|
| React, Vue and Angular wrappers | @maxgrid/core |
the maxgrid package (ESM) | maxgrid |
maxgrid.min.js (script tag) | the global MaxGrid.registerLocale |
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.
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.
<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.
| Situation | Result |
|---|---|
| same code, same content | ignored |
| same code, different content | Error: locale "ja" is already registered with different content. |
ko or en | TypeError: built in and cannot be replaced |
| HTML tag in a text, a non-string value, a missing section | TypeError 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.
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.
<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.
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.
- The grid options
messages,filterMessagesandpagination.messages - The pack (the
localePacksoption before the registry) - English
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.
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.
| Result | Meaning |
|---|---|
pager.next: missing | a key that the English pack has is missing |
filter.extra: unknown key | a key the English pack does not have (often a typo) |
pager.summary: placeholders differ from English | the set of {placeholder} names differs from English |
filter.all: contains HTML-like text | the text contains an HTML tag |
filter.rowLabel: empty | an 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.
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).
createGrid(el, { columns, rows, rowKey: 'id', direction: 'rtl' });
api.setOptions({ direction: 'ltr' });| Value | Meaning |
|---|---|
'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:
| Item | Behavior in RTL |
|---|---|
| Column placement | The first column sits at the right end; utility columns (row number, check, state, handle) also start on the right |
| Pinned columns | pinned: 'start' sticks to the right, 'end' to the left |
| Horizontal scroll | The 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 |
| Dragging | Column resize and move, cell range drag, the fill handle (end-side corner) and row drag (handle on the right) all follow the direction |
| Band body | Slots are a CSS grid, so they mirror on their own |
| Export | xlsx 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 ofleftandright. 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 usedirection: 'auto'. The pack'sdiris read only when the container CSS gives no answer. - Number and date shapes in
localetexts 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
directionoption (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.