next.js - 在 nextjs 中更改语言时如何使用 next-i18next 进行更改?
问题描述
我正在将 next-i18next 用于多语言网站,并且所有组件都运行良好,但我不知道如何更改 _document.js 文件中 html 标记的语言?
解决方案
这是我的解决方案。
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>
)
}
}
推荐阅读
- regex - 如何限制 Google Forms Regex 中每行的行数和字符数
- node.js - Flash 消息在重定向时被删除
- reactjs - Reactjs DevExtreme DataGrid Popup 编辑自定义事件 CRUD
- firebase - 用于订单管理应用的 Firebase 数据库设计
- javascript - 每 4 个项目重新启动每个循环
- r - R web 抓取包无法读取所有 url 表
- python - 每个 bin pandas 的平均分
- kubernetes - k8s 中自定义资源定义(CRD)与服务目录的使用
- php - 有没有办法下载没有开发文件夹的作曲家包?
- webassembly - 优化的 AssemblyScript 仍然是 4K,用于简单的乘法