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 從公開儲存庫中收錄這些內容。

檢舉或申請下架