Skip to content
Merged
Show file tree
Hide file tree
Changes from 4 commits
Commits
Show all changes
378 commits
Select commit Hold shift + click to select a range
b301d47
Improve docs
amannn Feb 13, 2023
436b0bb
Use `.ts` extension where possible in the docs
amannn Feb 14, 2023
53beb17
Use `.ts` extension in examples where possible
amannn Feb 14, 2023
63b279a
One more `tsx` -> `ts`
amannn Feb 14, 2023
f0bceeb
3.0.0-beta.1
amannn Feb 14, 2023
643af24
Revert "3.0.0-beta.1"
amannn Feb 14, 2023
a78b375
Add `use client` to `usePathname` so `NextIntlClientProvider` can sti…
wxh06 Feb 14, 2023
1df0996
2.11.0-beta.9
amannn Feb 14, 2023
70be9b0
Keep search params in middleware
amannn Feb 14, 2023
7c0d88b
2.11.0-beta.10
amannn Feb 14, 2023
bc41740
Add test for new API routes
amannn Feb 16, 2023
5d6ce8a
Use latest stable version of Next.js
amannn Feb 16, 2023
026691e
Use canary with support for new metadata API
amannn Feb 16, 2023
695c65b
Fix path in server-components.mdx (#191)
Tobi-mmt Feb 16, 2023
9b564f9
fix: Handle invalid `accept-language` header gracefully (#192)
CptCompiler Feb 17, 2023
5a6434a
Improve docs
amannn Feb 17, 2023
1deee08
2.11.0-beta.12
amannn Feb 17, 2023
7a76d2b
Default to disabling prefetching in `Link` when a `locale` is passed …
amannn Feb 19, 2023
9c843c9
Add image example and add clarification for `public` folder to docs
amannn Feb 19, 2023
5af108c
2.11.0-beta.13
amannn Feb 19, 2023
6878636
Add test for localized API routes in latest beta
amannn Feb 19, 2023
42c1155
Remove `api` from matcher
amannn Feb 19, 2023
e0bd177
fix: Add tests to ensure links work and downgrade Next.js (#196)
amannn Feb 19, 2023
f55424a
feat: Return alternate language links as headers from middleware (#195)
amannn Feb 19, 2023
8fc47fd
2.11.0-beta.15
amannn Feb 19, 2023
7dc5011
Merge remote-tracking branch 'origin/main' into feat/next-13-rsc
amannn Feb 19, 2023
f849669
Styling improvements for RSC docs
amannn Feb 19, 2023
629b3f4
Merge remote-tracking branch 'origin/main' into feat/next-13-rsc
amannn Feb 19, 2023
2aee5ea
Minor wording fixes
amannn Feb 19, 2023
531caaa
Merge remote-tracking branch 'origin/main' into feat/next-13-rsc
amannn Feb 20, 2023
1e77472
Fix not-found example
amannn Feb 21, 2023
6bae9cf
Fix build
amannn Feb 21, 2023
3d25ca5
Improve middleware docs
amannn Feb 21, 2023
c8566d6
Add docs about localized rewrites
amannn Feb 21, 2023
298dea8
Wording
amannn Feb 21, 2023
9112475
Gracefully handle invalid locales saved in the cookie
amannn Feb 21, 2023
b5cd0da
Named routes example for localized pathnames
amannn Feb 21, 2023
ab59451
Improve link
amannn Feb 21, 2023
1b2f3b2
Improve styling for callouts
amannn Feb 22, 2023
984a47a
docs: Improve landing page design (#200)
amannn Feb 22, 2023
dfa82ef
chore: Upgrade to Next.js 13.2 (#201)
amannn Feb 27, 2023
fc861f6
2.11.0-beta.16
amannn Feb 27, 2023
0eaeefa
Landing page finetuning
amannn Feb 27, 2023
b2f9112
Code samples for features on landing page
amannn Feb 27, 2023
bc1a5a6
Improve landing page
amannn Feb 28, 2023
ed64e22
Improve phrasing of landing page
amannn Feb 28, 2023
e351444
Add number example to landing page
amannn Feb 28, 2023
a52a74d
Add caching docs and test
amannn Mar 2, 2023
e076182
feat: Improve landing page design (#207)
amannn Mar 3, 2023
335243d
Merge remote-tracking branch 'origin/main' into feat/next-13-rsc
amannn Mar 3, 2023
f24919a
chore: Rebase Next.js 13 RSC (#211)
amannn Mar 6, 2023
87e77db
Merge remote-tracking branch 'origin/main' into feat/next-13-rsc
amannn Mar 6, 2023
a608512
v2.12.0-alpha.1
amannn Mar 6, 2023
b6f720a
v2.12.0-beta.1
amannn Mar 6, 2023
94e0a37
2.12.0-beta.1
amannn Mar 6, 2023
42a9b79
Include deprecation warning for `useIntl` in RSC
amannn Mar 6, 2023
c8b61b5
Simplify code snippet and get rid of tailwind warning
amannn Mar 6, 2023
9d2e025
Compile to ES2019
amannn Mar 10, 2023
2e9288e
2.12.0-beta.2
amannn Mar 10, 2023
cc6c9b8
feat: Next.js 13 RSC middleware improvements (#212)
amannn Mar 13, 2023
1ae18c1
[email protected]
amannn Mar 13, 2023
666c1df
feat: Improve named routes implementation (#213)
amannn Mar 14, 2023
0472497
Export `getFormatter`
amannn Mar 14, 2023
fe46d95
2.12.0-beta.4
amannn Mar 14, 2023
3d7cc1d
feat: Improve locale detection for prefixed routing (#214)
amannn Mar 14, 2023
b965568
2.12.0-beta.5
amannn Mar 14, 2023
7315a41
Merge remote-tracking branch 'origin/main' into feat/next-13-rsc
amannn Mar 15, 2023
8a30f81
Link to article on Smashing Magazine
amannn Mar 17, 2023
d60e63f
Improve wording about usage in Client Components
amannn Mar 17, 2023
17b245e
Improve error message for static rendering
amannn Mar 17, 2023
89e90e2
Upgrade example-next-13-with-pages to latest Next.js version
amannn Mar 17, 2023
79d95cc
Add Vercel Analytics
amannn Mar 21, 2023
93ccd0a
Fix typo (thanks to @frans-slabbekoorn!)
amannn Apr 3, 2023
36ae25d
feat: Next.js 13 RSC Domain middleware improvements (#223)
amannn Apr 5, 2023
f089e33
Merge remote-tracking branch 'origin/main' into feat/next-13-rsc
amannn Apr 5, 2023
da97714
v2.13.0-beta.1
amannn Apr 5, 2023
eb4fd67
Wording & latest beta
amannn Apr 5, 2023
dfb33fa
Fix link
amannn Apr 5, 2023
30232d6
Improve code samples
amannn Apr 5, 2023
cf87920
Use type-signatures from client-side in Server Component hooks to ens…
amannn Apr 6, 2023
bce9480
Include note about locales support in Polyfill.io (h/t to @alvarlager…
amannn Apr 6, 2023
5e3fb47
`localeDetection: false` should ignore the cookie too
amannn Apr 6, 2023
f7ce3ea
v2.13.0-beta.2
amannn Apr 6, 2023
7cc3b6c
2.13.0-beta.2
amannn Apr 6, 2023
21e9eae
Wording
amannn Apr 6, 2023
018c65b
Merge remote-tracking branch 'origin/main' into feat/next-13-rsc
amannn Apr 7, 2023
52195be
Add Google site verification to docs
amannn Apr 11, 2023
1c65538
Add sitemap
amannn Apr 11, 2023
b06d985
Static sitemap domain
amannn Apr 11, 2023
5ae58bb
chore: Rebase Next.js 13 RSC integration (#239)
amannn Apr 12, 2023
3e30b7b
Merge remote-tracking branch 'origin/main' into feat/next-13-rsc
amannn Apr 12, 2023
de5115c
fix: Fix type signature of the plugin and improve condition for print…
Apr 13, 2023
a8cf8f9
Merge remote-tracking branch 'origin/main' into feat/next-13-rsc
amannn Apr 13, 2023
f215760
Merge remote-tracking branch 'origin/main' into feat/next-13-rsc
amannn Apr 14, 2023
d60307b
Unnecessary destructuring
amannn Apr 14, 2023
d177b69
Merge remote-tracking branch 'origin/main' into feat/next-13-rsc
amannn Apr 27, 2023
c49dc2f
Fix lockfile
amannn Apr 27, 2023
a08b91b
feat: Improvements for localized `Link` (#257)
amannn Apr 27, 2023
84dc3b3
Merge remote-tracking branch 'origin/main' into feat/next-13-rsc
amannn May 2, 2023
bb9c7c2
Single playwright version
amannn May 2, 2023
b844b1a
Merge remote-tracking branch 'origin/main' into feat/next-13-rsc
amannn May 3, 2023
344762f
Update next and playwright to match versions
amannn May 3, 2023
7435a61
Merge remote-tracking branch 'origin/main' into feat/next-13-rsc-reba…
amannn May 4, 2023
3f64a4f
Fix playwright install
amannn May 4, 2023
61e200b
Distinct ports
amannn May 4, 2023
dd9aa33
Merge remote-tracking branch 'origin/main' into feat/next-13-rsc-reba…
amannn May 4, 2023
782d103
Update Next.js for newer examples
amannn May 4, 2023
25b22e4
Skip broken test
amannn May 4, 2023
4b8b6ba
Update lockfile
amannn May 4, 2023
b0f8d6e
chore: Rebase RSC (#272)
amannn May 4, 2023
23f44e2
fix(Next.js 13 RSC): Improvements for routing APIs (#277)
amannn May 9, 2023
73149e0
Merge remote-tracking branch 'origin/main' into feat/next-13-rsc
amannn May 9, 2023
504f5f7
Merge remote-tracking branch 'origin/main' into feat/next-13-rsc-reba…
amannn May 10, 2023
0ffb615
Fix lint
amannn May 10, 2023
f18e467
Remove unused files
amannn May 10, 2023
1b03065
feat(Next.js 13 RSC): Rebase (#284)
amannn May 10, 2023
e249b82
Merge remote-tracking branch 'origin/main' into feat/next-13-rsc-reba…
amannn May 10, 2023
918a7a4
Merge remote-tracking branch 'origin/main' into feat/next-13-rsc
amannn May 11, 2023
72f37b6
Merge remote-tracking branch 'origin/main' into feat/next-13-rsc
amannn May 12, 2023
46b0122
Add workaround to example-next-13-advanced to enable soft navigation …
amannn May 15, 2023
fa98d0f
Improve error message for calling hooks in async components
amannn May 15, 2023
d490c28
Merge remote-tracking branch 'origin/main' into feat/next-13-rsc
amannn May 22, 2023
4b61c06
feat(RSC): Add support for `redirect` in Client Components
amannn May 25, 2023
a325557
Merge remote-tracking branch 'origin/main' into feat/next-13-rsc-redi…
amannn May 25, 2023
2dff0b6
Fix tests
amannn May 25, 2023
b483109
Disable test for now [skip ci]
amannn May 25, 2023
5d1ac85
feat(RSC): Add support for `redirect` in Client Components (#308)
amannn May 25, 2023
8523dba
Make config passed to plugin optional
amannn May 27, 2023
017fd93
feat(RSC): Add CDN caching patch (#311)
amannn May 27, 2023
6e95b4b
Merge remote-tracking branch 'origin/main' into feat/next-13-rsc
amannn May 27, 2023
04bd7bd
Move patch
amannn May 27, 2023
335afcf
Remove patch
amannn May 27, 2023
b219e13
Merge remote-tracking branch 'origin/main' into feat/next-13-rsc
amannn Jun 20, 2023
808acab
Fix error when no config is provided
amannn Jun 20, 2023
0f3116b
feat: New APIs for using `next-intl` outside of components (#339)
amannn Jun 22, 2023
b405e61
Merge remote-tracking branch 'origin/main' into feat/next-13-rsc
amannn Jun 22, 2023
26f8d19
Merge remote-tracking branch 'origin/main' into feat/next-13-rsc
amannn Jun 23, 2023
873dc59
refactor: Switch to a string argument for the `locale` that is passed…
amannn Jun 23, 2023
16c8388
Merge remote-tracking branch 'origin/main' into feat/next-13-rsc
amannn Jun 29, 2023
bdbb558
Merge remote-tracking branch 'origin/main' into feat/next-13-rsc
amannn Jun 29, 2023
e6b3efb
Fix lockfile
amannn Jun 29, 2023
ca0cfe7
Fix TS
amannn Jun 29, 2023
cae306a
Merge remote-tracking branch 'origin/main' into feat/next-13-rsc
amannn Jun 30, 2023
3071d01
Update lockfile
amannn Jun 30, 2023
14aa6e8
Merge remote-tracking branch 'origin/main' into feat/next-13-rsc
amannn Jun 30, 2023
25c747a
Add retries for tests (Chrome dies occasionally)
amannn Jun 30, 2023
6f601a5
chore(Next.js 13 RSC): Switch to tsup for bundling
amannn Jun 30, 2023
e4b2275
Revert "chore(Next.js 13 RSC): Switch to tsup for bundling"
amannn Jun 30, 2023
fd1587b
Fix types when importing from `next-intl/server` with `moduleResoluti…
amannn Jun 30, 2023
4e7766b
chore(Next.js 13 RSC): Switch to `tsup` for bundling and `vitest` for…
amannn Jul 3, 2023
9c9bc8d
Merge remote-tracking branch 'origin/main' into feat/next-13-rsc
amannn Jul 4, 2023
1d66aec
Update links to docs
amannn Jul 4, 2023
4d5ee43
Merge remote-tracking branch 'origin/main' into feat/next-13-rsc
amannn Jul 4, 2023
7fa1424
Update lockfile
amannn Jul 4, 2023
7a6e0a6
Merge remote-tracking branch 'origin/main' into feat/next-13-rsc
amannn Jul 5, 2023
8a3946c
Merge remote-tracking branch 'origin/main' into feat/next-13-rsc
amannn Jul 5, 2023
41900d7
chore: Rebase RSC on `main` (#385)
amannn Jul 7, 2023
610c665
Merge remote-tracking branch 'origin/main' into feat/next-13-rsc
amannn Jul 11, 2023
22fe5d9
Upgrade TypeScript for new examples
amannn Jul 11, 2023
b423baa
fix(RSC): Return `string` from `(await getTranslator()).rich` (#395)
amannn Jul 11, 2023
add3e94
Merge remote-tracking branch 'origin/main' into feat/next-13-rsc
amannn Jul 17, 2023
f0ae6ce
Opengraph example
amannn Jul 19, 2023
e8ece99
Merge remote-tracking branch 'origin/main' into feat/next-13-rsc
amannn Jul 19, 2023
2c7ac92
Fix tests
amannn Jul 19, 2023
a371d39
refactor(RSC): Clean up package boundaries (#387)
amannn Jul 26, 2023
a2f3553
Use built-in RSC serialization for `now`
amannn Jul 26, 2023
4297a19
Merge remote-tracking branch 'origin/main' into feat/next-13-rsc
amannn Aug 24, 2023
dbc06d1
Fix lint
amannn Aug 24, 2023
e343ce0
Fix test
amannn Aug 24, 2023
f408d92
feat: Add built-in pathname localization (#426)
amannn Aug 25, 2023
0197a6f
Publish `navigation.d.ts`
amannn Aug 28, 2023
d4eee0d
Don't require `i18n.ts` for `next start`
amannn Aug 29, 2023
0e7835b
Fix return type of plugin
amannn Aug 29, 2023
e475cb2
feat(RSC): Optimize bundle size (#489)
amannn Sep 1, 2023
3481a59
fix: Allow unknown routes in localized pathnames navigation APIs (#493)
jlalmes Sep 5, 2023
ab48fd2
Merge remote-tracking branch 'origin/main' into feat/next-13-rsc
amannn Sep 7, 2023
37c131b
fix(RSC): Always read header in RSC render (#506)
amannn Sep 14, 2023
6c8eb13
Improve error handling when calling `redirect` on the client side
amannn Sep 15, 2023
0a089b8
Add comment why we don't provide a default `locale` for `NextIntlClie…
amannn Sep 15, 2023
0aa60ad
Increase bundle threshold
amannn Sep 15, 2023
106c098
feat(RSC): Better error handling for missing context (#508)
amannn Sep 15, 2023
50cd7ee
feat(RSC): Add `getPathname` for localized navigation (#510)
amannn Sep 18, 2023
7358907
docs(RSC): Update Next.js to 13.5.1 (#512)
amannn Sep 20, 2023
6836f20
feat(RSC): Experimental SSG (#509)
amannn Sep 21, 2023
3f85ffa
Merge remote-tracking branch 'origin/main' into feat/next-13-rsc
amannn Sep 21, 2023
975a1c0
Fix docs build
amannn Sep 21, 2023
b732305
Merge remote-tracking branch 'origin/main' into feat/next-13-rsc
amannn Sep 21, 2023
2bf4aef
Merge remote-tracking branch 'origin/main' into feat/next-13-rsc
amannn Sep 22, 2023
5a2b503
Increase size limit
amannn Sep 22, 2023
9697c3c
feat(RSC): Add defaults for `locale`, `now` and `timeZone` for `NextI…
amannn Sep 22, 2023
4f93607
fix(RSC): Remove pages router import and require explicit `locale` wh…
amannn Sep 22, 2023
54ddd45
Remove outdated named routes example
amannn Sep 22, 2023
d98a549
Update error message for static rendering
amannn Sep 25, 2023
38252e7
Upgrade to [email protected]
amannn Sep 25, 2023
ee25914
Improve error when middleware didn't match the request
amannn Sep 25, 2023
549dc17
feat(RSC): Remove deprecations and RSC-first docs (#522)
amannn Sep 28, 2023
4c42f52
Merge remote-tracking branch 'origin/main' into feat/next-13-rsc
amannn Sep 28, 2023
6bafe4e
Improve error handling docs
amannn Sep 28, 2023
e98e181
as-necessary -> as-needed
amannn Sep 28, 2023
07f8186
Add deep dive about RSC implementation
amannn Sep 28, 2023
a463263
Add note about how unstable_setRequestLocale works
amannn Sep 29, 2023
65d9212
Remove mentions of `createServerContext`
amannn Oct 1, 2023
efb5046
Improve hint in regard to `error.tsx`
amannn Oct 2, 2023
5c1bac3
Add note about when to call `unstable_setRequestLocale`
amannn Oct 3, 2023
214d8e7
Merge remote-tracking branch 'origin/main' into feat/next-13-rsc
amannn Oct 9, 2023
7f6365a
Fix redirect for requests for the default locale when prefixed at the…
amannn Oct 9, 2023
d133fd6
Update issue commenter template [skip ci]
amannn Oct 9, 2023
7582d4c
Merge remote-tracking branch 'origin/main' into feat/next-13-rsc
amannn Oct 9, 2023
2b7a0d6
Use non-nullable return type for `useMessages` by throwing if there a…
amannn Oct 9, 2023
631d12d
Update sizes
amannn Oct 9, 2023
fb80bd1
Clarify browser support
amannn Oct 10, 2023
c037a40
Fix tests
amannn Oct 10, 2023
fc4101b
Merge remote-tracking branch 'origin/main' into feat/next-13-rsc
amannn Oct 11, 2023
defa4b2
Remove more deprecations
amannn Oct 14, 2023
dbec9f3
Improve error message for missing context due to latest changes from …
amannn Oct 14, 2023
3522b43
Update tests
amannn Oct 15, 2023
7fd084f
Leave error messages in server-only code after production build, remo…
amannn Oct 16, 2023
d1b398d
fix(RSC): Fixed the search not being added on localized pathname redi…
BrendonSled Oct 18, 2023
1b2ed7d
Merge remote-tracking branch 'origin/main' into feat/next-13-rsc
amannn Oct 18, 2023
7f54ec2
Merge remote-tracking branch 'origin/main' into feat/next-13-rsc
amannn Oct 19, 2023
581c16b
feat(RSC): Add `t.markup` and unify function signature of `t.rich` (#…
amannn Oct 19, 2023
371203b
Merge remote-tracking branch 'origin/main' into feat/next-13-rsc
amannn Oct 19, 2023
f050808
Improve docs for missing middleware
amannn Oct 19, 2023
61b2bce
fix(RSC): Use `webpackConfig.context` instead of `process.cwd()` to d…
amannn Oct 25, 2023
0bcca2d
Merge remote-tracking branch 'origin/main' into feat/next-13-rsc
amannn Nov 2, 2023
ccf3810
Merge remote-tracking branch 'origin/main' into feat/next-13-rsc
amannn Nov 2, 2023
064c692
Merge remote-tracking branch 'origin/main' into feat/next-13-rsc
amannn Nov 3, 2023
49fce7c
Add note about localizing pathnames with a CMS [skip ci]
amannn Nov 3, 2023
633e07d
refactor(RSC): Refactor async APIs to make the locale optional (#600)
amannn Nov 7, 2023
abf54c3
fix(RSC): RSC bug fixes (#604)
amannn Nov 7, 2023
47d7c16
Latest RC
amannn Nov 7, 2023
59bdea3
Update docs:
amannn Nov 7, 2023
fd4b6a5
docs(RSC): Add Server Actions demo (#606)
amannn Nov 8, 2023
78bdcaa
docs: Add note on `force-static`
amannn Nov 8, 2023
e8c9818
docs: Fix typos, include more background info on `unstable_setRequest…
amannn Nov 9, 2023
286c96c
fix(RSC): Fix type of `namespace` in `getTranslations` (#616)
amannn Nov 9, 2023
3d2ccc1
Merge remote-tracking branch 'origin/main' into feat/next-13-rsc
amannn Nov 9, 2023
763c69a
Remove unused import in docs
amannn Nov 9, 2023
4c5e5aa
docs: Add links for dynamic rendering
amannn Nov 9, 2023
1b21dbf
Update banner and blog post
amannn Nov 10, 2023
f63bbfc
Add meta description and title for twitter
amannn Nov 10, 2023
e17b9db
Fix link
amannn Nov 10, 2023
2c88df3
docs: Add example for additional rewrites in middleware
amannn Nov 12, 2023
a0a1f04
Avoid re-rendering of context consumers if possible
amannn Nov 13, 2023
f542802
docs: Sync pathnames tabs in docs
amannn Nov 14, 2023
c7b2626
docs: Various fixes
amannn Nov 14, 2023
2ccb247
feat(RSC): Various fixes (#623)
amannn Nov 14, 2023
1603a34
Update blog post
amannn Nov 14, 2023
acf9698
docs: Update links
amannn Nov 14, 2023
b65d5d8
Merge branch 'feat/next-13-rsc-v3_final_FINAL' into feat/next-13-rsc
amannn Nov 14, 2023
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion docs/next.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ module.exports = withNextra({
},
{
source: '/examples',
destination: '/examples/minimal',
destination: '/examples/next-13',
permanent: false
},

Expand Down
10 changes: 10 additions & 0 deletions docs/pages/blog/index.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@ Failed attempts at writing docs that somehow turned into blog posts.

## Community links

Resources on `next-intl` created by and for the community.

<div className="flex flex-col gap-4 py-8">
<CommunityLink
href="https://www.smashingmagazine.com/2023/03/internationalization-nextjs-13-react-server-components/"
Expand All @@ -24,6 +26,14 @@ Failed attempts at writing docs that somehow turned into blog posts.
target="_blank"
type="article"
/>
<CommunityLink
href="https://buttercms.com/blog/nextjs-localization/"
title="Next.js Localization: How to Build a Multilingual Website with next-intl"
date="Nov 4, 2021"
author="By Nirmalya Ghosh for ButterCMS"
target="_blank"
type="article"
/>
<CommunityLink
href="https://www.thisdot.co/blog/next-js-adding-localization-with-next-intl"
title="Next.js: Adding Localization with next-intl"
Expand Down
10 changes: 6 additions & 4 deletions docs/pages/blog/translations-outside-of-react-components.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ title: How (not) to use translations outside of React components

Have you ever wondered why `next-intl` doesn’t provide an API to consume translations outside of React components?

The traditional way is to use the `useTranslations` hook.
The traditional way to internationalize your app with `next-intl` is to use the `useTranslations` hook:

```tsx
import {useTranslations} from 'next-intl';
Expand Down Expand Up @@ -34,8 +34,10 @@ import {addMinutes} from 'date-fns';
function sendFeedback() {
// ❌ Bad implementation: Returns formatted messages
API.sendFeedback().catch((error) => {
// In case of a gateway timeout, notify the
// user that we'll try again in 5 minutes
if (error.status === 504) {
// Notify the user that we'll try again in 5 minutes
// (let's assume `t` is defined here for the sake of the example)
return t('timeout', {nextAttempt: addMinutes(new Date(), 5)});
}
});
Expand Down Expand Up @@ -107,7 +109,7 @@ Additionally, this approach is more robust to possibly unexpected states, like t

## The exception that proves the rule

If you’re working with Next.js, you might like to translate i18n messages in [API routes](https://nextjs.org/docs/api-routes/introduction), [Route Handlers](https://beta.nextjs.org/docs/routing/route-handlers) or the [Metadata API](https://beta.nextjs.org/docs/api-reference/metadata).
If you’re working with Next.js, you might want to translate i18n messages in [API routes](https://nextjs.org/docs/api-routes/introduction), [Route Handlers](https://beta.nextjs.org/docs/routing/route-handlers) or the [Metadata API](https://beta.nextjs.org/docs/api-reference/metadata).

`next-intl` provides a [core library](/docs/usage/core-library) that is agnostic from React and can be used for these cases.

Expand All @@ -133,6 +135,6 @@ There's currently a proposal to further simplify this use case, by offering a se

If you’ve been working with React for a longer time, you might have experienced the change [from `component{DidMount,DidUpdate,WillUnmount}` to `useEffect`](https://legacy.reactjs.org/docs/hooks-effect.html#explanation-why-effects-run-on-each-update). The reason why `useEffect` is superior is because it nudges the developer into a direction where the app is always in sync and by doing this, a whole array of potential issues just magically disappear.

By limiting ourselves to only format messages during render, we're in a similar situation: The rendered output of translated messages is always in sync with app state.
By limiting ourselves to only format messages during render, we're in a similar situation: The rendered output of translated messages is always in sync with app state and we can rely on the app being consistent.

Related: ["How can I reuse messages?" in the structuring messages docs](/docs/usage/messages#structuring-messages)
3 changes: 2 additions & 1 deletion docs/pages/docs/next-13/_meta.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,6 @@
"index": "Getting started",
"client-components": "Client Components",
"server-components": "Server Components (beta)",
"middleware": "Middleware"
"middleware": "Middleware",
"navigation": "Navigation"
}
48 changes: 0 additions & 48 deletions docs/pages/docs/next-13/client-components.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -121,54 +121,6 @@ If you've encountered an issue, you can [explore the code for a working example]
version](/docs/next-13/server-components).
</Callout>

## Linking between pages

In the `pages` folder, Next.js automatically considers the current locale for `next/link`. Since this is no longer the case for the `app` directory, you can add a component that wraps `next/link` accordingly as a drop-in replacement.

```tsx filename="Link.tsx"
import {useLocale} from 'next-intl';
import NextLink from 'next/link';
import {ComponentProps, forwardRef} from 'react';

type Props = ComponentProps<typeof NextLink>;

function Link({href, ...rest}: Props, ref: Props['ref']) {
const locale = useLocale();

// Turn this off, to avoid updating the locale cookie for prefetch requests
const prefetch = false;

function getLocalizedHref(originalHref: string) {
return originalHref.replace(/^\//, '/' + locale + '/');
}

const localizedHref =
typeof href === 'string'
? getLocalizedHref(href)
: href.pathname != null
? {...href, pathname: getLocalizedHref(href.pathname)}
: href;

return (
<NextLink ref={ref} href={localizedHref} prefetch={prefetch} {...rest} />
);
}

export default forwardRef(Link);
```

```tsx
// Usage while being on `/en`
<Link href="/">Goes to `/en`</Link>
<Link href="/nested">Goes to `/en/nested`</Link>
<Link href={{pathname: "/nested"}}>Goes to `/en/nested`</Link>
```

<Callout>
Built-in support for i18n routing APIs is being considered (see [the Server
Components beta docs](/docs/next-13/server-components#routing)).
</Callout>

## Usage with the Metadata API

To provide metadata for a route, you can use the [core library](/docs/usage/core-library) from `next-intl`.
Expand Down
4 changes: 2 additions & 2 deletions docs/pages/docs/next-13/index.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ To fill in the gaps and to leverage the new capabilities, `next-intl` now suppor
<Card
arrow
icon={<LinkIcon />}
title="Localized routing APIs (beta)"
href="/docs/next-13/server-components#routing"
title="Localized navigation APIs"
href="/docs/next-13/navigation"
/>
</Cards>
2 changes: 1 addition & 1 deletion docs/pages/docs/next-13/middleware.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -199,7 +199,7 @@ module.exports = withNextIntl({

Since `next-intl` isn't aware of the rewrites you've configured, you likely want to make some adjustments:

1. Translate the pathnames you're passing to routing APIs like `Link` based on the `locale`. See the [named routes example](https://github.com/amannn/next-intl/blob/feat/next-13-rsc/packages/example-next-13-named-routes/) that uses the proposed [routing APIs from the Server Components beta](http://localhost:3000/docs/next-13/server-components#routing).
1. Translate the pathnames you're passing to [navigation APIs](/docs/next-13/navigation) like `Link` based on the `locale`. See the [named routes example](https://github.com/amannn/next-intl/blob/feat/next-13-rsc/packages/example-next-13-named-routes/) that uses the proposed APIs from [the Server Components beta](http://localhost:3000/docs/next-13/server-components).
2. Turn off [the `alternateLinks` option](/docs/next-13/middleware#disable-alternate-links) and provide [search engine hints about localized versions of your content](https://developers.google.com/search/docs/specialty/international/localized-versions) by yourself.

## Composing other middlewares
Expand Down
71 changes: 71 additions & 0 deletions docs/pages/docs/next-13/navigation.mdx
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
import Callout from 'components/Callout';

# Next.js 13 internationalized navigation

`next-intl` provides drop-in replacements for common Next.js navigation APIs that automatically handle the user locale behind the scenes.

### `Link`

This component wraps `next/link` and automatically prefixes the `href` with the current locale as necessary. If the default locale is matched, the `href` remains unchanged and no prefix is added.

```tsx
import {Link} from 'next-intl';

// When the user is on `/en`, the link will point to `/en/about`
<Link href="/about">About</Link>

// You can override the `locale` to switch to another language
<Link href="/" locale="de">Switch to German</Link>
```

### `useRouter`

If you need to navigate programmatically, e.g. in response to a form submission, `next-intl` provides a convience API that wraps `useRouter` from Next.js and automatically applies the locale of the user.

```tsx
'use client';

import {useRouter} from 'next-intl/client';

const router = useRouter();

// When the user is on `/en`, the router will navigate to `/en/about`
router.push('/about');
```

### `usePathname`

To retrieve the pathname without a potential locale prefix, you can call `usePathname`.

```tsx
'use client';

import {usePathname} from 'next-intl/client';

// When the user is on `/en`, this will be `/`
const pathname = usePathname();
```

### `redirect`

<Callout type="warning">
This API is only available in [the Server Components
beta](/docs/next-13/server-components).
</Callout>

If you want to interrupt the render of a Server Component and redirect to another page, you can invoke the `redirect` function from `next-intl/server`. This wraps [the `redirect` function from Next.js](https://beta.nextjs.org/docs/api-reference/redirect) and automatically applies the current locale.

```tsx {1, 8}
import {redirect} from 'next-intl/server';

export default async function Profile() {
const user = await fetchUser();

if (!user) {
// When the user is on `/en/profile`, this will be `/en/login`
redirect('/login');
}

// ...
}
```
72 changes: 7 additions & 65 deletions docs/pages/docs/next-13/server-components.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -167,71 +167,6 @@ If you've encountered an issue, you can [explore the code for a working example]

If you're in a transitioning phase, either from the `pages` directory to the `app` directory, or from Client Components to the Server Components beta, you can apply [`NextIntlClientProvider`](/docs/next-13/client-components) additionally ([example](https://github.com/amannn/next-intl/tree/feat/next-13-rsc/packages/example-next-13-with-pages)).

## Routing

`next-intl` provides drop-in replacements for common Next.js routing APIs that automatically handle the user locale behind the scenes.

### `Link`

`next-intl` provides a drop-in replacement for `next/link` that will automatically prefix the `href` with the current locale as necessary. If the default locale is matched, the `href` remains unchanged and no prefix is added.

```tsx
import {Link} from 'next-intl';

// When the user is on `/en`, the link will point to `/en/about`
<Link href="/about">About</Link>

// You can override the `locale` to switch to another language
<Link href="/" locale="de">Switch to German</Link>
```

### `useRouter`

If you need to navigate programmatically (e.g. in response to a form submission), `next-intl` provides a convience API that wraps `useRouter` from Next.js and automatically applies the locale of the user.

```tsx
'use client';

import {useRouter} from 'next-intl/client';

const router = useRouter();

// When the user is on `/en`, the router will navigate to `/en/about`
router.push('/about');
```

### `usePathname`

To retrieve the pathname without a potential locale prefix, you can call `usePathname`.

```tsx
'use client';

import {usePathname} from 'next-intl/client';

// When the user is on `/en`, this will be `/`
const pathname = usePathname();
```

### `redirect`

If you want to interrupt the render of a Server Component and redirect to another page, you can invoke the `redirect` function from `next-intl/server`. This wraps [the `redirect` function from Next.js](https://beta.nextjs.org/docs/api-reference/redirect) and automatically applies the current locale.

```tsx {1, 8}
import {redirect} from 'next-intl/server';

export default async function Profile() {
const user = await fetchUser();

if (!user) {
// When the user is on `/en/profile`, this will be `/en/login`
redirect('/login');
}

// ...
}
```

## Using translations in Client Components

If you need to use translations or other functionality from `next-intl` in Client Components, the best approach is to pass the labels as props or `children` from a Server Component.
Expand Down Expand Up @@ -395,6 +330,8 @@ import {
} from 'next-intl/server';
```

Note however that the `useTranslations` hook is the primary API to translate messages in your app. Related: [How (not) to use translations outside of React components](/blog/translations-outside-of-react-components)

## CDN caching

Since `next-intl` is currently SSR-only, it's a good idea to use [CDN caching](https://vercel.com/docs/concepts/edge-network/caching#stale-while-revalidate) via [`headers`](https://nextjs.org/docs/api-reference/next.config.js/headers) in `next.config.js` to get the same level of performance from dynamic rendering as you'd get from static rendering ([learn more](https://youtu.be/bfLFHp7Sbkg?t=490)). Also note that [the Next.js Cache](https://nextjs.org/blog/next-13-2#nextjs-cache) improves the performance for dynamically rendered pages.
Expand Down Expand Up @@ -435,6 +372,11 @@ module.exports = withNextIntl({
});
```

<Callout type="warning">
Unfortunately, this doesn't work anymore in Next.js 13.4. An alternative is
being investigated.
</Callout>

## Providing feedback

If you have feedback about using `next-intl` in the `app` directory, feel free to leave feedback in [the PR which implements the React Server Components support](https://github.com/amannn/next-intl/pull/149).
8 changes: 6 additions & 2 deletions docs/pages/examples/_meta.json
Original file line number Diff line number Diff line change
@@ -1,10 +1,14 @@
{
"next-13": {
"title": "App Router",
"theme": {"layout": "full"}
},
"minimal": {
"title": "Minimal setup",
"title": "Pages Router",
"theme": {"layout": "full"}
},
"advanced": {
"title": "Advanced usage",
"title": "Pages Router (advanced)",
"theme": {"layout": "full"}
}
}
4 changes: 2 additions & 2 deletions docs/pages/examples/advanced.mdx
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
---
title: Advanced usage
title: Pages Router (advanced)
full: true
---

import CodeSandbox from '../../components/CodeSandbox';

<CodeSandbox
title="Advanced usage"
title="Pages Router (advanced)"
src="https://codesandbox.io/s/github/amannn/next-intl/tree/main/examples/example-advanced?file=/src/pages/index.tsx"
/>
4 changes: 2 additions & 2 deletions docs/pages/examples/minimal.mdx
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
---
title: Minimal setup
title: Pages Router
full: true
---

import CodeSandbox from '../../components/CodeSandbox';

<CodeSandbox
title="Minimal setup"
title="Pages Router"
src="https://codesandbox.io/s/github/amannn/next-intl/tree/main/examples/example?file=/src/pages/index.tsx"
/>
11 changes: 11 additions & 0 deletions docs/pages/examples/next-13.mdx
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
---
title: App Router
full: true
---

import CodeSandbox from '../../components/CodeSandbox';

<CodeSandbox
title="App Router"
src="https://codesandbox.io/s/github/amannn/next-intl/tree/main/examples/example-next-13?file=/src/app/[locale]/page.tsx"
/>
2 changes: 1 addition & 1 deletion examples/example-next-13-advanced/playwright.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import type {PlaywrightTestConfig} from '@playwright/test';
import {devices} from '@playwright/test';

// Use a distinct port on CI to avoid conflicts during concurrent tests
const PORT = process.env.CI ? 3001 : 3000;
const PORT = process.env.CI ? 3003 : 3000;

const config: PlaywrightTestConfig = {
testDir: './tests',
Expand Down
2 changes: 1 addition & 1 deletion examples/example-next-13-named-routes/playwright.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import type {PlaywrightTestConfig} from '@playwright/test';
import {devices} from '@playwright/test';

// Use a distinct port on CI to avoid conflicts during concurrent tests
const PORT = process.env.CI ? 3003 : 3000;
const PORT = process.env.CI ? 3004 : 3000;

const config: PlaywrightTestConfig = {
testDir: './tests',
Expand Down
Loading