Skip to content

Commit 1647bb8

Browse files
authoredFeb 4, 2025··
fix: availableLocales not including configured locales (#3347)
1 parent b5f48dd commit 1647bb8

File tree

3 files changed

+36
-0
lines changed

3 files changed

+36
-0
lines changed
 

‎specs/basic_usage.spec.ts

+15
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,21 @@ describe('basic usage', async () => {
7575
expect(await page.url()).include('/user/profile?foo=1')
7676
})
7777

78+
test('(#3344) `availableLocales` includes all configured locales', async () => {
79+
const { page } = await renderPage('/')
80+
81+
// @ts-expect-error runtime types
82+
expect(await page.evaluate(() => window.useNuxtApp?.().$i18n.availableLocales)).toMatchInlineSnapshot(`
83+
[
84+
"en",
85+
"fr",
86+
"ja",
87+
"kr",
88+
"nl",
89+
]
90+
`)
91+
})
92+
7893
test('`v-t` directive SSR', async () => {
7994
const pageHTML = await $fetch('/')
8095
const pageDOM = getDom(pageHTML)

‎specs/basic_usage_compat_4.spec.ts

+15
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,21 @@ describe('basic usage - compatibilityVersion: 4', async () => {
7575
expect(await page.url()).include('/user/profile?foo=1')
7676
})
7777

78+
test('(#3344) `availableLocales` includes all configured locales', async () => {
79+
const { page } = await renderPage('/')
80+
81+
// @ts-expect-error runtime types
82+
expect(await page.evaluate(() => window.useNuxtApp?.().$i18n.availableLocales)).toMatchInlineSnapshot(`
83+
[
84+
"en",
85+
"fr",
86+
"ja",
87+
"kr",
88+
"nl",
89+
]
90+
`)
91+
})
92+
7893
test('`v-t` directive SSR', async () => {
7994
const pageHTML = await $fetch('/')
8095
const pageDOM = getDom(pageHTML)

‎src/runtime/plugins/i18n.ts

+6
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,12 @@ export default defineNuxtPlugin({
6666

6767
const vueI18nOptions: I18nOptions = await loadVueI18nOptions(vueI18nConfigs, useNuxtApp())
6868
vueI18nOptions.messages = vueI18nOptions.messages || {}
69+
70+
// initialize locale objects to make vue-i18n aware of available locales
71+
for (const l of localeCodes) {
72+
vueI18nOptions.messages[l] ??= {}
73+
}
74+
6975
vueI18nOptions.fallbackLocale = vueI18nOptions.fallbackLocale ?? false
7076
if (defaultLocaleDomain) {
7177
vueI18nOptions.locale = defaultLocaleDomain

0 commit comments

Comments
 (0)
Please sign in to comment.