Skip to content

Commit

Permalink
Support for universal apps / server-side rendering
Browse files Browse the repository at this point in the history
- Add `loadNamespaces` method that iterates through components, discovering and loading namespaces that are declared using `@translate`
- Add `namespaces` property to `Translate` wrapper returned by `@translate`.
  • Loading branch information
Kevin Mitchell committed Mar 30, 2016
1 parent 507f027 commit d7d21f4
Show file tree
Hide file tree
Showing 6 changed files with 2,293 additions and 265 deletions.
22 changes: 22 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -114,3 +114,25 @@ function TranslatableView(props) {
</div>
)
}
```

### Universal Rendering

__loadNamespaces__: Function that will pre-load all namespaces used by your components. Works well with `react-router` `match` function

__props__:

- components: Components that need to have namespaces loaded.
- i18n: the i18n instance to load translations into

```javascript
import { I18nextProvider, loadNamespaces } from 'react-i18next';
import { match } from 'react-router';

match({...matchArguments}, (error, redirectLocation, renderProps) => {
loadNamespaces({ ...renderProps, i18n: i18nInstance })
.then(()=>{
// All i18n namespaces required to render this route are loaded
})
});
```
Loading

0 comments on commit d7d21f4

Please sign in to comment.