I'm using next-i18next for multi language website and for all components works well but I dont know how to change the language of html tag in _document.js file?
how to change with next-i18next when language changed in nextjs?
Asked
Active
Viewed 2,238 times
1
-
Where can I find the sample _document.js file? I cannot find it in next-18next repo. – Pirun Seng Nov 26 '20 at 09:12
1 Answers
3
Here is my solution.
class MyDocument extends Document {
static async getInitialProps(ctx) {
const initialProps = await Document.getInitialProps(ctx)
const language = ctx.req.language
return { ...initialProps, language }
}
render() {
return (
<Html lang={this.props.language}>
<Head />
<body>
<Main />
<NextScript />
</body>
</Html>
)
}
}

bcjohn
- 2,383
- 12
- 27