【问题标题】:Implementing multiple language url nextjs and next-i18n-next实现多语言 url nextjs 和 next-i18n-next
【发布时间】:2020-08-24 05:55:06
【问题描述】:

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

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

我想知道如何更改网址路径的语言。像这样的:

/关于我们

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

提前致谢!

【问题讨论】:

  • 你找到解决办法了吗?请问可以分享吗?谢谢

标签: javascript reactjs url next.js i18next


【解决方案1】:

您必须在 next.config.js 中设置 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')
});

【讨论】:

    猜你喜欢
    • 2020-09-26
    • 2021-06-13
    • 1970-01-01
    • 2020-11-04
    • 2020-09-26
    • 2022-08-23
    • 2021-06-26
    • 2011-02-10
    • 2021-08-14
    相关资源
    最近更新 更多