From 1b4574f37df3eeb0ff14e8054368affd7a510a84 Mon Sep 17 00:00:00 2001 From: Bobbie Goede Date: Fri, 6 Dec 2024 09:18:45 +0100 Subject: [PATCH] feat: configurable `bundle.optimizeTranslationDirective` (#3256) --- docs/content/docs/4.api/0.options.md | 7 +++++++ src/bundler.ts | 4 ++-- src/constants.ts | 3 ++- src/types.ts | 7 ++++++- 4 files changed, 17 insertions(+), 4 deletions(-) diff --git a/docs/content/docs/4.api/0.options.md b/docs/content/docs/4.api/0.options.md index 0556562b3..13131c34c 100644 --- a/docs/content/docs/4.api/0.options.md +++ b/docs/content/docs/4.api/0.options.md @@ -443,6 +443,13 @@ It can be useful if you have one code base (e.g. [Nuxt Layers](https://nuxt.com/ The value of this **option will not be merged with other Nuxt Layers**. This option should only be specified in the final project config. :: +### `optimizeTranslationDirective` + +- type: `boolean`{lang="ts-type"} +- default: `true`{lang="ts"} + +Whether to optimize `v-t` directive by transforming it's usage into a vue-i18n translation function, this needs to be enabled for projects using the `v-t` directive with SSR. + ## experimental Experimental configuration property is an object with the following properties: diff --git a/src/bundler.ts b/src/bundler.ts index 8fd42eade..d0529d7a7 100644 --- a/src/bundler.ts +++ b/src/bundler.ts @@ -42,7 +42,7 @@ export async function extendBundler({ options: nuxtOptions }: I18nNuxtContext, n compositionOnly: nuxtOptions.bundle.compositionOnly, onlyLocales: nuxtOptions.bundle.onlyLocales, dropMessageCompiler: nuxtOptions.bundle.dropMessageCompiler, - optimizeTranslationDirective: true, + optimizeTranslationDirective: nuxtOptions.bundle.optimizeTranslationDirective, strictMessage: nuxtOptions.compilation.strictMessage, escapeHtml: nuxtOptions.compilation.escapeHtml, include: localeIncludePaths @@ -75,7 +75,7 @@ export async function extendBundler({ options: nuxtOptions }: I18nNuxtContext, n fullInstall: nuxtOptions.bundle.fullInstall, onlyLocales: nuxtOptions.bundle.onlyLocales, dropMessageCompiler: nuxtOptions.bundle.dropMessageCompiler, - optimizeTranslationDirective: true, + optimizeTranslationDirective: nuxtOptions.bundle.optimizeTranslationDirective, strictMessage: nuxtOptions.compilation.strictMessage, escapeHtml: nuxtOptions.compilation.escapeHtml, defaultSFCLang: nuxtOptions.customBlocks.defaultSFCLang, diff --git a/src/constants.ts b/src/constants.ts index ce141cac9..798c65f0a 100644 --- a/src/constants.ts +++ b/src/constants.ts @@ -38,7 +38,8 @@ export const DEFAULT_OPTIONS = { compositionOnly: true, runtimeOnly: false, fullInstall: true, - dropMessageCompiler: false + dropMessageCompiler: false, + optimizeTranslationDirective: true }, compilation: { jit: true, diff --git a/src/types.ts b/src/types.ts index 3a67267ff..766213837 100644 --- a/src/types.ts +++ b/src/types.ts @@ -132,7 +132,12 @@ export interface ExperimentalFeatures { export interface BundleOptions extends Pick< PluginOptions, - 'compositionOnly' | 'runtimeOnly' | 'fullInstall' | 'dropMessageCompiler' | 'onlyLocales' + | 'compositionOnly' + | 'runtimeOnly' + | 'fullInstall' + | 'dropMessageCompiler' + | 'onlyLocales' + | 'optimizeTranslationDirective' > {} export interface CustomBlocksOptions extends Pick {}