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 committed Sep 10, 2024
1 parent e84d530 commit a84630f
Show file tree
Hide file tree
Showing 10 changed files with 2,701 additions and 662 deletions.
14 changes: 7 additions & 7 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -84,9 +84,9 @@
"@intlify/unplugin-vue-i18n": "^3.0.1",
"@intlify/utils": "^0.12.0",
"@miyaneee/rollup-plugin-json5": "^1.2.0",
"@nuxt/kit": "^3.12.4",
"@nuxt/kit": "^3.13.1",
"@rollup/plugin-yaml": "^4.1.2",
"@vue/compiler-sfc": "^3.4.37",
"@vue/compiler-sfc": "^3.5.4",
"debug": "^4.3.5",
"defu": "^6.1.2",
"estree-walker": "^3.0.3",
Expand All @@ -100,15 +100,15 @@
"ufo": "^1.3.1",
"unplugin": "^1.10.1",
"vue-i18n": "^9.9.0",
"vue-router": "^4.4.0"
"vue-router": "^4.4.4"
},
"devDependencies": {
"@babel/parser": "^7.24.7",
"@babel/plugin-syntax-import-assertions": "^7.24.7",
"@babel/types": "^7.24.7",
"@eslint/js": "9.5.0",
"@nuxt/module-builder": "^0.8.3",
"@nuxt/schema": "^3.12.4",
"@nuxt/schema": "^3.13.1",
"@types/debug": "^4.1.9",
"@types/eslint": "^8.56.6",
"@unhead/vue": "^1.8.8",
Expand All @@ -128,10 +128,10 @@
"lint-staged": "^15.2.7",
"nitropack": "^2.9.6",
"npm-run-all2": "^6.2.0",
"nuxt": "^3.12.4",
"nuxt": "^3.13.1",
"ofetch": "^1.3.4",
"playwright": "^1.38.1",
"pkg-pr-new": "^0.0.20",
"playwright": "^1.38.1",
"prettier": "^3.3.2",
"ts-essentials": "^9.4.2",
"typescript": "^5.5.2",
Expand All @@ -140,7 +140,7 @@
"undici": "^6.19.2",
"unhead": "^1.8.8",
"vitest": "^1.6.0",
"vue": "^3.4.37"
"vue": "^3.5.4"
},
"lint-staged": {
"*.{json,md,yml}": [
Expand Down
3,289 changes: 2,637 additions & 652 deletions pnpm-lock.yaml

Large diffs are not rendered by default.

2 changes: 2 additions & 0 deletions specs/basic_usage.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,8 @@ describe('basic usage', async () => {
// @ts-ignore
delete x.components[component].__file
}
// @ts-ignore
delete x.mods
return x
})
expect(localeRoute).toMatchInlineSnapshot(
Expand Down
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

0 comments on commit a84630f

Please sign in to comment.