vue-i18n-routing
Advanced tools
Comparing version 0.0.0-9f94af5 to 0.0.0-b4f3a33
@@ -1,5 +0,5 @@ | ||
"use strict";var H=Object.defineProperty,Y=Object.defineProperties;var J=Object.getOwnPropertyDescriptors;var I=Object.getOwnPropertySymbols;var N=Object.prototype.hasOwnProperty,C=Object.prototype.propertyIsEnumerable;var X=(e,t,o)=>t in e?H(e,t,{enumerable:!0,configurable:!0,writable:!0,value:o}):e[t]=o,F=(e,t)=>{for(var o in t||(t={}))N.call(t,o)&&X(e,o,t[o]);if(I)for(var o of I(t))C.call(t,o)&&X(e,o,t[o]);return e},S=(e,t)=>Y(e,J(t));var M=(e,t)=>{var o={};for(var u in e)N.call(e,u)&&t.indexOf(u)<0&&(o[u]=e[u]);if(e!=null&&I)for(var u of I(e))t.indexOf(u)<0&&C.call(e,u)&&(o[u]=e[u]);return o};Object.defineProperty(exports,"__esModule",{value:!0});exports[Symbol.toStringTag]="Module";var i=require("vue-demi"),j=require("vue-router"),K=require("vue-i18n");/*! | ||
* shared v9.2.0-beta.25 | ||
* (c) 2021 kazuya kawaguchi | ||
"use strict";var ae=Object.defineProperty,oe=Object.defineProperties;var le=Object.getOwnPropertyDescriptors;var b=Object.getOwnPropertySymbols;var H=Object.prototype.hasOwnProperty,k=Object.prototype.propertyIsEnumerable;var Y=(e,a,t)=>a in e?ae(e,a,{enumerable:!0,configurable:!0,writable:!0,value:t}):e[a]=t,y=(e,a)=>{for(var t in a||(a={}))H.call(a,t)&&Y(e,t,a[t]);if(b)for(var t of b(a))k.call(a,t)&&Y(e,t,a[t]);return e},U=(e,a)=>oe(e,le(a));var J=(e,a)=>{var t={};for(var o in e)H.call(e,o)&&a.indexOf(o)<0&&(t[o]=e[o]);if(e!=null&&b)for(var o of b(e))a.indexOf(o)<0&&k.call(e,o)&&(t[o]=e[o]);return t};Object.defineProperty(exports,"__esModule",{value:!0});exports[Symbol.toStringTag]="Module";var h=require("vue-demi"),A=require("@intlify/vue-router-bridge"),K=require("@intlify/vue-i18n-bridge");function ne(e){return e&&typeof e=="object"&&"default"in e?e:{default:e}}var re=ne(A);/*! | ||
* shared v9.2.0-beta.28 | ||
* (c) 2022 kazuya kawaguchi | ||
* Released under the MIT License. | ||
*/const q=Object.assign,P=e=>typeof e=="string",Q=e=>typeof e=="symbol",Z=e=>typeof e=="symbol";new Set(Object.getOwnPropertyNames(Symbol).map(e=>Symbol[e]).filter(Z));function T(e){return Boolean(e&&e.__v_isRef===!0)}Promise.resolve();function ee(e){e=e||[];const t=[];for(const o of e)P(o)?t.push({code:o}):t.push(o);return t}function w(e,t){return T(e.locale)&&t==="composition"}function G(e){return"global"in e&&"mode"in e}function y(e){return G(e)?w(e.global,e.mode)?e.global.locale.value:e.global.locale:T(e.locale)?e.locale.value:e.locale}function B(e,t){G(e)?w(e.global,e.mode)?e.global.locale.value=t:e.global.locale=t:T(e.locale)&&(e.locale.value=t)}function oe(e,t,o){return e.replace(/\/+$/,"")+(t?"/":"")||(o?"":"/")}function te(e,{localeCodes:t=[]}={}){if(!w(e.global,e.mode))throw new Error("");const o=i.ref(t);e.global.locales=i.computed(()=>o.value),console.log("... extends i18n done")}const ne={PREFIX:"prefix",PREFIX_EXCEPT_DEFAULT:"prefix_except_default",PREFIX_AND_DEFAULT:"prefix_and_default",NO_PREFIX:"no_prefix"},O="",W=ne.PREFIX_EXCEPT_DEFAULT,D=!1,V="___",z="default";function U(e,{defaultLocale:t=O,strategy:o=W,trailingSlash:u=D,routesNameSeparator:d=V,defaultLocaleRouteNameSuffix:m=z,includeUprefixedFallback:f=!1,localeCodes:$=[]}={}){if(o==="no_prefix")return e;const _=$.map(n=>P(n)?n:n.code);function h(n,g,E=!1,R=!1){return n.redirect&&(!n.component||!n.file)?[n]:g.reduce((r,s)=>{const{name:c}=n;let{path:a}=n;const l=F({},n);c&&(l.name=`${c}${d}${s}`),n.children&&(l.children=n.children.reduce((b,A)=>[...b,...h(A,[s],!0,R)],[]));const x=s===t;if(x&&o==="prefix_and_default")if(E)E&&R&&c&&(l.name+=`${d}${m}`);else{const b=S(F({},l),{path:a});if(c&&(b.name=`${l.name}${d}${m}`),n.children){b.children=[];for(const A of n.children)b.children=b.children.concat(h(A,[s],!0,!0))}r.push(b)}const p=E&&!a.startsWith("/"),v=!p&&!(x&&o==="prefix_except_default");return v&&(a=`/${s}${a}`),a&&(a=oe(a,u,p)),v&&x&&o==="prefix"&&f&&r.push(F({},n)),l.path=a,r.push(l),r},[])}return e.reduce((n,g)=>[...n,...h(g,_||[])],[])}function ce(e){return new RegExp(`^/(${e.join("|")})(?:/|$)`,"i")}function re(e,t,o){const u=`(${e.join("|")})`,d=`(?:${t}${o})?`,m=new RegExp(`${t}${u}${d}$`,"i"),f=ce(e);return _=>{if(_.name){const n=(P(_.name)?_.name:_.name.toString()).match(m);if(n&&n.length>1)return n[1]}else if(_.path){const h=_.path.match(f);if(h&&h.length>1)return h[1]}return""}}function se({router:e,i18n:t,defaultLocale:o=O,strategy:u=W,trailingSlash:d=D,routesNameSeparator:m=V,defaultLocaleRouteNameSuffix:f=z,localeCodes:$=[]}={}){const _=ee($),h=re(_.map(n=>n.code),m,f);if(te(t,{localeCodes:_}),i.isVue2){const n=e,g=n.constructor,E=n.options.routes||[],R=U(E,{localeCodes:$,defaultLocale:o,strategy:u,trailingSlash:d,routesNameSeparator:m,defaultLocaleRouteNameSuffix:f});console.log("vue2 routes",E,R);const L=new g({mode:"history",base:n.options.base,routes:R});return L.__defaultLocale=o,L.__strategy=u,L.__trailingSlash=d,L.__routesNameSeparator=m,L.__defaultLocaleRouteNameSuffix=f,L.beforeEach((r,s,c)=>{console.log("beforeEach",r,s);const a=y(t),l=h(r)||a||o||"";console.log("currentLocale",a,"finalLocale",l),a!==l&&B(t,l),c()}),L}else{const n=e,g=n.options.routes||[],E=U(g,{localeCodes:$,defaultLocale:o,strategy:u,trailingSlash:d,routesNameSeparator:m,defaultLocaleRouteNameSuffix:f});return console.log("vue3 routes",g,E,n),g.forEach(R=>n.removeRoute(R.name)),E.forEach(R=>n.addRoute(R)),n.__defaultLocale=o,n.__strategy=u,n.__trailingSlash=d,n.__routesNameSeparator=m,n.__defaultLocaleRouteNameSuffix=f,n.beforeEach((R,L,r)=>{console.log("beforeEach",R,L);const s=y(t),c=h(R)||s||o||"";console.log("currentLocale",s,"finalLocale",c),s!==c&&B(t,c),r()}),n}}const ue=()=>{const e=i.getCurrentInstance();if(e==null)throw new Error("should be used in setup");return e.$router},le=()=>{const e=i.getCurrentInstance();if(e==null)throw new Error("should be used in setup");return i.computed(()=>e.$route)};function ae(){return i.isVue2?le():j.useRoute()}function ie(){return i.isVue2?ue():j.useRouter()}function fe(){return K.useI18n()}function de(e={}){const t=fe(),o=ie(),u=ae(),d=e.defaultLocaleRouteNameSuffix||o.__defaultLocaleRouteNameSuffix,m=e.defaultLocale||o.__defaultLocale,f=e.routesNameSeparator||o.__routesNameSeparator,$=e.strategy||o.__strategy;function _(r){const s=r!=null?r:i.isRef(u)?u.value:u;return s.name?k(s.name).split(f)[0]:void 0}function h(r,s){let c=k(r)+($==="no_prefix"?"":f+s);return s===m&&$==="prefix_and_default"&&(c+=f+d),c}function n(r,s){const c=s||y(t);let a=r;P(r)&&(r[0]==="/"?a={path:r}:a={name:r});let l=q({},a);if(l.path&&!l.name){const p=o.resolve(l),v=i.isVue2?p.route:p,b=_(v);P(b)&&(l={name:h(b,c),params:v.params,query:v.query,hash:v.hash})}else{l.name=h(l.name,c);const{params:p}=l;p&&p["0"]===void 0&&p.pathMatch&&(p["0"]=p.pathMatch)}const x=o.resolve(l);return(i.isVue2?x.route.name:x.name)?x:o.resolve(r)}function g(r,s){const c=n(r,s);return c==null?"":i.isVue2?c.route.redirectedFrom||c.route.fullPath:c.redirectedFrom||c.fullPath}function E(r,s){const c=n(r,s);return c==null?void 0:i.isVue2?c.route:c}function R(r,s){const c=n(r,s);return c==null?void 0:i.isVue2?c.location:c.href}function L(r){const s=_();if(!s)return"";const v=i.isVue2&&i.isRef(u)?u.value:u,{params:c}=v,a=M(v,["params"]),l={},x=q({},a,{name:s,params:S(F(F({},c),l),{0:c.pathMatch})}),p=g(x,r);return console.log("switchLocalePath",t.locale.value,r,p),p}return{localePath:g,localeRoute:E,localeLocation:R,switchLocalePath:L}}function k(e){return P(e)?e:Q(e)?e.toString():""}function me({router:e,i18n:t,defaultLocale:o=O,trailingSlash:u=D,routesNameSeparator:d=V,defaultLocaleRouteNameSuffix:m=z,localeCodes:f=[]}={}){if(e==null)throw new Error("TODO");return se({router:e,i18n:t,defaultLocale:o,trailingSlash:u,routesNameSeparator:d,defaultLocaleRouteNameSuffix:m,localeCodes:f})}const _e="";exports.VERSION=_e;exports.extendRouting=me;exports.localizeRoutes=U;exports.useI18nRouting=de; | ||
*/const X=Object.assign,T=e=>typeof e=="string",ue=e=>typeof e=="symbol";function ce(e){e=e||[];const a=[];for(const t of e)T(t)?a.push({code:t}):a.push(t);return a}function z(e,a){return h.isRef(e.locale)&&a==="composition"}function Q(e){return"global"in e&&"mode"in e}function C(e){return Q(e)?z(e.global,e.mode)?e.global.locale.value:e.global.locale:e.locale.value}function se(e,a){Q(e)?z(e.global,e.mode)?e.global.locale.value=a:e.global.locale=a:h.isRef(e.locale)&&(e.locale.value=a)}function fe(e,a,t){return e.replace(/\/+$/,"")+(a?"/":"")||(t?"":"/")}function M(e){return T(e)?e:ue(e)?e.toString():"(null)"}function O(e,a,{defaultLocale:t,strategy:o,routesNameSeparator:s,defaultLocaleRouteNameSuffix:_}){let d=M(e)+(o==="no_prefix"?"":s+a);return a===t&&o==="prefix_and_default"&&(d+=s+_),d}function ie(e={}){var f,r,E,m,i,L,$;const a=(f=e.i18n)!=null?f:K.useI18n(),t=(r=e.router)!=null?r:A.useRouter(),o=(E=e.route)!=null?E:A.useRoute(),s=(m=e.defaultLocaleRouteNameSuffix)!=null?m:t.__defaultLocaleRouteNameSuffix,_=(i=e.defaultLocale)!=null?i:t.__defaultLocale,d=(L=e.routesNameSeparator)!=null?L:t.__routesNameSeparator,S=($=e.strategy)!=null?$:t.__strategy;function c(u){const g=u!=null?u:h.isRef(o)?o.value:o;return g.name?M(g.name).split(d)[0]:null}function R(u,g){const n=g||C(a);let F=u;T(u)&&(u[0]==="/"?F={path:u}:F={name:u});let P=X({},F);if(P.path&&!P.name){const x=t.resolve(P),I=h.isVue2?x.route:x,W=c(I);T(W)&&(P={name:O(W,n,{defaultLocale:_,strategy:S,routesNameSeparator:d,defaultLocaleRouteNameSuffix:s}),params:I.params,query:I.query,hash:I.hash})}else{P.name=O(P.name,n,{defaultLocale:_,strategy:S,routesNameSeparator:d,defaultLocaleRouteNameSuffix:s});const{params:x}=P;x&&x["0"]===void 0&&x.pathMatch&&(x["0"]=x.pathMatch)}const D=t.resolve(P);return(h.isVue2?D.route.name:D.name)?D:t.resolve(u)}function l(u,g){const n=R(u,g);return n==null?"":h.isVue2?n.route.redirectedFrom||n.route.fullPath:n.redirectedFrom||n.fullPath}function p(u,g){const n=R(u,g);return n==null?void 0:h.isVue2?n.route:n}function v(u,g){const n=R(u,g);return n==null?void 0:h.isVue2?n.location:n}function N(u){const g=c();if(!g)return"";const I=h.isVue2&&h.isRef(o)?o.value:o,{params:n}=I,F=J(I,["params"]),P={},D=X({},F,{name:g,params:U(y(y({},n),P),{0:n.pathMatch})}),x=l(D,u);return console.log("switchLocalePath",a.locale.value,u,x),x}return{getRouteBaseName:c,localePath:l,localeRoute:p,localeLocation:v,switchLocalePath:N}}const de=/\/$|\/\?/;function j(e="",a=!1){return a?de.test(e):e.endsWith("/")}function me(e="",a=!1){if(!a)return(j(e)?e.slice(0,-1):e)||"/";if(!j(e,!0))return e||"/";const[t,...o]=e.split("?");return(t.slice(0,-1)||"/")+(o.length?`?${o.join("?")}`:"")}function he(e="",a=!1){if(!a)return e.endsWith("/")?e:e+"/";if(j(e,!0))return e||"/";const[t,...o]=e.split("?");return t+"/"+(o.length?`?${o.join("?")}`:"")}const V={PREFIX:"prefix",PREFIX_EXCEPT_DEFAULT:"prefix_except_default",PREFIX_AND_DEFAULT:"prefix_and_default",NO_PREFIX:"no_prefix"},q="",G=V.PREFIX_EXCEPT_DEFAULT,Z=!1,w="___",B="default";function ee(e=A.useRoute(),a=A.useRouter().__routesNameSeparator||w){const t=h.unref(e);return t.name?M(t.name).split(a)[0]:null}const _e=new Set([V.PREFIX_AND_DEFAULT,V.PREFIX_EXCEPT_DEFAULT]);function Re(e,a,t){const o=Le(e,a,t);return o==null?"":h.isVue2?o.route.redirectedFrom||o.route.fullPath:o.redirectedFrom||o.fullPath}function Le(e,a,{router:t=A.useRouter(),i18n:o=K.useI18n(),defaultLocale:s=q,defaultLocaleRouteNameSuffix:_=B,routesNameSeparator:d=w,strategy:S=G,trailingSlash:c=!1}={}){const R=t.__defaultLocaleRouteNameSuffix||_,l=t.__defaultLocale||s,p=t.__routesNameSeparator||d,v=t.__strategy||S,N=a||C(o);let f=e;T(e)&&(f[0]==="/"?f={path:e}:f={name:e});let r=X({},f);if(r.path&&!r.name){const m=t.resolve(r),i=h.isVue2?m.route:m,L=ee(i);T(L)?r={name:O(L,N,{defaultLocale:l,strategy:v,routesNameSeparator:p,defaultLocaleRouteNameSuffix:R}),params:i.params,query:i.query,hash:i.hash}:(!(N===s&&_e.has(v))&&v!==V.NO_PREFIX&&(r.path=`/${N}${r.path}`),r.path=c?he(r.path,!0):me(r.path,!0))}else{r.name=O(r.name,N,{defaultLocale:l,strategy:v,routesNameSeparator:p,defaultLocaleRouteNameSuffix:R});const{params:m}=r;m&&m["0"]===void 0&&m.pathMatch&&(m["0"]=m.pathMatch)}const E=t.resolve(r);return(h.isVue2?E.route.name:E.name)?E:t.resolve(e)}function te(e,{defaultLocale:a=q,strategy:t=G,trailingSlash:o=Z,routesNameSeparator:s=w,defaultLocaleRouteNameSuffix:_=B,includeUprefixedFallback:d=!1,locales:S=[]}={}){if(t==="no_prefix")return e;const c=S.map(l=>T(l)?l:l.code);function R(l,p,v=!1,N=!1){return l.redirect&&(!l.component||!l.file)?[l]:p.reduce((r,E)=>{const{name:m}=l;let{path:i}=l;const L=y({},l);m&&(L.name=`${m}${s}${E}`),l.children&&(L.children=l.children.reduce((n,F)=>[...n,...R(F,[E],!0,N)],[]));const $=E===a;if($&&t==="prefix_and_default")if(v)v&&N&&m&&(L.name+=`${s}${_}`);else{const n=U(y({},L),{path:i});if(m&&(n.name=`${L.name}${s}${_}`),l.children){n.children=[];for(const F of l.children)n.children=n.children.concat(R(F,[E],!0,!0))}r.push(n)}const u=v&&!i.startsWith("/"),g=!u&&!($&&t==="prefix_except_default");return g&&(i=`/${E}${i}`),i&&(i=fe(i,o,u)),g&&$&&t==="prefix"&&d&&r.push(y({},l)),L.path=i,r.push(L),r},[])}return e.reduce((l,p)=>[...l,...R(p,c||[])],[])}function ge(e,{locales:a=[]}={}){if(!z(e.global,e.mode))throw new Error("TODO:");const t=h.ref(a);e.global.locales=h.computed(()=>t.value)}function Se(e){return new RegExp(`^/(${e.join("|")})(?:/|$)`,"i")}function Ee(e,a,t){const o=`(${e.join("|")})`,s=`(?:${a}${t})?`,_=new RegExp(`${a}${o}${s}$`,"i"),d=Se(e);return c=>{if(c.name){const l=(T(c.name)?c.name:c.name.toString()).match(_);if(l&&l.length>1)return l[1]}else if(c.path){const R=c.path.match(d);if(R&&R.length>1)return R[1]}return""}}function ve(e){var a,t,o,s,_,d,S,c;return e.version=(a=e.version)!=null?a:4,e.defaultLocale=(t=e.defaultLocale)!=null?t:q,e.strategy=(o=e.strategy)!=null?o:G,e.trailingSlash=(s=e.trailingSlash)!=null?s:Z,e.routesNameSeparator=(_=e.routesNameSeparator)!=null?_:w,e.defaultLocaleRouteNameSuffix=(d=e.defaultLocaleRouteNameSuffix)!=null?d:B,e.locales=(S=e.locales)!=null?S:[],e.routes=(c=e.routes)!=null?c:[],e}function pe(e,a={}){const{version:t,defaultLocale:o,locales:s,strategy:_,trailingSlash:d,routesNameSeparator:S,defaultLocaleRouteNameSuffix:c,routes:R}=ve(a),l=ce(s),p=l.map(r=>r.code),v=Ee(p,S,c);ge(e,{locales:l});const N=te(R,{locales:s,defaultLocale:o,strategy:_,trailingSlash:d,routesNameSeparator:S,defaultLocaleRouteNameSuffix:c});a.routes=N;let f=null;if(h.isVue3&&t===4)f=A.createRouter(a);else if(h.isVue2&&t===3)f=new re.default(a);else throw new Error("TODO:");return f.__defaultLocale=o,f.__localeCodes=p,f.__strategy=_,f.__trailingSlash=d,f.__routesNameSeparator=S,f.__defaultLocaleRouteNameSuffix=c,f.beforeEach((r,E,m)=>{const i=C(e),L=v(r)||i||o||"";i!==L&&se(e,L),m()}),f}const Ne="0.0.0";exports.VERSION=Ne;exports.createRouter=pe;exports.getRouteBaseName=ee;exports.localePath=Re;exports.localizeRoutes=te;exports.useI18nRouting=ie; |
@@ -1,11 +0,36 @@ | ||
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 { Composer } from '@intlify/vue-i18n-bridge'; | ||
import type { I18n } from '@intlify/vue-i18n-bridge'; | ||
import { Locale } from '@intlify/vue-i18n-bridge'; | ||
import type { Location as Location_2 } from '@intlify/vue-router-bridge'; | ||
import type { RawLocation } from '@intlify/vue-router-bridge'; | ||
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 { useI18n } from '@intlify/vue-i18n-bridge'; | ||
import { useRoute } from '@intlify/vue-router-bridge'; | ||
import { useRouter } from '@intlify/vue-router-bridge'; | ||
import type { VueRouter } from '@intlify/vue-router-bridge'; | ||
/** | ||
* 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 | ||
@@ -15,16 +40,32 @@ */ | ||
export declare function extendRouting<TRouter extends VueRouter | Router>({ router, i18n, defaultLocale, trailingSlash, routesNameSeparator, defaultLocaleRouteNameSuffix, localeCodes }?: VueI18nRoutingOptions): TRouter; | ||
/** | ||
* Get route base name | ||
* | ||
* @param givenRoute - A route object, if not provided, the route is returned with `useRoute` will be used | ||
* @param routesNameSeparator - A route name separator, if not provided, default separator is `routesNameSeparator` option of {@link VueI18nRoutingOptions} will be used | ||
* | ||
* @returns The route base name, if route name is not defined, return null | ||
*/ | ||
export declare function getRouteBaseName(givenRoute?: Route_2 | RouteLocationNormalizedLoaded, routesNameSeparator?: string): string | null; | ||
export declare type I18nRoutingOptions = Pick<VueI18nRoutingOptions, 'defaultLocale' | 'strategy' | 'defaultLocaleRouteNameSuffix' | 'trailingSlash' | 'localeCodes'> & { | ||
routesNameSeparator?: string; | ||
}; | ||
export declare interface I18nRoutingReturn { | ||
getRouteBaseName(givenRoute?: Route_2 | RouteLocationNormalizedLoaded): string; | ||
localePath(route: any, locale?: Locale): string; | ||
localeRoute(route: any, locale?: Locale): any; | ||
localeLocation(route: any, locale?: Locale): any; | ||
export declare interface I18nRouting { | ||
getRouteBaseName(givenRoute?: Route_2 | RouteLocationNormalizedLoaded): string | null; | ||
localePath(route: RawLocation | RouteLocationRaw, locale?: Locale): string; | ||
localeRoute(route: RawLocation | RouteLocationRaw, locale?: Locale): Route_2 | ReturnType<Router['resolve']>; | ||
localeLocation(route: RawLocation | RouteLocationRaw, locale?: Locale): Location_2 | RouteLocation; | ||
switchLocalePath(locale: Locale): void; | ||
} | ||
export declare type I18nRoutingOptions = Pick<VueI18nRoutingOptions, 'defaultLocale' | 'strategy' | 'defaultLocaleRouteNameSuffix' | 'trailingSlash' | 'locales' | 'routesNameSeparator'> & { | ||
route?: ReturnType<typeof useRoute>; | ||
router?: ReturnType<typeof useRouter>; | ||
i18n?: ReturnType<typeof useI18n>; | ||
}; | ||
declare type I18nRoutingOptions_2 = Pick<VueI18nRoutingOptions, 'defaultLocale' | 'strategy' | 'defaultLocaleRouteNameSuffix' | 'trailingSlash' | 'locales' | 'routesNameSeparator'> & { | ||
route?: ReturnType<typeof useRoute>; | ||
router?: ReturnType<typeof useRouter>; | ||
i18n?: Composer; | ||
}; | ||
/** | ||
@@ -43,3 +84,15 @@ * Locale object | ||
export declare function localizeRoutes(routes: VueI18nRoute[], { defaultLocale, strategy, trailingSlash, routesNameSeparator, defaultLocaleRouteNameSuffix, includeUprefixedFallback, localeCodes }?: Pick<VueI18nRoutingOptions, 'defaultLocale' | 'strategy' | 'localeCodes' | 'routesNameSeparator' | 'trailingSlash' | 'defaultLocaleRouteNameSuffix'> & { | ||
/** | ||
* Resolve locale path | ||
* | ||
* @param route - A route location | ||
* @param locale - A locale, If not specified, uses the current locale | ||
* @param options - An options, see {@link I18nRoutingOptions} | ||
* | ||
* @returns Return localized path for passed in `route` | ||
*/ | ||
export declare function localePath(route: RawLocation | RouteLocationRaw, locale?: Locale, // TODO: locale should be more type inference (completion) | ||
options?: I18nRoutingOptions_2): string; | ||
export declare function localizeRoutes(routes: VueI18nRoute[], { defaultLocale, strategy, trailingSlash, routesNameSeparator, defaultLocaleRouteNameSuffix, includeUprefixedFallback, locales }?: Pick<VueI18nRoutingOptions, 'defaultLocale' | 'strategy' | 'locales' | 'routesNameSeparator' | 'trailingSlash' | 'defaultLocaleRouteNameSuffix'> & { | ||
includeUprefixedFallback?: boolean; | ||
@@ -84,3 +137,3 @@ }): VueI18nRoute[]; | ||
export declare function useI18nRouting<Legacy extends boolean = false>(options?: I18nRoutingOptions): I18nRoutingReturn; | ||
export declare function useI18nRouting(options?: I18nRoutingOptions): I18nRouting; | ||
@@ -93,3 +146,3 @@ /** | ||
*/ | ||
export declare const VERSION = ""; | ||
export declare const VERSION: string; | ||
@@ -104,28 +157,86 @@ /** | ||
/** | ||
* Vue I18n routing options | ||
* Options to initialize a VueRouter instance | ||
* | ||
* @remarks | ||
* This options is extended from Vue Router `RouterOptioins`, so you can specify those options. | ||
*/ | ||
export declare interface VueI18nRoutingOptions { | ||
export declare type VueI18nRoutingOptions = { | ||
/** | ||
* Vue Router instance | ||
* 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 | ||
*/ | ||
router?: VueRouter | Router; | ||
version?: 3 | 4; | ||
/** | ||
* Vue I18n instance | ||
* 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) | ||
*/ | ||
i18n?: VueI18n | I18n; | ||
defaultLocale?: string; | ||
localeCodes?: string[] | LocaleObject[]; | ||
/** | ||
* 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; | ||
} | ||
} & RouterOptions; | ||
export { } | ||
import type { ComputedRef } from 'vue' | ||
declare module 'vue-i18n' { | ||
export interface ComposerCustom { | ||
locales: ComputedRef<string[] | LocaleObject[]> | ||
locales: ComputedRef<LocaleObject[]> | ||
} | ||
} | ||
declare module 'vue-i18n-bridge' { | ||
export interface ComposerCustom { | ||
locales: ComputedRef<LocaleObject[]> | ||
} | ||
} |
@@ -32,8 +32,8 @@ var __defProp = Object.defineProperty; | ||
}; | ||
import { ref, computed, isVue2, getCurrentInstance, isRef as isRef$1 } from "vue-demi"; | ||
import { useRouter as useRouter$1, useRoute as useRoute$1 } from "vue-router"; | ||
import { useI18n as useI18n$1 } from "vue-i18n"; | ||
import { isRef, isVue2, unref, ref, computed, isVue3 } from "vue-demi"; | ||
import VueRouter3, { useRouter, useRoute, createRouter as createRouter$1 } from "@intlify/vue-router-bridge"; | ||
import { useI18n } from "@intlify/vue-i18n-bridge"; | ||
/*! | ||
* shared v9.2.0-beta.25 | ||
* (c) 2021 kazuya kawaguchi | ||
* shared v9.2.0-beta.28 | ||
* (c) 2022 kazuya kawaguchi | ||
* Released under the MIT License. | ||
@@ -43,9 +43,3 @@ */ | ||
const isString = (val) => typeof val === "string"; | ||
const isSymbol$1 = (val) => typeof val === "symbol"; | ||
const isSymbol = (val) => typeof val === "symbol"; | ||
new Set(Object.getOwnPropertyNames(Symbol).map((key) => Symbol[key]).filter(isSymbol)); | ||
function isRef(r) { | ||
return Boolean(r && r.__v_isRef === true); | ||
} | ||
Promise.resolve(); | ||
function getNormalizedLocales(locales) { | ||
@@ -70,3 +64,3 @@ locales = locales || []; | ||
function getLocale(i18n) { | ||
return isI18nInstance(i18n) ? isComposer(i18n.global, i18n.mode) ? i18n.global.locale.value : i18n.global.locale : isRef(i18n.locale) ? i18n.locale.value : i18n.locale; | ||
return isI18nInstance(i18n) ? isComposer(i18n.global, i18n.mode) ? i18n.global.locale.value : i18n.global.locale : i18n.locale.value; | ||
} | ||
@@ -87,10 +81,144 @@ function setLocale(i18n, locale) { | ||
} | ||
function extendI18n(i18n, { localeCodes = [] } = {}) { | ||
if (!isComposer(i18n.global, i18n.mode)) { | ||
throw new Error(""); | ||
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; | ||
} | ||
const _localeCodes = ref(localeCodes); | ||
i18n.global.locales = computed(() => _localeCodes.value); | ||
console.log("... extends i18n done"); | ||
return name; | ||
} | ||
function useI18nRouting(options = {}) { | ||
var _a, _b, _c, _d, _e, _f, _g; | ||
const $i18n = (_a = options.i18n) != null ? _a : useI18n(); | ||
const $router = (_b = options.router) != null ? _b : useRouter(); | ||
const $route = (_c = options.route) != null ? _c : useRoute(); | ||
const defaultLocaleRouteNameSuffix = (_d = options.defaultLocaleRouteNameSuffix) != null ? _d : $router.__defaultLocaleRouteNameSuffix; | ||
const defaultLocale = (_e = options.defaultLocale) != null ? _e : $router.__defaultLocale; | ||
const routesNameSeparator = (_f = options.routesNameSeparator) != null ? _f : $router.__routesNameSeparator; | ||
const strategy = (_g = options.strategy) != null ? _g : $router.__strategy; | ||
function getRouteBaseName2(givenRoute) { | ||
const route = givenRoute != null ? givenRoute : isRef($route) ? $route.value : $route; | ||
if (!route.name) { | ||
return null; | ||
} | ||
const name = getRouteName(route.name); | ||
return name.split(routesNameSeparator)[0]; | ||
} | ||
function resolveRoute2(route, locale) { | ||
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 = !isVue2 ? _resolvedRoute : _resolvedRoute.route; | ||
const resolvedRouteName = getRouteBaseName2(resolvedRoute2); | ||
if (isString(resolvedRouteName)) { | ||
localizedRoute = { | ||
name: getLocaleRouteName(resolvedRouteName, _locale, { | ||
defaultLocale, | ||
strategy, | ||
routesNameSeparator, | ||
defaultLocaleRouteNameSuffix | ||
}), | ||
params: resolvedRoute2.params, | ||
query: resolvedRoute2.query, | ||
hash: resolvedRoute2.hash | ||
}; | ||
} | ||
} else { | ||
localizedRoute.name = getLocaleRouteName(localizedRoute.name, _locale, { | ||
defaultLocale, | ||
strategy, | ||
routesNameSeparator, | ||
defaultLocaleRouteNameSuffix | ||
}); | ||
const { params } = localizedRoute; | ||
if (params && params["0"] === void 0 && params.pathMatch) { | ||
params["0"] = params.pathMatch; | ||
} | ||
} | ||
const resolvedRoute = $router.resolve(localizedRoute); | ||
if (isVue2 ? resolvedRoute.route.name : resolvedRoute.name) { | ||
return resolvedRoute; | ||
} | ||
return $router.resolve(route); | ||
} | ||
function localePath2(route, locale) { | ||
const localizedRoute = resolveRoute2(route, locale); | ||
return localizedRoute == null ? "" : isVue2 ? localizedRoute.route.redirectedFrom || localizedRoute.route.fullPath : localizedRoute.redirectedFrom || localizedRoute.fullPath; | ||
} | ||
function localeRoute(route, locale) { | ||
const resolved = resolveRoute2(route, locale); | ||
return resolved == null ? void 0 : isVue2 ? resolved.route : resolved; | ||
} | ||
function localeLocation(route, locale) { | ||
const resolved = resolveRoute2(route, locale); | ||
return resolved == null ? void 0 : isVue2 ? resolved.location : resolved; | ||
} | ||
function switchLocalePath(locale) { | ||
const name = getRouteBaseName2(); | ||
if (!name) { | ||
return ""; | ||
} | ||
const _a2 = isVue2 && isRef($route) ? $route.value : $route, { params } = _a2, routeCopy = __objRest(_a2, ["params"]); | ||
const langSwitchParams = {}; | ||
const baseRoute = assign({}, routeCopy, { | ||
name, | ||
params: __spreadProps(__spreadValues(__spreadValues({}, params), langSwitchParams), { | ||
0: params.pathMatch | ||
}) | ||
}); | ||
const path = localePath2(baseRoute, locale); | ||
console.log("switchLocalePath", $i18n.locale.value, locale, path); | ||
return path; | ||
} | ||
return { | ||
getRouteBaseName: getRouteBaseName2, | ||
localePath: localePath2, | ||
localeRoute, | ||
localeLocation, | ||
switchLocalePath | ||
}; | ||
} | ||
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("?")}` : ""); | ||
} | ||
const STRATEGIES = { | ||
@@ -107,2 +235,80 @@ PREFIX: "prefix", | ||
const DEFAULT_LOCALE_ROUTE_NAME_SUFFIX = "default"; | ||
function getRouteBaseName(givenRoute = useRoute(), routesNameSeparator = useRouter().__routesNameSeparator || DEFAULT_ROUTES_NAME_SEPARATOR) { | ||
const _route = unref(givenRoute); | ||
if (!_route.name) { | ||
return null; | ||
} | ||
const name = getRouteName(_route.name); | ||
return name.split(routesNameSeparator)[0]; | ||
} | ||
const RESOLVED_PREFIXED = new Set([STRATEGIES.PREFIX_AND_DEFAULT, STRATEGIES.PREFIX_EXCEPT_DEFAULT]); | ||
function localePath(route, locale, options) { | ||
const localizedRoute = resolveRoute(route, locale, options); | ||
return localizedRoute == null ? "" : isVue2 ? localizedRoute.route.redirectedFrom || localizedRoute.route.fullPath : localizedRoute.redirectedFrom || localizedRoute.fullPath; | ||
} | ||
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 = !isVue2 ? _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 (isVue2 ? resolvedRoute.route.name : resolvedRoute.name) { | ||
return resolvedRoute; | ||
} | ||
return router.resolve(route); | ||
} | ||
function localizeRoutes(routes, { | ||
@@ -115,3 +321,3 @@ defaultLocale = DEFAULT_LOCALE, | ||
includeUprefixedFallback = false, | ||
localeCodes = [] | ||
locales = [] | ||
} = {}) { | ||
@@ -121,3 +327,3 @@ if (strategy === "no_prefix") { | ||
} | ||
const _localeCodes = localeCodes.map((locale) => isString(locale) ? locale : locale.code); | ||
const _localeCodes = locales.map((locale) => isString(locale) ? locale : locale.code); | ||
function makeLocalizedRoutes(route, allowedLocaleCodes, isChild = false, isExtraPageTree = false) { | ||
@@ -174,2 +380,9 @@ if (route.redirect && (!route.component || !route.file)) { | ||
} | ||
function extendI18n(i18n, { locales = [] } = {}) { | ||
if (!isComposer(i18n.global, i18n.mode)) { | ||
throw new Error("TODO:"); | ||
} | ||
const _locales = ref(locales); | ||
i18n.global.locales = computed(() => _locales.value); | ||
} | ||
function getLocalesRegex(localeCodes) { | ||
@@ -200,225 +413,63 @@ return new RegExp(`^/(${localeCodes.join("|")})(?:/|$)`, "i"); | ||
} | ||
function extendRouter({ | ||
router, | ||
i18n, | ||
defaultLocale = DEFAULT_LOCALE, | ||
strategy = DEFAULT_STRATEGY, | ||
trailingSlash = DEFAULT_TRAILING_SLASH, | ||
routesNameSeparator = DEFAULT_ROUTES_NAME_SEPARATOR, | ||
defaultLocaleRouteNameSuffix = DEFAULT_LOCALE_ROUTE_NAME_SUFFIX, | ||
localeCodes = [] | ||
} = {}) { | ||
const normalizedLocaleCodes = getNormalizedLocales(localeCodes); | ||
const getLocaleFromRoute = createLocaleFromRouteGetter(normalizedLocaleCodes.map((l) => l.code), routesNameSeparator, defaultLocaleRouteNameSuffix); | ||
extendI18n(i18n, { localeCodes: normalizedLocaleCodes }); | ||
if (isVue2) { | ||
const _router = router; | ||
const _VueRouter = _router.constructor; | ||
const routes = _router.options.routes || []; | ||
const localizedRoutes = localizeRoutes(routes, { | ||
localeCodes, | ||
defaultLocale, | ||
strategy, | ||
trailingSlash, | ||
routesNameSeparator, | ||
defaultLocaleRouteNameSuffix | ||
}); | ||
console.log("vue2 routes", routes, localizedRoutes); | ||
const newRouter = new _VueRouter({ | ||
mode: "history", | ||
base: _router.options.base, | ||
routes: localizedRoutes | ||
}); | ||
newRouter.__defaultLocale = defaultLocale; | ||
newRouter.__strategy = strategy; | ||
newRouter.__trailingSlash = trailingSlash; | ||
newRouter.__routesNameSeparator = routesNameSeparator; | ||
newRouter.__defaultLocaleRouteNameSuffix = defaultLocaleRouteNameSuffix; | ||
newRouter.beforeEach((to, from, next) => { | ||
console.log("beforeEach", to, from); | ||
const currentLocale = getLocale(i18n); | ||
const finalLocale = getLocaleFromRoute(to) || currentLocale || defaultLocale || ""; | ||
console.log("currentLocale", currentLocale, "finalLocale", finalLocale); | ||
if (currentLocale !== finalLocale) { | ||
setLocale(i18n, finalLocale); | ||
} | ||
next(); | ||
}); | ||
return newRouter; | ||
} else { | ||
const _router = router; | ||
const routes = _router.options.routes || []; | ||
const localizedRoutes = localizeRoutes(routes, { | ||
localeCodes, | ||
defaultLocale, | ||
strategy, | ||
trailingSlash, | ||
routesNameSeparator, | ||
defaultLocaleRouteNameSuffix | ||
}); | ||
console.log("vue3 routes", routes, localizedRoutes, _router); | ||
routes.forEach((r) => _router.removeRoute(r.name)); | ||
localizedRoutes.forEach((route) => _router.addRoute(route)); | ||
_router.__defaultLocale = defaultLocale; | ||
_router.__strategy = strategy; | ||
_router.__trailingSlash = trailingSlash; | ||
_router.__routesNameSeparator = routesNameSeparator; | ||
_router.__defaultLocaleRouteNameSuffix = defaultLocaleRouteNameSuffix; | ||
_router.beforeEach((to, from, next) => { | ||
console.log("beforeEach", to, from); | ||
const currentLocale = getLocale(i18n); | ||
const finalLocale = getLocaleFromRoute(to) || currentLocale || defaultLocale || ""; | ||
console.log("currentLocale", currentLocale, "finalLocale", finalLocale); | ||
if (currentLocale !== finalLocale) { | ||
setLocale(i18n, finalLocale); | ||
} | ||
next(); | ||
}); | ||
return _router; | ||
} | ||
function asDefaultVueI18nRouterOptions(options) { | ||
var _a, _b, _c, _d, _e, _f, _g, _h; | ||
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.routes = (_h = options.routes) != null ? _h : []; | ||
return options; | ||
} | ||
const useLegacyRouter = () => { | ||
const vm = getCurrentInstance(); | ||
if (vm == null) { | ||
throw new Error(`should be used in setup`); | ||
} | ||
return vm.$router; | ||
}; | ||
const useLegacyRoute = () => { | ||
const vm = getCurrentInstance(); | ||
if (vm == null) { | ||
throw new Error(`should be used in setup`); | ||
} | ||
return computed(() => vm.$route); | ||
}; | ||
function useRoute() { | ||
return isVue2 ? useLegacyRoute() : useRoute$1(); | ||
} | ||
function useRouter() { | ||
return isVue2 ? useLegacyRouter() : useRouter$1(); | ||
} | ||
function useI18n() { | ||
return useI18n$1(); | ||
} | ||
function useI18nRouting(options = {}) { | ||
const $i18n = useI18n(); | ||
const $router = useRouter(); | ||
const $route = useRoute(); | ||
const defaultLocaleRouteNameSuffix = options.defaultLocaleRouteNameSuffix || $router.__defaultLocaleRouteNameSuffix; | ||
const defaultLocale = options.defaultLocale || $router.__defaultLocale; | ||
const routesNameSeparator = options.routesNameSeparator || $router.__routesNameSeparator; | ||
const strategy = options.strategy || $router.__strategy; | ||
function getRouteBaseName(givenRoute) { | ||
const route = givenRoute != null ? givenRoute : isRef$1($route) ? $route.value : $route; | ||
if (!route.name) { | ||
return; | ||
} | ||
const name = getRouteName(route.name); | ||
return name.split(routesNameSeparator)[0]; | ||
} | ||
function getLocaleRouteName(routeName, locale) { | ||
let name = getRouteName(routeName) + (strategy === "no_prefix" ? "" : routesNameSeparator + locale); | ||
if (locale === defaultLocale && strategy === "prefix_and_default") { | ||
name += routesNameSeparator + defaultLocaleRouteNameSuffix; | ||
} | ||
return name; | ||
} | ||
function resolveRoute(route, locale) { | ||
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 = !isVue2 ? _resolvedRoute : _resolvedRoute.route; | ||
const resolvedRouteName = getRouteBaseName(resolvedRoute2); | ||
if (isString(resolvedRouteName)) { | ||
localizedRoute = { | ||
name: getLocaleRouteName(resolvedRouteName, _locale), | ||
params: resolvedRoute2.params, | ||
query: resolvedRoute2.query, | ||
hash: resolvedRoute2.hash | ||
}; | ||
} | ||
} else { | ||
localizedRoute.name = getLocaleRouteName(localizedRoute.name, _locale); | ||
const { params } = localizedRoute; | ||
if (params && params["0"] === void 0 && params.pathMatch) { | ||
params["0"] = params.pathMatch; | ||
} | ||
} | ||
const resolvedRoute = $router.resolve(localizedRoute); | ||
if (isVue2 ? resolvedRoute.route.name : resolvedRoute.name) { | ||
return resolvedRoute; | ||
} | ||
return $router.resolve(route); | ||
} | ||
function localePath(route, locale) { | ||
const localizedRoute = resolveRoute(route, locale); | ||
return localizedRoute == null ? "" : isVue2 ? localizedRoute.route.redirectedFrom || localizedRoute.route.fullPath : localizedRoute.redirectedFrom || localizedRoute.fullPath; | ||
} | ||
function localeRoute(route, locale) { | ||
const resolved = resolveRoute(route, locale); | ||
return resolved == null ? void 0 : isVue2 ? resolved.route : resolved; | ||
} | ||
function localeLocation(route, locale) { | ||
const resolved = resolveRoute(route, locale); | ||
return resolved == null ? void 0 : isVue2 ? resolved.location : resolved.href; | ||
} | ||
function switchLocalePath(locale) { | ||
const name = getRouteBaseName(); | ||
if (!name) { | ||
return ""; | ||
} | ||
const _a = isVue2 && isRef$1($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); | ||
console.log("switchLocalePath", $i18n.locale.value, locale, path); | ||
return path; | ||
} | ||
return { | ||
localePath, | ||
localeRoute, | ||
localeLocation, | ||
switchLocalePath | ||
}; | ||
} | ||
function getRouteName(routeName) { | ||
return isString(routeName) ? routeName : isSymbol$1(routeName) ? routeName.toString() : ""; | ||
} | ||
function extendRouting({ | ||
router, | ||
i18n, | ||
defaultLocale = DEFAULT_LOCALE, | ||
trailingSlash = DEFAULT_TRAILING_SLASH, | ||
routesNameSeparator = DEFAULT_ROUTES_NAME_SEPARATOR, | ||
defaultLocaleRouteNameSuffix = DEFAULT_LOCALE_ROUTE_NAME_SUFFIX, | ||
localeCodes = [] | ||
} = {}) { | ||
if (router == null) { | ||
throw new Error("TODO"); | ||
} | ||
return extendRouter({ | ||
router, | ||
i18n, | ||
function createRouter(i18n, options = {}) { | ||
const { | ||
version, | ||
defaultLocale, | ||
locales, | ||
strategy, | ||
trailingSlash, | ||
routesNameSeparator, | ||
defaultLocaleRouteNameSuffix, | ||
localeCodes | ||
routes | ||
} = asDefaultVueI18nRouterOptions(options); | ||
const normalizedLocaleCodes = getNormalizedLocales(locales); | ||
const localeCodes = normalizedLocaleCodes.map((l) => l.code); | ||
const getLocaleFromRoute = createLocaleFromRouteGetter(localeCodes, routesNameSeparator, defaultLocaleRouteNameSuffix); | ||
extendI18n(i18n, { locales: normalizedLocaleCodes }); | ||
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.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 = ""; | ||
export { VERSION, extendRouting, localizeRoutes, useI18nRouting }; | ||
const VERSION = "0.0.0"; | ||
export { VERSION, createRouter, getRouteBaseName, localePath, localizeRoutes, useI18nRouting }; |
@@ -1,5 +0,5 @@ | ||
var _e=Object.defineProperty,he=Object.defineProperties;var Re=Object.getOwnPropertyDescriptors;var x=Object.getOwnPropertySymbols;var k=Object.prototype.hasOwnProperty,H=Object.prototype.propertyIsEnumerable;var Y=(a,n,f)=>n in a?_e(a,n,{enumerable:!0,configurable:!0,writable:!0,value:f}):a[n]=f,w=(a,n)=>{for(var f in n||(n={}))k.call(n,f)&&Y(a,f,n[f]);if(x)for(var f of x(n))H.call(n,f)&&Y(a,f,n[f]);return a},M=(a,n)=>he(a,Re(n));var J=(a,n)=>{var f={};for(var $ in a)k.call(a,$)&&n.indexOf($)<0&&(f[$]=a[$]);if(a!=null&&x)for(var $ of x(a))n.indexOf($)<0&&H.call(a,$)&&(f[$]=a[$]);return f};var VueI18nRouting=function(a,n,f,$){"use strict";/*! | ||
* shared v9.2.0-beta.25 | ||
* (c) 2021 kazuya kawaguchi | ||
var Pe=Object.defineProperty,pe=Object.defineProperties;var Fe=Object.getOwnPropertyDescriptors;var z=Object.getOwnPropertySymbols;var Z=Object.prototype.hasOwnProperty,ee=Object.prototype.propertyIsEnumerable;var te=(c,l,u)=>l in c?Pe(c,l,{enumerable:!0,configurable:!0,writable:!0,value:u}):c[l]=u,O=(c,l)=>{for(var u in l||(l={}))Z.call(l,u)&&te(c,u,l[u]);if(z)for(var u of z(l))ee.call(l,u)&&te(c,u,l[u]);return c},H=(c,l)=>pe(c,Fe(l));var ae=(c,l)=>{var u={};for(var p in c)Z.call(c,p)&&l.indexOf(p)<0&&(u[p]=c[p]);if(c!=null&&z)for(var p of z(c))l.indexOf(p)<0&&ee.call(c,p)&&(u[p]=c[p]);return u};var VueI18nRouting=function(c,l,u,p){"use strict";function oe(e){return e&&typeof e=="object"&&"default"in e?e:{default:e}}var le=oe(u);/*! | ||
* shared v9.2.0-beta.28 | ||
* (c) 2022 kazuya kawaguchi | ||
* Released under the MIT License. | ||
*/const j=Object.assign,T=e=>typeof e=="string",K=e=>typeof e=="symbol",Q=e=>typeof e=="symbol";new Set(Object.getOwnPropertyNames(Symbol).map(e=>Symbol[e]).filter(Q));function y(e){return Boolean(e&&e.__v_isRef===!0)}Promise.resolve();function Z(e){e=e||[];const r=[];for(const c of e)T(c)?r.push({code:c}):r.push(c);return r}function V(e,r){return y(e.locale)&&r==="composition"}function G(e){return"global"in e&&"mode"in e}function v(e){return G(e)?V(e.global,e.mode)?e.global.locale.value:e.global.locale:y(e.locale)?e.locale.value:e.locale}function q(e,r){G(e)?V(e.global,e.mode)?e.global.locale.value=r:e.global.locale=r:y(e.locale)&&(e.locale.value=r)}function D(e,r,c){return e.replace(/\/+$/,"")+(r?"/":"")||(c?"":"/")}function ee(e,{localeCodes:r=[]}={}){if(!V(e.global,e.mode))throw new Error("");const c=n.ref(r);e.global.locales=n.computed(()=>c.value),console.log("... extends i18n done")}const oe={PREFIX:"prefix",PREFIX_EXCEPT_DEFAULT:"prefix_except_default",PREFIX_AND_DEFAULT:"prefix_and_default",NO_PREFIX:"no_prefix"},O="",B=oe.PREFIX_EXCEPT_DEFAULT,z=!1,U="___",N="default";function C(e,{defaultLocale:r=O,strategy:c=B,trailingSlash:d=z,routesNameSeparator:h=U,defaultLocaleRouteNameSuffix:R=N,includeUprefixedFallback:_=!1,localeCodes:A=[]}={}){if(c==="no_prefix")return e;const m=A.map(o=>T(o)?o:o.code);function g(o,E,F=!1,p=!1){return o.redirect&&(!o.component||!o.file)?[o]:E.reduce((s,l)=>{const{name:t}=o;let{path:i}=o;const u=w({},o);t&&(u.name=`${t}${h}${l}`),o.children&&(u.children=o.children.reduce((P,X)=>[...P,...g(X,[l],!0,p)],[]));const S=l===r;if(S&&c==="prefix_and_default")if(F)F&&p&&t&&(u.name+=`${h}${R}`);else{const P=M(w({},u),{path:i});if(t&&(P.name=`${u.name}${h}${R}`),o.children){P.children=[];for(const X of o.children)P.children=P.children.concat(g(X,[l],!0,!0))}s.push(P)}const L=F&&!i.startsWith("/"),I=!L&&!(S&&c==="prefix_except_default");return I&&(i=`/${l}${i}`),i&&(i=D(i,d,L)),I&&S&&c==="prefix"&&_&&s.push(w({},o)),u.path=i,s.push(u),s},[])}return e.reduce((o,E)=>[...o,...g(E,m||[])],[])}function te(e){return new RegExp(`^/(${e.join("|")})(?:/|$)`,"i")}function ne(e,r,c){const d=`(${e.join("|")})`,h=`(?:${r}${c})?`,R=new RegExp(`${r}${d}${h}$`,"i"),_=te(e);return m=>{if(m.name){const o=(T(m.name)?m.name:m.name.toString()).match(R);if(o&&o.length>1)return o[1]}else if(m.path){const g=m.path.match(_);if(g&&g.length>1)return g[1]}return""}}function ce({router:e,i18n:r,defaultLocale:c=O,strategy:d=B,trailingSlash:h=z,routesNameSeparator:R=U,defaultLocaleRouteNameSuffix:_=N,localeCodes:A=[]}={}){const m=Z(A),g=ne(m.map(o=>o.code),R,_);if(ee(r,{localeCodes:m}),n.isVue2){const o=e,E=o.constructor,F=o.options.routes||[],p=C(F,{localeCodes:A,defaultLocale:c,strategy:d,trailingSlash:h,routesNameSeparator:R,defaultLocaleRouteNameSuffix:_});console.log("vue2 routes",F,p);const b=new E({mode:"history",base:o.options.base,routes:p});return b.__defaultLocale=c,b.__strategy=d,b.__trailingSlash=h,b.__routesNameSeparator=R,b.__defaultLocaleRouteNameSuffix=_,b.beforeEach((s,l,t)=>{console.log("beforeEach",s,l);const i=v(r),u=g(s)||i||c||"";console.log("currentLocale",i,"finalLocale",u),i!==u&&q(r,u),t()}),b}else{const o=e,E=o.options.routes||[],F=C(E,{localeCodes:A,defaultLocale:c,strategy:d,trailingSlash:h,routesNameSeparator:R,defaultLocaleRouteNameSuffix:_});return console.log("vue3 routes",E,F,o),E.forEach(p=>o.removeRoute(p.name)),F.forEach(p=>o.addRoute(p)),o.__defaultLocale=c,o.__strategy=d,o.__trailingSlash=h,o.__routesNameSeparator=R,o.__defaultLocaleRouteNameSuffix=_,o.beforeEach((p,b,s)=>{console.log("beforeEach",p,b);const l=v(r),t=g(p)||l||c||"";console.log("currentLocale",l,"finalLocale",t),l!==t&&q(r,t),s()}),o}}const se=()=>{const e=n.getCurrentInstance();if(e==null)throw new Error("should be used in setup");return e.$router},re=()=>{const e=n.getCurrentInstance();if(e==null)throw new Error("should be used in setup");return n.computed(()=>e.$route)};function le(){return n.isVue2?re():f.useRoute()}function ae(){return n.isVue2?se():f.useRouter()}function ue(){return $.useI18n()}function ie(e={}){const r=ue(),c=ae(),d=le(),h=e.defaultLocaleRouteNameSuffix||c.__defaultLocaleRouteNameSuffix,R=e.defaultLocale||c.__defaultLocale,_=e.routesNameSeparator||c.__routesNameSeparator,A=e.strategy||c.__strategy;function m(s){const l=s!=null?s:n.isRef(d)?d.value:d;return l.name?W(l.name).split(_)[0]:void 0}function g(s,l){let t=W(s)+(A==="no_prefix"?"":_+l);return l===R&&A==="prefix_and_default"&&(t+=_+h),t}function o(s,l){const t=l||v(r);let i=s;T(s)&&(s[0]==="/"?i={path:s}:i={name:s});let u=j({},i);if(u.path&&!u.name){const L=c.resolve(u),I=n.isVue2?L.route:L,P=m(I);T(P)&&(u={name:g(P,t),params:I.params,query:I.query,hash:I.hash})}else{u.name=g(u.name,t);const{params:L}=u;L&&L["0"]===void 0&&L.pathMatch&&(L["0"]=L.pathMatch)}const S=c.resolve(u);return(n.isVue2?S.route.name:S.name)?S:c.resolve(s)}function E(s,l){const t=o(s,l);return t==null?"":n.isVue2?t.route.redirectedFrom||t.route.fullPath:t.redirectedFrom||t.fullPath}function F(s,l){const t=o(s,l);return t==null?void 0:n.isVue2?t.route:t}function p(s,l){const t=o(s,l);return t==null?void 0:n.isVue2?t.location:t.href}function b(s){const l=m();if(!l)return"";const I=n.isVue2&&n.isRef(d)?d.value:d,{params:t}=I,i=J(I,["params"]),u={},S=j({},i,{name:l,params:M(w(w({},t),u),{0:t.pathMatch})}),L=E(S,s);return console.log("switchLocalePath",r.locale.value,s,L),L}return{localePath:E,localeRoute:F,localeLocation:p,switchLocalePath:b}}function W(e){return T(e)?e:K(e)?e.toString():""}function fe({router:e,i18n:r,defaultLocale:c=O,trailingSlash:d=z,routesNameSeparator:h=U,defaultLocaleRouteNameSuffix:R=N,localeCodes:_=[]}={}){if(e==null)throw new Error("TODO");return ce({router:e,i18n:r,defaultLocale:c,trailingSlash:d,routesNameSeparator:h,defaultLocaleRouteNameSuffix:R,localeCodes:_})}const de="";return a.VERSION=de,a.extendRouting=fe,a.localizeRoutes=C,a.useI18nRouting=ie,Object.defineProperty(a,"__esModule",{value:!0}),a[Symbol.toStringTag]="Module",a}({},VueDemi,VueRouter,VueI18n); | ||
*/const C=Object.assign,y=e=>typeof e=="string",ne=e=>typeof e=="symbol";function re(e){e=e||[];const a=[];for(const t of e)y(t)?a.push({code:t}):a.push(t);return a}function M(e,a){return l.isRef(e.locale)&&a==="composition"}function k(e){return"global"in e&&"mode"in e}function j(e){return k(e)?M(e.global,e.mode)?e.global.locale.value:e.global.locale:e.locale.value}function ce(e,a){k(e)?M(e.global,e.mode)?e.global.locale.value=a:e.global.locale=a:l.isRef(e.locale)&&(e.locale.value=a)}function se(e,a,t){return e.replace(/\/+$/,"")+(a?"/":"")||(t?"":"/")}function D(e){return y(e)?e:ne(e)?e.toString():"(null)"}function w(e,a,{defaultLocale:t,strategy:o,routesNameSeparator:d,defaultLocaleRouteNameSuffix:L}){let m=D(e)+(o==="no_prefix"?"":d+a);return a===t&&o==="prefix_and_default"&&(m+=d+L),m}function ue(e={}){var h,s,P,R,_,S,v;const a=(h=e.i18n)!=null?h:p.useI18n(),t=(s=e.router)!=null?s:u.useRouter(),o=(P=e.route)!=null?P:u.useRoute(),d=(R=e.defaultLocaleRouteNameSuffix)!=null?R:t.__defaultLocaleRouteNameSuffix,L=(_=e.defaultLocale)!=null?_:t.__defaultLocale,m=(S=e.routesNameSeparator)!=null?S:t.__routesNameSeparator,N=(v=e.strategy)!=null?v:t.__strategy;function i(f){const E=f!=null?f:l.isRef(o)?o.value:o;return E.name?D(E.name).split(m)[0]:null}function g(f,E){const r=E||j(a);let x=f;y(f)&&(f[0]==="/"?x={path:f}:x={name:f});let A=C({},x);if(A.path&&!A.name){const I=t.resolve(A),b=l.isVue2?I.route:I,Q=i(b);y(Q)&&(A={name:w(Q,r,{defaultLocale:L,strategy:N,routesNameSeparator:m,defaultLocaleRouteNameSuffix:d}),params:b.params,query:b.query,hash:b.hash})}else{A.name=w(A.name,r,{defaultLocale:L,strategy:N,routesNameSeparator:m,defaultLocaleRouteNameSuffix:d});const{params:I}=A;I&&I["0"]===void 0&&I.pathMatch&&(I["0"]=I.pathMatch)}const V=t.resolve(A);return(l.isVue2?V.route.name:V.name)?V:t.resolve(f)}function n(f,E){const r=g(f,E);return r==null?"":l.isVue2?r.route.redirectedFrom||r.route.fullPath:r.redirectedFrom||r.fullPath}function T(f,E){const r=g(f,E);return r==null?void 0:l.isVue2?r.route:r}function F(f,E){const r=g(f,E);return r==null?void 0:l.isVue2?r.location:r}function $(f){const E=i();if(!E)return"";const b=l.isVue2&&l.isRef(o)?o.value:o,{params:r}=b,x=ae(b,["params"]),A={},V=C({},x,{name:E,params:H(O(O({},r),A),{0:r.pathMatch})}),I=n(V,f);return console.log("switchLocalePath",a.locale.value,f,I),I}return{getRouteBaseName:i,localePath:n,localeRoute:T,localeLocation:F,switchLocalePath:$}}const fe=/\/$|\/\?/;function G(e="",a=!1){return a?fe.test(e):e.endsWith("/")}function ie(e="",a=!1){if(!a)return(G(e)?e.slice(0,-1):e)||"/";if(!G(e,!0))return e||"/";const[t,...o]=e.split("?");return(t.slice(0,-1)||"/")+(o.length?`?${o.join("?")}`:"")}function de(e="",a=!1){if(!a)return e.endsWith("/")?e:e+"/";if(G(e,!0))return e||"/";const[t,...o]=e.split("?");return t+"/"+(o.length?`?${o.join("?")}`:"")}const U={PREFIX:"prefix",PREFIX_EXCEPT_DEFAULT:"prefix_except_default",PREFIX_AND_DEFAULT:"prefix_and_default",NO_PREFIX:"no_prefix"},q="",W=U.PREFIX_EXCEPT_DEFAULT,Y=!1,X="___",B="default";function J(e=u.useRoute(),a=u.useRouter().__routesNameSeparator||X){const t=l.unref(e);return t.name?D(t.name).split(a)[0]:null}const he=new Set([U.PREFIX_AND_DEFAULT,U.PREFIX_EXCEPT_DEFAULT]);function _e(e,a,t){const o=me(e,a,t);return o==null?"":l.isVue2?o.route.redirectedFrom||o.route.fullPath:o.redirectedFrom||o.fullPath}function me(e,a,{router:t=u.useRouter(),i18n:o=p.useI18n(),defaultLocale:d=q,defaultLocaleRouteNameSuffix:L=B,routesNameSeparator:m=X,strategy:N=W,trailingSlash:i=!1}={}){const g=t.__defaultLocaleRouteNameSuffix||L,n=t.__defaultLocale||d,T=t.__routesNameSeparator||m,F=t.__strategy||N,$=a||j(o);let h=e;y(e)&&(h[0]==="/"?h={path:e}:h={name:e});let s=C({},h);if(s.path&&!s.name){const R=t.resolve(s),_=l.isVue2?R.route:R,S=J(_);y(S)?s={name:w(S,$,{defaultLocale:n,strategy:F,routesNameSeparator:T,defaultLocaleRouteNameSuffix:g}),params:_.params,query:_.query,hash:_.hash}:(!($===d&&he.has(F))&&F!==U.NO_PREFIX&&(s.path=`/${$}${s.path}`),s.path=i?de(s.path,!0):ie(s.path,!0))}else{s.name=w(s.name,$,{defaultLocale:n,strategy:F,routesNameSeparator:T,defaultLocaleRouteNameSuffix:g});const{params:R}=s;R&&R["0"]===void 0&&R.pathMatch&&(R["0"]=R.pathMatch)}const P=t.resolve(s);return(l.isVue2?P.route.name:P.name)?P:t.resolve(e)}function K(e,{defaultLocale:a=q,strategy:t=W,trailingSlash:o=Y,routesNameSeparator:d=X,defaultLocaleRouteNameSuffix:L=B,includeUprefixedFallback:m=!1,locales:N=[]}={}){if(t==="no_prefix")return e;const i=N.map(n=>y(n)?n:n.code);function g(n,T,F=!1,$=!1){return n.redirect&&(!n.component||!n.file)?[n]:T.reduce((s,P)=>{const{name:R}=n;let{path:_}=n;const S=O({},n);R&&(S.name=`${R}${d}${P}`),n.children&&(S.children=n.children.reduce((r,x)=>[...r,...g(x,[P],!0,$)],[]));const v=P===a;if(v&&t==="prefix_and_default")if(F)F&&$&&R&&(S.name+=`${d}${L}`);else{const r=H(O({},S),{path:_});if(R&&(r.name=`${S.name}${d}${L}`),n.children){r.children=[];for(const x of n.children)r.children=r.children.concat(g(x,[P],!0,!0))}s.push(r)}const f=F&&!_.startsWith("/"),E=!f&&!(v&&t==="prefix_except_default");return E&&(_=`/${P}${_}`),_&&(_=se(_,o,f)),E&&v&&t==="prefix"&&m&&s.push(O({},n)),S.path=_,s.push(S),s},[])}return e.reduce((n,T)=>[...n,...g(T,i||[])],[])}function Re(e,{locales:a=[]}={}){if(!M(e.global,e.mode))throw new Error("TODO:");const t=l.ref(a);e.global.locales=l.computed(()=>t.value)}function Le(e){return new RegExp(`^/(${e.join("|")})(?:/|$)`,"i")}function ge(e,a,t){const o=`(${e.join("|")})`,d=`(?:${a}${t})?`,L=new RegExp(`${a}${o}${d}$`,"i"),m=Le(e);return i=>{if(i.name){const n=(y(i.name)?i.name:i.name.toString()).match(L);if(n&&n.length>1)return n[1]}else if(i.path){const g=i.path.match(m);if(g&&g.length>1)return g[1]}return""}}function Se(e){var a,t,o,d,L,m,N,i;return e.version=(a=e.version)!=null?a:4,e.defaultLocale=(t=e.defaultLocale)!=null?t:q,e.strategy=(o=e.strategy)!=null?o:W,e.trailingSlash=(d=e.trailingSlash)!=null?d:Y,e.routesNameSeparator=(L=e.routesNameSeparator)!=null?L:X,e.defaultLocaleRouteNameSuffix=(m=e.defaultLocaleRouteNameSuffix)!=null?m:B,e.locales=(N=e.locales)!=null?N:[],e.routes=(i=e.routes)!=null?i:[],e}function Ee(e,a={}){const{version:t,defaultLocale:o,locales:d,strategy:L,trailingSlash:m,routesNameSeparator:N,defaultLocaleRouteNameSuffix:i,routes:g}=Se(a),n=re(d),T=n.map(s=>s.code),F=ge(T,N,i);Re(e,{locales:n});const $=K(g,{locales:d,defaultLocale:o,strategy:L,trailingSlash:m,routesNameSeparator:N,defaultLocaleRouteNameSuffix:i});a.routes=$;let h=null;if(l.isVue3&&t===4)h=u.createRouter(a);else if(l.isVue2&&t===3)h=new le.default(a);else throw new Error("TODO:");return h.__defaultLocale=o,h.__localeCodes=T,h.__strategy=L,h.__trailingSlash=m,h.__routesNameSeparator=N,h.__defaultLocaleRouteNameSuffix=i,h.beforeEach((s,P,R)=>{const _=j(e),S=F(s)||_||o||"";_!==S&&ce(e,S),R()}),h}const Ne="0.0.0";return c.VERSION=Ne,c.createRouter=Ee,c.getRouteBaseName=J,c.localePath=_e,c.localizeRoutes=K,c.useI18nRouting=ue,Object.defineProperty(c,"__esModule",{value:!0}),c[Symbol.toStringTag]="Module",c}({},VueDemi,VueRouter,VueI18n); |
{ | ||
"name": "vue-i18n-routing", | ||
"description": "The i18n routing with using vue-i18n", | ||
"version": "0.0.0-9f94af5", | ||
"version": "0.0.0-b4f3a33", | ||
"dependencies": { | ||
"@intlify/shared": "beta", | ||
"vue-demi": "*" | ||
"@intlify/vue-i18n-bridge": "^0.3.4", | ||
"@intlify/vue-router-bridge": "^0.3.4", | ||
"ufo": "^0.7.9", | ||
"vue-demi": "^0.12.1" | ||
}, | ||
"devDependencies": { | ||
"@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", | ||
@@ -19,2 +24,3 @@ "vite-plugin-dts": "^0.9.6", | ||
"vue-i18n-legacy": "npm:vue-i18n@latest", | ||
"vue-template-compiler": "^2.6.14", | ||
"vue-router": "^4.0.12", | ||
@@ -27,2 +33,4 @@ "vue-router3": "npm:vue-router@latest", | ||
"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-router": "^3.5.3 || ^4.0.0" | ||
@@ -87,4 +95,3 @@ }, | ||
"build:docs": "api-docs-gen ./temp/vue-i18n-routing.api.json -c ./docsgen.config.js -o ./ -g noprefix" | ||
}, | ||
"readme": "# vue-i18n-routing\n\nThe i18n routing with using vue-i18n\n\nWIP: đˇ\n\n## đ¤ API\n\nAbout details, See the [API References]('./api.md)\n\n## Šī¸ License\n\n[MIT](http://opensource.org/licenses/MIT)" | ||
} | ||
} |
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
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
Wildcard dependency
QualityPackage has a dependency with a floating version range. This can cause issues if the dependency publishes a new major version.
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
46710
752
0
10
15
+ Addedufo@^0.7.9
+ Added@intlify/core-base@9.14.2(transitive)
+ Added@intlify/message-compiler@9.14.2(transitive)
+ Added@intlify/shared@9.14.2(transitive)
+ Added@intlify/vue-devtools@9.14.2(transitive)
+ Added@intlify/vue-i18n-bridge@0.3.6(transitive)
+ Added@intlify/vue-router-bridge@0.3.6(transitive)
+ Addedufo@0.7.11(transitive)
+ Addedvue-demi@0.12.5(transitive)
+ Addedvue-i18n@9.14.2(transitive)
+ Addedvue-i18n-bridge@9.14.2(transitive)
Updatedvue-demi@^0.12.1