-
Notifications
You must be signed in to change notification settings - Fork 29k
Add initial example for i18n routing #18206
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from 15 commits
Commits
Show all changes
18 commits
Select commit
Hold shift + click to select a range
c220da6
Add initial i18n documentation
ijjk 70d1617
Merge remote-tracking branch 'upstream/canary' into docs/i18n
ijjk 05c0ffe
Apply suggestions from code review
ijjk 85f2728
Apply suggestions from code review
ijjk ba0247c
Apply more suggestions
ijjk 43d53f5
rephrase a bit more
ijjk 5fd6a11
Merge remote-tracking branch 'upstream/canary' into docs/i18n
ijjk d554ed5
Merge remote-tracking branch 'upstream/canary' into docs/i18n
ijjk 0025388
Add initial example files
ijjk 053d2a9
Update doc
timneutkens 9390744
Merge branch 'canary' into docs/i18n
kodiakhq[bot] f2d39e2
Merge branch 'docs/i18n' of github.com:ijjk/next.js into docs/i18n
ijjk 59ab380
Merge remote-tracking branch 'upstream/canary' into docs/i18n
ijjk 31cc439
Merge remote-tracking branch 'upstream/canary' into example/i18n
ijjk 6f30287
Add example pages for i18n routing
ijjk 29069f1
Apply suggestions from review
ijjk 94bbcc2
Merge remote-tracking branch 'upstream/canary' into example/i18n
ijjk 9cc0e5f
Merge branch 'canary' into example/i18n
kodiakhq[bot] File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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,34 @@ | ||
# See https://help.github.com/articles/ignoring-files/ for more about ignoring files. | ||
|
||
# dependencies | ||
/node_modules | ||
/.pnp | ||
.pnp.js | ||
|
||
# testing | ||
/coverage | ||
|
||
# next.js | ||
/.next/ | ||
/out/ | ||
|
||
# production | ||
/build | ||
|
||
# misc | ||
.DS_Store | ||
*.pem | ||
|
||
# debug | ||
npm-debug.log* | ||
yarn-debug.log* | ||
yarn-error.log* | ||
|
||
# local env files | ||
.env.local | ||
.env.development.local | ||
.env.test.local | ||
.env.production.local | ||
|
||
# vercel | ||
.vercel |
This file contains hidden or 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,23 @@ | ||
# Internationalized Routing | ||
|
||
This example shows how to create internationalized pages using Next.js and the i18n routing feature. It shows a normal page, a non-dynamic `getStaticProps` page, a dynamic `getStaticProps` page, and a `getServerSideProps` page. | ||
|
||
For further documentation on this feature see the documentation [here](https://nextjs.org/docs/advanced-features/i18n-routing) | ||
|
||
## Deploy your own | ||
|
||
Deploy the example using [Vercel](https://vercel.com): | ||
|
||
[](https://vercel.com/import/project?template=https://github.com/vercel/next.js/tree/canary/examples/amp) | ||
|
||
## How to use | ||
|
||
Execute [`create-next-app`](https://github.com/vercel/next.js/tree/canary/packages/create-next-app) with [npm](https://docs.npmjs.com/cli/init) or [Yarn](https://yarnpkg.com/lang/en/docs/cli/create/) to bootstrap the example: | ||
|
||
```bash | ||
npx create-next-app --example i18n-routing i18n-app | ||
# or | ||
yarn create next-app --example i18n-routing i18n-app | ||
``` | ||
|
||
Deploy it to the cloud with [Vercel](https://vercel.com/import?filter=next.js&utm_source=github&utm_medium=readme&utm_campaign=next-example) ([Documentation](https://nextjs.org/docs/deployment)). |
This file contains hidden or 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,8 @@ | ||
module.exports = { | ||
experimental: { | ||
i18n: { | ||
locales: ['en', 'fr', 'nl'], | ||
defaultLocale: 'en', | ||
}, | ||
}, | ||
} |
This file contains hidden or 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,15 @@ | ||
{ | ||
"name": "amp", | ||
ijjk marked this conversation as resolved.
Show resolved
Hide resolved
|
||
"version": "1.0.0", | ||
"scripts": { | ||
"dev": "next", | ||
"build": "next build", | ||
"start": "next start" | ||
}, | ||
"dependencies": { | ||
"next": "latest", | ||
"react": "^16.7.0", | ||
"react-dom": "^16.7.0" | ||
}, | ||
"license": "MIT" | ||
} |
This file contains hidden or 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,59 @@ | ||
import Link from 'next/link' | ||
import { useRouter } from 'next/router' | ||
|
||
export default function GspPage(props) { | ||
const router = useRouter() | ||
const { defaultLocale, isFallback, query } = router | ||
|
||
if (isFallback) { | ||
return 'Loading...' | ||
} | ||
|
||
return ( | ||
<div> | ||
<h1>getServerSideProps page</h1> | ||
<p>Current slug: {query.slug}</p> | ||
<p>Current locale: {props.locale}</p> | ||
<p>Default locale: {defaultLocale}</p> | ||
<p>Configured locales: {JSON.stringify(props.locales)}</p> | ||
|
||
<Link href="/gsp"> | ||
<a>To getStaticProps page</a> | ||
</Link> | ||
<br /> | ||
|
||
<Link href="/gssp"> | ||
<a>To getServerSideProps page</a> | ||
</Link> | ||
<br /> | ||
|
||
<Link href="/"> | ||
<a>To index page</a> | ||
</Link> | ||
<br /> | ||
</div> | ||
) | ||
} | ||
|
||
export const getStaticProps = ({ locale, locales }) => { | ||
return { | ||
props: { | ||
locale, | ||
locales, | ||
}, | ||
} | ||
} | ||
|
||
export const getStaticPaths = ({ locales }) => { | ||
const paths = [] | ||
|
||
for (const locale of locales) { | ||
paths.push({ params: { slug: 'first' }, locale }) | ||
paths.push({ params: { slug: 'second' }, locale }) | ||
} | ||
|
||
return { | ||
paths, | ||
fallback: true, | ||
} | ||
} |
This file contains hidden or 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,40 @@ | ||
import Link from 'next/link' | ||
import { useRouter } from 'next/router' | ||
|
||
export default function GspPage(props) { | ||
const router = useRouter() | ||
const { defaultLocale } = router | ||
|
||
return ( | ||
<div> | ||
<h1>getServerSideProps page</h1> | ||
<p>Current locale: {props.locale}</p> | ||
<p>Default locale: {defaultLocale}</p> | ||
<p>Configured locales: {JSON.stringify(props.locales)}</p> | ||
|
||
<Link href="/gsp/first"> | ||
<a>To dynamic getStaticProps page</a> | ||
</Link> | ||
<br /> | ||
|
||
<Link href="/gssp"> | ||
<a>To getServerSideProps page</a> | ||
</Link> | ||
<br /> | ||
|
||
<Link href="/"> | ||
<a>To index page</a> | ||
</Link> | ||
<br /> | ||
</div> | ||
) | ||
} | ||
|
||
export const getStaticProps = ({ locale, locales }) => { | ||
return { | ||
props: { | ||
locale, | ||
locales, | ||
}, | ||
} | ||
} |
This file contains hidden or 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,40 @@ | ||
import Link from 'next/link' | ||
import { useRouter } from 'next/router' | ||
|
||
export default function GsspPage(props) { | ||
const router = useRouter() | ||
const { defaultLocale } = router | ||
|
||
return ( | ||
<div> | ||
<h1>getServerSideProps page</h1> | ||
<p>Current locale: {props.locale}</p> | ||
<p>Default locale: {defaultLocale}</p> | ||
<p>Configured locales: {JSON.stringify(props.locales)}</p> | ||
|
||
<Link href="/gsp"> | ||
<a>To getStaticProps page</a> | ||
</Link> | ||
<br /> | ||
|
||
<Link href="/gsp/first"> | ||
<a>To dynamic getStaticProps page</a> | ||
</Link> | ||
<br /> | ||
|
||
<Link href="/"> | ||
<a>To index page</a> | ||
</Link> | ||
<br /> | ||
</div> | ||
) | ||
} | ||
|
||
export const getServerSideProps = ({ locale, locales }) => { | ||
return { | ||
props: { | ||
locale, | ||
locales, | ||
}, | ||
} | ||
} |
This file contains hidden or 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,31 @@ | ||
import Link from 'next/link' | ||
import { useRouter } from 'next/router' | ||
|
||
export default function IndexPage(props) { | ||
const router = useRouter() | ||
const { locale, locales, defaultLocale } = router | ||
|
||
return ( | ||
<div> | ||
<h1>Index page</h1> | ||
<p>Current locale: {locale}</p> | ||
<p>Default locale: {defaultLocale}</p> | ||
<p>Configured locales: {JSON.stringify(locales)}</p> | ||
|
||
<Link href="/gsp"> | ||
<a>To getStaticProps page</a> | ||
</Link> | ||
<br /> | ||
|
||
<Link href="/gsp/first"> | ||
<a>To dynamic getStaticProps page</a> | ||
</Link> | ||
<br /> | ||
|
||
<Link href="/gssp"> | ||
<a>To getServerSideProps page</a> | ||
</Link> | ||
<br /> | ||
</div> | ||
) | ||
} |
This file contains hidden or 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 |
---|---|---|
|
@@ -15826,9 +15826,10 @@ [email protected]: | |
postcss "^7.0.2" | ||
postcss-load-plugins "^2.3.0" | ||
|
||
[email protected]: | ||
version "3.3.0" | ||
resolved "https://registry.yarnpkg.com/styled-jsx/-/styled-jsx-3.3.0.tgz#32335c1a3ecfc923ba4f9c056eeb3d4699006b09" | ||
[email protected]: | ||
version "3.3.1" | ||
resolved "https://registry.yarnpkg.com/styled-jsx/-/styled-jsx-3.3.1.tgz#d79f306c42c99cefbe8e76f35dad8100dc5c9ecc" | ||
integrity sha512-RhW71t3k95E3g7Zq3lEBk+kmf+p4ZME7c5tfsYf9M5mq6CgIvFXkbvhawL2gWriXLRlMyKAYACE89Qa2JnTqUw== | ||
dependencies: | ||
"@babel/types" "7.8.3" | ||
babel-plugin-syntax-jsx "6.18.0" | ||
|
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.