Skip to content

Commit 2cbd9a9

Browse files
Merge pull request #19 from netlify/i18n
feat: i18n
2 parents fe18c64 + a11c57f commit 2cbd9a9

File tree

11 files changed

+28
-16
lines changed

11 files changed

+28
-16
lines changed

demo/components/Header.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
export default function Header() {
2-
return <h1>header</h1>
2+
return <h1>Next Demo!</h1>
33
}

demo/next.config.js

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,12 @@
11
module.exports = {
2+
// Configurable site features we support:
3+
// distDir: 'build',
24
generateBuildId: () => 'build-id',
3-
// Configurable site features to support:
4-
// i18n: {
5-
// defaultLocale: 'en',
6-
// locales: ['en', 'es', 'fr']
7-
// },
5+
i18n: {
6+
defaultLocale: 'en',
7+
locales: ['en', 'es', 'fr']
8+
},
9+
// trailingSlash: true,
10+
// Configurable site features _to_ support:
811
// basePath: '/docs',
9-
// distDir: 'build',
1012
}

demo/pages/404.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
export default function Custom404() {
2+
return <h1>Custom 404 - Page Not Found</h1>
3+
}

demo/pages/500.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
export default function Custom500() {
2+
return <h1>Custom 500 - Server-side error occurred</h1>
3+
}

demo/pages/index.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,12 @@
11
import Link from 'next/link'
2+
import dynamic from 'next/dynamic'
3+
const Header = dynamic(() => import(/* webpackChunkName: 'header' */ '../components/Header'), { ssr: true })
24

35
const Index = ({ shows }) => (
46
<div>
57
<img src="/next-on-netlify.png" alt="NextJS on Netlify Banner" style={{ maxWidth: '100%' }} />
8+
9+
<Header/>
610

711
<h1>NextJS on Netlify</h1>
812
<p>

demo/public/favicon.ico

-14.7 KB
Binary file not shown.

demo/public/next-on-netlify.png

37.3 KB
Loading

demo/public/vercel.svg

Lines changed: 0 additions & 4 deletions
This file was deleted.

src/helpers/config.js

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ const getNetlifyRoutes = (nextRoute) => {
5151
return netlifyRoutes
5252
}
5353

54-
exports.generateRedirects = async ({ netlifyConfig, basePath }) => {
54+
exports.generateRedirects = async ({ netlifyConfig, basePath, i18n }) => {
5555
const { dynamicRoutes } = await readJSON(join(netlifyConfig.build.publish, 'prerender-manifest.json'))
5656

5757
const redirects = []
@@ -76,9 +76,12 @@ exports.generateRedirects = async ({ netlifyConfig, basePath }) => {
7676
redirects.push(...getNetlifyRoutes(route), ...getNetlifyRoutes(dataRoute))
7777
})
7878

79+
// Needed only for /_next/static
80+
const i18nSplat = i18n ? '/:locale' : ''
81+
7982
// This is only used in prod, so dev uses `next dev` directly
8083
netlifyConfig.redirects.push(
81-
{ from: `${basePath}/_next/static/*`, to: '/static/:splat', status: 200 },
84+
{ from: `${basePath}${i18nSplat}/_next/static/*`, to: `${i18nSplat}/static/:splat`, status: 200 },
8285
{
8386
from: `${basePath}/*`,
8487
to: HANDLER_FUNCTION_PATH,

src/index.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ module.exports = {
4242

4343
checkNextSiteHasBuilt({ publish, failBuild })
4444

45-
const { images, target, appDir, basePath } = await getNextConfig({ publish, failBuild })
45+
const { appDir, basePath, i18n, images, target } = await getNextConfig({ publish, failBuild })
4646

4747
setBundler({ netlifyConfig, target })
4848

@@ -59,6 +59,7 @@ module.exports = {
5959
await generateRedirects({
6060
netlifyConfig,
6161
basePath,
62+
i18n,
6263
})
6364
},
6465

test/__snapshots__/index.js.snap

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -72,9 +72,9 @@ Array [
7272
"to": "/404.html",
7373
},
7474
Object {
75-
"from": "/_next/static/*",
75+
"from": "/:locale/_next/static/*",
7676
"status": 200,
77-
"to": "/static/:splat",
77+
"to": "/:locale/static/:splat",
7878
},
7979
Object {
8080
"conditions": Object {

0 commit comments

Comments
 (0)