Nuxt I18n

作者 onmax008232b5d7a5MIT719 个星标收录于 2026年10月8日更新于 2026年10月8日仓库2天前更新

Internationalize Nuxt applications with @nuxtjs/i18n. Use when configuring locales or browser detection, translating messages or routes, building locale switchers, handling fallbacks, lazy-loading messages, or adding locale SEO.

AI 生成的概览

指导使用 @nuxtjs/i18n 实现 Nuxt 应用国际化:语言区域、消息、路由、检测、回退与 SEO。

功能
提供在 Nuxt 项目中接入 @nuxtjs/i18n 的工作流程和参考指南。内容涵盖模块配置、语言区域文件、翻译消息、本地化路由、语言检测、回退、懒加载以及语言区域 SEO。它会引导代理查阅最匹配的参考文档,并给出基础配置示例。
适用场景
适用于在 Nuxt 应用中配置语言区域或浏览器检测、翻译消息或路由、构建语言切换器、处理回退、懒加载消息或添加语言区域 SEO 的场景。
运行要求
需要带有 @nuxtjs/i18n 模块的 Nuxt 项目;该技能仅为说明文档,不附带脚本。文中提到运行 nuxi prepare 以及项目的类型检查。

Nuxt I18n

Nuxt I18n owns locale messages, localized routes, language detection, and locale metadata. Nuxt owns the surrounding page, rendering, and server lifecycle.

Workflow

  1. Inspect the installed @nuxtjs/i18n version, nuxt.config.*, i18n/i18n.config.*, locale files, and affected pages. The setup is understood when locale codes, files, defaultLocale, and the routing strategy agree.
  2. Open the smallest matching guide below. Keep module options in nuxt.config, Vue I18n options in i18n.config, and translated messages in locale files.
  3. Implement with localized links and module composables so routing, message loading, and SEO share one locale state.
  4. Run nuxi prepare and the project's typecheck, then visit the affected route in the default and one secondary locale. The change is complete when both locales render the expected message, URL, language metadata, and fallback behavior.

Routing

TaskOpen
Installation, locale objects, file layout, browser detection, or Vue I18n configConfiguration [blocked]
Translation keys, interpolation, plurals, dates, numbers, or runtime message loadingMessages [blocked]
Route strategies, localized links, switchers, custom paths, dynamic slugs, or SEORouting and SEO [blocked]
Nuxt pages, middleware, data fetching, SSR state, or server routesnuxt skill

Baseline

bash
npx nuxi@latest module add @nuxtjs/i18n
ts
export default defineNuxtConfig({  modules: ['@nuxtjs/i18n'],  i18n: {    defaultLocale: 'en',    locales: [      { code: 'en', language: 'en-US', name: 'English', file: 'en.json' },      { code: 'fr', language: 'fr-FR', name: 'Français', file: 'fr.json' },    ],  },})
json
{  "welcome": "Welcome"}

Locale files resolve from i18n/locales/ by default. Use the same locale code in configuration, route helpers, locale files, and fallback rules.

来源与署名

来源:onmax/nuxt-skills位于skills/nuxt-i18n提交008232b

许可证: MIT

内容归原作者所有。SourceWeft 从公开仓库中收录这些内容。

举报或申请下架