Next.js Discord

Discord Forum

i18n root layout

Unanswered
Northeast Congo Lion posted this in #help-forum
Open in Discord
Northeast Congo LionOP
Hello,

I'm trying to find the best way to implement the root layout with the i18n.

My project is structured as follows:

- an app folder that contains neither layout nor page
- a [locale] folder under app containing a layout with the locale parameter for use in the <html> tag.

<html lang={locale}>
  <body>
    ...
  </body>
</html>


In some other pages of my application, I sometimes use NextJS's
js notFound()
, but as I don't have a root layout directly under the app folder, the application crashes.

So I've created a not-found.tsx under the [locale] folder and now the
js notFound()
that I use in some pages no longer crashes the application and my custom not found page is displayed correctly.

Now I have a page whose path is composed as follows: app/[locale]/blog/[category]/[slug]/page.tsx. There's no file under the [category] folder, but when I access a URL like https://domain.com/blog/azeerltkerlmt, the not found page displayed is not the one I've just created, but the default NextJS page.

To customize it, I understood that I had to make a not-found.tsx under the app folder, but I don't have a layout, which is a problem.

I'm sure I'm doing something wrong, but I'd like to know the best way to handle this lang property of the <html> tag while keeping NextJS's default operation.

11 Replies

here is our open source codebase if that's of any help
at this point I also have a warning related to the "lang" attribute on the html tag, I must admit our code might be buggy too :/
we also render the html part in another layout
I need to double check what happens
Northeast Congo LionOP
So you have html and body tags twice ?
Does it generates this king of error TypeError: Cannot read properties of null (reading 'classList')
@Northeast Congo Lion So you have html and body tags twice ?
I need to check, I thought not but had issues
so perhaps I've messed it up