Skip to content

Commit

Permalink
feat: v-t directive SSR fully (#3014)
Browse files Browse the repository at this point in the history
  • Loading branch information
kazupon committed Jul 4, 2024
1 parent 766c38f commit 0ef6d8b
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 2 deletions.
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
2 changes: 2 additions & 0 deletions src/bundler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@ export async function extendBundler(nuxt: Nuxt, nuxtOptions: Required<NuxtI18nOp
compositionOnly: nuxtOptions.bundle.compositionOnly,
onlyLocales: nuxtOptions.bundle.onlyLocales,
dropMessageCompiler: nuxtOptions.bundle.dropMessageCompiler,
optimizeTranslationDirective: true,
strictMessage: nuxtOptions.compilation.strictMessage,
escapeHtml: nuxtOptions.compilation.escapeHtml
}
Expand Down Expand Up @@ -104,6 +105,7 @@ export async function extendBundler(nuxt: Nuxt, nuxtOptions: Required<NuxtI18nOp
fullInstall: nuxtOptions.bundle.fullInstall,
onlyLocales: nuxtOptions.bundle.onlyLocales,
dropMessageCompiler: nuxtOptions.bundle.dropMessageCompiler,
optimizeTranslationDirective: true,
strictMessage: nuxtOptions.compilation.strictMessage,
escapeHtml: nuxtOptions.compilation.escapeHtml,
defaultSFCLang: nuxtOptions.customBlocks.defaultSFCLang,
Expand Down

0 comments on commit 0ef6d8b

Please sign in to comment.