Skip to content

Commit 08975bd

Browse files
authored
chore!: drop deprecated functions and composables (#3514)
* chore!: drop deprecated functions and composables * fix: remove unused export * test: remove import
1 parent 35c3601 commit 08975bd

8 files changed

Lines changed: 18 additions & 166 deletions

File tree

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

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,16 @@ description: Follow this guide to upgrade from one major version to the other.
55

66
## Upgrading from `nuxtjs/i18n` v9.x to v10.x
77

8+
### Dropped Nuxt context functions
9+
10+
The following functions have been removed from the Nuxt context.
11+
* `$resolveRoute()`{lang="ts"}
12+
* `$localeLocation()`{lang="ts"}
13+
14+
Steps to migrate
15+
* `$resolveRoute()`{lang="ts"} -> use `$localeRoute()` instead
16+
* `$localeLocation()`{lang="ts"} -> use `$localeRoute()` instead
17+
818
### Drop `bundle.optimizeTranslationDirective`
919
This feature has been disabled and the option to enable it has been removed, see [the discussion in this issue](https://github.com/nuxt-modules/i18n/issues/3238#issuecomment-2672492536) for context on this change.
1020

specs/fixtures/routing/pages/index.vue

Lines changed: 1 addition & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,7 @@
11
<script lang="ts" setup>
2-
import { useLocaleLocation, useLocalePath, useLocaleRoute } from '#i18n'
2+
import { useLocalePath, useLocaleRoute } from '#i18n'
33
44
const localePath = useLocalePath()
5-
const localeLocation = useLocaleLocation()
65
const localeRoute = useLocaleRoute()
76
</script>
87

@@ -66,21 +65,6 @@ const localeRoute = useLocaleRoute()
6665
<span class="undefined-name-ja">{{ JSON.stringify(localeRoute('vue-i18n', 'ja')) }}</span>
6766
</section>
6867
</ClientOnly>
69-
<ClientOnly>
70-
<section id="locale-location">
71-
<span class="index">{{ JSON.stringify(localeLocation('/')) }}</span>
72-
<span class="index-name-ja">{{ JSON.stringify(localeLocation('index', 'ja')) }}</span>
73-
<span class="about-name">{{ JSON.stringify(localeLocation('about')) }}</span>
74-
<span class="about-ja">{{ JSON.stringify(localeLocation('/about', 'ja')) }}</span>
75-
<span class="about-name-ja">{{ JSON.stringify(localeLocation('about', 'ja')) }}</span>
76-
<span class="about-object-ja">{{ JSON.stringify(localeLocation({ name: 'about' }, 'ja')) }}</span>
77-
<span class="path-match-ja">{{ JSON.stringify(localeLocation('/:pathMatch(.*)*', 'ja')) }}</span>
78-
<span class="path-match-name">{{ JSON.stringify(localeLocation('pathMatch')) }}</span>
79-
<span class="path-match-name-ja">{{ JSON.stringify(localeLocation('pathMatch', 'ja')) }}</span>
80-
<span class="undefined-path-ja">{{ JSON.stringify(localeRoute('/vue-i18n', 'ja')) }}</span>
81-
<span class="undefined-name-ja">{{ JSON.stringify(localeRoute('vue-i18n', 'ja')) }}</span>
82-
</section>
83-
</ClientOnly>
8468
</div>
8569
</template>
8670

specs/routing/composition.spec.ts

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import { fileURLToPath } from 'node:url'
22
import { describe, it } from 'vitest'
33

44
import { setup } from '../utils'
5-
import { localeLocationTests, localeRouteTests, switchLocalePathTests } from './routing-tests'
5+
import { localeRouteTests, switchLocalePathTests } from './routing-tests'
66

77
await setup({
88
rootDir: fileURLToPath(new URL(`../fixtures/routing`, import.meta.url)),
@@ -22,12 +22,6 @@ describe('localeRoute', async () => {
2222
})
2323
})
2424

25-
describe('localeLocation', async () => {
26-
it('should work', async () => {
27-
await localeLocationTests()
28-
})
29-
})
30-
3125
describe('switchLocalePath', async () => {
3226
it('should work', async () => {
3327
await switchLocalePathTests()

specs/routing/legacy.spec.ts

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import { fileURLToPath } from 'node:url'
22
import { describe, it } from 'vitest'
33

44
import { setup } from '../utils'
5-
import { localeLocationTests, localeRouteTests, switchLocalePathTests } from './routing-tests'
5+
import { localeRouteTests, switchLocalePathTests } from './routing-tests'
66

77
await setup({
88
rootDir: fileURLToPath(new URL(`../fixtures/routing`, import.meta.url)),
@@ -23,12 +23,6 @@ describe('localeRoute', async () => {
2323
})
2424
})
2525

26-
describe('localeLocation', async () => {
27-
it('should work', async () => {
28-
await localeLocationTests()
29-
})
30-
})
31-
3226
describe('switchLocalePath', async () => {
3327
it('should work', async () => {
3428
await switchLocalePathTests()

specs/routing/routing-tests.ts

Lines changed: 0 additions & 80 deletions
Original file line numberDiff line numberDiff line change
@@ -124,86 +124,6 @@ export async function switchLocalePathTests() {
124124
// expect(await getText(page, '#switch-locale-path .en')).toEqual('/en/not-found-english')
125125
}
126126

127-
export async function localeLocationTests() {
128-
const { page } = await renderPage('/en')
129-
130-
expect(JSON.parse(await getText(page, '#locale-location .index'))).include({
131-
fullPath: '/en',
132-
path: '/en',
133-
name: 'index___en',
134-
href: '/en'
135-
})
136-
137-
expect(JSON.parse(await getText(page, '#locale-location .index-name-ja'))).include({
138-
fullPath: '/ja',
139-
path: '/ja',
140-
name: 'index___ja',
141-
href: '/ja'
142-
})
143-
144-
expect(JSON.parse(await getText(page, '#locale-location .about-name'))).include({
145-
fullPath: '/en/about',
146-
path: '/en/about',
147-
name: 'about___en',
148-
href: '/en/about'
149-
})
150-
151-
expect(JSON.parse(await getText(page, '#locale-location .about-ja'))).include({
152-
fullPath: '/ja/about',
153-
path: '/ja/about',
154-
name: 'about___ja',
155-
href: '/ja/about'
156-
})
157-
158-
expect(JSON.parse(await getText(page, '#locale-location .about-name-ja'))).include({
159-
fullPath: '/ja/about',
160-
path: '/ja/about',
161-
name: 'about___ja',
162-
href: '/ja/about'
163-
})
164-
165-
expect(JSON.parse(await getText(page, '#locale-location .path-match-ja'))).include({
166-
fullPath: '/ja/:pathMatch(.*)*',
167-
path: '/ja/:pathMatch(.*)*',
168-
name: 'pathMatch___ja',
169-
href: '/ja/:pathMatch(.*)*'
170-
})
171-
172-
// name
173-
expect(JSON.parse(await getText(page, '#locale-location .path-match-name'))).include({
174-
fullPath: '/en',
175-
path: '/en',
176-
name: 'pathMatch___en',
177-
href: '/en'
178-
})
179-
180-
expect(JSON.parse(await getText(page, '#locale-location .path-match-name-ja'))).include({
181-
fullPath: '/ja',
182-
path: '/ja',
183-
name: 'pathMatch___ja',
184-
href: '/ja'
185-
})
186-
187-
// object
188-
expect(JSON.parse(await getText(page, '#locale-location .about-object-ja'))).include({
189-
fullPath: '/ja/about',
190-
path: '/ja/about',
191-
name: 'about___ja',
192-
href: '/ja/about'
193-
})
194-
195-
// undefined path
196-
expect(JSON.parse(await getText(page, '#locale-location .undefined-path-ja'))).include({
197-
fullPath: '/ja/vue-i18n',
198-
path: '/ja/vue-i18n',
199-
name: 'pathMatch___ja',
200-
href: '/ja/vue-i18n'
201-
})
202-
203-
// undefined name
204-
expect(await getText(page, '#locale-location .undefined-name-ja')).toEqual('')
205-
}
206-
207127
export async function localeRouteTests() {
208128
const { page } = await renderPage('/en')
209129

src/runtime/composables/index.ts

Lines changed: 1 addition & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -6,15 +6,8 @@ import { _useLocaleHead, _useSetI18nParams } from '../routing/head'
66
import { getRouteBaseName, localePath, localeRoute, switchLocalePath } from '../routing/routing'
77
import type { Ref } from 'vue'
88
import type { Locale } from 'vue-i18n'
9-
import type { resolveRoute } from '../routing/routing'
109
import type { I18nHeadMetaInfo, I18nHeadOptions, SeoAttributesOptions } from '#internal-i18n-types'
11-
import type {
12-
RouteLocationAsRelativeI18n,
13-
RouteLocationRaw,
14-
RouteLocationResolvedI18n,
15-
RouteMap,
16-
RouteMapI18n
17-
} from 'vue-router'
10+
import type { RouteLocationAsRelativeI18n, RouteLocationResolvedI18n, RouteMap, RouteMapI18n } from 'vue-router'
1811
import type { RouteLocationGenericPath, I18nRouteMeta } from '../types'
1912

2013
export * from 'vue-i18n'
@@ -74,18 +67,6 @@ export function useLocaleHead({
7467

7568
type RouteLocationI18nGenericPath = Omit<RouteLocationAsRelativeI18n, 'path'> & { path?: string }
7669

77-
/**
78-
* Revoles a localized route object for the passed route.
79-
*
80-
* @param route - a route name or route object.
81-
* @param locale - (default: current locale).
82-
*
83-
* @returns Localized route object
84-
*
85-
* @deprecated use {@link useLocalePath}/{@link LocalePathFunction $localePath} or {@link useLocaleRoute}/{@link LocaleRouteFunction $localeRoute} instead
86-
*/
87-
export type ResolveRouteFunction = (route: RouteLocationRaw, locale?: Locale) => ReturnType<typeof resolveRoute>
88-
8970
/**
9071
* Resolves the route base name for the given route.
9172
*
@@ -146,32 +127,6 @@ export function useLocaleRoute(): LocaleRouteFunction {
146127
return wrapComposable(localeRoute)
147128
}
148129

149-
/**
150-
* Resolves a localized variant of the passed route.
151-
*
152-
* @param route - a route name or route object.
153-
* @param locale - (default: current locale).
154-
*
155-
* @returns A resolved route object
156-
*
157-
* @deprecated use {@link useLocaleRoute}/{@link LocaleRouteFunction $localeRoute} instead
158-
*/
159-
export type LocaleLocationFunction = <Name extends keyof RouteMapI18n = keyof RouteMapI18n>(
160-
route: Name | RouteLocationI18nGenericPath,
161-
locale?: Locale
162-
) => RouteLocationResolvedI18n<Name> | undefined
163-
164-
/**
165-
* Returns a {@link LocaleLocationFunction} used to resolve localized route objects.
166-
*
167-
* @deprecated use {@link useLocaleRoute}/{@link LocaleRouteFunction $localeRoute} instead
168-
*/
169-
export function useLocaleLocation(): LocaleLocationFunction {
170-
// we wrap `localeRoute` as the implementation is identical
171-
// @ts-expect-error - generated types conflict with the generic types we accept
172-
return wrapComposable(localeRoute)
173-
}
174-
175130
/**
176131
* Resolves a localized variant of the current path.
177132
*

src/runtime/plugins/i18n.ts

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -22,15 +22,14 @@ import { createLocaleFromRouteGetter } from '../routing/utils'
2222
import { extendI18n } from '../routing/i18n'
2323
import { createLogger } from '#nuxt-i18n/logger'
2424
import { getI18nTarget } from '../compatibility'
25-
import { resolveRoute } from '../routing/routing'
2625
import { localeHead } from '../routing/head'
27-
import { useLocalePath, useLocaleRoute, useRouteBaseName, useSwitchLocalePath, useLocaleLocation } from '../composables'
26+
import { useLocalePath, useLocaleRoute, useRouteBaseName, useSwitchLocalePath } from '../composables'
2827
import { getDefaultLocaleForDomain, setupMultiDomainLocales } from '../domain'
2928

3029
import type { Locale, I18nOptions, Composer } from 'vue-i18n'
3130
import type { NuxtApp } from '#app'
3231
import type { LocaleObject, I18nPublicRuntimeConfig } from '#internal-i18n-types'
33-
import type { LocaleHeadFunction, ResolveRouteFunction } from '../composables'
32+
import type { LocaleHeadFunction } from '../composables'
3433

3534
export default defineNuxtPlugin({
3635
name: 'i18n:plugin',
@@ -212,11 +211,7 @@ export default defineNuxtPlugin({
212211
localePath: useLocalePath(),
213212
localeRoute: useLocaleRoute(),
214213
getRouteBaseName: useRouteBaseName(),
215-
switchLocalePath: useSwitchLocalePath(),
216-
// TODO: remove in v10
217-
resolveRoute: wrapComposable(resolveRoute) as ResolveRouteFunction,
218-
// TODO: remove in v10
219-
localeLocation: useLocaleLocation()
214+
switchLocalePath: useSwitchLocalePath()
220215
}
221216
}
222217
}

src/runtime/routing/routing.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -111,7 +111,7 @@ function resolveRouteObject(common: CommonComposableOptions, route: RouteLike, l
111111
return route
112112
}
113113

114-
export function resolveRoute(common: CommonComposableOptions, route: RouteLocationRaw, locale?: Locale) {
114+
function resolveRoute(common: CommonComposableOptions, route: RouteLocationRaw, locale?: Locale) {
115115
try {
116116
const _locale = locale || unref(getI18nTarget(common.i18n).locale)
117117
const normalized = normalizeRawLocation(route)

0 commit comments

Comments
 (0)