Skip to content

Commit 1b4574f

Browse files
authoredDec 6, 2024··
feat: configurable bundle.optimizeTranslationDirective (#3256)
1 parent 7348f7e commit 1b4574f

File tree

4 files changed

+17
-4
lines changed

4 files changed

+17
-4
lines changed
 

‎docs/content/docs/4.api/0.options.md

+7
Original file line numberDiff line numberDiff line change
@@ -443,6 +443,13 @@ It can be useful if you have one code base (e.g. [Nuxt Layers](https://nuxt.com/
443443
The value of this **option will not be merged with other Nuxt Layers**. This option should only be specified in the final project config.
444444
::
445445

446+
### `optimizeTranslationDirective`
447+
448+
- type: `boolean`{lang="ts-type"}
449+
- default: `true`{lang="ts"}
450+
451+
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.
452+
446453
## experimental
447454

448455
Experimental configuration property is an object with the following properties:

‎src/bundler.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ export async function extendBundler({ options: nuxtOptions }: I18nNuxtContext, n
4242
compositionOnly: nuxtOptions.bundle.compositionOnly,
4343
onlyLocales: nuxtOptions.bundle.onlyLocales,
4444
dropMessageCompiler: nuxtOptions.bundle.dropMessageCompiler,
45-
optimizeTranslationDirective: true,
45+
optimizeTranslationDirective: nuxtOptions.bundle.optimizeTranslationDirective,
4646
strictMessage: nuxtOptions.compilation.strictMessage,
4747
escapeHtml: nuxtOptions.compilation.escapeHtml,
4848
include: localeIncludePaths
@@ -75,7 +75,7 @@ export async function extendBundler({ options: nuxtOptions }: I18nNuxtContext, n
7575
fullInstall: nuxtOptions.bundle.fullInstall,
7676
onlyLocales: nuxtOptions.bundle.onlyLocales,
7777
dropMessageCompiler: nuxtOptions.bundle.dropMessageCompiler,
78-
optimizeTranslationDirective: true,
78+
optimizeTranslationDirective: nuxtOptions.bundle.optimizeTranslationDirective,
7979
strictMessage: nuxtOptions.compilation.strictMessage,
8080
escapeHtml: nuxtOptions.compilation.escapeHtml,
8181
defaultSFCLang: nuxtOptions.customBlocks.defaultSFCLang,

‎src/constants.ts

+2-1
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,8 @@ export const DEFAULT_OPTIONS = {
3838
compositionOnly: true,
3939
runtimeOnly: false,
4040
fullInstall: true,
41-
dropMessageCompiler: false
41+
dropMessageCompiler: false,
42+
optimizeTranslationDirective: true
4243
},
4344
compilation: {
4445
jit: true,

‎src/types.ts

+6-1
Original file line numberDiff line numberDiff line change
@@ -132,7 +132,12 @@ export interface ExperimentalFeatures {
132132
export interface BundleOptions
133133
extends Pick<
134134
PluginOptions,
135-
'compositionOnly' | 'runtimeOnly' | 'fullInstall' | 'dropMessageCompiler' | 'onlyLocales'
135+
| 'compositionOnly'
136+
| 'runtimeOnly'
137+
| 'fullInstall'
138+
| 'dropMessageCompiler'
139+
| 'onlyLocales'
140+
| 'optimizeTranslationDirective'
136141
> {}
137142

138143
export interface CustomBlocksOptions extends Pick<PluginOptions, 'defaultSFCLang' | 'globalSFCScope'> {}

0 commit comments

Comments
 (0)