实现多语言 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
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')
});
我即将使用 next-i18next 内部化库。
https://github.com/isaachinman/next-i18next
我想知道如何更改 url 路径的语言。像这样:
/关于我们
/over-ons -> 转到关于我们页面的荷兰语版本。
提前致谢!
您必须在 next.config.js
中设置 localeSubpathsnext.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')
});