2018-07-21 23:37:25 +00:00
|
|
|
import App, { Container } from 'next/app'
|
|
|
|
import React from 'react'
|
|
|
|
import { IntlProvider, addLocaleData } from 'react-intl'
|
|
|
|
|
|
|
|
// Register React Intl's locale data for the user's locale in the browser. This
|
|
|
|
// locale data was added to the page by `pages/_document.js`. This only happens
|
|
|
|
// once, on initial page load in the browser.
|
|
|
|
if (typeof window !== 'undefined' && window.ReactIntlLocaleData) {
|
2018-12-17 16:34:32 +00:00
|
|
|
Object.keys(window.ReactIntlLocaleData).forEach(lang => {
|
2018-07-21 23:37:25 +00:00
|
|
|
addLocaleData(window.ReactIntlLocaleData[lang])
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
|
|
|
export default class MyApp extends App {
|
|
|
|
static async getInitialProps ({ Component, router, ctx }) {
|
|
|
|
let pageProps = {}
|
|
|
|
|
|
|
|
if (Component.getInitialProps) {
|
|
|
|
pageProps = await Component.getInitialProps(ctx)
|
|
|
|
}
|
|
|
|
|
|
|
|
// Get the `locale` and `messages` from the request object on the server.
|
|
|
|
// In the browser, use the same values that the server serialized.
|
|
|
|
const { req } = ctx
|
2018-09-02 21:53:43 +00:00
|
|
|
const { locale, messages } = req || window.__NEXT_DATA__.props
|
2018-12-12 10:02:36 +00:00
|
|
|
const initialNow = Date.now()
|
2018-07-21 23:37:25 +00:00
|
|
|
|
2018-12-12 10:02:36 +00:00
|
|
|
return { pageProps, locale, messages, initialNow }
|
2018-07-21 23:37:25 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
render () {
|
2018-12-12 10:02:36 +00:00
|
|
|
const { Component, pageProps, locale, messages, initialNow } = this.props
|
2018-07-23 22:43:57 +00:00
|
|
|
|
2018-07-21 23:37:25 +00:00
|
|
|
return (
|
|
|
|
<Container>
|
2018-12-17 16:34:32 +00:00
|
|
|
<IntlProvider
|
|
|
|
locale={locale}
|
|
|
|
messages={messages}
|
|
|
|
initialNow={initialNow}
|
|
|
|
>
|
2018-07-21 23:37:25 +00:00
|
|
|
<Component {...pageProps} />
|
|
|
|
</IntlProvider>
|
|
|
|
</Container>
|
|
|
|
)
|
|
|
|
}
|
|
|
|
}
|