Next.js Discord

Discord Forum

How-to add lang attribute to html in the root layout

Answered
White-chinned Petrel posted this in #help-forum
Open in Discord
White-chinned PetrelOP
Hi everyone,
I need your help, I want to add lang attribute to html in the root layout, as stated in the title. The issue here is that I cannot do that because I am going to have the locale only in the following slug segment (named "[lang]").

- I cannot move the layout within the [lang] folder or I am going to lose "not-found.js" and "global-error.js" file features
- I cannot use generateStaticParams as suggested https://nextjs.org/docs/app/building-your-application/routing/internationalization#static-generationbecause it is working only if the root layout is within the [lang] folder
- I also cannot add <html> in others layout which are not Root layouts.

I am using latest nextjs 13 version.

Anyone of you have found a solution to this problem?
Thanks in advance

5 Replies

Answer
Or use a catch-all route segments /[lang]/[[…catchAll]]/page.tsx as an unofficial way to do global 404
White-chinned PetrelOP
Thanks for your reply, @joulev
I thought I cannot define <html> tags withing a layout which is not the root layout, can I?
@White-chinned Petrel Thanks for your reply, <@484037068239142956> I thought I cannot define <html> tags withing a layout which is not the root layout, can I?
My workaround relies on the fact that root layout behaves almost like normal layouts, and as long as you have the <html> and <body> tags in the rendered tree you will be fine (for now)
White-chinned PetrelOP
Right, thanks @joulev !