多语言支持
⚠️
此功能仅在文档主题中可用。
Nextra 支持开箱即用的 Next.js 国际化路由。
要将多语言页面添加到 Nextra 应用,只需在 next.config.js
中配置 i18n
:
// next.config.jsconst withNextra = require('nextra')('nextra-theme-docs', './theme.config.js')module.exports = withNextra({ i18n: { locales: ['en', 'zh', 'de'], defaultLocale: 'en', },})
然后,将语言代码添加到文件扩展名(默认语言也需要):
/pages index.en.md index.zh.md index.de.md meta.en.json meta.zh.json meta.de.json ...
最后,将 i18n
选项添加到 theme.config.js
以配置语言下拉列表:
i18n: [ { locale: 'en', text: 'English' }, { locale: 'zh', text: '中文' }, { locale: 'de', text: 'Deutsch' }, { locale: 'ar', text: 'العربية', direction: 'rtl' },]