【发布时间】:2020-11-04 19:54:02
【问题描述】:
我正在为多语言网站使用 next-i18next,并且所有组件都运行良好,但我不知道如何更改 _document.js 文件中 html 标记的语言?
【问题讨论】:
-
在哪里可以找到示例 _document.js 文件?我在 next-18next repo 中找不到它。
标签: next.js i18next next-i18next
我正在为多语言网站使用 next-i18next,并且所有组件都运行良好,但我不知道如何更改 _document.js 文件中 html 标记的语言?
【问题讨论】:
标签: next.js i18next next-i18next
这是我的解决方案。
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>
)
}
}
【讨论】: