Skip to content

Commit f3fe646

Browse files
update readme for i18n
1 parent fa477f7 commit f3fe646

File tree

1 file changed

+38
-1
lines changed

1 file changed

+38
-1
lines changed

README.md

+38-1
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@ For Production:
7070
- [ ] Redux-saga
7171
- [x] Jest
7272
- [x] Axios
73-
- [x] I18n [Not completed]
73+
- [x] I18n
7474
- [x] React-router
7575
- [x] Alias
7676
- [x] Hot reload
@@ -139,6 +139,43 @@ For Production:
139139

140140
_- You should use [BEM](http://getbem.com/) to write css without conflict_
141141

142+
- Using i18n
143+
144+
- Create new json file at `src/locales/resources/<file-name/>.json`
145+
- Add content follow this format into json file
146+
```javascript
147+
{
148+
"en": {
149+
"name": "Name"
150+
},
151+
"vi": {
152+
"name": "Tên"
153+
}
154+
}
155+
```
156+
- update `src/locales/resources/index.ts` like this:
157+
158+
```javascript
159+
/*
160+
* you can use other name instead `user`
161+
* this name will be used as path to key
162+
*/
163+
import user from './<file-name/>.json
164+
165+
const mergeResource: IResource = {
166+
..., // others json
167+
user
168+
};
169+
```
170+
171+
- Now inside any where, you can access to key like this:
172+
173+
```javascript
174+
const { t } = useTranslation()
175+
176+
t('user.name') will be render "Name" for `en` and "Tên" for `vi`
177+
```
178+
142179
---
143180

144181
## Tips

0 commit comments

Comments
 (0)