Server-render locale lang and JSON-LD inLanguage on localized pages

Merged
EL
3d ago
+491-146

Localized landing URLs such as /de and /pt-BR now server-render <html lang> for that locale. English pages stay en.

The [locale] segment sits under the root layout, so the layout cannot read it as a param. Proxy derives x-landing-locale from the public path (and drops a client-supplied value on other URLs). The root layout uses that header for lang and for the site-wide JSON-LD graph.

On a localized landing page:

  • WebSite and SoftwareApplication get inLanguage set to the locale (de, pt-BR, zh-CN, and the rest).
  • WebSite.url is the localized home (https://www.getinboxzero.com/de).
  • Organization.url stays the company homepage. There is no WebPage node in this graph.
  • The client script in BasicLayout that set document.documentElement.lang is removed. The client provider still updates lang on client navigations and for the app locale cookie.

English /, /home, and /pricing stay prerendered (dynamic = "force-static"). Localized landing routes are server-rendered on demand, because the root layout has to read the request. Other routes that render this layout and do not opt into static rendering are on demand as well.

Validation:

  • Unit tests for the locale header, proxy matcher, and JSON-LD graph.
  • next build (typecheck included).
  • Production next start: / is prerendered with lang="en" and no inLanguage. /de, /fr, /pt-BR, and /zh-CN respond with the matching lang, inLanguage, and localized WebSite.url. The old document.documentElement.lang script is gone.
Open in Web Open in Cursor 

Summary by CodeRabbit

  • Improvements
    • English landing pages, including home, pricing, login, and brand pages, are prerendered for faster delivery.
    • Localized landing pages display the appropriate language in page metadata and search-engine information.
    • Document requests are handled across a wider range of page routes; static and image asset routes are excluded.
    • Markdown responses are available for the home and pricing pages.
  • Bug Fixes
    • English requests no longer retain a client-supplied landing locale, while localized requests use the locale in their URL.