2018-03-05 11:46:13 +00:00
|
|
|
import { translate } from 'react-i18next'
|
2018-03-07 07:42:14 +00:00
|
|
|
import { getInitialProps, I18n } from '../i18n'
|
2018-03-05 11:46:13 +00:00
|
|
|
|
|
|
|
export const withI18next = (namespaces = ['common']) => ComposedComponent => {
|
2018-03-07 07:42:14 +00:00
|
|
|
const Extended = translate(namespaces, { i18n: 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)
|
|
|
|
: {}
|
|
|
|
|
|
|
|
const i18nInitialProps =
|
2018-03-07 07:42:14 +00:00
|
|
|
ctx.req && !process.browser ? getInitialProps(ctx.req, namespaces) : {}
|
2018-03-05 11:46:13 +00:00
|
|
|
|
|
|
|
return {
|
|
|
|
...composedInitialProps,
|
|
|
|
...i18nInitialProps
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return Extended
|
|
|
|
}
|