Skip to content

Commit

Permalink
fix: empty i18n options not loading vue-i18n config file (#3093)
Browse files Browse the repository at this point in the history
  • Loading branch information
BobbieGoede authored Sep 10, 2024
1 parent 80f9c56 commit c720b6d
Show file tree
Hide file tree
Showing 10 changed files with 2,445 additions and 243 deletions.
2,628 changes: 2,388 additions & 240 deletions pnpm-lock.yaml

Large diffs are not rendered by default.

18 changes: 18 additions & 0 deletions specs/empty_options.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
import { test, expect, describe } from 'vitest'
import { fileURLToPath } from 'node:url'
import { setup } from './utils'
import { renderPage } from './helper'

await setup({
rootDir: fileURLToPath(new URL(`./fixtures/empty_options`, import.meta.url)),
browser: true
})

describe('inline options are handled correctly', async () => {
test('inline options are handled correctly', async () => {
const { page } = await renderPage('/')

const text = await page.locator('#text-div').innerHTML()
expect(text).toMatchInlineSnapshot(`"Hi from @nuxtjs/i18n: from the en locale"`)
})
})
3 changes: 3 additions & 0 deletions specs/fixtures/empty_options/app.vue
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
<template>
<div id="text-div">Hi from @nuxtjs/i18n: {{ $t('hello') }}</div>
</template>
9 changes: 9 additions & 0 deletions specs/fixtures/empty_options/i18n.config.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
export default defineI18nConfig(() => ({
legacy: false,
locale: 'en',
messages: {
en: {
hello: 'from the en locale'
}
}
}))
5 changes: 5 additions & 0 deletions specs/fixtures/empty_options/nuxt.config.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
// https://nuxt.com/docs/guide/directory-structure/nuxt.config
export default defineNuxtConfig({
compatibilityDate: '2024-04-03',
modules: ['@nuxtjs/i18n']
})
15 changes: 15 additions & 0 deletions specs/fixtures/empty_options/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
{
"name": "nuxt3-test-empty-options",
"private": true,
"type": "module",
"scripts": {
"build": "nuxi build",
"dev": "nuxi dev",
"generate": "nuxi generate",
"preview": "nuxi preview"
},
"devDependencies": {
"@nuxtjs/i18n": "latest",
"nuxt": "latest"
}
}
4 changes: 4 additions & 0 deletions specs/fixtures/empty_options/tsconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
{
// https://nuxt.com/docs/guide/concepts/typescript
"extends": "./.nuxt/tsconfig.json"
}
4 changes: 1 addition & 3 deletions src/layers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -166,9 +166,7 @@ export async function resolveLayerVueI18nConfigInfo(options: NuxtI18nOptions) {

const resolveArr = nuxt.options._layers.map(async layer => {
const i18n = getLayerI18n(layer)
if (i18n == null) return undefined

const res = await resolveVueI18nConfigInfo(resolveI18nDir(layer, i18n, true), i18n.vueI18n)
const res = await resolveVueI18nConfigInfo(resolveI18nDir(layer, i18n || {}, true), i18n?.vueI18n)

if (res == null && i18n?.vueI18n != null) {
logger.warn(
Expand Down
1 change: 1 addition & 0 deletions src/module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -260,6 +260,7 @@ export default defineNuxtModule<NuxtI18nOptions>({
nuxt.hook('vite:extendConfig', cfg => {
// eslint-disable-next-line @typescript-eslint/no-floating-promises
cfg.plugins ||= []
// @ts-ignore NOTE: A type error occurs due to a mismatch between Vite plugins and those of Rollup
cfg.plugins.push(i18nVirtualLoggerPlugin(options.debug))
})

Expand Down
1 change: 1 addition & 0 deletions src/nitro.ts
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ export async function setupNitro(
? nitroConfig.rollupConfig.plugins
: [nitroConfig.rollupConfig.plugins]

// @ts-ignore NOTE: A type error occurs due to a mismatch between Vite plugins and those of Rollup
nitroConfig.rollupConfig.plugins.push(i18nVirtualLoggerPlugin(nuxtOptions.debug))

const yamlPaths = getResourcePaths(additionalParams.localeInfo, /\.ya?ml$/)
Expand Down

0 comments on commit c720b6d

Please sign in to comment.