You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

Nuxt 3 集成 i18n 突发翻译缺失及预渲染报错求助

问题排查请求:Nuxt3项目突发翻译缺失与预渲染404异常

问题现象

1. 翻译缺失异常

  • en语言包的locales/en.json中明确存在footer_returns键值,但执行pnpm run dev时仍弹出提示:[intlify] Not found 'footer_returns' key in 'en' locale messages
  • 切换语言时,v-if="locale === 'nl'"的逻辑可正常触发,但对应语言的翻译内容无法加载

2. 预渲染404报错

  • 构建项目时,预渲染/pages/blogs/blog1路径提示404,但项目中实际存在/pages/blogs/blog.vue文件

已尝试操作:删除.nuxt、.output、node_modules目录并重新执行pnpm install,问题未解决;近期未修改Node版本或依赖包。

项目配置文件

nuxt.config.ts

// https://nuxt.com/docs/api/configuration/nuxt-config
export default defineNuxtConfig({
  compatibilityDate: '2024-11-01',
  devtools: {
    enabled: false
  },
  ssr: true,
  build: {
    extractCSS: true
  },
  modules: ['@nuxtjs/i18n', '@nuxtjs/tailwindcss', '@nuxtjs/device', "nuxt-tiptap-editor", "@nuxtjs/sitemap", "@nuxtjs/robots", '@nuxt/scripts', 'nuxt-module-hotjar'],
  i18n: {
    legacy: false,
    globalInjection: true,
    strategy: 'prefix_and_default',
    defaultLocale: 'nl',
    locales: [
      {
        code: "en",
        iso: "en-EN",
        name: 'English'
      },
      {
        code: "nl",
        iso: "nl-NL",
        name: 'Nederlands'
      },
      {
        code: "de",
        iso: "de-DE",
        name: 'Deutsch'
      },
      {
        code: "it",
        iso: "it-IT",
        name: 'Italian'
      },
    ],

    vueI18n: './i18n.config.ts'
  },
  site: {  url: 'https://xxxx.com',  name: 'xxxx'  },
  routeRules: {
    // prerender, swr, isr, cors
    '/admin/**': { robots: false, ssr: false },
    // '/': { prerender: true },
    '/blogs/**': { prerender: true },
  },
  sitemap: {
    sources: [[]]
  },
  robots: {
    groups: []
  },
  hotjar: {
    hotjarId: xxx,
    scriptVersion: 6
  }
})

i18n.config.ts

import en from "./locales/en.json"
import nl from "./locales/nl.json"
import it from "./locales/it.json"
import de from "./locales/de.json"

export default defineI18nConfig(() => ({
    numberFormats: {
        en: {
            currency: {
                style: 'currency', currency: 'EUR'
            },
            decimal: {
                style: 'decimal', minimumFractionDigits: 2, maximumFractionDigits: 2
            }
        },
        nl: {
            currency: {
                style: 'currency', currency: 'EUR'
            },
            decimal: {
                style: 'decimal', minimumFractionDigits: 2, maximumFractionDigits: 2
            }
        },
        it: {
            currency: {
                style: 'currency', currency: 'EUR'
            },
            decimal: {
                style: 'decimal', minimumFractionDigits: 2, maximumFractionDigits: 2
            }
        },
        de: {
            currency: {
                style: 'currency', currency: 'EUR'
            },
            decimal: {
                style: 'decimal', minimumFractionDigits: 2, maximumFractionDigits: 2
            }
        },
    },
    datetimeFormats: {
        en: {
            short: {
                year: 'numeric', month: 'numeric', day: 'numeric'
            },
            long: {
                year: 'numeric', month: 'short', day: 'numeric', hour: 'numeric', minute: 'numeric'
            }
        },
        nl: {
            short: {
                day: 'numeric', month: 'numeric', year: 'numeric',
            },
            long: {
                day: 'numeric', month: 'short', year: 'numeric', hour: 'numeric', minute: 'numeric'
            }
        },
        it: {
            short: {
                day: 'numeric', month: 'numeric', year: 'numeric',
            },
            long: {
                day: 'numeric', month: 'short', year: 'numeric', hour: 'numeric', minute: 'numeric'
            }
        },
        de: {
            short: {
                day: 'numeric', month: 'numeric', year: 'numeric',
            },
            long: {
                day: 'numeric', month: 'short', year: 'numeric', hour: 'numeric', minute: 'numeric'
            }
        },
    },
    messages: {
        en: en,
        nl: nl,
        it: it,
        de: de,
    },
}))

内容的提问来源于stack exchange,提问作者Digital Forge

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.06.12 10:25:55