Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/473.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 实现多语言url nextjs和next-i18n-next_Javascript_Reactjs_Url_Next.js_I18next - Fatal编程技术网

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

Javascript 实现多语言url nextjs和next-i18n-next,javascript,reactjs,url,next.js,i18next,Javascript,Reactjs,Url,Next.js,I18next,我将要使用next-i18next内部化库 我想知道如何更改url路径的语言。如下所示: /关于我们 /通过ons->转到荷兰版的关于美国页面 提前感谢!您必须在next.config.js中设置localesubpath const {nextI18NextRewrites} = require('next-i18next/rewrites'); const localeSubpaths = { en: 'en', fr: 'fr', }; module.exports

我将要使用next-i18next内部化库

我想知道如何更改url路径的语言。如下所示:

/关于我们

/通过ons->转到荷兰版的关于美国页面


提前感谢!

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

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

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

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

next.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')
});

你找到什么解决办法了吗?请分享一下好吗?谢谢