Skip to content

Commit 10dd79d

Browse files
authored
feat!: promote autoImportTranslationFunctions (#3523)
1 parent edd838a commit 10dd79d

12 files changed

Lines changed: 44 additions & 35 deletions

File tree

docs/content/docs/02.guide/90.migrating.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,9 @@ We have upgrade from Vue I18n v10 to v11, this major version bump deprecates the
1010

1111
Check the documentation detailing the breaking changes [here](https://vue-i18n.intlify.dev/guide/migration/breaking11.html).
1212

13+
### Promote `experimental.autoImportTranslationFunctions` to `autoDeclare`
14+
This functionality is stable and is now enabled by default, the option has been moved out of the `experimental` configuration object and renamed to `autoDeclare`.
15+
1316
### Promote `experimental.switchLocalePathLinkSSR`
1417
This functionality is stable and is now enabled by default and the option to enable/disable it has been removed.
1518

docs/content/docs/04.api/00.options.md

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -452,16 +452,6 @@ Experimental configuration property is an object with the following properties:
452452
For more details on how to define the locale detector, see the [`defineI18nLocaleDetector()`{lang="ts"} API](/docs/composables/define-i18n-locale-detector)
453453
::
454454

455-
### `autoImportTranslationFunctions`
456-
457-
- type: `boolean`{lang="ts-type"}
458-
- default: `false`{lang="ts"}
459-
- Automatically imports/initializes `$t()`{lang="ts"}, `$rt()`{lang="ts"}, `$d()`{lang="ts"}, `$n()`{lang="ts"}, `$tm()`{lang="ts"} and `$te()`{lang="ts"} functions in `<script setup>`{lang="html"} when used.
460-
461-
::callout{icon="i-heroicons-exclamation-triangle" color="warning"}
462-
This feature relies on [Nuxt's Auto-imports](https://nuxt.com/docs/guide/concepts/auto-imports) and will not work if this has been disabled.
463-
::
464-
465455
### `typedPages`
466456

467457
- type: `boolean`{lang="ts-type"}
@@ -616,3 +606,13 @@ Set the plugin as `parallel`. See [nuxt plugin loading strategy](https://nuxt.co
616606
- default: `'i18n'`{lang="ts-type"}
617607

618608
Used to configure the directory used to resolve i18n files.
609+
610+
## autoDeclare
611+
612+
- type: `boolean`{lang="ts-type"}
613+
- default: `true`{lang="ts"}
614+
- Automatically imports/initializes `$t()`{lang="ts"}, `$rt()`{lang="ts"}, `$d()`{lang="ts"}, `$n()`{lang="ts"}, `$tm()`{lang="ts"} and `$te()`{lang="ts"} functions in `<script setup>`{lang="html"} when used.
615+
616+
::callout{icon="i-heroicons-exclamation-triangle" color="warning"}
617+
This feature relies on [Nuxt's Auto-imports](https://nuxt.com/docs/guide/concepts/auto-imports) and will not work if this has been disabled.
618+
::

specs/basic-usage-tests.ts

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -530,14 +530,12 @@ export function basicUsageTests() {
530530
expect(await getText(page, '#install-module-vue-i18n')).toEqual('Installer module vue-i18n works!')
531531
})
532532

533-
describe('experimental.autoImportTranslationFunctions', async () => {
534-
test('can use `$t` in `<template>`', async () => {
535-
const { consoleLogs } = await renderPage('/experimental/auto-import-translation-functions')
533+
test('can use `$t` in `<template>` with `autoDeclare``', async () => {
534+
const { consoleLogs } = await renderPage('/experimental/auto-import-translation-functions')
536535

537-
const logStrings = consoleLogs.map(x => x.text)
538-
expect(logStrings).toContain('[autoImportTranslationFunctions][default]: Welcome')
539-
expect(logStrings).toContain('[autoImportTranslationFunctions][fr]: Bienvenue')
540-
})
536+
const logStrings = consoleLogs.map(x => x.text)
537+
expect(logStrings).toContain('[autoDeclare][default]: Welcome')
538+
expect(logStrings).toContain('[autoDeclare][fr]: Bienvenue')
541539
})
542540

543541
test('dynamic parameters render and update reactively client-side', async () => {

specs/fixtures/basic_usage/nuxt.config.ts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,7 @@ export default defineNuxtConfig({
2020
locales: ['en', 'fr'],
2121
defaultLocale: 'en',
2222
experimental: {
23-
alternateLinkCanonicalQueries: false,
24-
autoImportTranslationFunctions: true
23+
alternateLinkCanonicalQueries: false
2524
}
2625
}
2726
})

specs/fixtures/basic_usage/pages/experimental/auto-import-translation-functions.vue

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
<script setup lang="ts">
2-
console.log(`[autoImportTranslationFunctions][default]: ${$t('welcome')}`)
3-
console.log(`[autoImportTranslationFunctions][fr]: ${$t('welcome', 1, { locale: 'fr' })}`)
2+
console.log(`[autoDeclare][default]: ${$t('welcome')}`)
3+
console.log(`[autoDeclare][fr]: ${$t('welcome', 1, { locale: 'fr' })}`)
44
</script>
55

66
<template>

specs/fixtures/basic_usage_compat_4/app/pages/experimental/auto-import-translation-functions.vue

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
<script setup lang="ts">
2-
console.log(`[autoImportTranslationFunctions][default]: ${$t('welcome')}`)
3-
console.log(`[autoImportTranslationFunctions][fr]: ${$t('welcome', 1, { locale: 'fr' })}`)
2+
console.log(`[autoDeclare][default]: ${$t('welcome')}`)
3+
console.log(`[autoDeclare][fr]: ${$t('welcome', 1, { locale: 'fr' })}`)
44
</script>
55

66
<template>

specs/fixtures/basic_usage_compat_4/nuxt.config.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,6 @@ export default defineNuxtConfig({
2424
defaultLocale: 'en',
2525
experimental: {
2626
alternateLinkCanonicalQueries: false,
27-
autoImportTranslationFunctions: true,
2827
localeDetector: './localeDetector.ts'
2928
}
3029
}

src/bundler.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,7 @@ export function createLogger(label) {
7474
webpack: () => VueI18nPlugin.webpack(vueI18nPluginOptions)
7575
})
7676
addBuildPlugin(TransformMacroPlugin(pluginOptions))
77-
if (options.experimental.autoImportTranslationFunctions) {
77+
if (options.autoDeclare) {
7878
addBuildPlugin(TransformI18nFunctionPlugin(pluginOptions))
7979
}
8080

src/constants.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,6 @@ export const DEFAULT_OPTIONS = {
2727
restructureDir: 'i18n',
2828
experimental: {
2929
localeDetector: '',
30-
autoImportTranslationFunctions: false,
3130
typedPages: true,
3231
typedOptionsAndMessages: false,
3332
alternateLinkCanonicalQueries: false,
@@ -77,7 +76,8 @@ export const DEFAULT_OPTIONS = {
7776
debug: false,
7877
parallelPlugin: false,
7978
multiDomainLocales: false,
80-
hmr: true
79+
hmr: true,
80+
autoDeclare: true
8181
} as const
8282

8383
export const NUXT_I18N_TEMPLATE_OPTIONS_KEY = 'i18n.options.mjs'

src/gen.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -245,7 +245,7 @@ declare module '#app' {
245245
246246
${typedRouterAugmentations}
247247
248-
${(options.experimental?.autoImportTranslationFunctions && globalTranslationTypes) || ''}
248+
${(options.autoDeclare && globalTranslationTypes) || ''}
249249
250250
export {}`
251251
}

0 commit comments

Comments
 (0)