Skip to content

Commit 6a80c49

Browse files
committed
[fixes #300] Add flat translation table usage example
1 parent 9ff6d2a commit 6a80c49

File tree

3 files changed

+1332
-1695
lines changed

3 files changed

+1332
-1695
lines changed

README.md

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -287,13 +287,24 @@ The first event in the above example will move the card `Buy Milk` from the plan
287287
Pass translation function to provide custom or localized texts:
288288
289289
```javascript
290+
291+
// If your translation table is flat
292+
//
293+
// For example: { 'placeholder.title': 'some text' }
290294
const customTranslation = (key) => TRANSLATION_TABLE[key]
291295

296+
// If your translation table has nested hashes (provided translations table is it)
297+
//
298+
// For example: { 'placeholder': { 'title': 'some text' } }
299+
import { createTranslate } from 'react-trello'
300+
const customTranslation = createTranslate(TRANSLATION_TABLE)
301+
292302
<Board t={customTranslation} .../>
293303
```
294304
295305
List of available keys - [locales/en/translation.json](https://github.com/rcdexta/react-trello/blob/master/locales/en/translation.json)
296306
307+
297308
### react-i18next example
298309
299310
```javascript

stories/I18n.story.js

Lines changed: 45 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -8,25 +8,6 @@ import createTranslate from 'rt/helpers/createTranslate'
88

99
const smallData = require('./data/data-sort')
1010

11-
const TEXTS = {
12-
"Add another lane": "NEW LANE",
13-
"Click to add card": "Click to add card",
14-
"Delete lane": "Delete lane",
15-
"Lane actions": "Lane actions",
16-
"button": {
17-
"Add lane": "Add lane",
18-
"Add card": "Add card",
19-
"Cancel": "Cancel"
20-
},
21-
"placeholder": {
22-
"title": "title",
23-
"description": "description",
24-
"label": "label"
25-
}
26-
}
27-
28-
const customTranslation = createTranslate(TEXTS)
29-
3011
const I18nBoard = () => {
3112
const { t } = useTranslation()
3213
return (
@@ -41,12 +22,55 @@ const I18nBoard = () => {
4122
}
4223

4324
storiesOf('I18n', module)
44-
.addDecorator(story => <I18nextProvider i18n={i18n}>{story()}</I18nextProvider>)
4525
.add(
4626
'Custom texts',
47-
() => <Board data={smallData} t={customTranslation} editable canAddLanes draggable /> ,
27+
() => {
28+
29+
const TEXTS = {
30+
"Add another lane": "NEW LANE",
31+
"Click to add card": "Click to add card",
32+
"Delete lane": "Delete lane",
33+
"Lane actions": "Lane actions",
34+
"button": {
35+
"Add lane": "Add lane",
36+
"Add card": "Add card",
37+
"Cancel": "Cancel"
38+
},
39+
"placeholder": {
40+
"title": "title",
41+
"description": "description",
42+
"label": "label"
43+
}
44+
}
45+
46+
const customTranslation = createTranslate(TEXTS)
47+
return <Board data={smallData} t={customTranslation} editable canAddLanes draggable />
48+
},
4849
{info: 'Have custom text titles'}
4950
)
51+
.add(
52+
'Flat translation table',
53+
() => {
54+
const FLAT_TRANSLATION_TABLE = {
55+
"Add another lane": "+ Weitere Liste erstellen",
56+
"Click to add card": "Klicken zum Erstellen einer Karte",
57+
"Delete lane": "Liste löschen",
58+
"Lane actions": "Listenaktionen",
59+
"button.Add lane": "Liste hinzufügen",
60+
"button.Add card": "Karte hinzufügen",
61+
"button.Cancel": "Abbrechen",
62+
"placeholder.title": "Titel",
63+
"placeholder.description": "Beschreibung",
64+
"placeholder.label": "Label"
65+
};
66+
67+
return <Board data={smallData} t={key => FLAT_TRANSLATION_TABLE[key]} editable canAddLanes draggable />
68+
},
69+
{info: 'Flat translation table'}
70+
)
71+
72+
storiesOf('I18n', module)
73+
.addDecorator(story => <I18nextProvider i18n={i18n}>{story()}</I18nextProvider>)
5074
.add(
5175
'Using i18next',
5276
() => <I18nBoard /> ,

0 commit comments

Comments
 (0)