Next.js 13.4 set HTML lang attribute dynamically

Hi,

the HTML tag is written in layout.js. The lang attribute must be set there. For example <html lang=“en” …>
I only know after fetching data (from a CMS) which language the current page content has.

Example:
URL: /summer/sports/golf
This URL is sent to an API in page.js. The result provides me with all information about the content, metadata, language, etc.

However, I don’t know how to use the result to set the HTML attribute “lang”.
In the layout.js I (unfortunately) obviously don’t have access to the current URL, so I can’t do a fetch there either.

I use the new App Router.

This topic was automatically closed 182 days after the last reply. New replies are no longer allowed.