next.js app目录 i18n国际化简单实现
warning:
这篇文章距离上次修改已过188天,其中的内容可能已经有所变动。
// next.config.js
const { i18n } = require('./next-i18next.config');
module.exports = {
i18n,
// 其他配置...
};
// next-i18next.config.js
const { i18n } = require('./i18n');
module.exports = {
i18n,
};
// i18n.js
module.exports = {
i18n: {
// 定义支持的语言列表
locales: ['en', 'fr', 'es'],
// 默认语言
defaultLocale: 'en',
},
// 其他配置...
};
这个代码实例展示了如何在Next.js应用中配置i18n国际化支持。首先,在next.config.js
中导入并使用next-i18next.config.js
中定义的i18n配置。然后,在next-i18next.config.js
中导出了一个对象,该对象包含了i18n
配置和语言列表。最后,在i18n.js
文件中定义了支持的语言列表和默认语言。这样,Next.js应用就可以支持国际化了。
评论已关闭