You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: README.md
+66-5Lines changed: 66 additions & 5 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -131,7 +131,7 @@ const mapStateToProps = state => ({
131
131
exportdefaultconnect(mapStateToProps)(Greeting);
132
132
```
133
133
134
-
For components not already using `connect` instead use [localize](#localizecomponent). This will automatically connect your component with the `translate` function and `currentLanguage` prop.
134
+
For components not already using `connect` instead use [localize](#localizecomponent-slice). This will automatically connect your component with the `translate` function and `currentLanguage` prop.
135
135
136
136
```javascript
137
137
import { localize } from'react-localize-redux';
@@ -204,6 +204,38 @@ Then pass in the data you want to swap in for placeholders to the `translate` fu
204
204
<h1>{ translate('info.greeting') }</h1>
205
205
```
206
206
207
+
### Pass multiple translations to child components
208
+
209
+
A parent component that has added the `translate` function by using [getTranslate](#gettranslatestate) or [localize](#localizecomponent-slice) can easily pass multiple translations down to it's child components. Just pass the `translate` function an array of translation keys instead of a single key.
210
+
211
+
```json
212
+
{
213
+
"heading": ["Heading", "Heading French"],
214
+
"article": {
215
+
"title": ["Title", "Title French"],
216
+
"author": ["By ${ name }", "By French ${ name }"],
If you have a larger app you may want to break your translation data up into multiple files, or maybe your translation data is being loaded from a service. Either way you can call [addTranslation](#addtranslationdata) for each new translation file/service, and the new translation data will be merged with any existing data.
@@ -216,12 +248,12 @@ Also If you are using a tool like [webpack](https://webpack.js.org) for bundling
216
248
217
249
A selector that takes the localeReducer slice of your `state` and returns the translate function. This function will have access to any and all translations that were added with [addTranslation](#addtranslationdata).
A selector that takes your redux `state` and returns the raw translation data.
329
+
330
+
### `localize(Component)`
270
331
271
332
If you have a Component that is not using `connect` you can wrap it with `localize` to automatically add the `translate` function and `currentLanguage` prop. When using `combineReducers` to add `localeReducer` you must pass the `slice` param to `localize`, where `slice` is the name of the prop you used with `combineReducers` (e.g. locale).
0 commit comments