我正在使用 next.js 11.1.0 + next-i18next 8.5.3。有了新版本的next和i18next,我不知道如何重写子路径。所以,我有一个多语言应用程序。并且在内容上有 en-GB/en-US/en-AU 差异很重要。
我根据官方自述文件 https://github.com/isaachinman/next-i18next进行了配置
所以我有
下一个 i18next.config.js
const path = require('path');
module.exports = {
i18n: {
defaultLocale : 'us',
locales : ['en-AU','en-US', 'en-GB', 'sv', 'fr', 'de'],
defaultNS : 'translate',
keySeparator : false,
ignoreRoutes : ['/terms', '/privacy', '/pass-guarantee', '/de/', '/die-sichersten-strassen-der-welt'],
localePath : path.resolve('./public/static/locales'),
localeDetection : true
},
}
和 next.config.js
const SentryWebpackPlugin = require('@sentry/webpack-plugin');
const { i18n } = require('./next-i18next.config');
const withBundleAnalyzer = require('@next/bundle-analyzer')({
enabled: process.env.ANALYZE === 'true'
});
const { NEXT_PUBLIC_SENTRY_DSN: SENTRY_DSN, SENTRY_ORG, SENTRY_PROJECT, SENTRY_AUTH_TOKEN, NODE_ENV } = process.env;
process.env.SENTRY_DSN = SENTRY_DSN;
const nextConfig = {
experimental: {
pageDataCollectionTimeout: 300
},
i18n,
webpack(config, options) {
if (!options.isServer) {
config.resolve.alias['@sentry/node'] = '@sentry/browser';
}
if (SENTRY_DSN && SENTRY_ORG && SENTRY_PROJECT && SENTRY_AUTH_TOKEN && NODE_ENV === 'production') {
config.plugins.push(
new SentryWebpackPlugin({
include: '.next',
ignore: ['node_modules'],
authToken: SENTRY_AUTH_TOKEN,
org: SENTRY_ORG,
project: SENTRY_PROJECT,
urlPrefix: '~/.next',
release: '1.0.0',
sourceMapReference: true
})
);
}
return config;
},
images: {
domains: [
............
],
deviceSizes: [250, 380, 510, 640, 770, 900, 1024, 1280, 1536, 1728, 1920, 2560],
imageSizes: [16, 32, 48, 64, 96, 128, 196]
}
};
module.exports = withBundleAnalyzer(nextConfig);
主要问题是,我不知道如何在新版本中重写子路径。
我希望如果它检测到 en-AU 它会生成子路径 au
它应该是 site.com/au,现在我有了 site.com/en-AU