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
A `<Proivider />` component which purpose is to provide the translations down the component tree.
17
19
20
+
##### `value: { [key: string]: string }`
21
+
Sets the current translations.
22
+
23
+
## `FetchingProvider`
24
+
A special `<Provider />` which can load translations from remote URL via a `GET` request and pass them down the component tree.
25
+
26
+
_**Note:** This Provider requires [fetch](https://developer.mozilla.org/en-US/docs/Web/API/Fetch_API) and [Promise](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Promise) APIs to be available on the `global` object in order to work properly. If you use this library in an older browser environment, please include the required polyfills._
27
+
28
+
##### `url: string`
29
+
An URL where text translations can be found. Whenever this prop changes, a new `GET /props.url` call will be made.
30
+
31
+
##### `blocking?: boolean`
32
+
Controls the rendering flow. When set to `true` it blocks the rendering of the component subtree until translations fetching is complete.
Applies a `transform` on the response received when `GET /props.url` finished. It comes handy in situation when the given `url` doesn't return translations in the expected format.
37
+
38
+
##### `onFetchingStart?: () => void`
39
+
An optional fetching lifecycle method. Invoked just before `GET /props.url` is executed.
40
+
41
+
##### `onFetchingEnd?: () => void`
42
+
An optional fetching lifecycle method. Invoked just after `GET /props.url` response is received.
43
+
44
+
##### `onFetchingError?: (e?: Error) => void`
45
+
An optional fetching lifecycle method. Invoked when error occurs during fetching/processing stage.
46
+
47
+
## `withMessages`
48
+
Creates a higher order component and provides the [ComponentAPI](#ComponentAPI) as `props`. It can be used in two ways:
49
+
50
+
##### `withMessages(Component)`
51
+
Wraps the given `Component` and passes down the [ComponentAPI](#ComponentAPI).
Similar like the example above, but in a curried format. Useful when decorating a `Component` with many higher order components:
55
+
```js
56
+
compose(
57
+
connect(mapStateToProps, mapDispatchToProps),
58
+
withRouter,
59
+
withMessages,
60
+
)(Component)
61
+
```
62
+
Additionally, the curried form of `withMessages` accepts an optional `keyPefix` which will be prepended before any translation lookup key (see the examples below). This feature comes quite useful when i18n-ing scoped presentational components.
Will retrieve a translation message specified by the given `key` with all indexed placeholders replaced according to the values given in the `params` array. See the examples below for more information.
Will retrieve a translation message specified by the given `key` with all named placeholders replaced according to the entries given in the `namedParams` object. See the examples below for more information.
80
+
81
+
## `propTypes`
82
+
Exposes the [ComponentAPI](#ComponentApi) as standard `prop-types` definition.
0 commit comments