-
-
Notifications
You must be signed in to change notification settings - Fork 217
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
docs: Example and docs for legacy Next.js versions (#1284)
Related to #1282
- Loading branch information
Showing
13 changed files
with
453 additions
and
69 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 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
module.exports = { | ||
env: { | ||
node: true | ||
}, | ||
parserOptions: { | ||
sourceType: 'module' | ||
}, | ||
extends: [ | ||
'molindo/javascript', | ||
'molindo/react', | ||
'plugin:@next/next/recommended' | ||
], | ||
rules: { | ||
'react/prop-types': 'off' | ||
} | ||
}; |
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,3 @@ | ||
/node_modules | ||
/.next/ | ||
.DS_Store |
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,9 @@ | ||
# example-pages-router-legacy | ||
|
||
This example is used to track legacy support of `next-intl` with Next.js and React. | ||
|
||
## Deploy your own | ||
|
||
By deploying to [Vercel](https://vercel.com), you can check out the example in action. Note that you'll be prompted to create a new GitHub repository as part of this, allowing you to make subsequent changes. | ||
|
||
[![Deploy with Vercel](https://vercel.com/button)](https://vercel.com/new/clone?repository-url=https://github.com/amannn/next-intl/tree/main/examples/example-pages-router-legacy) |
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,6 @@ | ||
{ | ||
"Index": { | ||
"title": "Home", | ||
"description": "This is the home page." | ||
} | ||
} |
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,6 @@ | ||
module.exports = { | ||
i18n: { | ||
defaultLocale: 'en', | ||
locales: ['en'] | ||
} | ||
}; |
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,21 @@ | ||
{ | ||
"name": "example-pages-router-legacy", | ||
"private": true, | ||
"scripts": { | ||
"dev": "next dev", | ||
"lint": "eslint src", | ||
"build": "next build", | ||
"start": "next start" | ||
}, | ||
"dependencies": { | ||
"next": "^12.0.0", | ||
"use-intl": "latest", | ||
"react": "^17.0.0", | ||
"react-dom": "^17.0.0" | ||
}, | ||
"devDependencies": { | ||
"eslint": "^8.56.0", | ||
"eslint-config-molindo": "^7.0.0", | ||
"eslint-config-next": "^14.2.4" | ||
} | ||
} |
Binary file not shown.
18 changes: 18 additions & 0 deletions
18
examples/example-pages-router-legacy/src/components/PageLayout.js
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,18 @@ | ||
export default function PageLayout({children, title}) { | ||
return ( | ||
<> | ||
<div | ||
style={{ | ||
padding: 24, | ||
fontFamily: 'system-ui, sans-serif', | ||
lineHeight: 1.5 | ||
}} | ||
> | ||
<div style={{maxWidth: 510}}> | ||
<h1>{title}</h1> | ||
{children} | ||
</div> | ||
</div> | ||
</> | ||
); | ||
} |
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,22 @@ | ||
import Head from 'next/head'; | ||
import {useRouter} from 'next/router'; | ||
import {IntlProvider} from 'use-intl'; | ||
|
||
export default function App({Component, pageProps}) { | ||
const router = useRouter(); | ||
const {messages, now, ...rest} = pageProps; | ||
|
||
return ( | ||
<IntlProvider | ||
locale={router.locale} | ||
messages={messages} | ||
now={new Date(now)} | ||
timeZone="Europe/Vienna" | ||
> | ||
<Head> | ||
<title>example-pages-router-legacy</title> | ||
</Head> | ||
<Component {...rest} /> | ||
</IntlProvider> | ||
); | ||
} |
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,27 @@ | ||
import {useFormatter, useNow, useTranslations} from 'use-intl'; | ||
import PageLayout from '../components/PageLayout'; | ||
|
||
export default function Index() { | ||
const t = useTranslations('Index'); | ||
const format = useFormatter(); | ||
const now = useNow(); | ||
|
||
return ( | ||
<PageLayout title={t('title')}> | ||
<p>{t('description')}</p> | ||
<p>{format.dateTime(now)}</p> | ||
</PageLayout> | ||
); | ||
} | ||
|
||
export async function getStaticProps(context) { | ||
return { | ||
props: { | ||
now: new Date().toISOString(), | ||
// You can get the messages from anywhere you like. The recommended | ||
// pattern is to put them in JSON files separated by locale and read | ||
// the desired one based on the `locale` received from Next.js. | ||
messages: (await import(`../../messages/${context.locale}.json`)).default | ||
} | ||
}; | ||
} |
Oops, something went wrong.