0

我正在将 next-i18next 用于多语言网站,并且所有组件都运行良好,但我不知道如何更改 _document.js 文件中 html 标记的语言?

4

1 回答 1

2

这是我的解决方案。

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>
    ) 
  } 
}
于 2020-07-15T11:48:25.143 回答