1

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?

brc-dd
  • 10,788
  • 3
  • 47
  • 67
Reza Ghorbani
  • 537
  • 4
  • 14

1 Answers1

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