Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

vue-i18n-routing

Package Overview
Dependencies
Maintainers
1
Versions
239
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

vue-i18n-routing - npm Package Compare versions

Comparing version 0.0.0-12d0627 to 0.0.0-154eaf0

6

dist/vue-i18n-routing.cjs.js

@@ -1,1 +0,5 @@

"use strict";Object.defineProperty(exports,"__esModule",{value:!0});exports[Symbol.toStringTag]="Module";const n=function(e,u={}){console.log("install vue-i18n-rouging!")},o="0.0.0";exports.VERSION=o;exports.VueI18nRoutingPlugin=n;
"use strict";var le=Object.defineProperty,ce=Object.defineProperties;var re=Object.getOwnPropertyDescriptors;var D=Object.getOwnPropertySymbols;var j=Object.prototype.hasOwnProperty,k=Object.prototype.propertyIsEnumerable;var B=(e,t,a)=>t in e?le(e,t,{enumerable:!0,configurable:!0,writable:!0,value:a}):e[t]=a,y=(e,t)=>{for(var a in t||(t={}))j.call(t,a)&&B(e,a,t[a]);if(D)for(var a of D(t))k.call(t,a)&&B(e,a,t[a]);return e},F=(e,t)=>ce(e,re(t));var G=(e,t)=>{var a={};for(var o in e)j.call(e,o)&&t.indexOf(o)<0&&(a[o]=e[o]);if(e!=null&&D)for(var o of D(e))t.indexOf(o)<0&&k.call(e,o)&&(a[o]=e[o]);return a};Object.defineProperty(exports,"__esModule",{value:!0});exports[Symbol.toStringTag]="Module";var g=require("vue-demi"),S=require("@intlify/vue-router-bridge"),H=require("@intlify/vue-i18n-bridge");function se(e){return e&&typeof e=="object"&&"default"in e?e:{default:e}}var ue=se(S);/*!
* shared v9.2.0-beta.30
* (c) 2022 kazuya kawaguchi
* Released under the MIT License.
*/const W=Object.assign,ie=Array.isArray,fe=e=>typeof e=="function",T=e=>typeof e=="string",de=e=>typeof e=="boolean",he=e=>typeof e=="symbol",_e=/\/$|\/\?/;function O(e="",t=!1){return t?_e.test(e):e.endsWith("/")}function me(e="",t=!1){if(!t)return(O(e)?e.slice(0,-1):e)||"/";if(!O(e,!0))return e||"/";const[a,...o]=e.split("?");return(a.slice(0,-1)||"/")+(o.length?`?${o.join("?")}`:"")}function Re(e="",t=!1){if(!t)return e.endsWith("/")?e:e+"/";if(O(e,!0))return e||"/";const[a,...o]=e.split("?");return a+"/"+(o.length?`?${o.join("?")}`:"")}function ge(e,t){typeof console!="undefined"&&(console.warn("[vue-i18n-routing] "+e),t&&console.warn(t.stack))}function Q(e){e=e||[];const t=[];for(const a of e)T(a)?t.push({code:a}):t.push(a);return t}function w(e,t){return g.isRef(e.locale)&&t==="composition"}function Y(e){return"global"in e&&"mode"in e}function C(e){return Y(e)?w(e.global,e.mode)?e.global.locale.value:e.global.locale:e.locale.value}function Le(e,t){Y(e)?w(e.global,e.mode)?e.global.locale.value=t:e.global.locale=t:g.isRef(e.locale)&&(e.locale.value=t)}function Ee(e,t,a){return e.replace(/\/+$/,"")+(t?"/":"")||(a?"":"/")}function J(e){return T(e)?e:he(e)?e.toString():"(null)"}function K(e,t,{defaultLocale:a,strategy:o,routesNameSeparator:l,defaultLocaleRouteNameSuffix:n}){let c=J(e)+(o==="no_prefix"?"":l+t);return t===a&&o==="prefix_and_default"&&(c+=l+n),c}function pe(e,t){return fe(e)?e(t):e}const P={PREFIX:"prefix",PREFIX_EXCEPT_DEFAULT:"prefix_except_default",PREFIX_AND_DEFAULT:"prefix_and_default",NO_PREFIX:"no_prefix"},N="",x=P.PREFIX_EXCEPT_DEFAULT,Z=!1,$="___",V="default",Se="ltr",ee="",ve=new Set([P.PREFIX_AND_DEFAULT,P.PREFIX_EXCEPT_DEFAULT]);function b(e=S.useRoute(),{router:t=S.useRouter(),routesNameSeparator:a=$}={}){const o=a||t.__routesNameSeparator,l=g.unref(e);return l.name?J(l.name).split(o)[0]:null}function te(e,t,a){const o=X(e,t,a);return o==null?"":g.isVue3?o.redirectedFrom||o.fullPath:o.route.redirectedFrom||o.route.fullPath}function ae(e,t,a){const o=X(e,t,a);return o==null?void 0:g.isVue3?o:o.route}function Ae(e,t,a){const o=X(e,t,a);return o==null?void 0:g.isVue3?o:o.location}function X(e,t,{router:a=S.useRouter(),i18n:o=H.useI18n(),defaultLocale:l=N,defaultLocaleRouteNameSuffix:n=V,routesNameSeparator:c=$,strategy:u=x,trailingSlash:i=!1}={}){const s=a.__defaultLocaleRouteNameSuffix||n,r=a.__defaultLocale||l,m=a.__routesNameSeparator||c,_=a.__strategy||u,R=t||C(o);let p=e;T(e)&&(p[0]==="/"?p={path:e}:p={name:e});let f=W({},p);if(f.path&&!f.name){const h=a.resolve(f),L=g.isVue3?h:h.route,E=b(L);T(E)?f={name:K(E,R,{defaultLocale:r,strategy:_,routesNameSeparator:m,defaultLocaleRouteNameSuffix:s}),params:L.params,query:L.query,hash:L.hash}:(!(R===l&&ve.has(_))&&_!==P.NO_PREFIX&&(f.path=`/${R}${f.path}`),f.path=i?Re(f.path,!0):me(f.path,!0))}else{f.name=K(f.name,R,{defaultLocale:r,strategy:_,routesNameSeparator:m,defaultLocaleRouteNameSuffix:s});const{params:h}=f;h&&h["0"]===void 0&&h.pathMatch&&(h["0"]=h.pathMatch)}const d=a.resolve(f);return(g.isVue3?d.name:d.route.name)?d:a.resolve(e)}function M(e,t){const a=t&&t.route||S.useRoute(),o=b(a,t);if(!o)return"";const s=!g.isVue3&&g.isRef(a)?a.value:a,{params:l}=s,n=G(s,["params"]),c={},u=W({},n,{name:o,params:F(y(y({},l),c),{0:l.pathMatch})});return te(u,e,t)}function ye({addDirAttribute:e=!1,addSeoAttributes:t=!1,strategy:a=x,defaultLocale:o=N,route:l=S.useRoute(),router:n=S.useRouter(),i18n:c=H.useI18n()}={}){const u=o||n.__defaultLocale,i=a||n.__strategy,s=g.ref({htmlAttrs:{},link:[],meta:[]});function r(){s.value={htmlAttrs:{},link:[],meta:[]}}function m(_){const R=C(c),p=Q(c.locales.value).find(h=>h.code===R)||{code:R},f=p.iso,d=p.dir||n.__defaultDetection;if(e&&(s.value.htmlAttrs.dir=d),t&&R&&c.locales){f&&(s.value.htmlAttrs.lang=f);const h=c.locales.value;Ie(h,c.__baseUrl,s.value.link,{defaultLocale:u,strategy:i,route:l,router:n,i18n:c}),Te(c.__baseUrl,s.value.link,t,{route:_,router:n,i18n:c}),Pe(p,f,s.value.meta),De(h,f,s.value.meta)}}return g.watch(n.currentRoute,_=>{r(),m(_)}),m(l),s}function Ie(e,t,a,o){if(o.strategy===P.NO_PREFIX)return;const l=new Map;for(const n of e){const c=n.iso;if(!c){ge("Locale ISO code is required to generate alternate link");continue}const[u,i]=c.split("-");u&&i&&(n.isCatchallLocale||!l.has(u))&&l.set(u,n),l.set(c,n)}for(const[n,c]of l.entries()){const u=M(c.code,o);u&&a.push({hid:`i18n-alt-${n}`,rel:"alternate",href:q(u,t),hreflang:n})}if(o.defaultLocale){const n=M(o.defaultLocale,o);n&&a.push({hid:"i18n-xd",rel:"alternate",href:q(n,t),hreflang:"x-default"})}}function Te(e,t,a,o){const{route:l}=o,n=ae(F(y({},l),{name:b(l,o)}),void 0,o);if(n){let c=q(n.path,e);const u=!de(a)&&a.canonicalQueries||[];if(u.length){const i=n.query,s=new URLSearchParams;for(const m of u)if(m in i){const _=i[m];ie(_)?_.forEach(R=>s.append(m,R||"")):s.append(m,_||"")}const r=s.toString();r&&(c=`${c}?${r}`)}t.push({hid:"i18n-can",rel:"canonical",href:c})}}function Pe(e,t,a){!(e&&t)||a.push({hid:"i18n-og",property:"og:locale",content:oe(t)})}function De(e,t,a){const o=e.filter(l=>{const n=l.iso;return n&&n!==t});if(o.length){const l=o.map(n=>({hid:`i18n-og-alt-${n.iso}`,property:"og:locale:alternate",content:oe(n.iso)}));a.push(...l)}}function oe(e){return(e||"").replace(/-/g,"_")}function q(e,t){return e.match(/^https?:\/\//)?e:t+e}function ne(e,{defaultLocale:t=N,strategy:a=x,trailingSlash:o=Z,routesNameSeparator:l=$,defaultLocaleRouteNameSuffix:n=V,includeUprefixedFallback:c=!1,locales:u=[]}={}){if(a==="no_prefix")return e;const i=u.map(r=>T(r)?r:r.code);function s(r,m,_=!1,R=!1){return r.redirect&&(!r.component||!r.file)?[r]:m.reduce((f,d)=>{const{name:h}=r;let{path:L}=r;const E=y({},r);h&&(E.name=`${h}${l}${d}`),r.children&&(E.children=r.children.reduce((A,U)=>[...A,...s(U,[d],!0,R)],[]));const v=d===t;if(v&&a==="prefix_and_default")if(_)_&&R&&h&&(E.name+=`${l}${n}`);else{const A=F(y({},E),{path:L});if(h&&(A.name=`${E.name}${l}${n}`),r.children){A.children=[];for(const U of r.children)A.children=A.children.concat(s(U,[d],!0,!0))}f.push(A)}const I=_&&!L.startsWith("/"),z=!I&&!(v&&a==="prefix_except_default");return z&&(L=`/${d}${L}`),L&&(L=Ee(L,o,I)),z&&v&&a==="prefix"&&c&&f.push(y({},r)),E.path=L,f.push(E),f},[])}return e.reduce((r,m)=>[...r,...s(m,i||[])],[])}function Fe(e,{locales:t=[],baseUrl:a=ee}={}){if(!w(e.global,e.mode))throw new Error("TODO:");const o=g.ref(t);e.global.locales=g.computed(()=>o.value),e.global.__baseUrl=pe(a,{})}function Ne(e){return new RegExp(`^/(${e.join("|")})(?:/|$)`,"i")}function xe(e,t,a){const o=`(${e.join("|")})`,l=`(?:${t}${a})?`,n=new RegExp(`${t}${o}${l}$`,"i"),c=Ne(e);return i=>{if(i.name){const r=(T(i.name)?i.name:i.name.toString()).match(n);if(r&&r.length>1)return r[1]}else if(i.path){const s=i.path.match(c);if(s&&s.length>1)return s[1]}return""}}function $e(e){var t,a,o,l,n,c,u,i,s,r;return e.version=(t=e.version)!=null?t:4,e.defaultLocale=(a=e.defaultLocale)!=null?a:N,e.strategy=(o=e.strategy)!=null?o:x,e.trailingSlash=(l=e.trailingSlash)!=null?l:Z,e.routesNameSeparator=(n=e.routesNameSeparator)!=null?n:$,e.defaultLocaleRouteNameSuffix=(c=e.defaultLocaleRouteNameSuffix)!=null?c:V,e.locales=(u=e.locales)!=null?u:[],e.defaultDetection=(i=e.defaultDetection)!=null?i:Se,e.baseUrl=(s=e.baseUrl)!=null?s:ee,e.routes=(r=e.routes)!=null?r:[],e}function be(e,t={}){const{version:a,defaultLocale:o,locales:l,strategy:n,trailingSlash:c,routesNameSeparator:u,defaultLocaleRouteNameSuffix:i,defaultDetection:s,baseUrl:r,routes:m}=$e(t),_=Q(l),R=_.map(h=>h.code),p=xe(R,u,i);Fe(e,{locales:_,baseUrl:r});const f=ne(m,{locales:l,defaultLocale:o,strategy:n,trailingSlash:c,routesNameSeparator:u,defaultLocaleRouteNameSuffix:i});t.routes=f;let d=null;if(g.isVue3&&a===4)d=S.createRouter(t);else if(g.isVue2&&a===3)d=new ue.default(t);else throw new Error("TODO:");return d.__defaultLocale=o,d.__localeCodes=R,d.__strategy=n,d.__trailingSlash=c,d.__routesNameSeparator=u,d.__defaultLocaleRouteNameSuffix=i,d.__defaultDetection=s,d.beforeEach((h,L,E)=>{const v=C(e),I=p(h)||v||o||"";v!==I&&Le(e,I),E()}),d}const Ue="0.0.0";exports.VERSION=Ue;exports.createRouter=be;exports.getRouteBaseName=b;exports.localeLocation=Ae;exports.localePath=te;exports.localeRoute=ae;exports.localizeRoutes=ne;exports.switchLocalePath=M;exports.useI18nHead=ye;

@@ -0,2 +1,212 @@

import { Composer } 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 type { Route as Route_2 } from '@intlify/vue-router-bridge';
import type { RouteConfig } from '@intlify/vue-router-bridge';
import type { RouteLocation } from '@intlify/vue-router-bridge';
import type { 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 { VueRouter } from '@intlify/vue-router-bridge';
export declare type BaseUrlResolveHandler = (context: unknown) => string;
export declare type ComposableOptions = {
route?: ReturnType<typeof useRoute>;
router?: ReturnType<typeof useRouter>;
i18n?: Composer;
};
/**
* 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 VueI18nRoutingOptions}
*
* @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).
*/
export declare function createRouter<Options extends VueI18nRoutingOptions = VueI18nRoutingOptions>(i18n: I18n, options?: Options): Options['version'] extends 4 ? Router : VueRouter;
/**
* Direction
*/
export declare type Directions = 'ltr' | 'rtl' | 'auto';
/**
* Get 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 getRouteBaseName(givenRoute?: Route_2 | RouteLocationNormalizedLoaded, { router, routesNameSeparator }?: I18nRoutingOptions): string | null;
/**
* I18n header meta info
*/
export declare interface I18nHeadMetaInfo {
htmlAttrs?: MetaAttrs;
meta?: MetaAttrs[];
link?: MetaAttrs[];
}
/**
* Options for {@link useI18nHead} 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;
}
/**
* Options for vue-i18n-routing common
*/
export declare type I18nRoutingOptions = Pick<VueI18nRoutingOptions, 'defaultLocale' | 'strategy' | 'defaultLocaleRouteNameSuffix' | 'trailingSlash' | 'locales' | 'routesNameSeparator'> & ComposableOptions;
/**
* Resolve locale location
*
* @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
* @param options - An options, see about details {@link I18nRoutingOptions}
*
* @returns Returns the location object for a given route, the location object is resolved by vue-router rather than just a full route path.
*/
export declare function localeLocation(route: RawLocation | RouteLocationRaw, locale?: Locale, // TODO: locale should be more type inference (completion)
options?: I18nRoutingOptions): Location | RouteLocation | undefined;
/**
* Locale object
*/
export declare interface LocaleObject extends Record<string, any> {
code: Locale;
name?: string;
dir?: Directions;
domain?: string;
file?: string;
isCatchallLocale?: boolean;
iso?: string;
}
/**
* Resolve locale path
*
* @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
* @param options - An options, see about details {@link I18nRoutingOptions}
*
* @returns Returns the localized URL for a given route
*/
export declare function localePath(route: RawLocation | RouteLocationRaw, locale?: Locale, // TODO: locale should be more type inference (completion)
options?: I18nRoutingOptions): string;
/**
* Resolve locale route
*
* @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
* @param options - An options, see about details {@link I18nRoutingOptions}
*
* @returns Returns the route object for a given route, the route object is resolved by vue-router rather than just a full route path.
*/
export declare function localeRoute(route: RawLocation | RouteLocationRaw, locale?: Locale, // TODO: locale should be more type inference (completion)
options?: I18nRoutingOptions): Route_2 | ReturnType<Router['resolve']> | undefined;
export declare function localizeRoutes(routes: VueI18nRoute[], { defaultLocale, strategy, trailingSlash, routesNameSeparator, defaultLocaleRouteNameSuffix, includeUprefixedFallback, locales }?: Pick<VueI18nRoutingOptions, 'defaultLocale' | 'strategy' | 'locales' | 'routesNameSeparator' | 'trailingSlash' | 'defaultLocaleRouteNameSuffix'> & {
includeUprefixedFallback?: boolean;
}): VueI18nRoute[];
export declare type MetaAttrs = Record<string, any>;
/**
* Route config for vue-router v4
*/
export declare interface Route {
name?: string;
path: string;
file?: string;
children?: Route[];
}
declare type _Route = UnionToIntersection<RouteConfig>;
/**
* Route config for lagacy vue-router v3
*/
export declare interface RouteLegacy extends Pick<_Route, Exclude<keyof _Route, 'children' | 'component'>> {
chunkName?: string;
chunkNames?: Record<string, string>;
component?: _Route['component'] | string;
children?: RouteLegacy[];
}
/**
* 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[];
}
declare const STRATEGIES: {
readonly PREFIX: "prefix";
readonly PREFIX_EXCEPT_DEFAULT: "prefix_except_default";
readonly PREFIX_AND_DEFAULT: "prefix_and_default";
readonly NO_PREFIX: "no_prefix";
};
/**
* Routing strategy
*/
export declare type Strategies = typeof STRATEGIES[keyof typeof STRATEGIES];
/**
* Switch locale path
*
* @param locale - A locale code, if not specified, uses the current locale
* @param options - An options, see about details {@link I18nRoutingOptions}
*
* @returns Returns a link to the current route in another language
*/
export declare function switchLocalePath(locale: Locale, options?: I18nRoutingOptions): string;
declare type UnionToIntersection<T> = (T extends any ? (k: T) => void : never) extends (k: infer U) => void ? U : never;
/**
* Generate SEO head meta information
*
* @param options - An options, see about details {@link I18nHeadOptions}
*
* @returns Genereated SEO head meta information
*/
export declare function useI18nHead({ addDirAttribute, addSeoAttributes, strategy, defaultLocale, route, router, i18n }?: Pick<I18nRoutingOptions, 'strategy' | 'defaultLocale'> & ComposableOptions & I18nHeadOptions): Ref<I18nHeadMetaInfo>;
/**
* Vue I18n Routing Version

@@ -9,8 +219,115 @@ *

export declare interface VueI18nRoutingOptions {
routes: [];
}
/**
* Route config for vue-i18n-routing
*/
export declare type VueI18nRoute = Route & RouteLegacy & {
redirect?: string;
};
export declare const VueI18nRoutingPlugin: (VueOrApp: any, options?: any) => void;
/**
* Options to initialize a VueRouter instance
*
* @remarks
* This options is extended from Vue Router `RouterOptioins`, so you can specify those options.
*/
export declare type VueI18nRoutingOptions<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 TODO:
*
* @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 detection direction
*
* @defaultValue 'ltr'
*/
defaultDetection?: 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;
} & RouterOptions;
export { }
declare module 'vue-i18n' {
export interface ComposerCustom {
locales: ComputedRef<string[] | LocaleObject[]>
__baseUrl: string
}
}
declare module 'vue-i18n-bridge' {
export interface ComposerCustom {
locales: ComputedRef<string[] | LocaleObject[]>
__baseUrl: string
}
}

@@ -1,5 +0,581 @@

const VueI18nRoutingPlugin = function(VueOrApp, options = {}) {
console.log("install vue-i18n-rouging!");
var __defProp = Object.defineProperty;
var __defProps = Object.defineProperties;
var __getOwnPropDescs = Object.getOwnPropertyDescriptors;
var __getOwnPropSymbols = Object.getOwnPropertySymbols;
var __hasOwnProp = Object.prototype.hasOwnProperty;
var __propIsEnum = Object.prototype.propertyIsEnumerable;
var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
var __spreadValues = (a, b) => {
for (var prop in b || (b = {}))
if (__hasOwnProp.call(b, prop))
__defNormalProp(a, prop, b[prop]);
if (__getOwnPropSymbols)
for (var prop of __getOwnPropSymbols(b)) {
if (__propIsEnum.call(b, prop))
__defNormalProp(a, prop, b[prop]);
}
return a;
};
var __spreadProps = (a, b) => __defProps(a, __getOwnPropDescs(b));
var __objRest = (source, exclude) => {
var target = {};
for (var prop in source)
if (__hasOwnProp.call(source, prop) && exclude.indexOf(prop) < 0)
target[prop] = source[prop];
if (source != null && __getOwnPropSymbols)
for (var prop of __getOwnPropSymbols(source)) {
if (exclude.indexOf(prop) < 0 && __propIsEnum.call(source, prop))
target[prop] = source[prop];
}
return target;
};
import { isRef, unref, isVue3, ref, watch, computed, isVue2 } from "vue-demi";
import VueRouter3, { useRoute, useRouter, createRouter as createRouter$1 } from "@intlify/vue-router-bridge";
import { useI18n } from "@intlify/vue-i18n-bridge";
/*!
* shared v9.2.0-beta.30
* (c) 2022 kazuya kawaguchi
* Released under the MIT License.
*/
const assign = Object.assign;
const isArray = Array.isArray;
const isFunction = (val) => typeof val === "function";
const isString = (val) => typeof val === "string";
const isBoolean = (val) => typeof val === "boolean";
const isSymbol = (val) => typeof val === "symbol";
const TRAILING_SLASH_RE = /\/$|\/\?/;
function hasTrailingSlash(input = "", queryParams = false) {
if (!queryParams) {
return input.endsWith("/");
}
return TRAILING_SLASH_RE.test(input);
}
function withoutTrailingSlash(input = "", queryParams = false) {
if (!queryParams) {
return (hasTrailingSlash(input) ? input.slice(0, -1) : input) || "/";
}
if (!hasTrailingSlash(input, true)) {
return input || "/";
}
const [s0, ...s] = input.split("?");
return (s0.slice(0, -1) || "/") + (s.length ? `?${s.join("?")}` : "");
}
function withTrailingSlash(input = "", queryParams = false) {
if (!queryParams) {
return input.endsWith("/") ? input : input + "/";
}
if (hasTrailingSlash(input, true)) {
return input || "/";
}
const [s0, ...s] = input.split("?");
return s0 + "/" + (s.length ? `?${s.join("?")}` : "");
}
function warn(msg, err) {
if (typeof console !== "undefined") {
console.warn(`[vue-i18n-routing] ` + msg);
if (err) {
console.warn(err.stack);
}
}
}
function getNormalizedLocales(locales) {
locales = locales || [];
const normalized = [];
for (const locale of locales) {
if (isString(locale)) {
normalized.push({ code: locale });
} else {
normalized.push(locale);
}
}
return normalized;
}
function isComposer(target, mode) {
return isRef(target.locale) && mode === "composition";
}
function isI18nInstance(i18n) {
return "global" in i18n && "mode" in i18n;
}
function getLocale(i18n) {
return isI18nInstance(i18n) ? isComposer(i18n.global, i18n.mode) ? i18n.global.locale.value : i18n.global.locale : i18n.locale.value;
}
function setLocale(i18n, locale) {
if (isI18nInstance(i18n)) {
if (isComposer(i18n.global, i18n.mode)) {
i18n.global.locale.value = locale;
} else {
i18n.global.locale = locale;
}
} else if (isRef(i18n.locale)) {
i18n.locale.value = locale;
}
}
function adjustRoutePathForTrailingSlash(pagePath, trailingSlash, isChildWithRelativePath) {
return pagePath.replace(/\/+$/, "") + (trailingSlash ? "/" : "") || (isChildWithRelativePath ? "" : "/");
}
function getRouteName(routeName) {
return isString(routeName) ? routeName : isSymbol(routeName) ? routeName.toString() : "(null)";
}
function getLocaleRouteName(routeName, locale, {
defaultLocale,
strategy,
routesNameSeparator,
defaultLocaleRouteNameSuffix
}) {
let name = getRouteName(routeName) + (strategy === "no_prefix" ? "" : routesNameSeparator + locale);
if (locale === defaultLocale && strategy === "prefix_and_default") {
name += routesNameSeparator + defaultLocaleRouteNameSuffix;
}
return name;
}
function resolveBaseUrl(baseUrl, context) {
if (isFunction(baseUrl)) {
return baseUrl(context);
}
return baseUrl;
}
const STRATEGIES = {
PREFIX: "prefix",
PREFIX_EXCEPT_DEFAULT: "prefix_except_default",
PREFIX_AND_DEFAULT: "prefix_and_default",
NO_PREFIX: "no_prefix"
};
const DEFAULT_LOCALE = "";
const DEFAULT_STRATEGY = STRATEGIES.PREFIX_EXCEPT_DEFAULT;
const DEFAULT_TRAILING_SLASH = false;
const DEFAULT_ROUTES_NAME_SEPARATOR = "___";
const DEFAULT_LOCALE_ROUTE_NAME_SUFFIX = "default";
const DEFAULT_DETECTION_DIRECTION = "ltr";
const DEFAULT_BASE_URL = "";
const RESOLVED_PREFIXED = new Set([STRATEGIES.PREFIX_AND_DEFAULT, STRATEGIES.PREFIX_EXCEPT_DEFAULT]);
function getRouteBaseName(givenRoute = useRoute(), { router = useRouter(), routesNameSeparator = DEFAULT_ROUTES_NAME_SEPARATOR } = {}) {
const _routesNameSeparator = routesNameSeparator || router.__routesNameSeparator;
const _route = unref(givenRoute);
if (!_route.name) {
return null;
}
const name = getRouteName(_route.name);
return name.split(_routesNameSeparator)[0];
}
function localePath(route, locale, options) {
const localizedRoute = resolveRoute(route, locale, options);
return localizedRoute == null ? "" : isVue3 ? localizedRoute.redirectedFrom || localizedRoute.fullPath : localizedRoute.route.redirectedFrom || localizedRoute.route.fullPath;
}
function localeRoute(route, locale, options) {
const resolved = resolveRoute(route, locale, options);
return resolved == null ? void 0 : isVue3 ? resolved : resolved.route;
}
function localeLocation(route, locale, options) {
const resolved = resolveRoute(route, locale, options);
return resolved == null ? void 0 : isVue3 ? resolved : resolved.location;
}
function resolveRoute(route, locale, {
router = useRouter(),
i18n = useI18n(),
defaultLocale = DEFAULT_LOCALE,
defaultLocaleRouteNameSuffix = DEFAULT_LOCALE_ROUTE_NAME_SUFFIX,
routesNameSeparator = DEFAULT_ROUTES_NAME_SEPARATOR,
strategy = DEFAULT_STRATEGY,
trailingSlash = false
} = {}) {
const _defaultLocaleRouteNameSuffix = router.__defaultLocaleRouteNameSuffix || defaultLocaleRouteNameSuffix;
const _defaultLocale = router.__defaultLocale || defaultLocale;
const _routesNameSeparator = router.__routesNameSeparator || routesNameSeparator;
const _strategy = router.__strategy || strategy;
const _locale = locale || getLocale(i18n);
let _route = route;
if (isString(route)) {
if (_route[0] === "/") {
_route = { path: route };
} else {
_route = { name: route };
}
}
let localizedRoute = assign({}, _route);
if (localizedRoute.path && !localizedRoute.name) {
const _resolvedRoute = router.resolve(localizedRoute);
const resolvedRoute2 = isVue3 ? _resolvedRoute : _resolvedRoute.route;
const resolvedRouteName = getRouteBaseName(resolvedRoute2);
if (isString(resolvedRouteName)) {
localizedRoute = {
name: getLocaleRouteName(resolvedRouteName, _locale, {
defaultLocale: _defaultLocale,
strategy: _strategy,
routesNameSeparator: _routesNameSeparator,
defaultLocaleRouteNameSuffix: _defaultLocaleRouteNameSuffix
}),
params: resolvedRoute2.params,
query: resolvedRoute2.query,
hash: resolvedRoute2.hash
};
} else {
const isDefaultLocale = _locale === defaultLocale;
const isPrefixed = !(isDefaultLocale && RESOLVED_PREFIXED.has(_strategy)) && !(_strategy === STRATEGIES.NO_PREFIX);
if (isPrefixed) {
localizedRoute.path = `/${_locale}${localizedRoute.path}`;
}
localizedRoute.path = trailingSlash ? withTrailingSlash(localizedRoute.path, true) : withoutTrailingSlash(localizedRoute.path, true);
}
} else {
localizedRoute.name = getLocaleRouteName(localizedRoute.name, _locale, {
defaultLocale: _defaultLocale,
strategy: _strategy,
routesNameSeparator: _routesNameSeparator,
defaultLocaleRouteNameSuffix: _defaultLocaleRouteNameSuffix
});
const { params } = localizedRoute;
if (params && params["0"] === void 0 && params.pathMatch) {
params["0"] = params.pathMatch;
}
}
const resolvedRoute = router.resolve(localizedRoute);
if (isVue3 ? resolvedRoute.name : resolvedRoute.route.name) {
return resolvedRoute;
}
return router.resolve(route);
}
function switchLocalePath(locale, options) {
const route = options && options.route || useRoute();
const name = getRouteBaseName(route, options);
if (!name) {
return "";
}
const _a = !isVue3 && isRef(route) ? route.value : route, { params } = _a, routeCopy = __objRest(_a, ["params"]);
const langSwitchParams = {};
const baseRoute = assign({}, routeCopy, {
name,
params: __spreadProps(__spreadValues(__spreadValues({}, params), langSwitchParams), {
0: params.pathMatch
})
});
const path = localePath(baseRoute, locale, options);
return path;
}
function useI18nHead({
addDirAttribute = false,
addSeoAttributes = false,
strategy = DEFAULT_STRATEGY,
defaultLocale = DEFAULT_LOCALE,
route = useRoute(),
router = useRouter(),
i18n = useI18n()
} = {}) {
const _defaultLocale = defaultLocale || router.__defaultLocale;
const _strategy = strategy || router.__strategy;
const metaObject = ref({
htmlAttrs: {},
link: [],
meta: []
});
function cleanMeta() {
metaObject.value = {
htmlAttrs: {},
link: [],
meta: []
};
}
function updateMeta(_route) {
const locale = getLocale(i18n);
const currentLocale = getNormalizedLocales(i18n.locales.value).find((l) => l.code === locale) || {
code: locale
};
const currentLocaleIso = currentLocale.iso;
const currentLocaleDir = currentLocale.dir || router.__defaultDetection;
if (addDirAttribute) {
metaObject.value.htmlAttrs.dir = currentLocaleDir;
}
if (addSeoAttributes && locale && i18n.locales) {
if (currentLocaleIso) {
metaObject.value.htmlAttrs.lang = currentLocaleIso;
}
const locales = i18n.locales.value;
addHreflangLinks(locales, i18n.__baseUrl, metaObject.value.link, {
defaultLocale: _defaultLocale,
strategy: _strategy,
route,
router,
i18n
});
addCanonicalLinks(i18n.__baseUrl, metaObject.value.link, addSeoAttributes, { route: _route, router, i18n });
addCurrentOgLocale(currentLocale, currentLocaleIso, metaObject.value.meta);
addAlternateOgLocales(locales, currentLocaleIso, metaObject.value.meta);
}
}
watch(router.currentRoute, (val) => {
cleanMeta();
updateMeta(val);
});
updateMeta(route);
return metaObject;
}
function addHreflangLinks(locales, baseUrl, link, options) {
if (options.strategy === STRATEGIES.NO_PREFIX) {
return;
}
const localeMap = new Map();
for (const locale of locales) {
const localeIso = locale.iso;
if (!localeIso) {
warn("Locale ISO code is required to generate alternate link");
continue;
}
const [language, region] = localeIso.split("-");
if (language && region && (locale.isCatchallLocale || !localeMap.has(language))) {
localeMap.set(language, locale);
}
localeMap.set(localeIso, locale);
}
for (const [iso, mapLocale] of localeMap.entries()) {
const localePath2 = switchLocalePath(mapLocale.code, options);
if (localePath2) {
link.push({
hid: `i18n-alt-${iso}`,
rel: "alternate",
href: toAbsoluteUrl(localePath2, baseUrl),
hreflang: iso
});
}
}
if (options.defaultLocale) {
const localePath2 = switchLocalePath(options.defaultLocale, options);
if (localePath2) {
link.push({
hid: "i18n-xd",
rel: "alternate",
href: toAbsoluteUrl(localePath2, baseUrl),
hreflang: "x-default"
});
}
}
}
function addCanonicalLinks(baseUrl, link, seoAttributesOptions, options) {
const { route } = options;
const currentRoute = localeRoute(__spreadProps(__spreadValues({}, route), {
name: getRouteBaseName(route, options)
}), void 0, options);
if (currentRoute) {
let href = toAbsoluteUrl(currentRoute.path, baseUrl);
const canonicalQueries = !isBoolean(seoAttributesOptions) && seoAttributesOptions.canonicalQueries || [];
if (canonicalQueries.length) {
const currentRouteQueryParams = currentRoute.query;
const params = new URLSearchParams();
for (const queryParamName of canonicalQueries) {
if (queryParamName in currentRouteQueryParams) {
const queryParamValue = currentRouteQueryParams[queryParamName];
if (isArray(queryParamValue)) {
queryParamValue.forEach((v) => params.append(queryParamName, v || ""));
} else {
params.append(queryParamName, queryParamValue || "");
}
}
}
const queryString = params.toString();
if (queryString) {
href = `${href}?${queryString}`;
}
}
link.push({
hid: "i18n-can",
rel: "canonical",
href
});
}
}
function addCurrentOgLocale(currentLocale, currentLocaleIso, meta) {
const hasCurrentLocaleAndIso = currentLocale && currentLocaleIso;
if (!hasCurrentLocaleAndIso) {
return;
}
meta.push({
hid: "i18n-og",
property: "og:locale",
content: hypenToUnderscore(currentLocaleIso)
});
}
function addAlternateOgLocales(locales, currentLocaleIso, meta) {
const localesWithoutCurrent = locales.filter((locale) => {
const localeIso = locale.iso;
return localeIso && localeIso !== currentLocaleIso;
});
if (localesWithoutCurrent.length) {
const alternateLocales = localesWithoutCurrent.map((locale) => ({
hid: `i18n-og-alt-${locale.iso}`,
property: "og:locale:alternate",
content: hypenToUnderscore(locale.iso)
}));
meta.push(...alternateLocales);
}
}
function hypenToUnderscore(str) {
return (str || "").replace(/-/g, "_");
}
function toAbsoluteUrl(urlOrPath, baseUrl) {
if (urlOrPath.match(/^https?:\/\//)) {
return urlOrPath;
}
return baseUrl + urlOrPath;
}
function localizeRoutes(routes, {
defaultLocale = DEFAULT_LOCALE,
strategy = DEFAULT_STRATEGY,
trailingSlash = DEFAULT_TRAILING_SLASH,
routesNameSeparator = DEFAULT_ROUTES_NAME_SEPARATOR,
defaultLocaleRouteNameSuffix = DEFAULT_LOCALE_ROUTE_NAME_SUFFIX,
includeUprefixedFallback = false,
locales = []
} = {}) {
if (strategy === "no_prefix") {
return routes;
}
const _localeCodes = locales.map((locale) => isString(locale) ? locale : locale.code);
function makeLocalizedRoutes(route, allowedLocaleCodes, isChild = false, isExtraPageTree = false) {
if (route.redirect && (!route.component || !route.file)) {
return [route];
}
const targetLocales = allowedLocaleCodes;
return targetLocales.reduce((_routes, locale) => {
const { name } = route;
let { path } = route;
const localizedRoute = __spreadValues({}, route);
if (name) {
localizedRoute.name = `${name}${routesNameSeparator}${locale}`;
}
if (route.children) {
localizedRoute.children = route.children.reduce((children, child) => [...children, ...makeLocalizedRoutes(child, [locale], true, isExtraPageTree)], []);
}
const isDefaultLocale = locale === defaultLocale;
if (isDefaultLocale && strategy === "prefix_and_default") {
if (!isChild) {
const defaultRoute = __spreadProps(__spreadValues({}, localizedRoute), { path });
if (name) {
defaultRoute.name = `${localizedRoute.name}${routesNameSeparator}${defaultLocaleRouteNameSuffix}`;
}
if (route.children) {
defaultRoute.children = [];
for (const childRoute of route.children) {
defaultRoute.children = defaultRoute.children.concat(makeLocalizedRoutes(childRoute, [locale], true, true));
}
}
_routes.push(defaultRoute);
} else if (isChild && isExtraPageTree && name) {
localizedRoute.name += `${routesNameSeparator}${defaultLocaleRouteNameSuffix}`;
}
}
const isChildWithRelativePath = isChild && !path.startsWith("/");
const shouldAddPrefix = !isChildWithRelativePath && !(isDefaultLocale && strategy === "prefix_except_default");
if (shouldAddPrefix) {
path = `/${locale}${path}`;
}
if (path) {
path = adjustRoutePathForTrailingSlash(path, trailingSlash, isChildWithRelativePath);
}
if (shouldAddPrefix && isDefaultLocale && strategy === "prefix" && includeUprefixedFallback) {
_routes.push(__spreadValues({}, route));
}
localizedRoute.path = path;
_routes.push(localizedRoute);
return _routes;
}, []);
}
return routes.reduce((localized, route) => [...localized, ...makeLocalizedRoutes(route, _localeCodes || [])], []);
}
function extendI18n(i18n, { locales = [], baseUrl = DEFAULT_BASE_URL } = {}) {
if (!isComposer(i18n.global, i18n.mode)) {
throw new Error("TODO:");
}
const _locales = ref(locales);
i18n.global.locales = computed(() => _locales.value);
i18n.global.__baseUrl = resolveBaseUrl(baseUrl, {});
}
function getLocalesRegex(localeCodes) {
return new RegExp(`^/(${localeCodes.join("|")})(?:/|$)`, "i");
}
function createLocaleFromRouteGetter(localeCodes, routesNameSeparator, defaultLocaleRouteNameSuffix) {
const localesPattern = `(${localeCodes.join("|")})`;
const defaultSuffixPattern = `(?:${routesNameSeparator}${defaultLocaleRouteNameSuffix})?`;
const regexpName = new RegExp(`${routesNameSeparator}${localesPattern}${defaultSuffixPattern}$`, "i");
const regexpPath = getLocalesRegex(localeCodes);
const getLocaleFromRoute = (route) => {
if (route.name) {
const name = isString(route.name) ? route.name : route.name.toString();
const matches = name.match(regexpName);
if (matches && matches.length > 1) {
return matches[1];
}
} else if (route.path) {
const matches = route.path.match(regexpPath);
if (matches && matches.length > 1) {
return matches[1];
}
}
return "";
};
return getLocaleFromRoute;
}
function asDefaultVueI18nRouterOptions(options) {
var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j;
options.version = (_a = options.version) != null ? _a : 4;
options.defaultLocale = (_b = options.defaultLocale) != null ? _b : DEFAULT_LOCALE;
options.strategy = (_c = options.strategy) != null ? _c : DEFAULT_STRATEGY;
options.trailingSlash = (_d = options.trailingSlash) != null ? _d : DEFAULT_TRAILING_SLASH;
options.routesNameSeparator = (_e = options.routesNameSeparator) != null ? _e : DEFAULT_ROUTES_NAME_SEPARATOR;
options.defaultLocaleRouteNameSuffix = (_f = options.defaultLocaleRouteNameSuffix) != null ? _f : DEFAULT_LOCALE_ROUTE_NAME_SUFFIX;
options.locales = (_g = options.locales) != null ? _g : [];
options.defaultDetection = (_h = options.defaultDetection) != null ? _h : DEFAULT_DETECTION_DIRECTION;
options.baseUrl = (_i = options.baseUrl) != null ? _i : DEFAULT_BASE_URL;
options.routes = (_j = options.routes) != null ? _j : [];
return options;
}
function createRouter(i18n, options = {}) {
const {
version,
defaultLocale,
locales,
strategy,
trailingSlash,
routesNameSeparator,
defaultLocaleRouteNameSuffix,
defaultDetection,
baseUrl,
routes
} = asDefaultVueI18nRouterOptions(options);
const normalizedLocaleCodes = getNormalizedLocales(locales);
const localeCodes = normalizedLocaleCodes.map((l) => l.code);
const getLocaleFromRoute = createLocaleFromRouteGetter(localeCodes, routesNameSeparator, defaultLocaleRouteNameSuffix);
extendI18n(i18n, { locales: normalizedLocaleCodes, baseUrl });
const localizedRoutes = localizeRoutes(routes, {
locales,
defaultLocale,
strategy,
trailingSlash,
routesNameSeparator,
defaultLocaleRouteNameSuffix
});
options.routes = localizedRoutes;
let router = null;
if (isVue3 && version === 4) {
router = createRouter$1(options);
} else if (isVue2 && version === 3) {
router = new VueRouter3(options);
} else {
throw new Error("TODO:");
}
router.__defaultLocale = defaultLocale;
router.__localeCodes = localeCodes;
router.__strategy = strategy;
router.__trailingSlash = trailingSlash;
router.__routesNameSeparator = routesNameSeparator;
router.__defaultLocaleRouteNameSuffix = defaultLocaleRouteNameSuffix;
router.__defaultDetection = defaultDetection;
router.beforeEach((to, from, next) => {
const currentLocale = getLocale(i18n);
const finalLocale = getLocaleFromRoute(to) || currentLocale || defaultLocale || "";
if (currentLocale !== finalLocale) {
setLocale(i18n, finalLocale);
}
next();
});
return router;
}
const VERSION = "0.0.0";
export { VERSION, VueI18nRoutingPlugin };
export { VERSION, createRouter, getRouteBaseName, localeLocation, localePath, localeRoute, localizeRoutes, switchLocalePath, useI18nHead };

@@ -1,1 +0,5 @@

(()=>{var t=function(n){"use strict";const u=function(o,e={}){console.log("install vue-i18n-rouging!")},i="0.0.0";return n.VERSION=i,n.VueI18nRoutingPlugin=u,Object.defineProperty(n,"__esModule",{value:!0}),n[Symbol.toStringTag]="Module",n}({});})();
var Oe=Object.defineProperty,we=Object.defineProperties;var xe=Object.getOwnPropertyDescriptors;var w=Object.getOwnPropertySymbols;var ae=Object.prototype.hasOwnProperty,ne=Object.prototype.propertyIsEnumerable;var le=(f,s,_)=>s in f?Oe(f,s,{enumerable:!0,configurable:!0,writable:!0,value:_}):f[s]=_,P=(f,s)=>{for(var _ in s||(s={}))ae.call(s,_)&&le(f,_,s[_]);if(w)for(var _ of w(s))ne.call(s,_)&&le(f,_,s[_]);return f},x=(f,s)=>we(f,xe(s));var oe=(f,s)=>{var _={};for(var p in f)ae.call(f,p)&&s.indexOf(p)<0&&(_[p]=f[p]);if(f!=null&&w)for(var p of w(f))s.indexOf(p)<0&&ne.call(f,p)&&(_[p]=f[p]);return _};var VueI18nRouting=function(f,s,_,p){"use strict";function ce(e){return e&&typeof e=="object"&&"default"in e?e:{default:e}}var re=ce(_);/*!
* shared v9.2.0-beta.30
* (c) 2022 kazuya kawaguchi
* Released under the MIT License.
*/const q=Object.assign,se=Array.isArray,ue=e=>typeof e=="function",F=e=>typeof e=="string",fe=e=>typeof e=="boolean",ie=e=>typeof e=="symbol",de=/\/$|\/\?/;function C(e="",t=!1){return t?de.test(e):e.endsWith("/")}function he(e="",t=!1){if(!t)return(C(e)?e.slice(0,-1):e)||"/";if(!C(e,!0))return e||"/";const[a,...n]=e.split("?");return(a.slice(0,-1)||"/")+(n.length?`?${n.join("?")}`:"")}function _e(e="",t=!1){if(!t)return e.endsWith("/")?e:e+"/";if(C(e,!0))return e||"/";const[a,...n]=e.split("?");return a+"/"+(n.length?`?${n.join("?")}`:"")}function me(e,t){typeof console!="undefined"&&(console.warn("[vue-i18n-routing] "+e),t&&console.warn(t.stack))}function G(e){e=e||[];const t=[];for(const a of e)F(a)?t.push({code:a}):t.push(a);return t}function D(e,t){return s.isRef(e.locale)&&t==="composition"}function H(e){return"global"in e&&"mode"in e}function X(e){return H(e)?D(e.global,e.mode)?e.global.locale.value:e.global.locale:e.locale.value}function Le(e,t){H(e)?D(e.global,e.mode)?e.global.locale.value=t:e.global.locale=t:s.isRef(e.locale)&&(e.locale.value=t)}function ge(e,t,a){return e.replace(/\/+$/,"")+(t?"/":"")||(a?"":"/")}function W(e){return F(e)?e:ie(e)?e.toString():"(null)"}function B(e,t,{defaultLocale:a,strategy:n,routesNameSeparator:o,defaultLocaleRouteNameSuffix:l}){let c=W(e)+(n==="no_prefix"?"":o+t);return t===a&&n==="prefix_and_default"&&(c+=o+l),c}function Re(e,t){return ue(e)?e(t):e}const $={PREFIX:"prefix",PREFIX_EXCEPT_DEFAULT:"prefix_except_default",PREFIX_AND_DEFAULT:"prefix_and_default",NO_PREFIX:"no_prefix"},U="",b=$.PREFIX_EXCEPT_DEFAULT,Q=!1,v="___",M="default",Ee="ltr",Y="",Se=new Set([$.PREFIX_AND_DEFAULT,$.PREFIX_EXCEPT_DEFAULT]);function O(e=_.useRoute(),{router:t=_.useRouter(),routesNameSeparator:a=v}={}){const n=a||t.__routesNameSeparator,o=s.unref(e);return o.name?W(o.name).split(n)[0]:null}function J(e,t,a){const n=V(e,t,a);return n==null?"":s.isVue3?n.redirectedFrom||n.fullPath:n.route.redirectedFrom||n.route.fullPath}function K(e,t,a){const n=V(e,t,a);return n==null?void 0:s.isVue3?n:n.route}function pe(e,t,a){const n=V(e,t,a);return n==null?void 0:s.isVue3?n:n.location}function V(e,t,{router:a=_.useRouter(),i18n:n=p.useI18n(),defaultLocale:o=U,defaultLocaleRouteNameSuffix:l=M,routesNameSeparator:c=v,strategy:i=b,trailingSlash:d=!1}={}){const u=a.__defaultLocaleRouteNameSuffix||l,r=a.__defaultLocale||o,R=a.__routesNameSeparator||c,g=a.__strategy||i,E=t||X(n);let I=e;F(e)&&(I[0]==="/"?I={path:e}:I={name:e});let h=q({},I);if(h.path&&!h.name){const L=a.resolve(h),S=s.isVue3?L:L.route,A=O(S);F(A)?h={name:B(A,E,{defaultLocale:r,strategy:g,routesNameSeparator:R,defaultLocaleRouteNameSuffix:u}),params:S.params,query:S.query,hash:S.hash}:(!(E===o&&Se.has(g))&&g!==$.NO_PREFIX&&(h.path=`/${E}${h.path}`),h.path=d?_e(h.path,!0):he(h.path,!0))}else{h.name=B(h.name,E,{defaultLocale:r,strategy:g,routesNameSeparator:R,defaultLocaleRouteNameSuffix:u});const{params:L}=h;L&&L["0"]===void 0&&L.pathMatch&&(L["0"]=L.pathMatch)}const m=a.resolve(h);return(s.isVue3?m.name:m.route.name)?m:a.resolve(e)}function z(e,t){const a=t&&t.route||_.useRoute(),n=O(a,t);if(!n)return"";const u=!s.isVue3&&s.isRef(a)?a.value:a,{params:o}=u,l=oe(u,["params"]),c={},i=q({},l,{name:n,params:x(P(P({},o),c),{0:o.pathMatch})});return J(i,e,t)}function Ae({addDirAttribute:e=!1,addSeoAttributes:t=!1,strategy:a=b,defaultLocale:n=U,route:o=_.useRoute(),router:l=_.useRouter(),i18n:c=p.useI18n()}={}){const i=n||l.__defaultLocale,d=a||l.__strategy,u=s.ref({htmlAttrs:{},link:[],meta:[]});function r(){u.value={htmlAttrs:{},link:[],meta:[]}}function R(g){const E=X(c),I=G(c.locales.value).find(L=>L.code===E)||{code:E},h=I.iso,m=I.dir||l.__defaultDetection;if(e&&(u.value.htmlAttrs.dir=m),t&&E&&c.locales){h&&(u.value.htmlAttrs.lang=h);const L=c.locales.value;Ie(L,c.__baseUrl,u.value.link,{defaultLocale:i,strategy:d,route:o,router:l,i18n:c}),Te(c.__baseUrl,u.value.link,t,{route:g,router:l,i18n:c}),ye(I,h,u.value.meta),Pe(L,h,u.value.meta)}}return s.watch(l.currentRoute,g=>{r(),R(g)}),R(o),u}function Ie(e,t,a,n){if(n.strategy===$.NO_PREFIX)return;const o=new Map;for(const l of e){const c=l.iso;if(!c){me("Locale ISO code is required to generate alternate link");continue}const[i,d]=c.split("-");i&&d&&(l.isCatchallLocale||!o.has(i))&&o.set(i,l),o.set(c,l)}for(const[l,c]of o.entries()){const i=z(c.code,n);i&&a.push({hid:`i18n-alt-${l}`,rel:"alternate",href:j(i,t),hreflang:l})}if(n.defaultLocale){const l=z(n.defaultLocale,n);l&&a.push({hid:"i18n-xd",rel:"alternate",href:j(l,t),hreflang:"x-default"})}}function Te(e,t,a,n){const{route:o}=n,l=K(x(P({},o),{name:O(o,n)}),void 0,n);if(l){let c=j(l.path,e);const i=!fe(a)&&a.canonicalQueries||[];if(i.length){const d=l.query,u=new URLSearchParams;for(const R of i)if(R in d){const g=d[R];se(g)?g.forEach(E=>u.append(R,E||"")):u.append(R,g||"")}const r=u.toString();r&&(c=`${c}?${r}`)}t.push({hid:"i18n-can",rel:"canonical",href:c})}}function ye(e,t,a){!(e&&t)||a.push({hid:"i18n-og",property:"og:locale",content:Z(t)})}function Pe(e,t,a){const n=e.filter(o=>{const l=o.iso;return l&&l!==t});if(n.length){const o=n.map(l=>({hid:`i18n-og-alt-${l.iso}`,property:"og:locale:alternate",content:Z(l.iso)}));a.push(...o)}}function Z(e){return(e||"").replace(/-/g,"_")}function j(e,t){return e.match(/^https?:\/\//)?e:t+e}function ee(e,{defaultLocale:t=U,strategy:a=b,trailingSlash:n=Q,routesNameSeparator:o=v,defaultLocaleRouteNameSuffix:l=M,includeUprefixedFallback:c=!1,locales:i=[]}={}){if(a==="no_prefix")return e;const d=i.map(r=>F(r)?r:r.code);function u(r,R,g=!1,E=!1){return r.redirect&&(!r.component||!r.file)?[r]:R.reduce((h,m)=>{const{name:L}=r;let{path:S}=r;const A=P({},r);L&&(A.name=`${L}${o}${m}`),r.children&&(A.children=r.children.reduce((y,k)=>[...y,...u(k,[m],!0,E)],[]));const T=m===t;if(T&&a==="prefix_and_default")if(g)g&&E&&L&&(A.name+=`${o}${l}`);else{const y=x(P({},A),{path:S});if(L&&(y.name=`${A.name}${o}${l}`),r.children){y.children=[];for(const k of r.children)y.children=y.children.concat(u(k,[m],!0,!0))}h.push(y)}const N=g&&!S.startsWith("/"),te=!N&&!(T&&a==="prefix_except_default");return te&&(S=`/${m}${S}`),S&&(S=ge(S,n,N)),te&&T&&a==="prefix"&&c&&h.push(P({},r)),A.path=S,h.push(A),h},[])}return e.reduce((r,R)=>[...r,...u(R,d||[])],[])}function Fe(e,{locales:t=[],baseUrl:a=Y}={}){if(!D(e.global,e.mode))throw new Error("TODO:");const n=s.ref(t);e.global.locales=s.computed(()=>n.value),e.global.__baseUrl=Re(a,{})}function Ne(e){return new RegExp(`^/(${e.join("|")})(?:/|$)`,"i")}function $e(e,t,a){const n=`(${e.join("|")})`,o=`(?:${t}${a})?`,l=new RegExp(`${t}${n}${o}$`,"i"),c=Ne(e);return d=>{if(d.name){const r=(F(d.name)?d.name:d.name.toString()).match(l);if(r&&r.length>1)return r[1]}else if(d.path){const u=d.path.match(c);if(u&&u.length>1)return u[1]}return""}}function Ue(e){var t,a,n,o,l,c,i,d,u,r;return e.version=(t=e.version)!=null?t:4,e.defaultLocale=(a=e.defaultLocale)!=null?a:U,e.strategy=(n=e.strategy)!=null?n:b,e.trailingSlash=(o=e.trailingSlash)!=null?o:Q,e.routesNameSeparator=(l=e.routesNameSeparator)!=null?l:v,e.defaultLocaleRouteNameSuffix=(c=e.defaultLocaleRouteNameSuffix)!=null?c:M,e.locales=(i=e.locales)!=null?i:[],e.defaultDetection=(d=e.defaultDetection)!=null?d:Ee,e.baseUrl=(u=e.baseUrl)!=null?u:Y,e.routes=(r=e.routes)!=null?r:[],e}function be(e,t={}){const{version:a,defaultLocale:n,locales:o,strategy:l,trailingSlash:c,routesNameSeparator:i,defaultLocaleRouteNameSuffix:d,defaultDetection:u,baseUrl:r,routes:R}=Ue(t),g=G(o),E=g.map(L=>L.code),I=$e(E,i,d);Fe(e,{locales:g,baseUrl:r});const h=ee(R,{locales:o,defaultLocale:n,strategy:l,trailingSlash:c,routesNameSeparator:i,defaultLocaleRouteNameSuffix:d});t.routes=h;let m=null;if(s.isVue3&&a===4)m=_.createRouter(t);else if(s.isVue2&&a===3)m=new re.default(t);else throw new Error("TODO:");return m.__defaultLocale=n,m.__localeCodes=E,m.__strategy=l,m.__trailingSlash=c,m.__routesNameSeparator=i,m.__defaultLocaleRouteNameSuffix=d,m.__defaultDetection=u,m.beforeEach((L,S,A)=>{const T=X(e),N=I(L)||T||n||"";T!==N&&Le(e,N),A()}),m}const ve="0.0.0";return f.VERSION=ve,f.createRouter=be,f.getRouteBaseName=O,f.localeLocation=pe,f.localePath=J,f.localeRoute=K,f.localizeRoutes=ee,f.switchLocalePath=z,f.useI18nHead=Ae,Object.defineProperty(f,"__esModule",{value:!0}),f[Symbol.toStringTag]="Module",f}({},VueDemi,VueRouter,VueI18n);

42

package.json
{
"name": "vue-i18n-routing",
"description": "The i18n routing with using vue-i18n",
"version": "0.0.0-12d0627",
"version": "0.0.0-154eaf0",
"dependencies": {
"vue-demi": "*"
"@intlify/shared": "beta",
"@intlify/vue-i18n-bridge": "^0.3.4",
"@intlify/vue-router-bridge": "^0.3.4",
"ufo": "^0.7.9",
"vue-demi": "^0.12.1"
},
"devDependencies": {
"vite": "^2.6.4",
"@microsoft/api-extractor": "^7.18.20",
"@vue/test-utils": "^1.3.0",
"api-docs-gen": "^0.4.0",
"rimraf": "^3.0.2",
"typescript": "^4.5.4",
"vite": "^2.7.4",
"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@8",
"vue-router": "^4.0.12",
"vue2": "npm:vue@2",
"vue-router3": "npm:vue-router@latest",
"rimraf": "^3.0.2",
"@microsoft/api-extractor": "^7.18.20",
"api-docs-gen": "^0.4.0"
"vue-router3": "npm:vue-router@3",
"vue-template-compiler": "^2.6.14",
"vue2": "npm:vue@2"
},
"peerDependencies": {
"@vue/composition-api": "^1.4.0",
"vue": "^2.6.14 || ^3.2.0",
"vue-i18n": "^8.26.1 || ^9.2.0-beta.30",
"vue-i18n-bridge": "^9.2.0-beta.30",
"vue-router": "^3.5.3 || ^4.0.0"
},
"peerDependenciesMeta": {
"@vue/composition-api": {
"optional": true
}
},
"keywords": [

@@ -46,4 +64,7 @@ "i18n",

},
"require": "./dist/vue-i18n-routing.cjs.js"
}
"require": "./dist/vue-i18n-routing.cjs.js",
"types": "./dist/vue-i18n-routing.d.ts"
},
"./dist/*": "./dist/*",
"./package.json": "./package.json"
},

@@ -74,4 +95,5 @@ "license": "MIT",

"build": "vite build",
"typecheck": "tsc -p . --noEmit",
"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

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc