繁体   English   中英

实现多语言 url nextjs 和 next-i18n-next

[英]Implementing multiple language url nextjs and next-i18n-next

我即将使用 next-i18next 内部化库。

https://github.com/isaachinman/next-i18next

我想知道如何更改我的 url 路径的语言。 像这样的东西:

/关于我们

/over-ons -> 转到关于我们页面的荷兰语版本。

提前致谢!

您必须在 next.config.js 中设置 localeSubpaths

下一个.config.js

const {nextI18NextRewrites} = require('next-i18next/rewrites');

const localeSubpaths = {
    en: 'en',
    fr: 'fr',
};

module.exports = {
    rewrites: async () => nextI18NextRewrites(localeSubpaths),
    publicRuntimeConfig: {
        localeSubpaths,
    },
};

i18n.js

const NextI18Next = require('next-i18next').default;
const {localeSubpaths} = require('next/config').default().publicRuntimeConfig;
const path = require('path');

module.exports = new NextI18Next({
    defaultLanguage: 'fr',
    otherLanguages: ['en'],
    defaultNS: 'common',
    browserLanguageDetection: false,
    serverLanguageDetection: false,
    localeSubpaths,
    localePath: path.resolve('./public/locales')
});

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM