Skip to content

Commit 0355466

Browse files
authored
fix: only optimize configured locale files (#3433)
1 parent b9e008c commit 0355466

13 files changed

Lines changed: 84 additions & 29 deletions

File tree

specs/fixtures/issues/3404/app.vue

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
<template>
2+
<div>
3+
<NuxtRouteAnnouncer />
4+
<NuxtPage />
5+
</div>
6+
</template>
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
import en from './locales/en'
2+
import nl from './locales/nl'
3+
4+
export default defineI18nConfig(() => ({
5+
messages: {
6+
en,
7+
nl
8+
}
9+
}))
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
export default {
2+
hello: 'Hello!'
3+
}
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
import greeting from './greeting'
2+
3+
export default {
4+
greeting
5+
}
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
export default {
2+
hello: 'Hallo!'
3+
}
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
import greeting from './greeting'
2+
3+
export default {
4+
greeting
5+
}
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
// https://nuxt.com/docs/api/configuration/nuxt-config
2+
export default defineNuxtConfig({
3+
modules: ['@nuxtjs/i18n'],
4+
i18n: {
5+
locales: ['en', 'nl']
6+
}
7+
})
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
{
2+
"name": "fixture-3404",
3+
"private": true,
4+
"scripts": {
5+
"build": "nuxt build",
6+
"dev": "nuxt dev",
7+
"generate": "nuxt generate",
8+
"preview": "nuxt preview"
9+
},
10+
"devDependencies": {
11+
"@nuxtjs/i18n": "latest",
12+
"nuxt": "latest"
13+
}
14+
}
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
<template>
2+
<div>
3+
<h1 id="translated-heading">{{ $t('greeting.hello') }}</h1>
4+
</div>
5+
</template>

specs/issues/3404.spec.ts

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
import { test, expect, describe } from 'vitest'
2+
import { fileURLToPath } from 'node:url'
3+
import { createPage, setup, url } from '../utils'
4+
import { getText } from '../helper'
5+
6+
describe('#3404', async () => {
7+
await setup({
8+
rootDir: fileURLToPath(new URL(`../fixtures/issues/3404`, import.meta.url)),
9+
browser: true
10+
})
11+
12+
test('resource optimization excludes files not configured in `i18n.locales.*.files`', async () => {
13+
const page = await createPage('/en')
14+
const heading = await getText(page, '#translated-heading')
15+
expect(heading).toEqual(`Hello!`)
16+
17+
await page.goto(url('/nl'))
18+
const heading2 = await getText(page, '#translated-heading')
19+
expect(heading2).toEqual(`Hallo!`)
20+
})
21+
})

0 commit comments

Comments
 (0)