Skip to content

Commit a42e746

Browse files
committed
translatr > 2.x.x with nested keys support
Examples added, readme updated
1 parent 3fb0bb2 commit a42e746

File tree

4 files changed

+50
-8
lines changed

4 files changed

+50
-8
lines changed

README.md

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -121,18 +121,26 @@ const store = createStore( combineReducers( reducers ) )
121121
...
122122
// Set dictionaries (simpliest example) -----------------------------------------------------------------------------------------------
123123

124-
// This dictionaries can be supported by Localization team without need to know somth about interface or project,
124+
// This dictionaries can be supported by Localization team without need to know somth about interface or project,
125125
// and you just can fetch it to your project
126126
const dictionaries = {
127127
'ru-RU': {
128128
'key_1': 'Первый дефолтный ключ',
129129
'key_2': [ '$Count', ' ', ['штучка','штучки','штучек']], // 1 штучка, 3 штучки, пять штучек
130+
'key_3': {
131+
'nested_1': 'Первый вложенный ключ',
132+
'nested_2': 'Второй вложенный ключ',
133+
},
130134
/* ... */
131135
/* Other keys */
132136
},
133137
'en-US': {
134138
'key_1': 'First default key',
135139
'key_2': [ '$Count', ' ', ['thing','things']], // 1 thing, 2 things, 153 things
140+
'key_3': {
141+
'nested_1': 'First nested key',
142+
'nested_2': 'Second nested key',
143+
},
136144
}
137145
/* ... */
138146
/* Other dictionaries */
@@ -174,6 +182,13 @@ import { Loc } from 'redux-react-i18n'
174182
<p>
175183
<Loc locKey="key_2" number={7}/> // => 7 штучек
176184
</p>
185+
186+
<p>
187+
<Loc locKey="key_3.nested_1"/> // => Первый вложенный ключ
188+
</p>
189+
<p>
190+
<Loc locKey="key_3.nested_2"/> // => Второй вложенный ключ
191+
</p>
177192
```
178193

179194
## If you don't want to use a complete solution:

example/src/app.js

Lines changed: 25 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -44,31 +44,51 @@ store.dispatch( i18nActions.setDictionaries(
4444
{
4545
'key_1': 'Первый дефолтный ключ из установленного нами словаря',
4646
'key_2': [ [ "Остался", "Осталось", "Осталось" ], " ", "$count", " ", [ "час", "часа", "часов" ] ],
47-
'key_3': 'Просто число после двоеточия: $Count'
47+
'key_3': 'Просто число после двоеточия: $Count',
48+
'key_4': {
49+
nested_1: 'Москва',
50+
nested_2: 'Санкт-Петербург'
51+
}
4852
},
4953
'en-US':
5054
{
5155
'key_1': 'First default key from our dictionary',
5256
'key_2': ["$count", " ", [ "hour", "hours"] ],
53-
'key_3': 'Number: $Count'
57+
'key_3': 'Number: $Count',
58+
'key_4': {
59+
nested_1: 'Moscow',
60+
nested_2: 'St. Petersburg'
61+
}
5462
},
5563
'pl':
5664
{
5765
'key_1': 'Prosze, dwa bilety drugiej klasy do Warszawy.',
5866
'key_2': [[ "Pozostała", "Pozostały", "Pozostało" ], " ", "$count", " ", [ "godzina", "godziny", "godzin" ] ],
59-
'key_3': 'Numer: $Count'
67+
'key_3': 'Numer: $Count',
68+
'key_4': {
69+
nested_1: 'Moskwa',
70+
nested_2: 'Petersburg'
71+
}
6072
},
6173
'fr':
6274
{
6375
'key_1': 'Ayant risqué une fois-on peut rester heureux toute la vie',
6476
'key_2': ["$count", " ", [ "heure", "heures"], " ", [ "restante", "restantes"] ],
65-
'key_3': 'Nombre: $Count'
77+
'key_3': 'Nombre: $Count',
78+
'key_4': {
79+
nested_1: 'Moscou',
80+
nested_2: 'St. Pétersbourg'
81+
}
6682
},
6783
'be':
6884
{
6985
'key_1': 'Адзін квіток да Мінска, калі ласка',
7086
'key_2': [ [ "Засталася", "Засталося", "Засталося" ], " ", "$count", " ", [ "гадзіна", "гадзіны", "гадзін" ] ],
71-
'key_3': 'Засталося: $Count'
87+
'key_3': 'Засталося: $Count',
88+
'key_4': {
89+
nested_1: 'Масква',
90+
nested_2: 'Санкт-Пецярбург'
91+
}
7292
}
7393
}
7494
) );

example/src/components/Texts.js

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,13 @@ const Texts = ( { count } ) => {
1717
<div>
1818
<h3><Loc locKey="key_3" number={count}/></h3>
1919
</div>
20+
21+
<div>
22+
<h3><Loc locKey="key_4.nested_1"/></h3>
23+
</div>
24+
<div>
25+
<h3><Loc locKey="key_4.nested_2"/></h3>
26+
</div>
2027
</div>
2128
}
2229

package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "redux-react-i18n",
3-
"version": "1.2.0",
3+
"version": "1.3.0",
44
"description": "i18n solution for react/redux",
55
"main": "lib/index.js",
66
"scripts": {
@@ -47,7 +47,7 @@
4747
"react": ">=16.0.0"
4848
},
4949
"dependencies": {
50-
"translatr": ">=1.0.0"
50+
"translatr": ">=2.1.0"
5151
},
5252
"jest": {
5353
"rootDir": "./tests",

0 commit comments

Comments
 (0)