-
Notifications
You must be signed in to change notification settings - Fork 26.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
update with-react-intl example (#4817)
- Loading branch information
1 parent
0d93d42
commit 822cc3c
Showing
5 changed files
with
45 additions
and
50 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
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) { | ||
Object.keys(window.ReactIntlLocaleData).forEach((lang) => { | ||
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 | ||
const { locale, messages } = req || window.__NEXT_DATA__.props.pageProps | ||
|
||
return { pageProps, locale, messages } | ||
} | ||
|
||
render () { | ||
const { Component, pageProps, locale, messages } = this.props | ||
const now = Date.now() | ||
return ( | ||
<Container> | ||
<IntlProvider locale={locale} messages={messages} initialNow={now}> | ||
<Component {...pageProps} /> | ||
</IntlProvider> | ||
</Container> | ||
) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters