Skip to content

Commit b40920b

Browse files
committed
feat: adding i18n
1 parent 4875717 commit b40920b

File tree

2 files changed

+41
-2
lines changed

2 files changed

+41
-2
lines changed

docs/examples/i18n.md

Lines changed: 39 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,43 @@ keywords:
1818

1919
import { LiveExample } from "../../lib/liveExample.js";
2020

21-
You can easily customize Grid.js messages and add your language. Simply extend the `language` config to replace the strings:
21+
Grid.js has support for multiple languages. Import your language file first:
22+
23+
```js
24+
import { frFR } from "gridjs/dist/gridjs.lang.es";
25+
```
26+
27+
:::note
28+
"es" in `gridjs/dist/gridjs.lang.es` refers to the file format (ECMAScript). All language files are combined into one file.
29+
There is a UMD format for web-browsers as well: `gridjs/dist/gridjs.lang`
30+
:::
31+
32+
Then pass it to the `language` setting of your Grid.js:
33+
34+
<LiveExample children={
35+
`
36+
const grid = new Grid({
37+
columns: ['Name', 'Email', 'Title'],
38+
sort: true,
39+
search: true,
40+
pagination: {
41+
limit: 5
42+
},
43+
data: Array(50).fill().map(x => [
44+
faker.name.findName(),
45+
faker.internet.email(),
46+
faker.name.title(),
47+
]),
48+
language: frFR
49+
});
50+
`
51+
} />
52+
53+
:::tip
54+
You can find a list of supported languages here https://github.com/grid-js/gridjs/tree/master/packages/gridjs/src/i18n
55+
:::
56+
57+
Also, you can easily customize Grid.js messages and add your language. Simply extend the `language` config to replace the strings:
2258

2359
<LiveExample children={
2460
`
@@ -54,3 +90,5 @@ const grid = new Grid({
5490
:::tip
5591
See [en_US](https://github.com/grid-js/gridjs/blob/master/packages/gridjs/src/i18n/en_US.ts) for a full list of messages.
5692
:::
93+
94+

lib/liveExample.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import { Grid, html, h, createRef as gCreateRef, Component as gComponent, PluginPosition, BaseComponent } from "gridjs";
2+
import { esES, frFR } from "gridjs/dist/gridjs.lang.es";
23
import CodeBlock from "@theme/CodeBlock";
34
import React, {Component, useEffect, useRef} from "react";
45
import * as faker from 'faker';
@@ -25,7 +26,7 @@ function () {
2526
<div ref={wrapperRef} />
2627
);
2728
}
28-
` } live={true} scope={{ Grid, html, h, gCreateRef, gComponent, PluginPosition, BaseComponent, CodeBlock, useEffect, useRef, faker, ...this.props.scope }} />
29+
` } live={true} scope={{ Grid, html, h, gCreateRef, gComponent, PluginPosition, BaseComponent, CodeBlock, useEffect, useRef, faker, esES, frFR, ...this.props.scope }} />
2930
)
3031
}
3132
}

0 commit comments

Comments
 (0)