Skip to content

Commit

Permalink
fix: v-t SSR
Browse files Browse the repository at this point in the history
  • Loading branch information
BobbieGoede committed Jun 23, 2024
1 parent cddb8b3 commit 0347987
Show file tree
Hide file tree
Showing 6 changed files with 49 additions and 3 deletions.
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,7 @@
"@intlify/shared": "^9.9.0",
"@intlify/unplugin-vue-i18n": "^3.0.1",
"@intlify/utils": "^0.12.0",
"@intlify/vue-i18n-extensions": "^5.0.1",
"@miyaneee/rollup-plugin-json5": "^1.1.2",
"@nuxt/kit": "^3.10.3",
"@rollup/plugin-yaml": "^4.1.2",
Expand Down
17 changes: 17 additions & 0 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

12 changes: 12 additions & 0 deletions specs/basic_usage.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,18 @@ describe('basic usage', async () => {
expect(await page.url()).include('/user/profile?foo=1')
})

test('`v-t` directive SSR', async () => {
const pageHTML = await $fetch('/')
const pageDOM = getDom(pageHTML)
expect(pageDOM.querySelector('#t-directive #t-directive-path')?.textContent).toEqual('Welcome')
expect(pageDOM.querySelector('#t-directive #t-directive-argument')?.textContent).toEqual('Hello directive!')

const pageHTMLFrench = await $fetch('/fr')
const pageDOMFrench = getDom(pageHTMLFrench)
expect(pageDOMFrench.querySelector('#t-directive #t-directive-path')?.textContent).toEqual('Bienvenue')
expect(pageDOMFrench.querySelector('#t-directive #t-directive-argument')?.textContent).toEqual('Bonjour directive!')
})

test('nuxt context extension', async () => {
const { page } = await renderPage('/nuxt-context-extension')

Expand Down
6 changes: 4 additions & 2 deletions specs/fixtures/basic_usage/config/i18n.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,8 @@ export default defineI18nConfig(() => {
snakeCaseText: "@.snakeCase:{'aboutSite'}",
pascalCaseText: "@.pascalCase:{'aboutSite'}",
hello: 'Bonjour le monde!',
modifier: "@.snakeCase:{'hello'}"
modifier: "@.snakeCase:{'hello'}",
helloMessage: 'Bonjour {name}!'
},
en: {
home: 'Homepage',
Expand All @@ -28,7 +29,8 @@ export default defineI18nConfig(() => {
hello: 'Hello world!',
modifier: "@.snakeCase:{'hello'}",
fallbackMessage: 'This is the fallback message!',
runtimeKey: config.public.runtimeValue
runtimeKey: config.public.runtimeValue,
helloMessage: 'Hello {name}!'
},
nl: {
aboutSite: 'Over deze site',
Expand Down
4 changes: 4 additions & 0 deletions specs/fixtures/basic_usage/pages/index.vue
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,10 @@ useHead({
>:
<code id="home-use-locale-head">{{ i18nHead }}</code>
</section>
<section id="t-directive">
<p id="t-directive-path" v-t="'welcome'"></p>
<p id="t-directive-argument" v-t="{ path: 'helloMessage', args: { name: 'directive' } }"></p>
</section>
<section id="locale-path-usages">
<h3>localePath</h3>
<ul>
Expand Down
12 changes: 11 additions & 1 deletion src/module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import {
useLogger
} from '@nuxt/kit'
import { resolve, relative } from 'pathe'
import { transformVTDirective } from '@intlify/vue-i18n-extensions'
import { defu } from 'defu'
import { setupAlias } from './alias'
import { setupPages } from './pages'
Expand Down Expand Up @@ -360,7 +361,16 @@ export default defineNuxtModule<NuxtI18nOptions>({
])

/**
* transpile @nuxtjs/i18n
* Directive transformation for `v-t` SSR
*/

// Use `legacy` as global injections are prefixed (`$t`)
const transformVT = transformVTDirective({ mode: 'legacy' })
nuxt.options.vue.compilerOptions.directiveTransforms ??= {}
nuxt.options.vue.compilerOptions.directiveTransforms.t = transformVT

/**
* Transpile @nuxtjs/i18n
*/

// https://github.com/nuxt/framework/issues/5257
Expand Down

0 comments on commit 0347987

Please sign in to comment.