Skip to content

Commit

Permalink
test: confirm runtime config can be used in vue i18n config file
Browse files Browse the repository at this point in the history
  • Loading branch information
BobbieGoede committed Nov 13, 2023
1 parent 178aff0 commit 52fefba
Show file tree
Hide file tree
Showing 4 changed files with 49 additions and 30 deletions.
6 changes: 6 additions & 0 deletions specs/basic_usage.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,12 @@ test('register module hook', async () => {
expect(await getText(page, '#register-module')).toEqual('This is a merged module layer locale key in French')
})

test('vueI18n config file can access runtimeConfig', async () => {
const { page } = await renderPage('/')

expect(await getText(page, '#runtime-config')).toEqual('Hello from runtime config!')
})

test('layer provides locale `nl` and translation for key `hello`', async () => {
const { page } = await renderPage('/layer-page')

Expand Down
65 changes: 35 additions & 30 deletions specs/fixtures/basic_usage/config/i18n.config.ts
Original file line number Diff line number Diff line change
@@ -1,33 +1,38 @@
export default defineI18nConfig(() => ({
legacy: false,
locale: 'en',
messages: {
fr: {
welcome: 'Bienvenue',
home: 'Accueil',
profile: 'Profil',
aboutSite: 'À propos de ce site',
snakeCaseText: "@.snakeCase:{'aboutSite'}",
pascalCaseText: "@.pascalCase:{'aboutSite'}",
hello: 'Bonjour le monde!',
modifier: "@.snakeCase:{'hello'}"
export default defineI18nConfig(() => {
const config = useRuntimeConfig()

return {
legacy: false,
locale: 'en',
messages: {
fr: {
welcome: 'Bienvenue',
home: 'Accueil',
profile: 'Profil',
aboutSite: 'À propos de ce site',
snakeCaseText: "@.snakeCase:{'aboutSite'}",
pascalCaseText: "@.pascalCase:{'aboutSite'}",
hello: 'Bonjour le monde!',
modifier: "@.snakeCase:{'hello'}"
},
en: {
welcome: 'Welcome',
home: 'Homepage',
profile: 'Profile',
hello: 'Hello world!',
modifier: "@.snakeCase:{'hello'}",
fallbackMessage: 'This is the fallback message!',
runtimeKey: config.public.runtimeValue
},
nl: {
aboutSite: 'Over deze site',
snakeCaseText: "@.snakeCase:{'aboutSite'}",
pascalCaseText: "@.pascalCase:{'aboutSite'}"
}
},
en: {
welcome: 'Welcome',
home: 'Homepage',
profile: 'Profile',
hello: 'Hello world!',
modifier: "@.snakeCase:{'hello'}",
fallbackMessage: 'This is the fallback message!'
},
nl: {
aboutSite: 'Over deze site',
snakeCaseText: "@.snakeCase:{'aboutSite'}",
pascalCaseText: "@.pascalCase:{'aboutSite'}"
modifiers: {
// @ts-ignore
snakeCase: (str: string) => str.split(' ').join('-')
}
},
modifiers: {
// @ts-ignore
snakeCase: (str: string) => str.split(' ').join('-')
}
}))
})
5 changes: 5 additions & 0 deletions specs/fixtures/basic_usage/nuxt.config.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,11 @@
// https://nuxt.com/docs/guide/directory-structure/nuxt.config
export default defineNuxtConfig({
modules: ['./layer-module', '@nuxtjs/i18n'],
runtimeConfig: {
public: {
runtimeValue: 'Hello from runtime config!'
}
},

i18n: {
vueI18n: './config/i18n.config.ts'
Expand Down
3 changes: 3 additions & 0 deletions specs/fixtures/basic_usage/pages/index.vue
Original file line number Diff line number Diff line change
Expand Up @@ -172,5 +172,8 @@ useHead({
<section>
<div id="fallback-key">{{ $t('fallbackMessage') }}</div>
</section>
<section>
<div id="runtime-config">{{ $t('runtimeKey') }}</div>
</section>
</div>
</template>

0 comments on commit 52fefba

Please sign in to comment.