vue-i18n-routing
Advanced tools
Comparing version 0.0.0-e9e5447 to 0.0.0-eba77a5
@@ -1,5 +0,5 @@ | ||
"use strict";var W=Object.defineProperty,k=Object.defineProperties;var H=Object.getOwnPropertyDescriptors;var A=Object.getOwnPropertySymbols;var y=Object.prototype.hasOwnProperty,D=Object.prototype.propertyIsEnumerable;var O=(e,t,a)=>t in e?W(e,t,{enumerable:!0,configurable:!0,writable:!0,value:a}):e[t]=a,F=(e,t)=>{for(var a in t||(t={}))y.call(t,a)&&O(e,a,t[a]);if(A)for(var a of A(t))D.call(t,a)&&O(e,a,t[a]);return e},T=(e,t)=>k(e,H(t));var V=(e,t)=>{var a={};for(var n in e)y.call(e,n)&&t.indexOf(n)<0&&(a[n]=e[n]);if(e!=null&&A)for(var n of A(e))t.indexOf(n)<0&&D.call(e,n)&&(a[n]=e[n]);return a};Object.defineProperty(exports,"__esModule",{value:!0});exports[Symbol.toStringTag]="Module";var m=require("vue-demi"),N=require("@intlify/vue-router-bridge"),Y=require("@intlify/vue-i18n-bridge");function J(e){return e&&typeof e=="object"&&"default"in e?e:{default:e}}var K=J(N);/*! | ||
* shared v9.2.0-beta.26 | ||
* (c) 2021 kazuya kawaguchi | ||
"use strict";var ce=Object.defineProperty,se=Object.defineProperties;var ue=Object.getOwnPropertyDescriptors;var D=Object.getOwnPropertySymbols;var B=Object.prototype.hasOwnProperty,G=Object.prototype.propertyIsEnumerable;var H=(e,t,a)=>t in e?ce(e,t,{enumerable:!0,configurable:!0,writable:!0,value:a}):e[t]=a,I=(e,t)=>{for(var a in t||(t={}))B.call(t,a)&&H(e,a,t[a]);if(D)for(var a of D(t))G.call(t,a)&&H(e,a,t[a]);return e},F=(e,t)=>se(e,ue(t));var W=(e,t)=>{var a={};for(var n in e)B.call(e,n)&&t.indexOf(n)<0&&(a[n]=e[n]);if(e!=null&&D)for(var n of D(e))t.indexOf(n)<0&&G.call(e,n)&&(a[n]=e[n]);return a};Object.defineProperty(exports,"__esModule",{value:!0});exports[Symbol.toStringTag]="Module";var R=require("vue-demi"),A=require("@intlify/vue-router-bridge"),Q=require("@intlify/vue-i18n-bridge");function ie(e){return e&&typeof e=="object"&&"default"in e?e:{default:e}}var fe=ie(A);/*! | ||
* shared v9.2.0-beta.30 | ||
* (c) 2022 kazuya kawaguchi | ||
* Released under the MIT License. | ||
*/const U=Object.assign,b=e=>typeof e=="string",Q=e=>typeof e=="symbol";function Z(e){e=e||[];const t=[];for(const a of e)b(a)?t.push({code:a}):t.push(a);return t}function I(e,t){return m.isRef(e.locale)&&t==="composition"}function w(e){return"global"in e&&"mode"in e}function z(e){return w(e)?I(e.global,e.mode)?e.global.locale.value:e.global.locale:e.locale.value}function ee(e,t){w(e)?I(e.global,e.mode)?e.global.locale.value=t:e.global.locale=t:m.isRef(e.locale)&&(e.locale.value=t)}function te(e,t,a){return e.replace(/\/+$/,"")+(t?"/":"")||(a?"":"/")}function ae(e={}){const t=Y.useI18n(),a=N.useRouter(),n=N.useRoute(),R=e.defaultLocaleRouteNameSuffix||a.__defaultLocaleRouteNameSuffix,g=e.defaultLocale||a.__defaultLocale,h=e.routesNameSeparator||a.__routesNameSeparator,L=e.strategy||a.__strategy;function u(r){const c=r!=null?r:m.isRef(n)?n.value:n;return c.name?X(c.name).split(h)[0]:void 0}function _(r,c){let o=X(r)+(L==="no_prefix"?"":h+c);return c===g&&L==="prefix_and_default"&&(o+=h+R),o}function l(r,c){const o=c||z(t);let s=r;b(r)&&(r[0]==="/"?s={path:r}:s={name:r});let f=U({},s);if(f.path&&!f.name){const d=a.resolve(f),v=m.isVue2?d.route:d,E=u(v);b(E)&&(f={name:_(E,o),params:v.params,query:v.query,hash:v.hash})}else{f.name=_(f.name,o);const{params:d}=f;d&&d["0"]===void 0&&d.pathMatch&&(d["0"]=d.pathMatch)}const p=a.resolve(f);return(m.isVue2?p.route.name:p.name)?p:a.resolve(r)}function S(r,c){const o=l(r,c);return o==null?"":m.isVue2?o.route.redirectedFrom||o.route.fullPath:o.redirectedFrom||o.fullPath}function x(r,c){const o=l(r,c);return o==null?void 0:m.isVue2?o.route:o}function i(r,c){const o=l(r,c);return o==null?void 0:m.isVue2?o.location:o.href}function $(r){const c=u();if(!c)return"";const v=m.isVue2&&m.isRef(n)?n.value:n,{params:o}=v,s=V(v,["params"]),f={},p=U({},s,{name:c,params:T(F(F({},o),f),{0:o.pathMatch})}),d=S(p,r);return console.log("switchLocalePath",t.locale.value,r,d),d}return{getRouteBaseName:u,localePath:S,localeRoute:x,localeLocation:i,switchLocalePath:$}}function X(e){return b(e)?e:Q(e)?e.toString():"(null)"}const oe={PREFIX:"prefix",PREFIX_EXCEPT_DEFAULT:"prefix_except_default",PREFIX_AND_DEFAULT:"prefix_and_default",NO_PREFIX:"no_prefix"},M="",j=oe.PREFIX_EXCEPT_DEFAULT,C=!1,q="___",G="default";function B(e,{defaultLocale:t=M,strategy:a=j,trailingSlash:n=C,routesNameSeparator:R=q,defaultLocaleRouteNameSuffix:g=G,includeUprefixedFallback:h=!1,locales:L=[]}={}){if(a==="no_prefix")return e;const u=L.map(l=>b(l)?l:l.code);function _(l,S,x=!1,i=!1){return l.redirect&&(!l.component||!l.file)?[l]:S.reduce((r,c)=>{const{name:o}=l;let{path:s}=l;const f=F({},l);o&&(f.name=`${o}${R}${c}`),l.children&&(f.children=l.children.reduce((E,P)=>[...E,..._(P,[c],!0,i)],[]));const p=c===t;if(p&&a==="prefix_and_default")if(x)x&&i&&o&&(f.name+=`${R}${g}`);else{const E=T(F({},f),{path:s});if(o&&(E.name=`${f.name}${R}${g}`),l.children){E.children=[];for(const P of l.children)E.children=E.children.concat(_(P,[c],!0,!0))}r.push(E)}const d=x&&!s.startsWith("/"),v=!d&&!(p&&a==="prefix_except_default");return v&&(s=`/${c}${s}`),s&&(s=te(s,n,d)),v&&p&&a==="prefix"&&h&&r.push(F({},l)),f.path=s,r.push(f),r},[])}return e.reduce((l,S)=>[...l,..._(S,u||[])],[])}function le(e,{locales:t=[]}={}){if(!I(e.global,e.mode))throw new Error("");const a=m.ref(t);e.global.locales=m.computed(()=>a.value),console.log("... extends i18n done")}function ne(e){return new RegExp(`^/(${e.join("|")})(?:/|$)`,"i")}function re(e,t,a){const n=`(${e.join("|")})`,R=`(?:${t}${a})?`,g=new RegExp(`${t}${n}${R}$`,"i"),h=ne(e);return u=>{if(u.name){const l=(b(u.name)?u.name:u.name.toString()).match(g);if(l&&l.length>1)return l[1]}else if(u.path){const _=u.path.match(h);if(_&&_.length>1)return _[1]}return""}}function ce(e){var t,a,n,R,g,h,L,u;return e.version=(t=e.version)!=null?t:4,e.defaultLocale=(a=e.defaultLocale)!=null?a:M,e.strategy=(n=e.strategy)!=null?n:j,e.trailingSlash=(R=e.trailingSlash)!=null?R:C,e.routesNameSeparator=(g=e.routesNameSeparator)!=null?g:q,e.defaultLocaleRouteNameSuffix=(h=e.defaultLocaleRouteNameSuffix)!=null?h:G,e.locales=(L=e.locales)!=null?L:[],e.routes=(u=e.routes)!=null?u:[],e}function ue(e,t={}){const{version:a,defaultLocale:n,locales:R,strategy:g,trailingSlash:h,routesNameSeparator:L,defaultLocaleRouteNameSuffix:u,routes:_}=ce(t),l=Z(R),S=re(l.map($=>$.code),L,u);le(e,{locales:l});const x=B(_,{locales:R,defaultLocale:n,strategy:g,trailingSlash:h,routesNameSeparator:L,defaultLocaleRouteNameSuffix:u});t.routes=x;let i=null;if(m.isVue3&&a===4)i=N.createRouter(t);else if(m.isVue2&&a===3)i=new K.default(t);else throw new Error("TODO:");return i.__defaultLocale=n,i.__strategy=g,i.__trailingSlash=h,i.__routesNameSeparator=L,i.__defaultLocaleRouteNameSuffix=u,i.beforeEach(($,r,c)=>{console.log("beforeEach",$,r);const o=z(e),s=S($)||o||n||"";console.log("currentLocale",o,"finalLocale",s),o!==s&&ee(e,s),c()}),console.log("create router",i),i}const se="";exports.VERSION=se;exports.createRouter=ue;exports.localizeRoutes=B;exports.useI18nRouting=ae; | ||
*/const Y=Object.assign,de=Array.isArray,he=e=>typeof e=="function",T=e=>typeof e=="string",_e=e=>typeof e=="boolean",me=e=>typeof e=="symbol",ge=/\/$|\/\?/;function w(e="",t=!1){return t?ge.test(e):e.endsWith("/")}function Re(e="",t=!1){if(!t)return(w(e)?e.slice(0,-1):e)||"/";if(!w(e,!0))return e||"/";const[a,...n]=e.split("?");return(a.slice(0,-1)||"/")+(n.length?`?${n.join("?")}`:"")}function Le(e="",t=!1){if(!t)return e.endsWith("/")?e:e+"/";if(w(e,!0))return e||"/";const[a,...n]=e.split("?");return a+"/"+(n.length?`?${n.join("?")}`:"")}function Ee(e,t){typeof console!="undefined"&&(console.warn("[vue-i18n-routing] "+e),t&&console.warn(t.stack))}function J(e){e=e||[];const t=[];for(const a of e)T(a)?t.push({code:a}):t.push(a);return t}function C(e,t){return R.isRef(e.locale)&&t==="composition"}function K(e){return"global"in e&&"mode"in e}function V(e){return K(e)?C(e.global,e.mode)?e.global.locale.value:e.global.locale:e.locale.value}function pe(e,t){K(e)?C(e.global,e.mode)?e.global.locale.value=t:e.global.locale=t:R.isRef(e.locale)&&(e.locale.value=t)}function Se(e,t,a){return e.replace(/\/+$/,"")+(t?"/":"")||(a?"":"/")}function Z(e){return T(e)?e:me(e)?e.toString():"(null)"}function ee(e,t,{defaultLocale:a,strategy:n,routesNameSeparator:o,defaultLocaleRouteNameSuffix:l}){let r=Z(e)+(n==="no_prefix"?"":o+t);return t===a&&n==="prefix_and_default"&&(r+=o+l),r}function ve(e,t){return he(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,te=!1,$="___",X="default",Ae="ltr",ae="",ye=new Set([P.PREFIX_AND_DEFAULT,P.PREFIX_EXCEPT_DEFAULT]);function b(e=A.useRoute(),{router:t=A.useRouter(),routesNameSeparator:a=$}={}){const n=a||t.__routesNameSeparator,o=R.unref(e);return o.name?Z(o.name).split(n)[0]:null}function ne(e,t,a){const n=M(e,t,a);return n==null?"":R.isVue3?n.redirectedFrom||n.fullPath:n.route.redirectedFrom||n.route.fullPath}function le(e,t,a){const n=M(e,t,a);return n==null?void 0:R.isVue3?n:n.route}function Ie(e,t,a){const n=M(e,t,a);return n==null?void 0:R.isVue3?n:n.location}function M(e,t,{router:a=A.useRouter(),i18n:n=Q.useI18n(),defaultLocale:o=N,defaultLocaleRouteNameSuffix:l=X,routesNameSeparator:r=$,strategy:u=x,trailingSlash:i=!1}={}){const s=a.__defaultLocaleRouteNameSuffix||l,h=a.__defaultLocale||o,c=a.__routesNameSeparator||r,_=a.__strategy||u,g=t||V(n);let L=e;T(e)&&(L[0]==="/"?L={path:e}:L={name:e});let f=Y({},L);if(f.path&&!f.name){const d=a.resolve(f),p=R.isVue3?d:d.route,v=b(p);T(v)?f={name:ee(v,g,{defaultLocale:h,strategy:_,routesNameSeparator:c,defaultLocaleRouteNameSuffix:s}),params:p.params,query:p.query,hash:p.hash}:(!(g===o&&ye.has(_))&&_!==P.NO_PREFIX&&(f.path=`/${g}${f.path}`),f.path=i?Le(f.path,!0):Re(f.path,!0))}else{f.name=ee(f.name,g,{defaultLocale:h,strategy:_,routesNameSeparator:c,defaultLocaleRouteNameSuffix:s});const{params:d}=f;d&&d["0"]===void 0&&d.pathMatch&&(d["0"]=d.pathMatch)}const m=a.resolve(f);return(R.isVue3?m.name:m.route.name)?m:a.resolve(e)}function q(e,t){const a=t&&t.route||A.useRoute(),n=b(a,t);if(!n)return"";const s=!R.isVue3&&R.isRef(a)?a.value:a,{params:o}=s,l=W(s,["params"]),r={},u=Y({},l,{name:n,params:F(I(I({},o),r),{0:o.pathMatch})});return ne(u,e,t)}function Te({addDirAttribute:e=!1,addSeoAttributes:t=!1,strategy:a=x,defaultLocale:n=N,route:o=A.useRoute(),router:l=A.useRouter(),i18n:r=Q.useI18n()}={}){const u=n||l.__defaultLocale,i=a||l.__strategy,s=R.ref({htmlAttrs:{},link:[],meta:[]});function h(){s.value={htmlAttrs:{},link:[],meta:[]}}function c(_){const g=V(r),L=J(r.locales.value).find(d=>d.code===g)||{code:g},f=L.iso,m=L.dir||l.__defaultDirection;if(e&&(s.value.htmlAttrs.dir=m),t&&g&&r.locales){f&&(s.value.htmlAttrs.lang=f);const d=r.locales.value;Pe(d,r.__baseUrl,s.value.link,{defaultLocale:u,strategy:i,route:o,router:l,i18n:r}),De(r.__baseUrl,s.value.link,t,{route:_,router:l,i18n:r}),Fe(L,f,s.value.meta),Ne(d,f,s.value.meta)}}return R.watch(l.currentRoute,_=>{h(),c(_)}),c(o),s}function Pe(e,t,a,n){if(n.strategy===P.NO_PREFIX)return;const o=new Map;for(const l of e){const r=l.iso;if(!r){Ee("Locale ISO code is required to generate alternate link");continue}const[u,i]=r.split("-");u&&i&&(l.isCatchallLocale||!o.has(u))&&o.set(u,l),o.set(r,l)}for(const[l,r]of o.entries()){const u=q(r.code,n);u&&a.push({hid:`i18n-alt-${l}`,rel:"alternate",href:z(u,t),hreflang:l})}if(n.defaultLocale){const l=q(n.defaultLocale,n);l&&a.push({hid:"i18n-xd",rel:"alternate",href:z(l,t),hreflang:"x-default"})}}function De(e,t,a,n){const{route:o}=n,l=le(F(I({},o),{name:b(o,n)}),void 0,n);if(l){let r=z(l.path,e);const u=!_e(a)&&a.canonicalQueries||[];if(u.length){const i=l.query,s=new URLSearchParams;for(const c of u)if(c in i){const _=i[c];de(_)?_.forEach(g=>s.append(c,g||"")):s.append(c,_||"")}const h=s.toString();h&&(r=`${r}?${h}`)}t.push({hid:"i18n-can",rel:"canonical",href:r})}}function Fe(e,t,a){!(e&&t)||a.push({hid:"i18n-og",property:"og:locale",content:oe(t)})}function Ne(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:oe(l.iso)}));a.push(...o)}}function oe(e){return(e||"").replace(/-/g,"_")}function z(e,t){return e.match(/^https?:\/\//)?e:t+e}function re(e,{defaultLocale:t=N,strategy:a=x,trailingSlash:n=te,routesNameSeparator:o=$,defaultLocaleRouteNameSuffix:l=X,includeUprefixedFallback:r=!1,optionResolver:u=void 0,locales:i=[]}={}){if(a==="no_prefix")return e;const s=i.map(c=>T(c)?c:c.code);function h(c,_,g=!1,L=!1){if(c.redirect&&(!c.component||!c.file))return[c];let f=null;return u!=null&&(f=u(c,_),f==null)?[c]:_.reduce((d,p)=>{const{name:v}=c;let{path:E}=c;const S=I({},c);v&&(S.name=`${v}${o}${p}`),c.children&&(S.children=c.children.reduce((y,O)=>[...y,...h(O,[p],!0,L)],[]));const U=p===t;if(U&&a==="prefix_and_default")if(g)g&&L&&v&&(S.name+=`${o}${l}`);else{const y=F(I({},S),{path:E});if(v&&(y.name=`${S.name}${o}${l}`),c.children){y.children=[];for(const O of c.children)y.children=y.children.concat(h(O,[p],!0,!0))}d.push(y)}const j=g&&!E.startsWith("/"),k=!j&&!(U&&a==="prefix_except_default");return k&&(E=`/${p}${E}`),E&&(E=Se(E,n,j)),k&&U&&a==="prefix"&&r&&d.push(I({},c)),S.path=E,d.push(S),d},[])}return e.reduce((c,_)=>[...c,...h(_,s||[])],[])}function xe(e,{locales:t=[],baseUrl:a=ae}={}){if(!C(e.global,e.mode))throw new Error("TODO:");const n=R.ref(t);e.global.locales=R.computed(()=>n.value),e.global.__baseUrl=ve(a,{})}function $e(e){return new RegExp(`^/(${e.join("|")})(?:/|$)`,"i")}function be(e,t,a){const n=`(${e.join("|")})`,o=`(?:${t}${a})?`,l=new RegExp(`${t}${n}${o}$`,"i"),r=$e(e);return i=>{if(i.name){const h=(T(i.name)?i.name:i.name.toString()).match(l);if(h&&h.length>1)return h[1]}else if(i.path){const s=i.path.match(r);if(s&&s.length>1)return s[1]}return""}}function Ue(e){var t,a,n,o,l,r,u,i,s,h;return e.version=(t=e.version)!=null?t:4,e.defaultLocale=(a=e.defaultLocale)!=null?a:N,e.strategy=(n=e.strategy)!=null?n:x,e.trailingSlash=(o=e.trailingSlash)!=null?o:te,e.routesNameSeparator=(l=e.routesNameSeparator)!=null?l:$,e.defaultLocaleRouteNameSuffix=(r=e.defaultLocaleRouteNameSuffix)!=null?r:X,e.locales=(u=e.locales)!=null?u:[],e.defaultDirection=(i=e.defaultDirection)!=null?i:Ae,e.baseUrl=(s=e.baseUrl)!=null?s:ae,e.routes=(h=e.routes)!=null?h:[],e}function Oe(e,t={}){const{version:a,defaultLocale:n,locales:o,strategy:l,trailingSlash:r,routesNameSeparator:u,defaultLocaleRouteNameSuffix:i,defaultDirection:s,baseUrl:h,routes:c}=Ue(t),_=J(o),g=_.map(d=>d.code),L=be(g,u,i);xe(e,{locales:_,baseUrl:h});const f=re(c,{locales:o,defaultLocale:n,strategy:l,trailingSlash:r,routesNameSeparator:u,defaultLocaleRouteNameSuffix:i});t.routes=f;let m=null;if(R.isVue3&&a===4)m=A.createRouter(t);else if(R.isVue2&&a===3)m=new fe.default(t);else throw new Error("TODO:");return m.__defaultLocale=n,m.__localeCodes=g,m.__strategy=l,m.__trailingSlash=r,m.__routesNameSeparator=u,m.__defaultLocaleRouteNameSuffix=i,m.__defaultDirection=s,m.beforeEach((d,p,v)=>{const E=V(e),S=L(d)||E||n||"";E!==S&&pe(e,S),v()}),m}const we="0.0.0";exports.VERSION=we;exports.createRouter=Oe;exports.getRouteBaseName=b;exports.localeLocation=Ie;exports.localePath=ne;exports.localeRoute=le;exports.localizeRoutes=re;exports.switchLocalePath=q;exports.useI18nHead=Te; |
@@ -0,10 +1,30 @@ | ||
import { Composer } from '@intlify/vue-i18n-bridge'; | ||
import type { I18n } from '@intlify/vue-i18n-bridge'; | ||
import { Locale } 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; | ||
}; | ||
export declare type ComputedRouteOptions = { | ||
locales?: readonly string[]; | ||
paths?: Record<string, string>; | ||
}; | ||
/** | ||
@@ -32,15 +52,57 @@ * Create a Vue Router instance | ||
export declare interface I18nRouting { | ||
getRouteBaseName(givenRoute?: Route_2 | RouteLocationNormalizedLoaded): string; | ||
localePath(route: any, locale?: Locale): string; | ||
localeRoute(route: any, locale?: Locale): any; | ||
localeLocation(route: any, locale?: Locale): any; | ||
switchLocalePath(locale: Locale): void; | ||
/** | ||
* 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[]; | ||
} | ||
export declare type I18nRoutingOptions = Pick<VueI18nRoutingOptions, 'defaultLocale' | 'strategy' | 'defaultLocaleRouteNameSuffix' | 'trailingSlash' | 'locales'> & { | ||
routesNameSeparator?: string; | ||
}; | ||
/** | ||
* 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 | ||
@@ -58,6 +120,33 @@ */ | ||
export declare function localizeRoutes(routes: VueI18nRoute[], { defaultLocale, strategy, trailingSlash, routesNameSeparator, defaultLocaleRouteNameSuffix, includeUprefixedFallback, locales }?: Pick<VueI18nRoutingOptions, 'defaultLocale' | 'strategy' | 'locales' | 'routesNameSeparator' | 'trailingSlash' | 'defaultLocaleRouteNameSuffix'> & { | ||
/** | ||
* 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, optionResolver, locales }?: Pick<VueI18nRoutingOptions, 'defaultLocale' | 'strategy' | 'locales' | 'routesNameSeparator' | 'trailingSlash' | 'defaultLocaleRouteNameSuffix'> & { | ||
includeUprefixedFallback?: boolean; | ||
optionResolver?: RouteOptionsResolver; | ||
}): VueI18nRoute[]; | ||
export declare type MetaAttrs = Record<string, any>; | ||
/** | ||
@@ -85,2 +174,16 @@ * Route config for vue-router v4 | ||
export declare type RouteOptionsResolver = (route: VueI18nRoute, allowedLocaleCodes: string[]) => ComputedRouteOptions | null; | ||
/** | ||
* 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: { | ||
@@ -98,5 +201,22 @@ readonly PREFIX: "prefix"; | ||
/** | ||
* 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; | ||
export declare function useI18nRouting<Legacy extends boolean = false>(options?: I18nRoutingOptions): I18nRouting; | ||
/** | ||
* 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>; | ||
@@ -109,3 +229,3 @@ /** | ||
*/ | ||
export declare const VERSION = ""; | ||
export declare const VERSION: string; | ||
@@ -125,3 +245,3 @@ /** | ||
*/ | ||
export declare type VueI18nRoutingOptions = { | ||
export declare type VueI18nRoutingOptions<BaseUrl extends BaseUrlResolveHandler = BaseUrlResolveHandler> = { | ||
/** | ||
@@ -192,2 +312,21 @@ * Vue Router version | ||
defaultLocaleRouteNameSuffix?: string; | ||
/** | ||
* Default direction direction | ||
* | ||
* @defaultValue 'ltr' | ||
*/ | ||
defaultDirection?: Directions; | ||
/** | ||
* The fallback base URL to use as a prefix for alternate URLs in hreflang tags. | ||
* | ||
* @remarks | ||
* By default VueRouter's base URL will be used and only if that is not available, fallback URL will be used. | ||
* | ||
* Can also be a function (will be passed a Nuxt Context as a parameter) that returns a string. | ||
* | ||
* Useful to make base URL dynamic based on request headers. | ||
* | ||
* @defaultValue '' | ||
*/ | ||
baseUrl?: string | BaseUrl; | ||
} & RouterOptions; | ||
@@ -200,2 +339,3 @@ | ||
locales: ComputedRef<string[] | LocaleObject[]> | ||
__baseUrl: string | ||
} | ||
@@ -206,3 +346,4 @@ } | ||
locales: ComputedRef<string[] | LocaleObject[]> | ||
__baseUrl: string | ||
} | ||
} |
@@ -32,13 +32,51 @@ var __defProp = Object.defineProperty; | ||
}; | ||
import { isRef, isVue2, ref, computed, isVue3 } from "vue-demi"; | ||
import VueRouter3, { useRouter, useRoute, createRouter as createRouter$1 } from "@intlify/vue-router-bridge"; | ||
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.26 | ||
* (c) 2021 kazuya kawaguchi | ||
* 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) { | ||
@@ -79,112 +117,304 @@ locales = locales || []; | ||
} | ||
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($route) ? $route.value : $route; | ||
if (!route.name) { | ||
return; | ||
} | ||
const name = getRouteName(route.name); | ||
return name.split(routesNameSeparator)[0]; | ||
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; | ||
} | ||
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 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 }; | ||
} | ||
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 | ||
}; | ||
} | ||
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 { | ||
localizedRoute.name = getLocaleRouteName(localizedRoute.name, _locale); | ||
const { params } = localizedRoute; | ||
if (params && params["0"] === void 0 && params.pathMatch) { | ||
params["0"] = params.pathMatch; | ||
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); | ||
} | ||
const resolvedRoute = $router.resolve(localizedRoute); | ||
if (isVue2 ? resolvedRoute.route.name : resolvedRoute.name) { | ||
return resolvedRoute; | ||
} 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; | ||
} | ||
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; | ||
const resolvedRoute = router.resolve(localizedRoute); | ||
if (isVue3 ? resolvedRoute.name : resolvedRoute.route.name) { | ||
return resolvedRoute; | ||
} | ||
function localeRoute(route, locale) { | ||
const resolved = resolveRoute(route, locale); | ||
return resolved == null ? void 0 : isVue2 ? resolved.route : resolved; | ||
return router.resolve(route); | ||
} | ||
function switchLocalePath(locale, options) { | ||
const route = options && options.route || useRoute(); | ||
const name = getRouteBaseName(route, options); | ||
if (!name) { | ||
return ""; | ||
} | ||
function localeLocation(route, locale) { | ||
const resolved = resolveRoute(route, locale); | ||
return resolved == null ? void 0 : isVue2 ? resolved.location : resolved.href; | ||
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 switchLocalePath(locale) { | ||
const name = getRouteBaseName(); | ||
if (!name) { | ||
return ""; | ||
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.__defaultDirection; | ||
if (addDirAttribute) { | ||
metaObject.value.htmlAttrs.dir = currentLocaleDir; | ||
} | ||
const _a = isVue2 && 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 | ||
}) | ||
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 | ||
}); | ||
const path = localePath(baseRoute, locale); | ||
console.log("switchLocalePath", $i18n.locale.value, locale, path); | ||
return path; | ||
} | ||
return { | ||
getRouteBaseName, | ||
localePath, | ||
localeRoute, | ||
localeLocation, | ||
switchLocalePath | ||
}; | ||
} | ||
function getRouteName(routeName) { | ||
return isString(routeName) ? routeName : isSymbol(routeName) ? routeName.toString() : "(null)"; | ||
function addCurrentOgLocale(currentLocale, currentLocaleIso, meta) { | ||
const hasCurrentLocaleAndIso = currentLocale && currentLocaleIso; | ||
if (!hasCurrentLocaleAndIso) { | ||
return; | ||
} | ||
meta.push({ | ||
hid: "i18n-og", | ||
property: "og:locale", | ||
content: hypenToUnderscore(currentLocaleIso) | ||
}); | ||
} | ||
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"; | ||
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, { | ||
@@ -197,2 +427,3 @@ defaultLocale = DEFAULT_LOCALE, | ||
includeUprefixedFallback = false, | ||
optionResolver = void 0, | ||
locales = [] | ||
@@ -208,2 +439,9 @@ } = {}) { | ||
} | ||
let routeOptions = null; | ||
if (optionResolver != null) { | ||
routeOptions = optionResolver(route, allowedLocaleCodes); | ||
if (routeOptions == null) { | ||
return [route]; | ||
} | ||
} | ||
const targetLocales = allowedLocaleCodes; | ||
@@ -256,9 +494,9 @@ return targetLocales.reduce((_routes, locale) => { | ||
} | ||
function extendI18n(i18n, { locales = [] } = {}) { | ||
function extendI18n(i18n, { locales = [], baseUrl = DEFAULT_BASE_URL } = {}) { | ||
if (!isComposer(i18n.global, i18n.mode)) { | ||
throw new Error(""); | ||
throw new Error("TODO:"); | ||
} | ||
const _locales = ref(locales); | ||
i18n.global.locales = computed(() => _locales.value); | ||
console.log("... extends i18n done"); | ||
i18n.global.__baseUrl = resolveBaseUrl(baseUrl, {}); | ||
} | ||
@@ -291,3 +529,3 @@ function getLocalesRegex(localeCodes) { | ||
function asDefaultVueI18nRouterOptions(options) { | ||
var _a, _b, _c, _d, _e, _f, _g, _h; | ||
var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j; | ||
options.version = (_a = options.version) != null ? _a : 4; | ||
@@ -300,3 +538,5 @@ options.defaultLocale = (_b = options.defaultLocale) != null ? _b : DEFAULT_LOCALE; | ||
options.locales = (_g = options.locales) != null ? _g : []; | ||
options.routes = (_h = options.routes) != null ? _h : []; | ||
options.defaultDirection = (_h = options.defaultDirection) != null ? _h : DEFAULT_DETECTION_DIRECTION; | ||
options.baseUrl = (_i = options.baseUrl) != null ? _i : DEFAULT_BASE_URL; | ||
options.routes = (_j = options.routes) != null ? _j : []; | ||
return options; | ||
@@ -313,7 +553,10 @@ } | ||
defaultLocaleRouteNameSuffix, | ||
defaultDirection, | ||
baseUrl, | ||
routes | ||
} = asDefaultVueI18nRouterOptions(options); | ||
const normalizedLocaleCodes = getNormalizedLocales(locales); | ||
const getLocaleFromRoute = createLocaleFromRouteGetter(normalizedLocaleCodes.map((l) => l.code), routesNameSeparator, defaultLocaleRouteNameSuffix); | ||
extendI18n(i18n, { locales: normalizedLocaleCodes }); | ||
const localeCodes = normalizedLocaleCodes.map((l) => l.code); | ||
const getLocaleFromRoute = createLocaleFromRouteGetter(localeCodes, routesNameSeparator, defaultLocaleRouteNameSuffix); | ||
extendI18n(i18n, { locales: normalizedLocaleCodes, baseUrl }); | ||
const localizedRoutes = localizeRoutes(routes, { | ||
@@ -337,2 +580,3 @@ locales, | ||
router.__defaultLocale = defaultLocale; | ||
router.__localeCodes = localeCodes; | ||
router.__strategy = strategy; | ||
@@ -342,7 +586,6 @@ router.__trailingSlash = trailingSlash; | ||
router.__defaultLocaleRouteNameSuffix = defaultLocaleRouteNameSuffix; | ||
router.__defaultDirection = defaultDirection; | ||
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) { | ||
@@ -353,6 +596,5 @@ setLocale(i18n, finalLocale); | ||
}); | ||
console.log("create router", router); | ||
return router; | ||
} | ||
const VERSION = ""; | ||
export { VERSION, createRouter, localizeRoutes, useI18nRouting }; | ||
const VERSION = "0.0.0"; | ||
export { VERSION, createRouter, getRouteBaseName, localeLocation, localePath, localeRoute, localizeRoutes, switchLocalePath, useI18nHead }; |
@@ -1,5 +0,5 @@ | ||
var ue=Object.defineProperty,se=Object.defineProperties;var fe=Object.getOwnPropertyDescriptors;var b=Object.getOwnPropertySymbols;var W=Object.prototype.hasOwnProperty,k=Object.prototype.propertyIsEnumerable;var B=(r,a,s)=>a in r?ue(r,a,{enumerable:!0,configurable:!0,writable:!0,value:s}):r[a]=s,T=(r,a)=>{for(var s in a||(a={}))W.call(a,s)&&B(r,s,a[s]);if(b)for(var s of b(a))k.call(a,s)&&B(r,s,a[s]);return r},O=(r,a)=>se(r,fe(a));var D=(r,a)=>{var s={};for(var p in r)W.call(r,p)&&a.indexOf(p)<0&&(s[p]=r[p]);if(r!=null&&b)for(var p of b(r))a.indexOf(p)<0&&k.call(r,p)&&(s[p]=r[p]);return s};var VueI18nRouting=function(r,a,s,p){"use strict";function H(e){return e&&typeof e=="object"&&"default"in e?e:{default:e}}var Y=H(s);/*! | ||
* shared v9.2.0-beta.26 | ||
* (c) 2021 kazuya kawaguchi | ||
var we=Object.defineProperty,De=Object.defineProperties;var Ce=Object.getOwnPropertyDescriptors;var x=Object.getOwnPropertySymbols;var le=Object.prototype.hasOwnProperty,oe=Object.prototype.propertyIsEnumerable;var ce=(u,s,h)=>s in u?we(u,s,{enumerable:!0,configurable:!0,writable:!0,value:h}):u[s]=h,F=(u,s)=>{for(var h in s||(s={}))le.call(s,h)&&ce(u,h,s[h]);if(x)for(var h of x(s))oe.call(s,h)&&ce(u,h,s[h]);return u},w=(u,s)=>De(u,Ce(s));var re=(u,s)=>{var h={};for(var p in u)le.call(u,p)&&s.indexOf(p)<0&&(h[p]=u[p]);if(u!=null&&x)for(var p of x(u))s.indexOf(p)<0&&oe.call(u,p)&&(h[p]=u[p]);return h};var VueI18nRouting=function(u,s,h,p){"use strict";function se(e){return e&&typeof e=="object"&&"default"in e?e:{default:e}}var ue=se(h);/*! | ||
* shared v9.2.0-beta.30 | ||
* (c) 2022 kazuya kawaguchi | ||
* Released under the MIT License. | ||
*/const V=Object.assign,P=e=>typeof e=="string",J=e=>typeof e=="symbol";function K(e){e=e||[];const o=[];for(const l of e)P(l)?o.push({code:l}):o.push(l);return o}function y(e,o){return a.isRef(e.locale)&&o==="composition"}function U(e){return"global"in e&&"mode"in e}function w(e){return U(e)?y(e.global,e.mode)?e.global.locale.value:e.global.locale:e.locale.value}function Q(e,o){U(e)?y(e.global,e.mode)?e.global.locale.value=o:e.global.locale=o:a.isRef(e.locale)&&(e.locale.value=o)}function Z(e,o,l){return e.replace(/\/+$/,"")+(o?"/":"")||(l?"":"/")}function ee(e={}){const o=p.useI18n(),l=s.useRouter(),h=s.useRoute(),m=e.defaultLocaleRouteNameSuffix||l.__defaultLocaleRouteNameSuffix,E=e.defaultLocale||l.__defaultLocale,g=e.routesNameSeparator||l.__routesNameSeparator,S=e.strategy||l.__strategy;function f(c){const u=c!=null?c:a.isRef(h)?h.value:h;return u.name?z(u.name).split(g)[0]:void 0}function L(c,u){let t=z(c)+(S==="no_prefix"?"":g+u);return u===E&&S==="prefix_and_default"&&(t+=g+m),t}function n(c,u){const t=u||w(o);let i=c;P(c)&&(c[0]==="/"?i={path:c}:i={name:c});let d=V({},i);if(d.path&&!d.name){const _=l.resolve(d),$=a.isVue2?_.route:_,F=f($);P(F)&&(d={name:L(F,t),params:$.params,query:$.query,hash:$.hash})}else{d.name=L(d.name,t);const{params:_}=d;_&&_["0"]===void 0&&_.pathMatch&&(_["0"]=_.pathMatch)}const x=l.resolve(d);return(a.isVue2?x.route.name:x.name)?x:l.resolve(c)}function A(c,u){const t=n(c,u);return t==null?"":a.isVue2?t.route.redirectedFrom||t.route.fullPath:t.redirectedFrom||t.fullPath}function I(c,u){const t=n(c,u);return t==null?void 0:a.isVue2?t.route:t}function R(c,u){const t=n(c,u);return t==null?void 0:a.isVue2?t.location:t.href}function N(c){const u=f();if(!u)return"";const $=a.isVue2&&a.isRef(h)?h.value:h,{params:t}=$,i=D($,["params"]),d={},x=V({},i,{name:u,params:O(T(T({},t),d),{0:t.pathMatch})}),_=A(x,c);return console.log("switchLocalePath",o.locale.value,c,_),_}return{getRouteBaseName:f,localePath:A,localeRoute:I,localeLocation:R,switchLocalePath:N}}function z(e){return P(e)?e:J(e)?e.toString():"(null)"}const te={PREFIX:"prefix",PREFIX_EXCEPT_DEFAULT:"prefix_except_default",PREFIX_AND_DEFAULT:"prefix_and_default",NO_PREFIX:"no_prefix"},X="",M=te.PREFIX_EXCEPT_DEFAULT,j=!1,C="___",G="default";function q(e,{defaultLocale:o=X,strategy:l=M,trailingSlash:h=j,routesNameSeparator:m=C,defaultLocaleRouteNameSuffix:E=G,includeUprefixedFallback:g=!1,locales:S=[]}={}){if(l==="no_prefix")return e;const f=S.map(n=>P(n)?n:n.code);function L(n,A,I=!1,R=!1){return n.redirect&&(!n.component||!n.file)?[n]:A.reduce((c,u)=>{const{name:t}=n;let{path:i}=n;const d=T({},n);t&&(d.name=`${t}${m}${u}`),n.children&&(d.children=n.children.reduce((F,v)=>[...F,...L(v,[u],!0,R)],[]));const x=u===o;if(x&&l==="prefix_and_default")if(I)I&&R&&t&&(d.name+=`${m}${E}`);else{const F=O(T({},d),{path:i});if(t&&(F.name=`${d.name}${m}${E}`),n.children){F.children=[];for(const v of n.children)F.children=F.children.concat(L(v,[u],!0,!0))}c.push(F)}const _=I&&!i.startsWith("/"),$=!_&&!(x&&l==="prefix_except_default");return $&&(i=`/${u}${i}`),i&&(i=Z(i,h,_)),$&&x&&l==="prefix"&&g&&c.push(T({},n)),d.path=i,c.push(d),c},[])}return e.reduce((n,A)=>[...n,...L(A,f||[])],[])}function ae(e,{locales:o=[]}={}){if(!y(e.global,e.mode))throw new Error("");const l=a.ref(o);e.global.locales=a.computed(()=>l.value),console.log("... extends i18n done")}function oe(e){return new RegExp(`^/(${e.join("|")})(?:/|$)`,"i")}function ne(e,o,l){const h=`(${e.join("|")})`,m=`(?:${o}${l})?`,E=new RegExp(`${o}${h}${m}$`,"i"),g=oe(e);return f=>{if(f.name){const n=(P(f.name)?f.name:f.name.toString()).match(E);if(n&&n.length>1)return n[1]}else if(f.path){const L=f.path.match(g);if(L&&L.length>1)return L[1]}return""}}function le(e){var o,l,h,m,E,g,S,f;return e.version=(o=e.version)!=null?o:4,e.defaultLocale=(l=e.defaultLocale)!=null?l:X,e.strategy=(h=e.strategy)!=null?h:M,e.trailingSlash=(m=e.trailingSlash)!=null?m:j,e.routesNameSeparator=(E=e.routesNameSeparator)!=null?E:C,e.defaultLocaleRouteNameSuffix=(g=e.defaultLocaleRouteNameSuffix)!=null?g:G,e.locales=(S=e.locales)!=null?S:[],e.routes=(f=e.routes)!=null?f:[],e}function ce(e,o={}){const{version:l,defaultLocale:h,locales:m,strategy:E,trailingSlash:g,routesNameSeparator:S,defaultLocaleRouteNameSuffix:f,routes:L}=le(o),n=K(m),A=ne(n.map(N=>N.code),S,f);ae(e,{locales:n});const I=q(L,{locales:m,defaultLocale:h,strategy:E,trailingSlash:g,routesNameSeparator:S,defaultLocaleRouteNameSuffix:f});o.routes=I;let R=null;if(a.isVue3&&l===4)R=s.createRouter(o);else if(a.isVue2&&l===3)R=new Y.default(o);else throw new Error("TODO:");return R.__defaultLocale=h,R.__strategy=E,R.__trailingSlash=g,R.__routesNameSeparator=S,R.__defaultLocaleRouteNameSuffix=f,R.beforeEach((N,c,u)=>{console.log("beforeEach",N,c);const t=w(e),i=A(N)||t||h||"";console.log("currentLocale",t,"finalLocale",i),t!==i&&Q(e,i),u()}),console.log("create router",R),R}const re="";return r.VERSION=re,r.createRouter=ce,r.localizeRoutes=q,r.useI18nRouting=ee,Object.defineProperty(r,"__esModule",{value:!0}),r[Symbol.toStringTag]="Module",r}({},VueDemi,VueRouter,VueI18n); | ||
*/const G=Object.assign,fe=Array.isArray,ie=e=>typeof e=="function",N=e=>typeof e=="string",de=e=>typeof e=="boolean",he=e=>typeof e=="symbol",_e=/\/$|\/\?/;function D(e="",t=!1){return t?_e.test(e):e.endsWith("/")}function me(e="",t=!1){if(!t)return(D(e)?e.slice(0,-1):e)||"/";if(!D(e,!0))return e||"/";const[a,...n]=e.split("?");return(a.slice(0,-1)||"/")+(n.length?`?${n.join("?")}`:"")}function ge(e="",t=!1){if(!t)return e.endsWith("/")?e:e+"/";if(D(e,!0))return e||"/";const[a,...n]=e.split("?");return a+"/"+(n.length?`?${n.join("?")}`:"")}function Le(e,t){typeof console!="undefined"&&(console.warn("[vue-i18n-routing] "+e),t&&console.warn(t.stack))}function H(e){e=e||[];const t=[];for(const a of e)N(a)?t.push({code:a}):t.push(a);return t}function C(e,t){return s.isRef(e.locale)&&t==="composition"}function W(e){return"global"in e&&"mode"in e}function X(e){return W(e)?C(e.global,e.mode)?e.global.locale.value:e.global.locale:e.locale.value}function Re(e,t){W(e)?C(e.global,e.mode)?e.global.locale.value=t:e.global.locale=t:s.isRef(e.locale)&&(e.locale.value=t)}function Ee(e,t,a){return e.replace(/\/+$/,"")+(t?"/":"")||(a?"":"/")}function B(e){return N(e)?e:he(e)?e.toString():"(null)"}function Q(e,t,{defaultLocale:a,strategy:n,routesNameSeparator:o,defaultLocaleRouteNameSuffix:l}){let c=B(e)+(n==="no_prefix"?"":o+t);return t===a&&n==="prefix_and_default"&&(c+=o+l),c}function Se(e,t){return ie(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,Y=!1,v="___",M="default",pe="ltr",J="",Ae=new Set([$.PREFIX_AND_DEFAULT,$.PREFIX_EXCEPT_DEFAULT]);function O(e=h.useRoute(),{router:t=h.useRouter(),routesNameSeparator:a=v}={}){const n=a||t.__routesNameSeparator,o=s.unref(e);return o.name?B(o.name).split(n)[0]:null}function K(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 Z(e,t,a){const n=V(e,t,a);return n==null?void 0:s.isVue3?n:n.route}function Ie(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=h.useRouter(),i18n:n=p.useI18n(),defaultLocale:o=U,defaultLocaleRouteNameSuffix:l=M,routesNameSeparator:c=v,strategy:i=b,trailingSlash:d=!1}={}){const f=a.__defaultLocaleRouteNameSuffix||l,g=a.__defaultLocale||o,r=a.__routesNameSeparator||c,L=a.__strategy||i,E=t||X(n);let S=e;N(e)&&(S[0]==="/"?S={path:e}:S={name:e});let _=G({},S);if(_.path&&!_.name){const m=a.resolve(_),I=s.isVue3?m:m.route,y=O(I);N(y)?_={name:Q(y,E,{defaultLocale:g,strategy:L,routesNameSeparator:r,defaultLocaleRouteNameSuffix:f}),params:I.params,query:I.query,hash:I.hash}:(!(E===o&&Ae.has(L))&&L!==$.NO_PREFIX&&(_.path=`/${E}${_.path}`),_.path=d?ge(_.path,!0):me(_.path,!0))}else{_.name=Q(_.name,E,{defaultLocale:g,strategy:L,routesNameSeparator:r,defaultLocaleRouteNameSuffix:f});const{params:m}=_;m&&m["0"]===void 0&&m.pathMatch&&(m["0"]=m.pathMatch)}const R=a.resolve(_);return(s.isVue3?R.name:R.route.name)?R:a.resolve(e)}function z(e,t){const a=t&&t.route||h.useRoute(),n=O(a,t);if(!n)return"";const f=!s.isVue3&&s.isRef(a)?a.value:a,{params:o}=f,l=re(f,["params"]),c={},i=G({},l,{name:n,params:w(F(F({},o),c),{0:o.pathMatch})});return K(i,e,t)}function Te({addDirAttribute:e=!1,addSeoAttributes:t=!1,strategy:a=b,defaultLocale:n=U,route:o=h.useRoute(),router:l=h.useRouter(),i18n:c=p.useI18n()}={}){const i=n||l.__defaultLocale,d=a||l.__strategy,f=s.ref({htmlAttrs:{},link:[],meta:[]});function g(){f.value={htmlAttrs:{},link:[],meta:[]}}function r(L){const E=X(c),S=H(c.locales.value).find(m=>m.code===E)||{code:E},_=S.iso,R=S.dir||l.__defaultDirection;if(e&&(f.value.htmlAttrs.dir=R),t&&E&&c.locales){_&&(f.value.htmlAttrs.lang=_);const m=c.locales.value;ye(m,c.__baseUrl,f.value.link,{defaultLocale:i,strategy:d,route:o,router:l,i18n:c}),Pe(c.__baseUrl,f.value.link,t,{route:L,router:l,i18n:c}),Fe(S,_,f.value.meta),Ne(m,_,f.value.meta)}}return s.watch(l.currentRoute,L=>{g(),r(L)}),r(o),f}function ye(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){Le("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 Pe(e,t,a,n){const{route:o}=n,l=Z(w(F({},o),{name:O(o,n)}),void 0,n);if(l){let c=j(l.path,e);const i=!de(a)&&a.canonicalQueries||[];if(i.length){const d=l.query,f=new URLSearchParams;for(const r of i)if(r in d){const L=d[r];fe(L)?L.forEach(E=>f.append(r,E||"")):f.append(r,L||"")}const g=f.toString();g&&(c=`${c}?${g}`)}t.push({hid:"i18n-can",rel:"canonical",href:c})}}function Fe(e,t,a){!(e&&t)||a.push({hid:"i18n-og",property:"og:locale",content:ee(t)})}function Ne(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:ee(l.iso)}));a.push(...o)}}function ee(e){return(e||"").replace(/-/g,"_")}function j(e,t){return e.match(/^https?:\/\//)?e:t+e}function te(e,{defaultLocale:t=U,strategy:a=b,trailingSlash:n=Y,routesNameSeparator:o=v,defaultLocaleRouteNameSuffix:l=M,includeUprefixedFallback:c=!1,optionResolver:i=void 0,locales:d=[]}={}){if(a==="no_prefix")return e;const f=d.map(r=>N(r)?r:r.code);function g(r,L,E=!1,S=!1){if(r.redirect&&(!r.component||!r.file))return[r];let _=null;return i!=null&&(_=i(r,L),_==null)?[r]:L.reduce((m,I)=>{const{name:y}=r;let{path:A}=r;const T=F({},r);y&&(T.name=`${y}${o}${I}`),r.children&&(T.children=r.children.reduce((P,q)=>[...P,...g(q,[I],!0,S)],[]));const k=I===t;if(k&&a==="prefix_and_default")if(E)E&&S&&y&&(T.name+=`${o}${l}`);else{const P=w(F({},T),{path:A});if(y&&(P.name=`${T.name}${o}${l}`),r.children){P.children=[];for(const q of r.children)P.children=P.children.concat(g(q,[I],!0,!0))}m.push(P)}const ae=E&&!A.startsWith("/"),ne=!ae&&!(k&&a==="prefix_except_default");return ne&&(A=`/${I}${A}`),A&&(A=Ee(A,n,ae)),ne&&k&&a==="prefix"&&c&&m.push(F({},r)),T.path=A,m.push(T),m},[])}return e.reduce((r,L)=>[...r,...g(L,f||[])],[])}function $e(e,{locales:t=[],baseUrl:a=J}={}){if(!C(e.global,e.mode))throw new Error("TODO:");const n=s.ref(t);e.global.locales=s.computed(()=>n.value),e.global.__baseUrl=Se(a,{})}function Ue(e){return new RegExp(`^/(${e.join("|")})(?:/|$)`,"i")}function be(e,t,a){const n=`(${e.join("|")})`,o=`(?:${t}${a})?`,l=new RegExp(`${t}${n}${o}$`,"i"),c=Ue(e);return d=>{if(d.name){const g=(N(d.name)?d.name:d.name.toString()).match(l);if(g&&g.length>1)return g[1]}else if(d.path){const f=d.path.match(c);if(f&&f.length>1)return f[1]}return""}}function ve(e){var t,a,n,o,l,c,i,d,f,g;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:Y,e.routesNameSeparator=(l=e.routesNameSeparator)!=null?l:v,e.defaultLocaleRouteNameSuffix=(c=e.defaultLocaleRouteNameSuffix)!=null?c:M,e.locales=(i=e.locales)!=null?i:[],e.defaultDirection=(d=e.defaultDirection)!=null?d:pe,e.baseUrl=(f=e.baseUrl)!=null?f:J,e.routes=(g=e.routes)!=null?g:[],e}function Oe(e,t={}){const{version:a,defaultLocale:n,locales:o,strategy:l,trailingSlash:c,routesNameSeparator:i,defaultLocaleRouteNameSuffix:d,defaultDirection:f,baseUrl:g,routes:r}=ve(t),L=H(o),E=L.map(m=>m.code),S=be(E,i,d);$e(e,{locales:L,baseUrl:g});const _=te(r,{locales:o,defaultLocale:n,strategy:l,trailingSlash:c,routesNameSeparator:i,defaultLocaleRouteNameSuffix:d});t.routes=_;let R=null;if(s.isVue3&&a===4)R=h.createRouter(t);else if(s.isVue2&&a===3)R=new ue.default(t);else throw new Error("TODO:");return R.__defaultLocale=n,R.__localeCodes=E,R.__strategy=l,R.__trailingSlash=c,R.__routesNameSeparator=i,R.__defaultLocaleRouteNameSuffix=d,R.__defaultDirection=f,R.beforeEach((m,I,y)=>{const A=X(e),T=S(m)||A||n||"";A!==T&&Re(e,T),y()}),R}const xe="0.0.0";return u.VERSION=xe,u.createRouter=Oe,u.getRouteBaseName=O,u.localeLocation=Ie,u.localePath=K,u.localeRoute=Z,u.localizeRoutes=te,u.switchLocalePath=z,u.useI18nHead=Te,Object.defineProperty(u,"__esModule",{value:!0}),u[Symbol.toStringTag]="Module",u}({},VueDemi,VueRouter,VueI18n); |
{ | ||
"name": "vue-i18n-routing", | ||
"description": "The i18n routing with using vue-i18n", | ||
"version": "0.0.0-e9e5447", | ||
"version": "0.0.0-eba77a5", | ||
"dependencies": { | ||
@@ -9,2 +9,3 @@ "@intlify/shared": "beta", | ||
"@intlify/vue-router-bridge": "^0.3.4", | ||
"ufo": "^0.7.9", | ||
"vue-demi": "^0.12.1" | ||
@@ -14,2 +15,3 @@ }, | ||
"@microsoft/api-extractor": "^7.18.20", | ||
"@vue/test-utils": "^1.3.0", | ||
"api-docs-gen": "^0.4.0", | ||
@@ -23,5 +25,6 @@ "rimraf": "^3.0.2", | ||
"vue-i18n-bridge": "beta", | ||
"vue-i18n-legacy": "npm:vue-i18n@latest", | ||
"vue-i18n-legacy": "npm:vue-i18n@8", | ||
"vue-router": "^4.0.12", | ||
"vue-router3": "npm:vue-router@latest", | ||
"vue-router3": "npm:vue-router@3", | ||
"vue-template-compiler": "^2.6.14", | ||
"vue2": "npm:vue@2" | ||
@@ -32,4 +35,4 @@ }, | ||
"vue": "^2.6.14 || ^3.2.0", | ||
"vue-i18n": "^8.26.1 || ^9.2.0-beta.25", | ||
"vue-i18n-bridge": "^9.2.0-beta.25", | ||
"vue-i18n": "^8.26.1 || ^9.2.0-beta.30", | ||
"vue-i18n-bridge": "^9.2.0-beta.30", | ||
"vue-router": "^3.5.3 || ^4.0.0" | ||
@@ -65,4 +68,7 @@ }, | ||
}, | ||
"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" | ||
}, | ||
@@ -69,0 +75,0 @@ "license": "MIT", |
Sorry, the diff of this file is not supported yet
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
56327
980
0
10
15
+ Addedufo@^0.7.9
+ Addedufo@0.7.11(transitive)