Skip to content

docs: enable static rendering in the Next.js next-intl guide - #1160

Merged
Anty0 merged 3 commits into
tolgee:mainfrom
AnderiPopescu:docs/next-intl-static-rendering
Dec 4, 2026
Merged

Anty0 merged 3 commits into
tolgee:mainfrom
AnderiPopescu:docs/next-intl-static-rendering

Conversation

@AnderiPopescu

Copy link
Copy Markdown
Contributor

Fixes the guide side of tolgee/tolgee-js#3526.

Problem

In the App Router with next-intl guide, the layout calls getTolgee(), which resolves the locale with next-intl's getLocale(). Without setRequestLocale(locale), next-intl reads the locale from request headers, so every route under the layout is forced into dynamic rendering:

Route /[locale]/… with `dynamic = "error"` couldn't be rendered statically because it used `headers()`.

TolgeeProvider is not the cause: with the provider removed but getTolgee() kept, the error remains. Without getTolgee(), the provider renders statically.

Changes

  • Layout: call setRequestLocale(locale) before getTolgee(), and add generateStaticParams
  • New "Static rendering" section: every page that uses getTranslate() must call setRequestLocale too, because layouts and pages render independently. With it only in the layout, such a page still fails.
  • src/i18n/request.ts: return locale. The current { messages: { locale } } doesn't type-check with next-intl 4 (RequestConfig requires locale).

Verified

Built with @tolgee/react / @tolgee/web 7.3.0, next 16.2.12, next-intl 4.13.7, React 19:

Setup next build
Guide as written ❌ used headers()
This PR ✅ SSG; /en renders "Hello world!", /cs renders "Ahoj světe!"

getTolgee() and getTranslate() resolve the locale with next-intl's
getLocale(), which falls back to reading request headers unless
setRequestLocale() was called. That opts every route under the layout
into dynamic rendering (tolgee/tolgee-js#3526).

- Call setRequestLocale() in the layout and add generateStaticParams
- Add a "Static rendering" section: pages using getTranslate() must
  call setRequestLocale() too
- Return `locale` from i18n/request.ts, which next-intl 4 requires

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@netlify

netlify Bot commented Oct 23, 2026 •

Copy link
Copy Markdown

👷 Deploy request for tolgee-docs pending review.

Visit the deploys page to approve it

Name Link
🔨 Latest commit a5c9b00

Anty0 added 2 commits December 4, 2026 18:27
- rename the section to "Rendering Pages Statically" and open it with what to do
- call setRequestLocale in every layout and page, also for getTolgee and the server T component
- load messages/*.json through staticData in src/tolgee/shared.ts
- note that static pages hold build-time translations and how revalidate refreshes them
- link the section from the App router guide and the Next.js overview

@Anty0 Anty0 left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the PR! ^^

@Anty0
Anty0 enabled auto-merge (squash) December 4, 2026 17:34
@Anty0
Anty0 merged commit 19cb61c into tolgee:main Dec 4, 2026
2 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants