NextJS i18n 匹配语言环境与 pages 子目录

时间:2021-05-26 08:51:39

标签: internationalization next.js i18next react-i18next

背景

在 NextJS 中使用 i18n 时,会自动检测语言环境,但会在没有语言环境的情况下匹配路由。

next.config.js

module.exports = {
  i18n: {
    locales: ['en', 'fr', 'nl', 'es'],
    defaultLocale: 'en',
    // localeDetection: false
  }
}

我想在页面中有一个结构,允许我以与语言环境匹配的方式放置翻译的文件

文件夹结构:

pages
├── es
│   ├── gsp
│   │   ├── [slug].js
│   │   └── index.js
│   └── gssp.js
├── gsp
│   ├── [slug].js
│   └── index.js
├── gssp.js
└── index.js

以上示例取自 i18n-routing example,您可以使用 yarn create next-app --example i18n-routing i18n-app

轻松重现

问题

我想要这个文件结构,因为我将使用 mdx/md 文件并且翻译将是完整的,所以 i18n 翻译与单个文件(如 [sulg].js)通过 useRouter() 检测区域设置不起作用对于我要解决的问题。

问题

我如何设置服务器以便locale在像

这样的路由中
  • /some-random-route(默认为“en”)或
  • /es/some-random-route(将显式设置为“es”)

是否匹配以提供 pages 子目录中的文件?

0 个答案:

没有答案
相关问题