next.js serverSideTranslations不适用于动态路由

2wnc66cl  于 2022-12-18  发布在  其他
关注(0)|答案(1)|浏览(114)

我在互联网上做了一些研究,文档和其他答案我不能使它工作,所以现在我一无所知。我有一个动态的路线和翻译索引。这是不工作时,建立。路径是/用户/[id]/index.js

export const getStaticPaths = ({ locale }) => {
return {
  paths: [
    // if no `locale` is provided only the defaultLocale will be generated
    { params: { slug: ["shop", "account", "navbar", "footer"], id: `1` }, locale: "en" },
    { params: { slug: ["shop", "account", "navbar", "footer"], id: `1` }, locale: "hu" },
    { params: { slug: ["shop", "account", "navbar", "footer"], id: `1` }, locale: "de" },
    { params: { slug: ["shop", "account", "navbar", "footer"], id: `1` }, locale: "lt" },
    { params: { slug: ["shop", "account", "navbar", "footer"], id: `1` }, locale: "cz" },
    { params: { slug: ["shop", "account", "navbar", "footer"], id: `1` }, locale: "pl" },
    { params: { slug: ["shop", "account", "navbar", "footer"], id: `1` }, locale: "ru" },
  ],
  fallback: true,
}
}


export async function getStaticProps({ locale }) {

return {
  props: {
    ...(await serverSideTranslations(locale, ["shop", "account", "navbar", "footer"])),
    // Will be passed to the page component as props
  },
};
}

//config
  i18n: {
     // providing the locales supported by your application
    locales: ["en", "ru", "hu", "cz", "pl", "de", "lt"],
    //  default locale used when the non-locale paths are visited
    defaultLocale: "en",
    localePath: "./lang"
  },
qv7cva1a

qv7cva1a1#

从下一个-i18下一个documentation
默认情况下,next-i18 next希望您的翻译是这样组织的:

└── locales
    ├── en
    |   └── common.json
    └── de
        └── common.json

因此,如果您切换到lang文件夹,请确保:
如果你想以自定义的方式构建你的翻译/命名空间,你需要将修改过的localePath和localeStructure值传递到初始化配置中。
此外,请仔细检查是否已将next-i18next.config.js配置为:

module.exports = {
  i18n: {
    defaultLocale: 'fr',
    locales: ['fr'],
  },
};

相关问题