lemooljiang avatar

Nuxt i18n多国语言模块集成 / 网络研习社#93

lemooljiang

Published: 17 Nov 2025 › Updated: 17 Nov 2025Nuxt  i18n多国语言模块集成 / 网络研习社#93

Nuxt i18n多国语言模块集成 / 网络研习社#93

i18n.jpg
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:

Written by

Designer , Poet , Technology enthusiasts

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