Languages and right-to-left
The grid UI in 14 languages, picked from the browser or set with locale, and direction: 'rtl' for Arabic, Hebrew and other right-to-left languages.
Live demo14 languages & right to left
Switch the grid UI between 14 languages, from Korean and Japanese to Vietnamese, Thai and Russian, and lay it out right to left.
Code for this demo
import { createGrid, type GridApi, type LocalePack } from '@freegridjs/core';
import de from '@freegridjs/core/locales/de';
import en from '@freegridjs/core/locales/en';
import es from '@freegridjs/core/locales/es';
import fr from '@freegridjs/core/locales/fr';
import ja from '@freegridjs/core/locales/ja';
import ko from '@freegridjs/core/locales/ko';
import zhCN from '@freegridjs/core/locales/zh-CN';
import zhTW from '@freegridjs/core/locales/zh-TW';
import vi from '@freegridjs/core/locales/vi';
import th from '@freegridjs/core/locales/th';
import id from '@freegridjs/core/locales/id';
import ru from '@freegridjs/core/locales/ru';
import ptBR from '@freegridjs/core/locales/pt-BR';
import it from '@freegridjs/core/locales/it';
import { localColumns, localRows, type DataLang } from '../localData';
import { select, text, toggle, tr, type DemoContext } from '../ui';
const PACKS: Record<string, LocalePack> = { en, ko, 'zh-CN': zhCN, 'zh-TW': zhTW, ja, vi, th, id, es, 'pt-BR': ptBR, fr, de, it, ru };
export default function mount(ctx: DemoContext) {
const { lang } = ctx;
let code: DataLang = lang;
// names, companies, countries and column headers follow the grid language
let rows: 0 | 1000 = 1000;
const data = () => (rows ? localRows(code, rows) : []);
let grid: GridApi;
const rebuild = (rtl: boolean) => {
grid?.destroy();
grid = createGrid(ctx.host, {
columns: localColumns(code),
data: data(),
rowSelection: 'multiple',
locale: PACKS[code],
direction: rtl ? 'rtl' : 'ltr', // right to left: first column on the right
});
};
let rtl = false;
rebuild(rtl);
select(ctx, tr(lang, { en: 'Grid language', ko: '그리드 언어' }), [
['en', 'English'], ['ko', '한국어'], ['zh-CN', '简体中文'], ['zh-TW', '繁體中文'], ['ja', '日本語'], ['vi', 'Tiếng Việt'], ['th', 'ไทย'], ['id', 'Bahasa Indonesia'], ['es', 'Español'], ['pt-BR', 'Português (Brasil)'], ['fr', 'Français'], ['de', 'Deutsch'], ['it', 'Italiano'], ['ru', 'Русский'],
], lang, c => {
code = c as DataLang;
grid.setLocale(PACKS[c]);
// the app's own words: column headers and the rows are in the same language
grid.setColumns(localColumns(code));
grid.setData(data());
ctx.log(`setLocale('${c}') + setColumns + setData → ${PACKS[c].noRows}`);
});
select(ctx, tr(lang, { en: 'Rows', ko: '데이터' }), [['1000', '1,000'], ['0', tr(lang, { en: 'Empty (shows the no-rows message)', ko: '비어 있음 (데이터 없음 안내 확인)' })]], '1000', v => {
rows = v === '0' ? 0 : 1000;
grid.setData(data());
});
toggle(ctx, tr(lang, { en: 'Right to left', ko: '오른쪽→왼쪽' }), false, on => {
rtl = on;
rebuild(rtl);
ctx.log(`direction: '${on ? 'rtl' : 'ltr'}'`);
});
text(ctx, tr(lang, { en: 'Pick a language: the grid texts, the column headers and the 1,000 rows change together, and numbers and dates follow the language. Open a column menu (⋮) or Choose columns to see more translations.', ko: '언어를 고르면 그리드 문구, 컬럼명, 1,000건의 데이터가 함께 바뀌고 숫자와 날짜도 그 언어 형식을 따릅니다. 컬럼 메뉴(⋮)나 컬럼 선택 창을 열어 번역을 더 확인해 보세요.' }));
return grid!;
}English is built in. Korean, Simplified and Traditional Chinese, Japanese, Vietnamese, Thai, Indonesian, Spanish, Portuguese (Brazil), French, German, Italian and Russian are separate imports so you only ship what you use. Without a locale option the grid picks the browser language when that pack is registered, otherwise English.
A language pack translates the grid's own words: menus, filters, the status bar, messages. Numbers and dates follow the language by themselves. Column headers and the rows are your data, so give them in the same language: the demo below calls setLocale(), setColumns() with translated headers and setData() with 1,000 rows of names, companies and countries in each of the 14 languages.
import ko from '@freegridjs/core/locales/ko';
createGrid(el, { columns, data, locale: ko });
// or register once and use codes
import { registerLocale } from '@freegridjs/core';
import ja from '@freegridjs/core/locales/ja';
registerLocale(ja);
grid.setLocale('ja');
// override a few messages
createGrid(el, { columns, data, locale: { ...ko, noRows: '조회 결과가 없습니다' } });Right to left
direction: 'rtl' lays the grid out for Arabic, Hebrew, Persian and other right-to-left languages: the first column is on the right, resizing and dragging columns work mirrored, and the left and right arrow keys follow the screen. Give the grid a language pack of your own for the menu texts.
import ar from './my-arabic-pack'; // your own language pack (see registerLocale)
createGrid(el, {
columns,
data,
direction: 'rtl', // first column on the right, scrollbars and pinning mirrored
locale: ar,
});