Next.js 13.4 set HTML lang attribute dynamically


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.

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.

Please post a linl to your project code.