-
-
Notifications
You must be signed in to change notification settings - Fork 207
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Support Next.js 13 app-dir for server/client pages/components (#982)
* Support to Next.js 13 app-dir * Add tests + fix files * Add docs
- Loading branch information
Showing
32 changed files
with
431 additions
and
71 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
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
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,13 @@ | ||
# Complex example | ||
|
||
Similar than the basic example but with some extras: | ||
|
||
- TypeScript | ||
- Webpack 5 | ||
- MDX | ||
- With _app.js on top | ||
- Custom interpolation with ${thisFormat} instead of the {{defaultFormat}} | ||
- pages located on src/pages folder | ||
- Loading locales from src/translations with a different structure | ||
|
||
![next-translate](../../images/translation-prerendered.gif 'Translations in prerendered pages') |
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 @@ | ||
module.exports = { | ||
locales: ['en', 'ca', 'es'], | ||
defaultLocale: 'en', | ||
pages: { | ||
'*': ['common'], | ||
'/': ['home'], | ||
'/second-page': ['home'], | ||
}, | ||
} |
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,4 @@ | ||
{ | ||
"title": "Llibreria next-translate", | ||
"second-page": "Segona <0>pàgina</0>" | ||
} |
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 @@ | ||
{ | ||
"client-only": "Només al client" | ||
} |
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,4 @@ | ||
{ | ||
"title": "next-translate library", | ||
"second-page": "Second <0>page</0>" | ||
} |
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 @@ | ||
{ | ||
"client-only": "Only client-side" | ||
} |
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,4 @@ | ||
{ | ||
"title": "Librería next-translate", | ||
"second-page": "Segunda <0>página</0>" | ||
} |
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 @@ | ||
{ | ||
"client-only": "Sólo al lado del cliente" | ||
} |
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,5 @@ | ||
/// <reference types="next" /> | ||
/// <reference types="next/image-types/global" /> | ||
|
||
// NOTE: This file should not be edited | ||
// see https://nextjs.org/docs/basic-features/typescript for more information. |
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 @@ | ||
const nextTranslate = require('next-translate-plugin') | ||
|
||
module.exports = nextTranslate({ experimental: { appDir: true } }) |
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,31 @@ | ||
{ | ||
"name": "-", | ||
"version": "1.0.0", | ||
"private": true, | ||
"license": "MIT", | ||
"scripts": { | ||
"dev": "next dev", | ||
"build": "next build", | ||
"start": "next start", | ||
"analyze": "ANALYZE=true yarn build" | ||
}, | ||
"dependencies": { | ||
"@mdx-js/loader": "2.3.0", | ||
"@mdx-js/react": "2.3.0", | ||
"@next/mdx": "13.1.6", | ||
"next": "13.1.7-canary.11", | ||
"next-translate": "link:../../", | ||
"react": "link:../../node_modules/react", | ||
"react-dom": "link:../../node_modules/react-dom" | ||
}, | ||
"devDependencies": { | ||
"@next/bundle-analyzer": "13.1.6", | ||
"@types/node": "18.13.0", | ||
"@types/react": "18.0.28", | ||
"next-translate-plugin": "2.0.0", | ||
"typescript": "4.9.5" | ||
}, | ||
"resolutions": { | ||
"webpack": "5.11.1" | ||
} | ||
} |
Binary file not shown.
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 @@ | ||
export default function Head() { | ||
return ( | ||
<> | ||
<title>App dir</title> | ||
<meta content="width=device-width, initial-scale=1" name="viewport" /> | ||
<link rel="icon" href="/favicon.ico" /> | ||
</> | ||
) | ||
} |
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,12 @@ | ||
export default function RootLayout({ | ||
children, | ||
}: { | ||
children: React.ReactNode | ||
}) { | ||
return ( | ||
<html> | ||
<head /> | ||
<body>{children}</body> | ||
</html> | ||
) | ||
} |
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,31 @@ | ||
import Link from 'next/link' | ||
import useTranslation from 'next-translate/useTranslation' | ||
import ClientCode from '../components/client-code' | ||
|
||
export default function Page() { | ||
const { t, lang } = useTranslation('common') | ||
|
||
return ( | ||
<> | ||
<h1>{t('title')}</h1> | ||
|
||
<ClientCode /> | ||
|
||
<div style={{ marginTop: 20 }}> | ||
<Link href="/?lang=en">English</Link> | ||
</div> | ||
|
||
<div> | ||
<Link href="/?lang=es">Español</Link> | ||
</div> | ||
|
||
<div> | ||
<Link href="/?lang=ca">Català</Link> | ||
</div> | ||
|
||
<div> | ||
<Link href={`/second-page?lang=${lang}`}>➡️</Link> | ||
</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,16 @@ | ||
import Link from 'next/link' | ||
import useTranslation from 'next-translate/useTranslation' | ||
import Trans from 'next-translate/Trans' | ||
|
||
export default function Page() { | ||
const { t, lang } = useTranslation('common') | ||
return ( | ||
<> | ||
<h1>{t`title`}</h1> | ||
<Trans i18nKey="common:second-page" components={[<b />]} /> | ||
<div> | ||
<Link href={`/?lang=${lang}`}>⬅️</Link> | ||
</div> | ||
</> | ||
) | ||
} |
17 changes: 17 additions & 0 deletions
17
examples/with-app-directory/src/components/client-code.tsx
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,17 @@ | ||
'use client' | ||
import useTranslation from 'next-translate/useTranslation' | ||
import { useState } from 'react' | ||
|
||
export default function ClientCode() { | ||
const [count, setCount] = useState(0) | ||
const { t } = useTranslation('home') | ||
|
||
return ( | ||
<div> | ||
{t('client-only')}: | ||
<button onClick={() => setCount((v) => v + 1)}>+</button> | ||
{count} | ||
<button onClick={() => setCount((v) => v - 1)}>-</button> | ||
</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,27 @@ | ||
{ | ||
"compilerOptions": { | ||
"target": "es5", | ||
"lib": ["dom", "dom.iterable", "esnext"], | ||
"allowJs": true, | ||
"skipLibCheck": true, | ||
"strict": true, | ||
"noImplicitAny": true, | ||
"forceConsistentCasingInFileNames": true, | ||
"noEmit": true, | ||
"esModuleInterop": true, | ||
"module": "esnext", | ||
"moduleResolution": "node", | ||
"resolveJsonModule": true, | ||
"isolatedModules": true, | ||
"jsx": "preserve", | ||
"incremental": true, | ||
"plugins": [ | ||
{ | ||
"name": "next" | ||
} | ||
] | ||
}, | ||
"exclude": ["node_modules"], | ||
"include": ["next-env.d.ts", "**/*.ts", "**/*.tsx", ".next/types/**/*.ts"], | ||
"typeRoots": ["./src/mdx.d.ts"] | ||
} |
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
Oops, something went wrong.