2018-08-24 07:49:10 +00:00
|
|
|
import { translate } from 'react-i18next'
|
|
|
|
import i18n from '../i18n'
|
2018-03-05 11:46:13 +00:00
|
|
|
|
|
|
|
export const withI18next = (namespaces = ['common']) => ComposedComponent => {
|
2018-08-24 07:49:10 +00:00
|
|
|
const Extended = translate(namespaces, { i18n, wait: process.browser })(
|
2018-03-05 11:46:13 +00:00
|
|
|
ComposedComponent
|
|
|
|
)
|
|
|
|
|
|
|
|
Extended.getInitialProps = async (ctx) => {
|
|
|
|
const composedInitialProps = ComposedComponent.getInitialProps
|
|
|
|
? await ComposedComponent.getInitialProps(ctx)
|
|
|
|
: {}
|
|
|
|
|
2018-08-20 06:31:24 +00:00
|
|
|
const i18nInitialProps = ctx.req
|
2018-08-24 07:49:10 +00:00
|
|
|
? i18n.getInitialProps(ctx.req, namespaces)
|
|
|
|
: {}
|
2018-03-05 11:46:13 +00:00
|
|
|
|
|
|
|
return {
|
|
|
|
...composedInitialProps,
|
|
|
|
...i18nInitialProps
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return Extended
|
|
|
|
}
|