Published: 17 Nov 2025 › Updated: 17 Nov 2025
Nuxt i18n多国语言模块集成 / 网络研习社#93
https://nuxt.com.cn/modules/i18n
i18n是多国语言模块,主要是在前端集成多种语言的。以前的应用倒也集成过英语,但设计起来有些麻烦,再就是用户多是中文,就没去集成了。这一拖,就是好几年过去了。
现在想在项目中集成,比如AIJoe,还是有点国际范比较好呢。找了下,Nuxt i18n模块已经准备好了。
看了下文档,试了下手,不是很复杂。看来要更新项目啰。以下是集成步骤,可以参考:
yarn add @nuxtjs/i18n //^10.2.0"
1. nuxt.config.ts 配置
export default defineNuxtConfig({
modules: [ '@nuxtjs/i18n'],
i18n: {
defaultLocale: 'zh',
strategy: 'no_prefix',
locales: [
{ code: 'en', name: 'English', file: 'en.json' },
{ code: 'zh', name: 'Chinese', file: 'zh.json' }
]
},
})
2. locale 文件
Nuxt I18n 默认从一个(可配置的)目录结构中加载 locale 文件,默认应在 <rootDir>/i18n/locales 下创建这些 locale 文件。
这步是在项目的根目录下创建这个文件夹`i18n`.
// i18n/locales/en.json
{
"welcome": "Welcom"
}
3. 前端使用
<h1>{{ $t('welcome') }}</h1>
4. 切换语言
const { locales, setLocale } = useI18n()
<div>
<button v-for="locale in locales" @click="setLocale(locale.code)">
{{ locale.name }}
</button>
<h1>{{ $t('welcome') }}</h1>
</div>
Leave Nuxt i18n多国语言模块集成 / 网络研习社#93 to:
Read more #cn posts
Best Posts From lemooljiang
We have not curated any of lemooljiang's posts yet. But you can encourage our curation team to review posts by visiting them regularly and by referring other readers. Because we give priority to frequently read content.
More Posts From lemooljiang
- Nextjs初体验,和Nuxt的异同
- DeepTutor:AI个性化辅导平台 / ai #57
- ComfyUI:可编程和自动化的PS / ai #56
- 将Neo4j封装进Agent / ai #55
- 闲鱼省钱大法:极限0.5折!
- 对Neo4j批量导入结构化数据 / ai #54
- langchain对neo4j进行交互,写入和查询数据 / ai #53
- 知识图谱和图数据库Neo4j的作用和使用场景 / ai #52
- SpaceX、美股和比特币
- 又是币圈血洗日!
- 链股合流,当币安也开始卖股票啰
- 天涯社区重启,爷青回?
- 诺基亚在AI时代重新杀回来啦
- 《2049:未来10000天的可能》书中的镜像世界为什么不叫元宇宙
- 今天适合吃披萨
- 开通即被封,别再给Claude送人头了!
- 两根内存条引发的“官司”
- AI·Joe V12更新, 更新GPT-5.5和DeepSeek V4 等
- 中医进校园活动反响热烈
- 猪价低伤农,猪价贵伤民