vue-i18n-routing
Advanced tools
Comparing version 0.0.0-50f6b19 to 0.0.0-56e9ef8
@@ -1,11 +0,109 @@ | ||
import type { I18n } from 'vue-i18n'; | ||
import { Locale } from 'vue-i18n'; | ||
import type { Route as Route_2 } from 'vue-router3'; | ||
import type { RouteConfig } from 'vue-router3'; | ||
import type { RouteLocationNormalizedLoaded } from 'vue-router'; | ||
import type { Router } from 'vue-router'; | ||
import VueI18n from 'vue-i18n-legacy'; | ||
import VueRouter from 'vue-router3'; | ||
import type { Composer } from '@intlify/vue-i18n-bridge'; | ||
import { EffectScope } from 'vue-demi'; | ||
import type { ExportedGlobalComposer } from '@intlify/vue-i18n-bridge'; | ||
import type { I18n } from '@intlify/vue-i18n-bridge'; | ||
import type { Locale } from '@intlify/vue-i18n-bridge'; | ||
import type { RawLocation } from '@intlify/vue-router-bridge'; | ||
import type { Ref } from 'vue-demi'; | ||
import { Route } from '@intlify/vue-router-bridge'; | ||
import type { RouteConfig } from '@intlify/vue-router-bridge'; | ||
import type { RouteLocation } from '@intlify/vue-router-bridge'; | ||
import { RouteLocationNormalized } from '@intlify/vue-router-bridge'; | ||
import { RouteLocationNormalizedLoaded } from '@intlify/vue-router-bridge'; | ||
import type { RouteLocationRaw } from '@intlify/vue-router-bridge'; | ||
import type { Router } from '@intlify/vue-router-bridge'; | ||
import type { RouterOptions } from '@intlify/vue-router-bridge'; | ||
import { useRoute } from '@intlify/vue-router-bridge'; | ||
import { useRouter } from '@intlify/vue-router-bridge'; | ||
import type { VueI18n } from '@intlify/vue-i18n-bridge'; | ||
import type { VueRouter } from '@intlify/vue-router-bridge'; | ||
export declare type BaseUrlResolveHandler<Context = unknown> = (context: Context) => string; | ||
/** | ||
* The browser locale info | ||
* | ||
* @remarks | ||
* This type is used by {@link FindBrowserLocaleOptions#sorter | sorter} in {@link findBrowserLocale} function | ||
*/ | ||
export declare type BrowserLocale = { | ||
/** | ||
* The locale code, such as BCP 47 (e.g `en-US`), or `ja` | ||
*/ | ||
code: string; | ||
/** | ||
* The score number | ||
* | ||
* @remarks | ||
* The score number that is used by `sorter` of {@link FindBrowserLocaleOptions} | ||
*/ | ||
score: number; | ||
}; | ||
/** | ||
* The browser locale matcher | ||
* | ||
* @remarks | ||
* This matcher is used by {@link findBrowserLocale} function | ||
* | ||
* @param locales - The target {@link LocaleObject | locale} list | ||
* @param browserLocales - The locale code list that is used in browser | ||
* | ||
* @returns The matched {@link BrowserLocale | locale info} | ||
*/ | ||
export declare type BrowserLocaleMatcher = (locales: TargetLocale[], browserLocales: string[]) => BrowserLocale[]; | ||
export declare type ComposableOptions = { | ||
route?: ReturnType<typeof useRoute>; | ||
router?: ReturnType<typeof useRouter>; | ||
i18n?: Composer; | ||
}; | ||
/** | ||
* Options to compute route localizing | ||
* | ||
* @remarks | ||
* The route options that is compute the route to be localized on {@link localizeRoutes} | ||
*/ | ||
export declare type ComputedRouteOptions = { | ||
locales: readonly string[]; | ||
paths: Record<string, string>; | ||
}; | ||
export declare function createLocaleFromRouteGetter(localeCodes: string[], routesNameSeparator: string, defaultLocaleRouteNameSuffix: string): (route: Route | RouteLocationNormalizedLoaded | RouteLocationNormalized | string) => string; | ||
/** | ||
* Create a Vue Router instance | ||
* | ||
* @param i18n - A Vue I18n instance, see [Vue I18n API docs](https://vue-i18n.intlify.dev/api/general.html#i18n) | ||
* @param options - An options, see {@link I18nRoutingOptions} | ||
* | ||
* @returns A Vue Router instance | ||
* | ||
* @remakrs | ||
* You can create a vue router instance to be used by the Vue app. | ||
* | ||
* The routes of the created router instance are handled with i18n routing. | ||
* | ||
* At the Vue 2 will return a [Vue Router v3 instance](https://router.vuejs.org/api/#router-construction-options), and at the Vue 3 will return a [Vue Router v4 instance](https://next.router.vuejs.org/api/#createrouter). | ||
* | ||
* @public | ||
*/ | ||
export declare function createRouter<Options extends I18nRoutingOptions = I18nRoutingOptions>(i18n: I18n, options?: Options): Options['version'] extends 4 ? Router : VueRouter; | ||
export declare const DEFAULT_BASE_URL = ""; | ||
export declare const DEFAULT_DETECTION_DIRECTION = "ltr"; | ||
export declare const DEFAULT_LOCALE = ""; | ||
export declare const DEFAULT_LOCALE_ROUTE_NAME_SUFFIX = "default"; | ||
export declare const DEFAULT_ROUTES_NAME_SEPARATOR = "___"; | ||
export declare const DEFAULT_STRATEGY: "prefix_except_default"; | ||
export declare const DEFAULT_TRAILING_SLASH = false; | ||
/** | ||
* Direction | ||
@@ -15,17 +113,237 @@ */ | ||
export declare function extendRouting<TRouter extends VueRouter | Router>({ router, i18n, defaultLocale, trailingSlash, routesNameSeparator, defaultLocaleRouteNameSuffix, localeCodes }?: VueI18nRoutingOptions): TRouter; | ||
export declare type ExtendComposerHook = (compser: Composer) => void; | ||
export declare interface I18nRouting { | ||
getRouteBaseName(givenRoute?: Route_2 | RouteLocationNormalizedLoaded): string; | ||
localePath(route: any, locale?: Locale): string; | ||
localeRoute(route: any, locale?: Locale): any; | ||
localeLocation(route: any, locale?: Locale): any; | ||
switchLocalePath(locale: Locale): void; | ||
export declare type ExtendExportedGlobalHook = (global: Composer) => ExtendProperyDescripters; | ||
export declare interface ExtendHooks { | ||
onExtendComposer?: ExtendComposerHook; | ||
onExtendExportedGlobal?: ExtendExportedGlobalHook; | ||
onExtendVueI18n?: ExtendVueI18nHook; | ||
} | ||
export declare type I18nRoutingOptions = Pick<VueI18nRoutingOptions, 'defaultLocale' | 'strategy' | 'defaultLocaleRouteNameSuffix' | 'trailingSlash' | 'localeCodes'> & { | ||
routesNameSeparator?: string; | ||
export declare function extendI18n<TI18n extends I18n>(i18n: TI18n, { locales, localeCodes, baseUrl, hooks }?: VueI18nExtendOptions): EffectScope; | ||
export declare type ExtendProperyDescripters = { | ||
[key: string]: Pick<PropertyDescriptor, 'get'>; | ||
}; | ||
export declare type ExtendVueI18nHook = (composer: Composer) => ExtendProperyDescripters; | ||
/** | ||
* Find the browser locale | ||
* | ||
* @param locales - The target {@link LocaleObject | locale} list | ||
* @param browserLocales - The locale code list that is used in browser | ||
* @param options - The options for {@link findBrowserLocale} function | ||
* | ||
* @returns The matched the locale code | ||
*/ | ||
export declare function findBrowserLocale(locales: LocaleObject[], browserLocales: string[], { matcher, comparer }?: FindBrowserLocaleOptions): string | ''; | ||
/** | ||
* The options for {@link findBrowserLocale} function | ||
*/ | ||
export declare type FindBrowserLocaleOptions = { | ||
matcher?: BrowserLocaleMatcher; | ||
comparer?: (a: BrowserLocale, b: BrowserLocale) => number; | ||
}; | ||
/** | ||
* Get global i18n routing options | ||
* | ||
* @param router - A router instance, about router type | ||
* | ||
* @returns - {@link I18nRoutingGlobalOptions | global options} from i18n routing options registory, if registered, return it, else empty object | ||
*/ | ||
export declare function getGlobalOptions(router: Router | VueRouter): I18nRoutingGlobalOptions; | ||
/** | ||
* Get a locale | ||
* | ||
* @param i18n - An [I18n](https://vue-i18n.intlify.dev/api/general.html#i18n) instance or a [Composer](https://vue-i18n.intlify.dev/api/composition.html#composer) instance | ||
* | ||
* @returns A locale | ||
*/ | ||
export declare function getLocale(i18n: I18n | Composer | VueI18n): Locale; | ||
export declare function getLocaleCodes(i18n: I18n | VueI18n | Composer): string[]; | ||
export declare function getLocales(i18n: I18n | VueI18n | Composer): string[] | LocaleObject[]; | ||
export declare function getLocalesRegex(localeCodes: string[]): RegExp; | ||
export declare function getRouteBaseName(this: RoutingProxy, givenRoute?: Route | RouteLocationNormalizedLoaded): string | undefined; | ||
export declare type I18nCommonRoutingOptions = Pick<I18nRoutingOptions, 'defaultLocale' | 'strategy' | 'defaultLocaleRouteNameSuffix' | 'trailingSlash' | 'locales' | 'routesNameSeparator'>; | ||
export declare type I18nCommonRoutingOptionsWithComposable = I18nCommonRoutingOptions & ComposableOptions; | ||
/** | ||
* I18n header meta info | ||
*/ | ||
export declare interface I18nHeadMetaInfo { | ||
htmlAttrs?: MetaAttrs; | ||
meta?: MetaAttrs[]; | ||
link?: MetaAttrs[]; | ||
} | ||
/** | ||
* Options for {@link localeHead} function | ||
*/ | ||
export declare interface I18nHeadOptions { | ||
/** | ||
* Adds a `dir` attribute to the HTML element. | ||
* | ||
* @defaultValue false | ||
*/ | ||
addDirAttribute?: boolean; | ||
/** | ||
* Adds various SEO attributes. | ||
* | ||
* @defaultValue false | ||
*/ | ||
addSeoAttributes?: boolean | SeoAttributesOptions; | ||
} | ||
/** | ||
* Route config for vue-i18n-routing | ||
*/ | ||
export declare type I18nRoute = Route_2 & RouteLegacy & { | ||
redirect?: string; | ||
}; | ||
/** | ||
* Global options for i18n routing | ||
*/ | ||
export declare type I18nRoutingGlobalOptions<BaseUrl extends BaseUrlResolveHandler = BaseUrlResolveHandler> = Pick<I18nRoutingOptions<BaseUrl>, 'defaultLocale' | 'defaultDirection' | 'defaultLocaleRouteNameSuffix' | 'trailingSlash' | 'routesNameSeparator' | 'strategy'> & { | ||
localeCodes?: string[]; | ||
}; | ||
/** | ||
* Options to initialize a VueRouter instance | ||
* | ||
* @remarks | ||
* This options is extended from Vue Router `RouterOptioins`, so you can specify those options. | ||
*/ | ||
export declare type I18nRoutingOptions<BaseUrl extends BaseUrlResolveHandler = BaseUrlResolveHandler> = { | ||
/** | ||
* Vue Router version | ||
* | ||
* @remarks | ||
* You can choice between vue-router v3 and v4. | ||
* | ||
* If you specify `3`, this function return Vue Router v3 instance, else specify `4`, this function return Vue Router v4 instance. | ||
* | ||
* @defaultValue 4 | ||
*/ | ||
version?: 3 | 4; | ||
/** | ||
* The app's default locale | ||
* | ||
* @remarks | ||
* When using `prefix_except_default` strategy, URLs for locale specified here won't have a prefix. | ||
* | ||
* It's recommended to set this to some locale regardless of chosen strategy, as it will be used as a fallback locale when navigating to a non-existent route | ||
* | ||
* @defaultValue '' (emputy string) | ||
*/ | ||
defaultLocale?: string; | ||
/** | ||
* List of locales supported by your app | ||
* | ||
* @remarks | ||
* Can either be an array of string codes (e.g. `['en', 'fr']`) or an array of {@link LocaleObject} for more complex configurations | ||
* | ||
* @defaultValue [] | ||
*/ | ||
locales?: string[] | LocaleObject[]; | ||
/** | ||
* Routes strategy | ||
* | ||
* @remarks | ||
* Can be set to one of the following: | ||
* | ||
* - `no_prefix`: routes won't have a locale prefix | ||
* - `prefix_except_default`: locale prefix added for every locale except default | ||
* - `prefix`: locale prefix added for every locale | ||
* - `prefix_and_default`: locale prefix added for every locale and default | ||
* | ||
* @defaultValue 'prefix_except_default' | ||
*/ | ||
strategy?: Strategies; | ||
/** | ||
* Whether to use trailing slash | ||
* | ||
* @defaultValue false | ||
*/ | ||
trailingSlash?: boolean; | ||
/** | ||
* Internal separator used for generated route names for each locale. You shouldn't need to change this | ||
* | ||
* @defaultValue '___' | ||
*/ | ||
routesNameSeparator?: string; | ||
/** | ||
* Internal suffix added to generated route names for default locale | ||
* | ||
* @remarks | ||
* if strategy is prefix_and_default. You shouldn't need to change this. | ||
* | ||
* @defaultValue 'default' | ||
*/ | ||
defaultLocaleRouteNameSuffix?: string; | ||
/** | ||
* Default direction direction | ||
* | ||
* @defaultValue 'ltr' | ||
*/ | ||
defaultDirection?: Directions; | ||
/** | ||
* The fallback base URL to use as a prefix for alternate URLs in hreflang tags. | ||
* | ||
* @remarks | ||
* By default VueRouter's base URL will be used and only if that is not available, fallback URL will be used. | ||
* | ||
* Can also be a function (will be passed a Nuxt Context as a parameter) that returns a string. | ||
* | ||
* Useful to make base URL dynamic based on request headers. | ||
* | ||
* @defaultValue '' | ||
*/ | ||
baseUrl?: string | BaseUrl; | ||
/** | ||
* Route options resolver | ||
* | ||
* @defaultValue undefined | ||
*/ | ||
routeOptionsResolver?: RouteOptionsResolver; | ||
} & RouterOptions; | ||
export declare function isComposer(target: any): target is Composer; | ||
export declare function isExportedGlobalComposer(target: any): target is ExportedGlobalComposer; | ||
export declare function isI18nInstance(i18n: any): i18n is I18n; | ||
export declare function isLegacyVueI18n(target: any): target is Pick<VueI18n, 'locale'>; | ||
export declare function isVueI18n(target: any): target is VueI18n; | ||
export declare function localeHead(this: RoutingProxy, { addDirAttribute, addSeoAttributes }?: I18nHeadOptions): I18nHeadMetaInfo; | ||
export declare function localeLocation(this: RoutingProxy, route: RawLocation | RouteLocationRaw, locale?: Locale): Location | RouteLocation | undefined; | ||
/** | ||
* Resolve locale location function | ||
* | ||
* @param route - A route location. The path or name of the route or an object for more complex routes | ||
* @param locale - A locale code, if not specified, uses the current locale | ||
* | ||
* @returns Returns the location object for a given route, the location object is resolved by vue-router rather than just a full route path. | ||
* | ||
* @see {@link useLocaleLocation} | ||
*/ | ||
export declare type LocaleLocationFunction = (route: RawLocation | RouteLocationRaw, locale?: Locale) => Location | RouteLocation | undefined; | ||
/** | ||
* Locale object | ||
@@ -43,18 +361,83 @@ */ | ||
export declare function localizeRoutes(routes: VueI18nRoute[], { defaultLocale, strategy, trailingSlash, routesNameSeparator, defaultLocaleRouteNameSuffix, includeUprefixedFallback, localeCodes }?: Pick<VueI18nRoutingOptions, 'defaultLocale' | 'strategy' | 'localeCodes' | 'routesNameSeparator' | 'trailingSlash' | 'defaultLocaleRouteNameSuffix'> & { | ||
export declare function localePath(this: RoutingProxy, route: RawLocation | RouteLocationRaw, locale?: Locale): string; | ||
/** | ||
* Resolve locale path function | ||
* | ||
* @param route - A route location. The path or name of the route or an object for more complex routes | ||
* @param locale - A locale code, if not specified, uses the current locale | ||
* | ||
* @returns Returns the localized URL for a given route | ||
* | ||
* @see {@link useLocalePath} | ||
*/ | ||
export declare type LocalePathFunction = (route: RawLocation | RouteLocation, locale?: Locale) => string; | ||
export declare function localeRoute(this: RoutingProxy, route: RawLocation | RouteLocationRaw, locale?: Locale): Route | ReturnType<Router['resolve']> | undefined; | ||
/** | ||
* Resolve route fucntion | ||
* | ||
* @param route - A route location. The path or name of the route or an object for more complex routes | ||
* @param locale - A locale code, if not specified, uses the current locale | ||
* | ||
* @returns Returns the route object for a given route, the route object is resolved by vue-router rather than just a full route path. | ||
* | ||
* @see {@link useLocaleRoute} | ||
*/ | ||
export declare type LocaleRouteFunction = (route: RawLocation | RouteLocationRaw, locale?: Locale) => Route | ReturnType<Router['resolve']> | undefined; | ||
/** | ||
* Localize routes | ||
* | ||
* @param routes - Some routes | ||
* @param options - An options | ||
* | ||
* @returns Localized routes | ||
* | ||
* @public | ||
*/ | ||
export declare function localizeRoutes(routes: I18nRoute[], { defaultLocale, strategy, trailingSlash, routesNameSeparator, defaultLocaleRouteNameSuffix, includeUprefixedFallback, optionsResolver, locales }?: Pick<I18nRoutingOptions, 'defaultLocale' | 'strategy' | 'locales' | 'routesNameSeparator' | 'trailingSlash' | 'defaultLocaleRouteNameSuffix'> & { | ||
includeUprefixedFallback?: boolean; | ||
}): VueI18nRoute[]; | ||
optionsResolver?: RouteOptionsResolver; | ||
}): I18nRoute[]; | ||
export declare type MetaAttrs = Record<string, any>; | ||
export declare function proxyVueInstance(target: Function): Function; | ||
/** | ||
* Register global i18n routing option registory | ||
* | ||
* @param router - A router instance, about router type | ||
* @param options - A global options, about options type, see {@link I18nRoutingGlobalOptions} | ||
*/ | ||
export declare function registerGlobalOptions<BaseUrl extends BaseUrlResolveHandler = BaseUrlResolveHandler>(router: Router | VueRouter, options: I18nRoutingGlobalOptions<BaseUrl>): void; | ||
/** | ||
* Resolve base url | ||
* | ||
* @param baseUrl - A base url to resolve on SEO and domain. if you want to resolve with dynamically, you can spacify {@link BaseUrlResolveHandler} | ||
* @param context - A context to resolve base url, if you want to resolve base url with {@link BaseUrlResolveHandler} | ||
* | ||
* @returns A resolved base url | ||
*/ | ||
export declare function resolveBaseUrl<Context = unknown>(baseUrl: string | BaseUrlResolveHandler<Context>, context: Context): string; | ||
export declare function resolveRoute(this: RoutingProxy, route: any, locale?: Locale): any; | ||
export { Route } | ||
declare type _Route = UnionToIntersection<RouteConfig>; | ||
/** | ||
* Route config for vue-router v4 | ||
*/ | ||
export declare interface Route { | ||
declare interface Route_2 { | ||
name?: string; | ||
path: string; | ||
file?: string; | ||
children?: Route[]; | ||
children?: Route_2[]; | ||
} | ||
declare type _Route = UnionToIntersection<RouteConfig>; | ||
/** | ||
@@ -70,3 +453,55 @@ * Route config for lagacy vue-router v3 | ||
declare const STRATEGIES: { | ||
export { RouteLocationNormalized } | ||
export { RouteLocationNormalizedLoaded } | ||
/** | ||
* Resolver for route localizing options | ||
*/ | ||
export declare type RouteOptionsResolver = (route: I18nRoute, localeCodes: string[]) => ComputedRouteOptions | null; | ||
/** | ||
* Routing Proxy | ||
*/ | ||
export declare type RoutingProxy = { | ||
i18n: any; | ||
getRouteBaseName: any; | ||
localePath: any; | ||
localeRoute: any; | ||
localeLocation: any; | ||
resolveRoute: any; | ||
switchLocalePath: any; | ||
localeHead: any; | ||
route: Route | RouteLocationNormalizedLoaded; | ||
router: Router | VueRouter; | ||
defaultLocale?: string; | ||
localeCodes?: string[]; | ||
strategy?: Strategies; | ||
defaultDirection?: Directions; | ||
defaultLocaleRouteNameSuffix?: string; | ||
trailingSlash?: boolean; | ||
routesNameSeparator?: string; | ||
}; | ||
/** | ||
* SEO Attribute options | ||
*/ | ||
export declare interface SeoAttributesOptions { | ||
/** | ||
* An array of strings corresponding to query params you would like to include in your canonical URL. | ||
* | ||
* @defaultValue [] | ||
*/ | ||
canonicalQueries?: string[]; | ||
} | ||
/** | ||
* Set a locale | ||
* | ||
* @param i18n - An [I18n](https://vue-i18n.intlify.dev/api/general.html#i18n) instance or a [Composer](https://vue-i18n.intlify.dev/api/composition.html#composer) instance | ||
* @param locale - A target locale | ||
*/ | ||
export declare function setLocale(i18n: I18n | Composer, locale: Locale): void; | ||
export declare const STRATEGIES: { | ||
readonly PREFIX: "prefix"; | ||
@@ -83,7 +518,81 @@ readonly PREFIX_EXCEPT_DEFAULT: "prefix_except_default"; | ||
export declare function switchLocalePath(this: RoutingProxy, locale: Locale): string; | ||
/** | ||
* Swtich locale path function | ||
* | ||
* @param locale - A locale code, if not specified, uses the current locale | ||
* | ||
* @returns Returns a link to the current route in another language | ||
* | ||
* @see {@link useSwitchLocalePath} | ||
*/ | ||
export declare type SwitchLocalePathFunction = (locale?: Locale) => string; | ||
/** | ||
* The target locale info | ||
* | ||
* @remarks | ||
* This type is used by {@link BrowserLocaleMatcher} first argument | ||
*/ | ||
export declare type TargetLocale = Required<Pick<LocaleObject, 'code' | 'iso'>>; | ||
declare type UnionToIntersection<T> = (T extends any ? (k: T) => void : never) extends (k: infer U) => void ? U : never; | ||
export declare function useI18nRouting<Legacy extends boolean = false>(options?: I18nRoutingOptions): I18nRouting; | ||
/** | ||
* Use localize head meta | ||
* | ||
* @param options - An options, see about details {@link I18nHeadOptions}, {@link ComposableOptions}, {@link I18nCommonRoutingOptions} | ||
* | ||
* @returns Genereated SEO head meta information | ||
*/ | ||
export declare function useLocaleHead({ addDirAttribute, addSeoAttributes, strategy, defaultLocale, route, router, i18n }?: Pick<I18nCommonRoutingOptionsWithComposable, 'strategy' | 'defaultLocale' | 'route' | 'router' | 'i18n'> & I18nHeadOptions): Ref<I18nHeadMetaInfo>; | ||
/** | ||
* Use resolve locale location | ||
* | ||
* @param options - An options, see about details {@link I18nRoutingOptions} | ||
* | ||
* @returns Returns a {@link LocaleLocationFunction} | ||
*/ | ||
export declare function useLocaleLocation({ router, route, i18n, defaultLocale, defaultLocaleRouteNameSuffix, routesNameSeparator, strategy, trailingSlash }?: I18nCommonRoutingOptionsWithComposable): LocaleLocationFunction; | ||
/** | ||
* Use resolve locale path | ||
* | ||
* @param options - An options, see about details {@link I18nRoutingOptions} | ||
* | ||
* @returns Returns a {@link LocalePathFunction} | ||
*/ | ||
export declare function useLocalePath({ router, route, i18n, defaultLocale, defaultLocaleRouteNameSuffix, routesNameSeparator, strategy, trailingSlash }?: I18nCommonRoutingOptionsWithComposable): LocalePathFunction; | ||
/** | ||
* Use resolve locale route | ||
* | ||
* @param options - An options, see about details {@link I18nRoutingOptions} | ||
* | ||
* @returns Returns a {@link LocaleRouteFunction} | ||
*/ | ||
export declare function useLocaleRoute({ router, route, i18n, defaultLocale, defaultLocaleRouteNameSuffix, routesNameSeparator, strategy, trailingSlash }?: I18nCommonRoutingOptionsWithComposable): LocaleRouteFunction; | ||
/** | ||
* Use route base name | ||
* | ||
* @param givenRoute - A route object, if not provided, the route is returned with `useRoute` will be used | ||
* @param options - An options, see about details {@link I18nRoutingOptions} | ||
* | ||
* @returns The route base name, if route name is not defined, return null | ||
*/ | ||
export declare function useRouteBaseName(givenRoute?: Route | RouteLocationNormalizedLoaded, { router, routesNameSeparator }?: I18nCommonRoutingOptionsWithComposable): string | undefined; | ||
/** | ||
* Use swtich locale path | ||
* | ||
* @param options - An options, see about details {@link I18nRoutingOptions} | ||
* | ||
* @returns Returns a {@link SwitchLocalePathFunction} | ||
*/ | ||
export declare function useSwitchLocalePath({ router, route, i18n, defaultLocale, defaultLocaleRouteNameSuffix, routesNameSeparator, strategy, trailingSlash }?: I18nCommonRoutingOptionsWithComposable): SwitchLocalePathFunction; | ||
/** | ||
* Vue I18n Routing Version | ||
@@ -94,29 +603,20 @@ * | ||
*/ | ||
export declare const VERSION = ""; | ||
export declare const VERSION: string; | ||
/** | ||
* Route config for vue-i18n-routing | ||
*/ | ||
export declare type VueI18nRoute = Route & RouteLegacy & { | ||
redirect?: string; | ||
export declare type VueI18nExtendOptions = Pick<I18nRoutingOptions, 'baseUrl'> & { | ||
locales?: string[] | LocaleObject[]; | ||
localeCodes?: string[]; | ||
hooks?: ExtendHooks; | ||
}; | ||
/** | ||
* Vue I18n routing options | ||
* An options of Vue I18n Routing Plugin | ||
*/ | ||
export declare interface VueI18nRoutingOptions { | ||
export declare interface VueI18nRoutingPluginOptions { | ||
/** | ||
* Vue Router instance | ||
* Whether to inject some option APIs style methods into Vue instance | ||
* | ||
* @defaultValue `true` | ||
*/ | ||
router?: VueRouter | Router; | ||
/** | ||
* Vue I18n instance | ||
*/ | ||
i18n?: VueI18n | I18n; | ||
defaultLocale?: string; | ||
localeCodes?: string[] | LocaleObject[]; | ||
strategy?: Strategies; | ||
trailingSlash?: boolean; | ||
routesNameSeparator?: string; | ||
defaultLocaleRouteNameSuffix?: string; | ||
inject?: boolean; | ||
} | ||
@@ -127,11 +627,28 @@ | ||
export interface ComposerCustomProperties { | ||
/** | ||
* List of locales | ||
* | ||
* @remarks | ||
* Can either be an array of string codes (e.g. `['en', 'fr']`) or an array of {@link LocaleObject} for more complex configurations | ||
*/ | ||
locales: ComputedRef<string[] | LocaleObject[]> | ||
/** | ||
* List of locale codes | ||
*/ | ||
localeCodes: ComputedRef<string[]> | ||
__baseUrl: string | ||
} | ||
declare module 'vue-i18n' { | ||
export interface ComposerCustom { | ||
locales: ComputedRef<string[] | LocaleObject[]> | ||
} | ||
// eslint-disable-next-line @typescript-eslint/no-empty-interface | ||
export interface ComposerCustom extends ComposerCustomProperties {} | ||
} | ||
declare module 'vue-i18n-bridge' { | ||
export interface ComposerCustom { | ||
locales: ComputedRef<string[] | LocaleObject[]> | ||
} | ||
// eslint-disable-next-line @typescript-eslint/no-empty-interface | ||
export interface ComposerCustom extends ComposerCustomProperties {} | ||
} | ||
declare module '@intlify/vue-i18n-bridge' { | ||
// eslint-disable-next-line @typescript-eslint/no-empty-interface | ||
export interface ComposerCustom extends ComposerCustomProperties {} | ||
} |
@@ -1,5 +0,5 @@ | ||
var ae=Object.defineProperty,se=Object.defineProperties;var re=Object.getOwnPropertyDescriptors;var V=Object.getOwnPropertySymbols;var k=Object.prototype.hasOwnProperty,H=Object.prototype.propertyIsEnumerable;var Y=(r,l,f)=>l in r?ae(r,l,{enumerable:!0,configurable:!0,writable:!0,value:f}):r[l]=f,S=(r,l)=>{for(var f in l||(l={}))k.call(l,f)&&Y(r,f,l[f]);if(V)for(var f of V(l))H.call(l,f)&&Y(r,f,l[f]);return r},M=(r,l)=>se(r,re(l));var B=(r,l)=>{var f={};for(var F in r)k.call(r,F)&&l.indexOf(F)<0&&(f[F]=r[F]);if(r!=null&&V)for(var F of V(r))l.indexOf(F)<0&&H.call(r,F)&&(f[F]=r[F]);return f};var VueI18nRouting=function(r,l,f,F){"use strict";/*! | ||
* shared v9.2.0-beta.26 | ||
* (c) 2021 kazuya kawaguchi | ||
const VueI18nRouting=function(f,h,g,w){"use strict";const ye=(e=>e&&typeof e=="object"&&"default"in e?e:{default:e})(g),Q={PREFIX:"prefix",PREFIX_EXCEPT_DEFAULT:"prefix_except_default",PREFIX_AND_DEFAULT:"prefix_and_default",NO_PREFIX:"no_prefix"},G="",B=Q.PREFIX_EXCEPT_DEFAULT,M=!1,k="___",D="default",Y="ltr",J="";/*! | ||
* shared v9.2.2 | ||
* (c) 2022 kazuya kawaguchi | ||
* Released under the MIT License. | ||
*/const C=Object.assign,x=e=>typeof e=="string",D=e=>typeof e=="symbol";function J(e){e=e||[];const a=[];for(const n of e)x(n)?a.push({code:n}):a.push(n);return a}function v(e,a){return l.isRef(e.locale)&&a==="composition"}function j(e){return"global"in e&&"mode"in e}function O(e){return j(e)?v(e.global,e.mode)?e.global.locale.value:e.global.locale:e.locale.value}function G(e,a){j(e)?v(e.global,e.mode)?e.global.locale.value=a:e.global.locale=a:l.isRef(e.locale)&&(e.locale.value=a)}function K(e,a,n){return e.replace(/\/+$/,"")+(a?"/":"")||(n?"":"/")}function Q(e,{localeCodes:a=[]}={}){if(!v(e.global,e.mode))throw new Error("");const n=l.ref(a);e.global.locales=l.computed(()=>n.value),console.log("... extends i18n done")}const Z={PREFIX:"prefix",PREFIX_EXCEPT_DEFAULT:"prefix_except_default",PREFIX_AND_DEFAULT:"prefix_and_default",NO_PREFIX:"no_prefix"},w="",q=Z.PREFIX_EXCEPT_DEFAULT,z=!1,U="___",y="default";function N(e,{defaultLocale:a=w,strategy:n=q,trailingSlash:d=z,routesNameSeparator:R=U,defaultLocaleRouteNameSuffix:m=y,includeUprefixedFallback:_=!1,localeCodes:T=[]}={}){if(n==="no_prefix")return e;const h=T.map(o=>x(o)?o:o.code);function g(o,E,b=!1,p=!1){return o.redirect&&(!o.component||!o.file)?[o]:E.reduce((c,s)=>{const{name:t}=o;let{path:i}=o;const u=S({},o);t&&(u.name=`${t}${R}${s}`),o.children&&(u.children=o.children.reduce((P,X)=>[...P,...g(X,[s],!0,p)],[]));const I=s===a;if(I&&n==="prefix_and_default")if(b)b&&p&&t&&(u.name+=`${R}${m}`);else{const P=M(S({},u),{path:i});if(t&&(P.name=`${u.name}${R}${m}`),o.children){P.children=[];for(const X of o.children)P.children=P.children.concat(g(X,[s],!0,!0))}c.push(P)}const L=b&&!i.startsWith("/"),A=!L&&!(I&&n==="prefix_except_default");return A&&(i=`/${s}${i}`),i&&(i=K(i,d,L)),A&&I&&n==="prefix"&&_&&c.push(S({},o)),u.path=i,c.push(u),c},[])}return e.reduce((o,E)=>[...o,...g(E,h||[])],[])}function ee(e){return new RegExp(`^/(${e.join("|")})(?:/|$)`,"i")}function oe(e,a,n){const d=`(${e.join("|")})`,R=`(?:${a}${n})?`,m=new RegExp(`${a}${d}${R}$`,"i"),_=ee(e);return h=>{if(h.name){const o=(x(h.name)?h.name:h.name.toString()).match(m);if(o&&o.length>1)return o[1]}else if(h.path){const g=h.path.match(_);if(g&&g.length>1)return g[1]}return""}}function te({router:e,i18n:a,defaultLocale:n=w,strategy:d=q,trailingSlash:R=z,routesNameSeparator:m=U,defaultLocaleRouteNameSuffix:_=y,localeCodes:T=[]}={}){const h=J(T),g=oe(h.map(o=>o.code),m,_);if(Q(a,{localeCodes:h}),l.isVue2){const o=e,E=o.constructor,b=o.options.routes||[],p=N(b,{localeCodes:T,defaultLocale:n,strategy:d,trailingSlash:R,routesNameSeparator:m,defaultLocaleRouteNameSuffix:_});console.log("vue2 routes",b,p);const $=new E({mode:"history",base:o.options.base,routes:p});return $.__defaultLocale=n,$.__strategy=d,$.__trailingSlash=R,$.__routesNameSeparator=m,$.__defaultLocaleRouteNameSuffix=_,$.beforeEach((c,s,t)=>{console.log("beforeEach",c,s);const i=O(a),u=g(c)||i||n||"";console.log("currentLocale",i,"finalLocale",u),i!==u&&G(a,u),t()}),$}else{const o=e,E=o.options.routes||[],b=N(E,{localeCodes:T,defaultLocale:n,strategy:d,trailingSlash:R,routesNameSeparator:m,defaultLocaleRouteNameSuffix:_});return console.log("vue3 routes",E,b,o),E.forEach(p=>o.removeRoute(p.name)),b.forEach(p=>o.addRoute(p)),o.__defaultLocale=n,o.__strategy=d,o.__trailingSlash=R,o.__routesNameSeparator=m,o.__defaultLocaleRouteNameSuffix=_,o.beforeEach((p,$,c)=>{console.log("beforeEach",p,$);const s=O(a),t=g(p)||s||n||"";console.log("currentLocale",s,"finalLocale",t),s!==t&&G(a,t),c()}),o}}function ne(e={}){const a=F.useI18n(),n=f.useRouter(),d=f.useRoute(),R=e.defaultLocaleRouteNameSuffix||n.__defaultLocaleRouteNameSuffix,m=e.defaultLocale||n.__defaultLocale,_=e.routesNameSeparator||n.__routesNameSeparator,T=e.strategy||n.__strategy;function h(c){const s=c!=null?c:l.isRef(d)?d.value:d;return s.name?W(s.name).split(_)[0]:void 0}function g(c,s){let t=W(c)+(T==="no_prefix"?"":_+s);return s===m&&T==="prefix_and_default"&&(t+=_+R),t}function o(c,s){const t=s||O(a);let i=c;x(c)&&(c[0]==="/"?i={path:c}:i={name:c});let u=C({},i);if(u.path&&!u.name){const L=n.resolve(u),A=l.isVue2?L.route:L,P=h(A);x(P)&&(u={name:g(P,t),params:A.params,query:A.query,hash:A.hash})}else{u.name=g(u.name,t);const{params:L}=u;L&&L["0"]===void 0&&L.pathMatch&&(L["0"]=L.pathMatch)}const I=n.resolve(u);return(l.isVue2?I.route.name:I.name)?I:n.resolve(c)}function E(c,s){const t=o(c,s);return t==null?"":l.isVue2?t.route.redirectedFrom||t.route.fullPath:t.redirectedFrom||t.fullPath}function b(c,s){const t=o(c,s);return t==null?void 0:l.isVue2?t.route:t}function p(c,s){const t=o(c,s);return t==null?void 0:l.isVue2?t.location:t.href}function $(c){const s=h();if(!s)return"";const A=l.isVue2&&l.isRef(d)?d.value:d,{params:t}=A,i=B(A,["params"]),u={},I=C({},i,{name:s,params:M(S(S({},t),u),{0:t.pathMatch})}),L=E(I,c);return console.log("switchLocalePath",a.locale.value,c,L),L}return{getRouteBaseName:h,localePath:E,localeRoute:b,localeLocation:p,switchLocalePath:$}}function W(e){return x(e)?e:D(e)?e.toString():"(null)"}function ce({router:e,i18n:a,defaultLocale:n=w,trailingSlash:d=z,routesNameSeparator:R=U,defaultLocaleRouteNameSuffix:m=y,localeCodes:_=[]}={}){if(e==null)throw new Error("TODO");return te({router:e,i18n:a,defaultLocale:n,trailingSlash:d,routesNameSeparator:R,defaultLocaleRouteNameSuffix:m,localeCodes:_})}const le="";return r.VERSION=le,r.extendRouting=ce,r.localizeRoutes=N,r.useI18nRouting=ne,Object.defineProperty(r,"__esModule",{value:!0}),r[Symbol.toStringTag]="Module",r}({},VueDemi,VueRouter,VueI18n); | ||
*/process.env.NODE_ENV;const Ie=typeof Symbol=="function"&&typeof Symbol.toStringTag=="symbol",Ce=e=>Ie?Symbol(e):e,z=Object.assign,Te=Array.isArray,Oe=e=>typeof e=="function",T=e=>typeof e=="string",Pe=e=>typeof e=="boolean",be=e=>typeof e=="symbol",K=e=>e!==null&&typeof e=="object",Ue=/\/$|\/\?/;function Z(e="",t=!1){return t?Ue.test(e):e.endsWith("/")}function Ne(e="",t=!1){if(!t)return(Z(e)?e.slice(0,-1):e)||"/";if(!Z(e,!0))return e||"/";const[o,...n]=e.split("?");return(o.slice(0,-1)||"/")+(n.length?`?${n.join("?")}`:"")}function Fe(e="",t=!1){if(!t)return e.endsWith("/")?e:e+"/";if(Z(e,!0))return e||"/";const[o,...n]=e.split("?");return o+"/"+(n.length?`?${n.join("?")}`:"")}const we=typeof window<"u";function ae(e,t){typeof console<"u"&&(console.warn("[vue-i18n-routing] "+e),t&&console.warn(t.stack))}function ce(e){e=e||[];const t=[];for(const o of e)T(o)?t.push({code:o}):t.push(o);return t}function U(e){return e!=null&&"global"in e&&"mode"in e}function N(e){return e!=null&&!("__composer"in e)&&h.isRef(e.locale)}function O(e){return e!=null&&"__composer"in e}function $(e){return e!=null&&!("__composer"in e)&&!h.isRef(e.locale)}function y(e){return e!=null&&("__VUE_I18N_BRIDGE__"in e||"_sync"in e)}function se(e){return U(e)?N(e.global)?e.global:e.global.__composer:O(e)?e.__composer:e}function H(e){const t=U(e)?e.global:e;return N(t)?h.isVue2&&y(e)?e.locale:t.locale.value:($(t)||O(t)||y(t),t.locale)}function re(e){const t=U(e)?e.global:e;return N(t)?h.isVue2&&y(e)?e.locales:t.locales.value:($(t)||O(t)||y(t),t.locales)}function $e(e){const t=U(e)?e.global:e;return N(t)?h.isVue2&&y(e)?e.localeCodes:t.localeCodes.value:($(t)||O(t)||y(t),t.localeCodes)}function ie(e,t){const o=U(e)?e.global:e;if(N(o))h.isVue2&&y(e)?e.locale=t:o.locale.value=t;else if($(o)||O(o)||y(o))o.locale=t;else throw new Error("TODO:")}function Ve(e,t,o){return e.replace(/\/+$/,"")+(t?"/":"")||(o?"":"/")}function ue(e){return g.isVueRouter4,h.isRef(e)?e.value:e}function fe(e){return T(e)?e:be(e)?e.toString():"(null)"}function de(e,t,{defaultLocale:o,strategy:n,routesNameSeparator:a,defaultLocaleRouteNameSuffix:l}){let c=fe(e)+(n==="no_prefix"?"":a+t);return t===o&&n==="prefix_and_default"&&(c+=a+l),c}function he(e,t){return Oe(e)?e(t):e}function ve(e,t){const o=[];for(const[n,a]of t.entries()){const l=e.find(c=>c.iso.toLowerCase()===a.toLowerCase());if(l){o.push({code:l.code,score:1-n/t.length});break}}for(const[n,a]of t.entries()){const l=a.split("-")[0].toLowerCase(),c=e.find(s=>s.iso.split("-")[0].toLowerCase()===l);if(c){o.push({code:c.code,score:.999-n/t.length});break}}return o}const je=ve;function Ge(e,t){return e.score===t.score?t.code.length-e.code.length:t.score-e.score}const Be=Ge;function Me(e,t,{matcher:o=je,comparer:n=Be}={}){const a=[];for(const c of e){const{code:s}=c,i=c.iso||s;a.push({code:s,iso:i})}const l=o(a,t);return l.length>1&&l.sort(n),l.length?l[0].code:""}function C(e){return function(){return Reflect.apply(e,{getRouteBaseName:this.getRouteBaseName,localePath:this.localePath,localeRoute:this.localeRoute,localeLocation:this.localeLocation,resolveRoute:this.resolveRoute,switchLocalePath:this.switchLocalePath,localeHead:this.localeHead,i18n:this.$i18n,route:this.$route,router:this.$router},arguments)}}function Le(e,{locales:t=[],localeCodes:o=[],baseUrl:n=J,hooks:a={}}={}){const l=h.effectScope(),c=e.install;return e.install=(s,...i)=>{Reflect.apply(c,e,[s,...i]);const u=se(e);l.run(()=>ke(u,{locales:t,localeCodes:o,baseUrl:n,hooks:a})),O(e.global)&&ze(e.global,a.onExtendVueI18n);const d=s,r=e.mode==="composition"?h.isVue3?d.config.globalProperties.$i18n:e:h.isVue2?e:null;if(r&&De(r,u,a.onExtendExportedGlobal),(He(i[0])?i[0]:{inject:!0}).inject&&s.mixin({methods:{resolveRoute:C(V),localePath:C(q),localeRoute:C(x),localeLocation:C(te),switchLocalePath:C(v),getRouteBaseName:C(P),localeHead:C(oe)}}),d.unmount){const _=d.unmount;d.unmount=()=>{l.stop(),_()}}},l}function ke(e,t){const{locales:o,localeCodes:n,baseUrl:a}=t,l=h.ref(o),c=h.ref(n);e.locales=h.computed(()=>l.value),e.localeCodes=h.computed(()=>c.value),e.__baseUrl=he(a,{}),t.hooks&&t.hooks.onExtendComposer&&t.hooks.onExtendComposer(e)}function De(e,t,o){const n=[{locales:{get(){return t.locales.value}},localeCodes:{get(){return t.localeCodes.value}},__baseUrl:{get(){return t.__baseUrl}}}];o&&n.push(o(t));for(const a of n)for(const[l,c]of Object.entries(a))Object.defineProperty(e,l,c)}function ze(e,t){const o=se(e),n=[{locales:{get(){return o.locales.value}},localeCodes:{get(){return o.localeCodes.value}},__baseUrl:{get(){return o.__baseUrl}}}];t&&n.push(t(o));for(const a of n)for(const[l,c]of Object.entries(a))Object.defineProperty(e,l,c)}function He(e){return K(e)&&"inject"in e&&Pe(e.inject)}function ge(e,{defaultLocale:t=G,strategy:o=B,trailingSlash:n=M,routesNameSeparator:a=k,defaultLocaleRouteNameSuffix:l=D,includeUprefixedFallback:c=!1,optionsResolver:s=void 0,locales:i=[]}={}){if(o==="no_prefix")return e;const u=i.map(r=>T(r)?r:r.code);function d(r,L,_=!1,I=!1){if(r.redirect&&(!r.component||!r.file))return[r];let p=null;if(s!=null&&(p=s(r,L),p==null))return[r];const R={locales:u,paths:{}};if(p!=null&&z(R,p),z(R,{locales:L}),R.locales.length>0&&p&&p.locales!=null&&p.locales.length>0){const E=[];for(const m of R.locales)p.locales.includes(m)&&E.push(m);R.locales=E}return R.locales.reduce((E,m)=>{const{name:j}=r;let{path:S}=r;const A={...r};j&&(A.name=`${j}${a}${m}`),r.children&&(A.children=r.children.reduce((b,le)=>[...b,...d(le,[m],!0,I)],[])),R.paths&&R.paths[m]&&(S=R.paths[m]);const F=m===t;if(F&&o==="prefix_and_default")if(_)_&&I&&j&&(A.name+=`${a}${l}`);else{const b={...A,path:S};if(j&&(b.name=`${A.name}${a}${l}`),r.children){b.children=[];for(const le of r.children)b.children=b.children.concat(d(le,[m],!0,!0))}E.push(b)}const Se=_&&!S.startsWith("/"),Ae=!Se&&!(F&&o==="prefix_except_default");return Ae&&(S=`/${m}${S}`),S&&(S=Ve(S,n,Se)),Ae&&F&&o==="prefix"&&c&&E.push({...r}),A.path=S,E.push(A),E},[])}return e.reduce((r,L)=>[...r,...d(L,u||[])],[])}const ee=Ce("vue-i18n-routing-gor");function _e(e,t){e[ee]?ae("already registered global options"):e[ee]=t}function me(e){var t;return(t=e[ee])!=null?t:{}}function Xe(e,t={}){const{version:o,defaultLocale:n,locales:a,strategy:l,trailingSlash:c,routesNameSeparator:s,defaultLocaleRouteNameSuffix:i,defaultDirection:u,baseUrl:d,routes:r,routeOptionsResolver:L}=xe(t),_=ce(a),I=_.map(m=>m.code),p=pe(I,s,i);Le(e,{locales:_,baseUrl:d,localeCodes:I});const R=ge(r,{locales:a,defaultLocale:n,strategy:l,trailingSlash:c,routesNameSeparator:s,defaultLocaleRouteNameSuffix:i,optionsResolver:L});t.routes=R;const E=qe(t,o);return _e(E,{defaultLocale:n,localeCodes:I,strategy:l,trailingSlash:c,routesNameSeparator:s,defaultLocaleRouteNameSuffix:i,defaultDirection:u}),E.beforeEach((m,j,S)=>{const A=H(e),F=p(m)||A||n||"";A!==F&&ie(e,F),S()}),E}function qe(e,t){if(h.isVue3&&t===4)return g.createRouter(e);if(h.isVue2&&t===3)return new ye.default(e);throw new Error("TODO:")}function Re(e){return new RegExp(`^/(${e.join("|")})(?:/|$)`,"i")}function pe(e,t,o){const n=`(${e.join("|")})`,a=`(?:${t}${o})?`,l=new RegExp(`${t}${n}${a}$`,"i"),c=Re(e);return i=>{if(K(i)){if(i.name){const d=(T(i.name)?i.name:i.name.toString()).match(l);if(d&&d.length>1)return d[1]}else if(i.path){const u=i.path.match(c);if(u&&u.length>1)return u[1]}}else if(T(i)){const u=i.match(c);if(u&&u.length>1)return u[1]}return""}}function xe(e){var t,o,n,a,l,c,s,i,u,d;return e.version=(t=e.version)!=null?t:4,e.defaultLocale=(o=e.defaultLocale)!=null?o:G,e.strategy=(n=e.strategy)!=null?n:B,e.trailingSlash=(a=e.trailingSlash)!=null?a:M,e.routesNameSeparator=(l=e.routesNameSeparator)!=null?l:k,e.defaultLocaleRouteNameSuffix=(c=e.defaultLocaleRouteNameSuffix)!=null?c:D,e.locales=(s=e.locales)!=null?s:[],e.defaultDirection=(i=e.defaultDirection)!=null?i:Y,e.baseUrl=(u=e.baseUrl)!=null?u:J,e.routes=(d=e.routes)!=null?d:[],e}function X(e,t,{defaultLocale:o=G,defaultDirection:n=Y,defaultLocaleRouteNameSuffix:a=D,routesNameSeparator:l=k,strategy:c=B,trailingSlash:s=M,localeCodes:i=[]}={}){const u=me(e);return{defaultLocale:t.defaultLocale||u.defaultLocale||o,defaultDirection:t.defaultDirection||u.defaultDirection||n,defaultLocaleRouteNameSuffix:t.defaultLocaleRouteNameSuffix||u.defaultLocaleRouteNameSuffix||a,routesNameSeparator:t.routesNameSeparator||u.routesNameSeparator||l,strategy:t.strategy||u.strategy||c,trailingSlash:t.trailingSlash||u.trailingSlash||s,localeCodes:t.localeCodes||u.localeCodes||i}}const We=new Set(["prefix_and_default","prefix_except_default"]);function P(e){const t=this.router,{routesNameSeparator:o}=X(t,this),n=e!=null?h.isRef(e)?h.unref(e):e:this.route;return n==null||!n.name?void 0:fe(n.name).split(o)[0]}function q(e,t){const o=V.call(this,e,t);return o==null?"":h.isVue3?o.redirectedFrom||o.fullPath:o.route.redirectedFrom||o.route.fullPath}function x(e,t){const o=V.call(this,e,t);return o==null?void 0:h.isVue3?o:o.route}function te(e,t){const o=V.call(this,e,t);return o==null?void 0:h.isVue3?o:o.location}function V(e,t){const o=this.router,n=this.i18n,a=t||H(n),{routesNameSeparator:l,defaultLocale:c,defaultLocaleRouteNameSuffix:s,strategy:i,trailingSlash:u}=X(o,this);let d=e;T(e)&&(d[0]==="/"?d={path:e}:d={name:e});let r=z({},d);if(r.path&&!r.name){let L=null;try{L=o.resolve(r)}catch{}const _=h.isVue3?L:L.route,I=P.call(this,_);T(I)?r={name:de(I,a,{defaultLocale:c,strategy:i,routesNameSeparator:l,defaultLocaleRouteNameSuffix:s}),params:_.params,query:_.query,hash:_.hash}:(!(a===c&&We.has(i))&&i!=="no_prefix"&&(r.path=`/${a}${r.path}`),r.path=u?Fe(r.path,!0):Ne(r.path,!0))}else{!r.name&&!r.path&&(r.name=P.call(this,this.route)),r.name=de(r.name,a,{defaultLocale:c,strategy:i,routesNameSeparator:l,defaultLocaleRouteNameSuffix:s});const{params:L}=r;L&&L[0]===void 0&&L.pathMatch&&(L[0]=L.pathMatch)}try{const L=o.resolve(r);return(h.isVue3?L.name:L.route.name)?L:o.resolve(e)}catch(L){if(h.isVue3&&L.type===1)return null;if(h.isVue2)return null}}function v(e){const t=this.route,o=P.call(this,t);if(!o)return"";const{params:n,...a}=!h.isVue3&&h.isRef(t)?t.value:t,c=z({},a,{name:o,params:{...n,...{},0:n.pathMatch}});return q.call(this,c,e)}function oe({addDirAttribute:e=!1,addSeoAttributes:t=!1}={}){const o=this.router,n=this.i18n,{defaultDirection:a}=X(o,this),l={htmlAttrs:{},link:[],meta:[]};if(n.locales==null||n.__baseUrl==null)return l;const c=H(n),s=re(n),i=ce(s).find(r=>r.code===c)||{code:c},u=i.iso,d=i.dir||a;return e&&(l.htmlAttrs.dir=d),t&&c&&n.locales&&(u&&(l.htmlAttrs.lang=u),Qe.call(this,s,n.__baseUrl,l.link),Ye.call(this,n.__baseUrl,l.link,t),Je(i,u,l.meta),Ke(s,u,l.meta)),l}function Qe(e,t,o){const n=this.router,{defaultLocale:a,strategy:l}=X(n,this);if(l===Q.NO_PREFIX)return;const c=new Map;for(const s of e){const i=s.iso;if(!i){ae("Locale ISO code is required to generate alternate link");continue}const[u,d]=i.split("-");u&&d&&(s.isCatchallLocale||!c.has(u))&&c.set(u,s),c.set(i,s)}for(const[s,i]of c.entries()){const u=v.call(this,i.code);u&&o.push({hid:`i18n-alt-${s}`,rel:"alternate",href:ne(u,t),hreflang:s})}if(a){const s=v.call(this,a);s&&o.push({hid:"i18n-xd",rel:"alternate",href:ne(s,t),hreflang:"x-default"})}}function Ye(e,t,o){const n=this.route,a=x.call(this,{...n,name:P.call(this,n)});if(a){let l=ne(a.path,e);const c=K(o)&&o.canonicalQueries||[];if(c.length){const s=a.query,i=new URLSearchParams;for(const d of c)if(d in s){const r=s[d];Te(r)?r.forEach(L=>i.append(d,L||"")):i.append(d,r||"")}const u=i.toString();u&&(l=`${l}?${u}`)}t.push({hid:"i18n-can",rel:"canonical",href:l})}}function Je(e,t,o){!(e&&t)||o.push({hid:"i18n-og",property:"og:locale",content:Ee(t)})}function Ke(e,t,o){const n=e.filter(a=>{const l=a.iso;return l&&l!==t});if(n.length){const a=n.map(l=>({hid:`i18n-og-alt-${l.iso}`,property:"og:locale:alternate",content:Ee(l.iso)}));o.push(...a)}}function Ee(e){return(e||"").replace(/-/g,"_")}function ne(e,t){return e.match(/^https?:\/\//)?e:t+e}function W(e,t){const{router:o,route:n,i18n:a,defaultLocale:l,strategy:c,defaultLocaleRouteNameSuffix:s,trailingSlash:i,routesNameSeparator:u}=e;return function(...d){return Reflect.apply(t,{router:o,route:n,i18n:a,defaultLocale:l,strategy:c,defaultLocaleRouteNameSuffix:s,trailingSlash:i,routesNameSeparator:u},d)}}function Ze(e=g.useRoute(),{router:t=g.useRouter(),routesNameSeparator:o=void 0}={}){const n={router:t,route:e,routesNameSeparator:o};return P.call(n,e)}function et({router:e=g.useRouter(),route:t=g.useRoute(),i18n:o=w.useI18n(),defaultLocale:n=void 0,defaultLocaleRouteNameSuffix:a=void 0,routesNameSeparator:l=void 0,strategy:c=void 0,trailingSlash:s=void 0}={}){return W({router:e,route:t,i18n:o,defaultLocale:n,defaultLocaleRouteNameSuffix:a,routesNameSeparator:l,strategy:c,trailingSlash:s},q)}function tt({router:e=g.useRouter(),route:t=g.useRoute(),i18n:o=w.useI18n(),defaultLocale:n=void 0,defaultLocaleRouteNameSuffix:a=void 0,routesNameSeparator:l=void 0,strategy:c=void 0,trailingSlash:s=void 0}={}){return W({router:e,route:t,i18n:o,defaultLocale:n,defaultLocaleRouteNameSuffix:a,routesNameSeparator:l,strategy:c,trailingSlash:s},x)}function ot({router:e=g.useRouter(),route:t=g.useRoute(),i18n:o=w.useI18n(),defaultLocale:n=void 0,defaultLocaleRouteNameSuffix:a=void 0,routesNameSeparator:l=void 0,strategy:c=void 0,trailingSlash:s=void 0}={}){return W({router:e,route:t,i18n:o,defaultLocale:n,defaultLocaleRouteNameSuffix:a,routesNameSeparator:l,strategy:c,trailingSlash:s},te)}function nt({router:e=g.useRouter(),route:t=g.useRoute(),i18n:o=w.useI18n(),defaultLocale:n=void 0,defaultLocaleRouteNameSuffix:a=void 0,routesNameSeparator:l=void 0,strategy:c=void 0,trailingSlash:s=void 0}={}){return W({router:e,route:t,i18n:o,defaultLocale:n,defaultLocaleRouteNameSuffix:a,routesNameSeparator:l,strategy:c,trailingSlash:s},v)}function lt({addDirAttribute:e=!1,addSeoAttributes:t=!1,strategy:o=void 0,defaultLocale:n=void 0,route:a=g.useRoute(),router:l=g.useRouter(),i18n:c=w.useI18n()}={}){const s=l,i=h.ref({htmlAttrs:{},link:[],meta:[]});function u(){i.value={htmlAttrs:{},link:[],meta:[]}}function d(r){i.value=Reflect.apply(oe,{router:l,route:r,i18n:c,defaultLocale:n,strategy:o},[{addDirAttribute:e,addSeoAttributes:t}])}if(we)if(h.isVue3){const r=h.watchEffect(()=>{u(),d(ue(s.currentRoute))});h.onUnmounted(()=>r())}else{const r=s.afterEach((L,_)=>{u(),d(L)});h.onUnmounted(()=>r()),d(a)}else d(ue(s.currentRoute));return i}const at="0.0.0";return f.DEFAULT_BASE_URL=J,f.DEFAULT_DETECTION_DIRECTION=Y,f.DEFAULT_LOCALE=G,f.DEFAULT_LOCALE_ROUTE_NAME_SUFFIX=D,f.DEFAULT_ROUTES_NAME_SEPARATOR=k,f.DEFAULT_STRATEGY=B,f.DEFAULT_TRAILING_SLASH=M,f.STRATEGIES=Q,f.VERSION=at,f.createLocaleFromRouteGetter=pe,f.createRouter=Xe,f.extendI18n=Le,f.findBrowserLocale=Me,f.getGlobalOptions=me,f.getLocale=H,f.getLocaleCodes=$e,f.getLocales=re,f.getLocalesRegex=Re,f.getRouteBaseName=P,f.isComposer=N,f.isExportedGlobalComposer=$,f.isI18nInstance=U,f.isLegacyVueI18n=y,f.isVueI18n=O,f.localeHead=oe,f.localeLocation=te,f.localePath=q,f.localeRoute=x,f.localizeRoutes=ge,f.proxyVueInstance=C,f.registerGlobalOptions=_e,f.resolveBaseUrl=he,f.resolveRoute=V,f.setLocale=ie,f.switchLocalePath=v,f.useLocaleHead=lt,f.useLocaleLocation=ot,f.useLocalePath=et,f.useLocaleRoute=tt,f.useRouteBaseName=Ze,f.useSwitchLocalePath=nt,Object.defineProperties(f,{__esModule:{value:!0},[Symbol.toStringTag]:{value:"Module"}}),f}({},VueDemi,VueRouter,VueI18n); |
{ | ||
"name": "vue-i18n-routing", | ||
"description": "The i18n routing with using vue-i18n", | ||
"version": "0.0.0-50f6b19", | ||
"version": "0.0.0-56e9ef8", | ||
"dependencies": { | ||
"@intlify/shared": "beta", | ||
"@intlify/vue-i18n-bridge": "^0.1.0", | ||
"@intlify/vue-router-bridge": "^0.1.0", | ||
"vue-demi": "^0.12.1" | ||
"@intlify/shared": "latest", | ||
"@intlify/vue-i18n-bridge": "0.3.6", | ||
"@intlify/vue-router-bridge": "0.3.6", | ||
"ufo": "^0.8.5", | ||
"vue-demi": "0.13.5" | ||
}, | ||
"devDependencies": { | ||
"@microsoft/api-extractor": "^7.18.20", | ||
"@microsoft/api-extractor": "^7.28.4", | ||
"api-docs-gen": "^0.4.0", | ||
"rimraf": "^3.0.2", | ||
"vite": "^2.7.4", | ||
"typescript": "^4.7.4", | ||
"vite": "^3.0.0", | ||
"vite-plugin-dts": "^0.9.6", | ||
"vue": "^3.2.23", | ||
"vue-i18n": "npm:vue-i18n@next", | ||
"vue-i18n-bridge": "beta", | ||
"vue-i18n-legacy": "npm:vue-i18n@latest", | ||
"vue-router": "^4.0.12", | ||
"vue-router3": "npm:vue-router@latest", | ||
"vue2": "npm:vue@2", | ||
"typescript": "^4.5.4" | ||
"vitest": "^0.19.0", | ||
"vue": "^3.2.27", | ||
"vue-i18n": "npm:vue-i18n@latest", | ||
"vue-i18n-bridge": "latest", | ||
"vue-i18n-legacy": "npm:vue-i18n@8", | ||
"vue-router": "^4.0.15", | ||
"vue-router3": "npm:vue-router@3", | ||
"vue-template-compiler": "^2.6.14", | ||
"vue2": "npm:vue@2" | ||
}, | ||
@@ -29,4 +32,4 @@ "peerDependencies": { | ||
"vue": "^2.6.14 || ^3.2.0", | ||
"vue-i18n": "^8.26.1 || ^9.2.0-beta.25", | ||
"vue-i18n-bridge": "^9.2.0-beta.25", | ||
"vue-i18n": "^8.26.1 || ^9.2.0", | ||
"vue-i18n-bridge": "^9.2.0", | ||
"vue-router": "^3.5.3 || ^4.0.0" | ||
@@ -37,2 +40,14 @@ }, | ||
"optional": true | ||
}, | ||
"vue": { | ||
"optional": true | ||
}, | ||
"vue-i18n": { | ||
"optional": true | ||
}, | ||
"vue-i18n-bridge": { | ||
"optional": true | ||
}, | ||
"vue-router": { | ||
"optional": true | ||
} | ||
@@ -49,7 +64,8 @@ }, | ||
"index.mjs", | ||
"types.d.ts", | ||
"LICENSE", | ||
"README.md" | ||
], | ||
"main": "./dist/vue-i18n-routing.cjs.js", | ||
"module": "./dist/vue-i18n-routing.es.js", | ||
"main": "./dist/vue-i18n-routing.js", | ||
"module": "./dist/vue-i18n-routing.mjs", | ||
"unpkg": "dist/vue-i18n-routing.iife.js", | ||
@@ -62,6 +78,12 @@ "jsdelivr": "dist/vue-i18n-routing.iife.js", | ||
"node": "./index.mjs", | ||
"default": "./dist/vue-i18n-routing.es.js" | ||
"default": "./dist/vue-i18n-routing.mjs" | ||
}, | ||
"require": "./dist/vue-i18n-routing.cjs.js" | ||
} | ||
"require": "./dist/vue-i18n-routing.js", | ||
"types": "./dist/vue-i18n-routing.d.ts" | ||
}, | ||
"./types": { | ||
"types": "./types.d.ts" | ||
}, | ||
"./package.json": "./package.json", | ||
"./dist/*": "./dist/*" | ||
}, | ||
@@ -83,3 +105,3 @@ "license": "MIT", | ||
"engines": { | ||
"node": ">= 12" | ||
"node": ">= 14.6" | ||
}, | ||
@@ -94,4 +116,7 @@ "publishConfig": { | ||
"typecheck": "tsc -p . --noEmit", | ||
"test": "vitest run", | ||
"test:watch": "vitest", | ||
"test:cover": "vitest --coverage", | ||
"build:docs": "api-docs-gen ./temp/vue-i18n-routing.api.json -c ./docsgen.config.js -o ./ -g noprefix" | ||
} | ||
} |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
Found 1 instance in 1 package
Environment variable access
Supply chain riskPackage accesses environment variables, which may be a sign of credential stuffing or data theft.
Found 1 instance in 1 package
Minified code
QualityThis package contains minified code. This may be harmless in some cases where minified code is included in packaged libraries, however packages on npm should not minify code.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
Minified code
QualityThis package contains minified code. This may be harmless in some cases where minified code is included in packaged libraries, however packages on npm should not minify code.
Found 1 instance in 1 package
84371
19759
11
1565
10
15
2
1
+ Addedufo@^0.8.5
+ Added@intlify/shared@11.0.1(transitive)
+ Added@intlify/vue-i18n-bridge@0.3.6(transitive)
+ Added@intlify/vue-router-bridge@0.3.6(transitive)
+ Addedufo@0.8.6(transitive)
+ Addedvue-demi@0.13.5(transitive)
- Removed@intlify/shared@9.3.0-beta.27(transitive)
- Removed@intlify/vue-i18n-bridge@0.1.0(transitive)
- Removed@intlify/vue-router-bridge@0.1.0(transitive)
- Removedvue-demi@0.12.5(transitive)
Updated@intlify/shared@latest
Updatedvue-demi@0.13.5