如何解决实现多种语言的URL nextjs和next-i18n-next
我将要使用next-i18next内部化库。
https://github.com/isaachinman/next-i18next
我想知道如何更改网址路径的语言。像这样:
/关于我们
/ over-ons->转到关于我们页面的荷兰语版本。
谢谢!
解决方法
您必须在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')
});
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。