提交正式官网
This commit is contained in:
@@ -0,0 +1,20 @@
|
||||
import { stripLocalePrefix, toLocalePath } from '~/utils/locale-path'
|
||||
import type { SiteLocale } from '~/types/locale'
|
||||
|
||||
export function useLocalePath() {
|
||||
const { locale } = useSiteLocale()
|
||||
|
||||
return (path: string, targetLocale?: SiteLocale) =>
|
||||
toLocalePath(path, targetLocale ?? locale.value)
|
||||
}
|
||||
|
||||
export function useSwitchLocale() {
|
||||
const route = useRoute()
|
||||
const { setLocale } = useSiteLocale()
|
||||
|
||||
return (next: SiteLocale) => {
|
||||
const basePath = stripLocalePrefix(route.path)
|
||||
setLocale(next)
|
||||
return navigateTo(toLocalePath(basePath, next))
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user