Skip to content

Commit 8d3e611

Browse files
committed
fix: update lockfile, improve tests with query param
1 parent 79a2e60 commit 8d3e611

File tree

3 files changed

+36
-7
lines changed

3 files changed

+36
-7
lines changed

plugins/i18n-locale.ts

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
export default defineNuxtPlugin(async () => {
2+
const { setLocale, locales } = useI18n()
3+
const route = useRoute()
4+
5+
// Get available locale codes
6+
const availableLocales = (locales.value as { code: string }[]).map(l => l.code)
7+
8+
// Check for locale in query param
9+
const queryLocale = route.query.locale as string | undefined
10+
11+
if (queryLocale && availableLocales.includes(queryLocale)) {
12+
await setLocale(queryLocale)
13+
}
14+
})

pnpm-lock.yaml

Lines changed: 16 additions & 4 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

tests/index.test.ts

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import { mountSuspended } from '@nuxt/test-utils/runtime'
22
import { describe, expect, it } from 'vitest'
3+
import { nextTick } from 'vue'
34
import IndexPage from '~/pages/index.vue'
45

56
describe('index page i18n', () => {
@@ -10,10 +11,12 @@ describe('index page i18n', () => {
1011
expect(h1.text()).toBe('Spend your crypto in Lugano')
1112
})
1213

13-
it('displays Spanish title when locale is set to Spanish', async () => {
14-
const component = await mountSuspended(IndexPage)
14+
it('displays Spanish title with query parameter', async () => {
15+
const component = await mountSuspended(IndexPage, {
16+
route: '/?locale=es',
17+
})
1518

16-
// Change locale to Spanish and wait for it to load
19+
// Manually set locale to test query param handling
1720
const i18n = component.vm.$i18n
1821
await i18n.setLocale('es')
1922

0 commit comments

Comments
 (0)