vue-i18n-routing
Advanced tools
Comparing version 0.0.0-8a8e08f to 0.0.0-8fbb24d
@@ -1,5 +0,5 @@ | ||
"use strict";var le=Object.defineProperty,ce=Object.defineProperties;var re=Object.getOwnPropertyDescriptors;var D=Object.getOwnPropertySymbols;var j=Object.prototype.hasOwnProperty,k=Object.prototype.propertyIsEnumerable;var B=(e,t,a)=>t in e?le(e,t,{enumerable:!0,configurable:!0,writable:!0,value:a}):e[t]=a,y=(e,t)=>{for(var a in t||(t={}))j.call(t,a)&&B(e,a,t[a]);if(D)for(var a of D(t))k.call(t,a)&&B(e,a,t[a]);return e},F=(e,t)=>ce(e,re(t));var G=(e,t)=>{var a={};for(var o in e)j.call(e,o)&&t.indexOf(o)<0&&(a[o]=e[o]);if(e!=null&&D)for(var o of D(e))t.indexOf(o)<0&&k.call(e,o)&&(a[o]=e[o]);return a};Object.defineProperty(exports,"__esModule",{value:!0});exports[Symbol.toStringTag]="Module";var g=require("vue-demi"),S=require("@intlify/vue-router-bridge"),H=require("@intlify/vue-i18n-bridge");function se(e){return e&&typeof e=="object"&&"default"in e?e:{default:e}}var ue=se(S);/*! | ||
* shared v9.2.0-beta.28 | ||
"use strict";var ue=Object.defineProperty,ie=Object.defineProperties;var fe=Object.getOwnPropertyDescriptors;var D=Object.getOwnPropertySymbols;var G=Object.prototype.hasOwnProperty,H=Object.prototype.propertyIsEnumerable;var B=(e,t,a)=>t in e?ue(e,t,{enumerable:!0,configurable:!0,writable:!0,value:a}):e[t]=a,I=(e,t)=>{for(var a in t||(t={}))G.call(t,a)&&B(e,a,t[a]);if(D)for(var a of D(t))H.call(t,a)&&B(e,a,t[a]);return e},N=(e,t)=>ie(e,fe(t));var W=(e,t)=>{var a={};for(var l in e)G.call(e,l)&&t.indexOf(l)<0&&(a[l]=e[l]);if(e!=null&&D)for(var l of D(e))t.indexOf(l)<0&&H.call(e,l)&&(a[l]=e[l]);return a};Object.defineProperty(exports,"__esModule",{value:!0});exports[Symbol.toStringTag]="Module";var m=require("vue-demi"),A=require("@intlify/vue-router-bridge"),Y=require("@intlify/vue-i18n-bridge");function de(e){return e&&typeof e=="object"&&"default"in e?e:{default:e}}var he=de(A);/*! | ||
* shared v9.2.0-beta.30 | ||
* (c) 2022 kazuya kawaguchi | ||
* Released under the MIT License. | ||
*/const W=Object.assign,ie=Array.isArray,fe=e=>typeof e=="function",T=e=>typeof e=="string",de=e=>typeof e=="boolean",he=e=>typeof e=="symbol",_e=/\/$|\/\?/;function O(e="",t=!1){return t?_e.test(e):e.endsWith("/")}function me(e="",t=!1){if(!t)return(O(e)?e.slice(0,-1):e)||"/";if(!O(e,!0))return e||"/";const[a,...o]=e.split("?");return(a.slice(0,-1)||"/")+(o.length?`?${o.join("?")}`:"")}function Re(e="",t=!1){if(!t)return e.endsWith("/")?e:e+"/";if(O(e,!0))return e||"/";const[a,...o]=e.split("?");return a+"/"+(o.length?`?${o.join("?")}`:"")}function ge(e,t){typeof console!="undefined"&&(console.warn("[vue-i18n-routing] "+e),t&&console.warn(t.stack))}function Q(e){e=e||[];const t=[];for(const a of e)T(a)?t.push({code:a}):t.push(a);return t}function w(e,t){return g.isRef(e.locale)&&t==="composition"}function Y(e){return"global"in e&&"mode"in e}function C(e){return Y(e)?w(e.global,e.mode)?e.global.locale.value:e.global.locale:e.locale.value}function Le(e,t){Y(e)?w(e.global,e.mode)?e.global.locale.value=t:e.global.locale=t:g.isRef(e.locale)&&(e.locale.value=t)}function Ee(e,t,a){return e.replace(/\/+$/,"")+(t?"/":"")||(a?"":"/")}function J(e){return T(e)?e:he(e)?e.toString():"(null)"}function K(e,t,{defaultLocale:a,strategy:o,routesNameSeparator:l,defaultLocaleRouteNameSuffix:n}){let c=J(e)+(o==="no_prefix"?"":l+t);return t===a&&o==="prefix_and_default"&&(c+=l+n),c}function pe(e,t){return fe(e)?e(t):e}const P={PREFIX:"prefix",PREFIX_EXCEPT_DEFAULT:"prefix_except_default",PREFIX_AND_DEFAULT:"prefix_and_default",NO_PREFIX:"no_prefix"},N="",x=P.PREFIX_EXCEPT_DEFAULT,Z=!1,$="___",V="default",Se="ltr",ee="",ve=new Set([P.PREFIX_AND_DEFAULT,P.PREFIX_EXCEPT_DEFAULT]);function b(e=S.useRoute(),{router:t=S.useRouter(),routesNameSeparator:a=$}={}){const o=a||t.__routesNameSeparator,l=g.unref(e);return l.name?J(l.name).split(o)[0]:null}function te(e,t,a){const o=X(e,t,a);return o==null?"":g.isVue3?o.redirectedFrom||o.fullPath:o.route.redirectedFrom||o.route.fullPath}function ae(e,t,a){const o=X(e,t,a);return o==null?void 0:g.isVue3?o:o.route}function Ae(e,t,a){const o=X(e,t,a);return o==null?void 0:g.isVue3?o:o.location}function X(e,t,{router:a=S.useRouter(),i18n:o=H.useI18n(),defaultLocale:l=N,defaultLocaleRouteNameSuffix:n=V,routesNameSeparator:c=$,strategy:u=x,trailingSlash:i=!1}={}){const s=a.__defaultLocaleRouteNameSuffix||n,r=a.__defaultLocale||l,m=a.__routesNameSeparator||c,_=a.__strategy||u,R=t||C(o);let p=e;T(e)&&(p[0]==="/"?p={path:e}:p={name:e});let f=W({},p);if(f.path&&!f.name){const h=a.resolve(f),L=g.isVue3?h:h.route,E=b(L);T(E)?f={name:K(E,R,{defaultLocale:r,strategy:_,routesNameSeparator:m,defaultLocaleRouteNameSuffix:s}),params:L.params,query:L.query,hash:L.hash}:(!(R===l&&ve.has(_))&&_!==P.NO_PREFIX&&(f.path=`/${R}${f.path}`),f.path=i?Re(f.path,!0):me(f.path,!0))}else{f.name=K(f.name,R,{defaultLocale:r,strategy:_,routesNameSeparator:m,defaultLocaleRouteNameSuffix:s});const{params:h}=f;h&&h["0"]===void 0&&h.pathMatch&&(h["0"]=h.pathMatch)}const d=a.resolve(f);return(g.isVue3?d.name:d.route.name)?d:a.resolve(e)}function M(e,t){const a=t&&t.route||S.useRoute(),o=b(a,t);if(!o)return"";const s=!g.isVue3&&g.isRef(a)?a.value:a,{params:l}=s,n=G(s,["params"]),c={},u=W({},n,{name:o,params:F(y(y({},l),c),{0:l.pathMatch})});return te(u,e,t)}function ye({addDirAttribute:e=!1,addSeoAttributes:t=!1,strategy:a=x,defaultLocale:o=N,route:l=S.useRoute(),router:n=S.useRouter(),i18n:c=H.useI18n()}={}){const u=o||n.__defaultLocale,i=a||n.__strategy,s=g.ref({htmlAttrs:{},link:[],meta:[]});function r(){s.value={htmlAttrs:{},link:[],meta:[]}}function m(_){const R=C(c),p=Q(c.locales.value).find(h=>h.code===R)||{code:R},f=p.iso,d=p.dir||n.__defaultDetection;if(e&&(s.value.htmlAttrs.dir=d),t&&R&&c.locales){f&&(s.value.htmlAttrs.lang=f);const h=c.locales.value;Ie(h,c.__baseUrl,s.value.link,{defaultLocale:u,strategy:i,route:l,router:n,i18n:c}),Te(c.__baseUrl,s.value.link,t,{route:_,router:n,i18n:c}),Pe(p,f,s.value.meta),De(h,f,s.value.meta)}}return g.watch(n.currentRoute,_=>{r(),m(_)}),m(l),s}function Ie(e,t,a,o){if(o.strategy===P.NO_PREFIX)return;const l=new Map;for(const n of e){const c=n.iso;if(!c){ge("Locale ISO code is required to generate alternate link");continue}const[u,i]=c.split("-");u&&i&&(n.isCatchallLocale||!l.has(u))&&l.set(u,n),l.set(c,n)}for(const[n,c]of l.entries()){const u=M(c.code,o);u&&a.push({hid:`i18n-alt-${n}`,rel:"alternate",href:q(u,t),hreflang:n})}if(o.defaultLocale){const n=M(o.defaultLocale,o);n&&a.push({hid:"i18n-xd",rel:"alternate",href:q(n,t),hreflang:"x-default"})}}function Te(e,t,a,o){const{route:l}=o,n=ae(F(y({},l),{name:b(l,o)}),void 0,o);if(n){let c=q(n.path,e);const u=!de(a)&&a.canonicalQueries||[];if(u.length){const i=n.query,s=new URLSearchParams;for(const m of u)if(m in i){const _=i[m];ie(_)?_.forEach(R=>s.append(m,R||"")):s.append(m,_||"")}const r=s.toString();r&&(c=`${c}?${r}`)}t.push({hid:"i18n-can",rel:"canonical",href:c})}}function Pe(e,t,a){!(e&&t)||a.push({hid:"i18n-og",property:"og:locale",content:oe(t)})}function De(e,t,a){const o=e.filter(l=>{const n=l.iso;return n&&n!==t});if(o.length){const l=o.map(n=>({hid:`i18n-og-alt-${n.iso}`,property:"og:locale:alternate",content:oe(n.iso)}));a.push(...l)}}function oe(e){return(e||"").replace(/-/g,"_")}function q(e,t){return e.match(/^https?:\/\//)?e:t+e}function ne(e,{defaultLocale:t=N,strategy:a=x,trailingSlash:o=Z,routesNameSeparator:l=$,defaultLocaleRouteNameSuffix:n=V,includeUprefixedFallback:c=!1,locales:u=[]}={}){if(a==="no_prefix")return e;const i=u.map(r=>T(r)?r:r.code);function s(r,m,_=!1,R=!1){return r.redirect&&(!r.component||!r.file)?[r]:m.reduce((f,d)=>{const{name:h}=r;let{path:L}=r;const E=y({},r);h&&(E.name=`${h}${l}${d}`),r.children&&(E.children=r.children.reduce((A,U)=>[...A,...s(U,[d],!0,R)],[]));const v=d===t;if(v&&a==="prefix_and_default")if(_)_&&R&&h&&(E.name+=`${l}${n}`);else{const A=F(y({},E),{path:L});if(h&&(A.name=`${E.name}${l}${n}`),r.children){A.children=[];for(const U of r.children)A.children=A.children.concat(s(U,[d],!0,!0))}f.push(A)}const I=_&&!L.startsWith("/"),z=!I&&!(v&&a==="prefix_except_default");return z&&(L=`/${d}${L}`),L&&(L=Ee(L,o,I)),z&&v&&a==="prefix"&&c&&f.push(y({},r)),E.path=L,f.push(E),f},[])}return e.reduce((r,m)=>[...r,...s(m,i||[])],[])}function Fe(e,{locales:t=[],baseUrl:a=ee}={}){if(!w(e.global,e.mode))throw new Error("TODO:");const o=g.ref(t);e.global.locales=g.computed(()=>o.value),e.global.__baseUrl=pe(a,{})}function Ne(e){return new RegExp(`^/(${e.join("|")})(?:/|$)`,"i")}function xe(e,t,a){const o=`(${e.join("|")})`,l=`(?:${t}${a})?`,n=new RegExp(`${t}${o}${l}$`,"i"),c=Ne(e);return i=>{if(i.name){const r=(T(i.name)?i.name:i.name.toString()).match(n);if(r&&r.length>1)return r[1]}else if(i.path){const s=i.path.match(c);if(s&&s.length>1)return s[1]}return""}}function $e(e){var t,a,o,l,n,c,u,i,s,r;return e.version=(t=e.version)!=null?t:4,e.defaultLocale=(a=e.defaultLocale)!=null?a:N,e.strategy=(o=e.strategy)!=null?o:x,e.trailingSlash=(l=e.trailingSlash)!=null?l:Z,e.routesNameSeparator=(n=e.routesNameSeparator)!=null?n:$,e.defaultLocaleRouteNameSuffix=(c=e.defaultLocaleRouteNameSuffix)!=null?c:V,e.locales=(u=e.locales)!=null?u:[],e.defaultDetection=(i=e.defaultDetection)!=null?i:Se,e.baseUrl=(s=e.baseUrl)!=null?s:ee,e.routes=(r=e.routes)!=null?r:[],e}function be(e,t={}){const{version:a,defaultLocale:o,locales:l,strategy:n,trailingSlash:c,routesNameSeparator:u,defaultLocaleRouteNameSuffix:i,defaultDetection:s,baseUrl:r,routes:m}=$e(t),_=Q(l),R=_.map(h=>h.code),p=xe(R,u,i);Fe(e,{locales:_,baseUrl:r});const f=ne(m,{locales:l,defaultLocale:o,strategy:n,trailingSlash:c,routesNameSeparator:u,defaultLocaleRouteNameSuffix:i});t.routes=f;let d=null;if(g.isVue3&&a===4)d=S.createRouter(t);else if(g.isVue2&&a===3)d=new ue.default(t);else throw new Error("TODO:");return d.__defaultLocale=o,d.__localeCodes=R,d.__strategy=n,d.__trailingSlash=c,d.__routesNameSeparator=u,d.__defaultLocaleRouteNameSuffix=i,d.__defaultDetection=s,d.beforeEach((h,L,E)=>{const v=C(e),I=p(h)||v||o||"";v!==I&&Le(e,I),E()}),d}const Ue="0.0.0";exports.VERSION=Ue;exports.createRouter=be;exports.getRouteBaseName=b;exports.localeLocation=Ae;exports.localePath=te;exports.localeRoute=ae;exports.localizeRoutes=ne;exports.switchLocalePath=M;exports.useI18nHead=ye; | ||
*/const J=Object.assign,_e=Array.isArray,me=e=>typeof e=="function",F=e=>typeof e=="string",Re=e=>typeof e=="boolean",ge=e=>typeof e=="symbol",Le=/\/$|\/\?/;function C(e="",t=!1){return t?Le.test(e):e.endsWith("/")}function Ee(e="",t=!1){if(!t)return(C(e)?e.slice(0,-1):e)||"/";if(!C(e,!0))return e||"/";const[a,...l]=e.split("?");return(a.slice(0,-1)||"/")+(l.length?`?${l.join("?")}`:"")}function pe(e="",t=!1){if(!t)return e.endsWith("/")?e:e+"/";if(C(e,!0))return e||"/";const[a,...l]=e.split("?");return a+"/"+(l.length?`?${l.join("?")}`:"")}function ve(e,t){typeof console!="undefined"&&(console.warn("[vue-i18n-routing] "+e),t&&console.warn(t.stack))}function K(e){e=e||[];const t=[];for(const a of e)F(a)?t.push({code:a}):t.push(a);return t}function M(e,t){return m.isRef(e.locale)&&t==="composition"}function Z(e){return"global"in e&&"mode"in e}function x(e){return Z(e)?M(e.global,e.mode)?e.global.locale.value:e.global.locale:e.locale.value}function ee(e,t){Z(e)?M(e.global,e.mode)?e.global.locale.value=t:e.global.locale=t:m.isRef(e.locale)&&(e.locale.value=t)}function Se(e,t,a){return e.replace(/\/+$/,"")+(t?"/":"")||(a?"":"/")}function te(e){return F(e)?e:ge(e)?e.toString():"(null)"}function Q(e,t,{defaultLocale:a,strategy:l,routesNameSeparator:n,defaultLocaleRouteNameSuffix:o}){let r=te(e)+(l==="no_prefix"?"":n+t);return t===a&&l==="prefix_and_default"&&(r+=n+o),r}function Ae(e,t){return me(e)?e(t):e}const P={PREFIX:"prefix",PREFIX_EXCEPT_DEFAULT:"prefix_except_default",PREFIX_AND_DEFAULT:"prefix_and_default",NO_PREFIX:"no_prefix"},$="",b=P.PREFIX_EXCEPT_DEFAULT,ae=!1,U="___",q="default",ye="ltr",le="",Ie=new Set([P.PREFIX_AND_DEFAULT,P.PREFIX_EXCEPT_DEFAULT]);function O(e=A.useRoute(),{router:t=A.useRouter(),routesNameSeparator:a=U}={}){const l=a||t.__routesNameSeparator,n=m.unref(e);return n.name?te(n.name).split(l)[0]:null}function oe(e,t,a){const l=z(e,t,a);return l==null?"":m.isVue3?l.redirectedFrom||l.fullPath:l.route.redirectedFrom||l.route.fullPath}function ne(e,t,a){const l=z(e,t,a);return l==null?void 0:m.isVue3?l:l.route}function Te(e,t,a){const l=z(e,t,a);return l==null?void 0:m.isVue3?l:l.location}function z(e,t,{router:a=A.useRouter(),i18n:l=Y.useI18n(),defaultLocale:n=$,defaultLocaleRouteNameSuffix:o=q,routesNameSeparator:r=U,strategy:i=b,trailingSlash:f=!1}={}){const s=a.__defaultLocaleRouteNameSuffix||o,h=a.__defaultLocale||n,c=a.__routesNameSeparator||r,_=a.__strategy||i,R=t||x(l);let g=e;F(e)&&(g[0]==="/"?g={path:e}:g={name:e});let d=J({},g);if(d.path&&!d.name){const u=a.resolve(d),L=m.isVue3?u:u.route,S=O(L);F(S)?d={name:Q(S,R,{defaultLocale:h,strategy:_,routesNameSeparator:c,defaultLocaleRouteNameSuffix:s}),params:L.params,query:L.query,hash:L.hash}:(!(R===n&&Ie.has(_))&&_!==P.NO_PREFIX&&(d.path=`/${R}${d.path}`),d.path=f?pe(d.path,!0):Ee(d.path,!0))}else{d.name=Q(d.name,R,{defaultLocale:h,strategy:_,routesNameSeparator:c,defaultLocaleRouteNameSuffix:s});const{params:u}=d;u&&u["0"]===void 0&&u.pathMatch&&(u["0"]=u.pathMatch)}const v=a.resolve(d);return(m.isVue3?v.name:v.route.name)?v:a.resolve(e)}function V(e,t){const a=t&&t.route||A.useRoute(),l=O(a,t);if(!l)return"";const s=!m.isVue3&&m.isRef(a)?a.value:a,{params:n}=s,o=W(s,["params"]),r={},i=J({},o,{name:l,params:N(I(I({},n),r),{0:n.pathMatch})});return oe(i,e,t)}function Fe({addDirAttribute:e=!1,addSeoAttributes:t=!1,strategy:a=b,defaultLocale:l=$,route:n=A.useRoute(),router:o=A.useRouter(),i18n:r=Y.useI18n()}={}){const i=l||o.__defaultLocale,f=a||o.__strategy,s=m.ref({htmlAttrs:{},link:[],meta:[]});function h(){s.value={htmlAttrs:{},link:[],meta:[]}}function c(_){if(r.locales==null||r.__baseUrl==null)return;const R=x(r),g=K(r.locales.value).find(u=>u.code===R)||{code:R},d=g.iso,v=g.dir||o.__defaultDirection;if(e&&(s.value.htmlAttrs.dir=v),t&&R&&r.locales){d&&(s.value.htmlAttrs.lang=d);const u=r.locales.value;Pe(u,r.__baseUrl,s.value.link,{defaultLocale:i,strategy:f,route:n,router:o,i18n:r}),De(r.__baseUrl,s.value.link,t,{route:_,router:o,i18n:r}),Ne(g,d,s.value.meta),xe(u,d,s.value.meta)}}return m.watch(o.currentRoute,_=>{h(),c(_)}),c(n),s}function Pe(e,t,a,l){if(l.strategy===P.NO_PREFIX)return;const n=new Map;for(const o of e){const r=o.iso;if(!r){ve("Locale ISO code is required to generate alternate link");continue}const[i,f]=r.split("-");i&&f&&(o.isCatchallLocale||!n.has(i))&&n.set(i,o),n.set(r,o)}for(const[o,r]of n.entries()){const i=V(r.code,l);i&&a.push({hid:`i18n-alt-${o}`,rel:"alternate",href:X(i,t),hreflang:o})}if(l.defaultLocale){const o=V(l.defaultLocale,l);o&&a.push({hid:"i18n-xd",rel:"alternate",href:X(o,t),hreflang:"x-default"})}}function De(e,t,a,l){const{route:n}=l,o=ne(N(I({},n),{name:O(n,l)}),void 0,l);if(o){let r=X(o.path,e);const i=!Re(a)&&a.canonicalQueries||[];if(i.length){const f=o.query,s=new URLSearchParams;for(const c of i)if(c in f){const _=f[c];_e(_)?_.forEach(R=>s.append(c,R||"")):s.append(c,_||"")}const h=s.toString();h&&(r=`${r}?${h}`)}t.push({hid:"i18n-can",rel:"canonical",href:r})}}function Ne(e,t,a){!(e&&t)||a.push({hid:"i18n-og",property:"og:locale",content:re(t)})}function xe(e,t,a){const l=e.filter(n=>{const o=n.iso;return o&&o!==t});if(l.length){const n=l.map(o=>({hid:`i18n-og-alt-${o.iso}`,property:"og:locale:alternate",content:re(o.iso)}));a.push(...n)}}function re(e){return(e||"").replace(/-/g,"_")}function X(e,t){return e.match(/^https?:\/\//)?e:t+e}function ce(e,{defaultLocale:t=$,strategy:a=b,trailingSlash:l=ae,routesNameSeparator:n=U,defaultLocaleRouteNameSuffix:o=q,includeUprefixedFallback:r=!1,optionsResolver:i=void 0,locales:f=[]}={}){if(a==="no_prefix")return e;const s=f.map(c=>F(c)?c:c.code);function h(c,_,R=!1,g=!1){if(c.redirect&&(!c.component||!c.file))return[c];let d=null;return i!=null&&(d=i(c,_),d==null)?[c]:_.reduce((u,L)=>{const{name:S}=c;let{path:E}=c;const p=I({},c);S&&(p.name=`${S}${n}${L}`),c.children&&(p.children=c.children.reduce((y,w)=>[...y,...h(w,[L],!0,g)],[]));const T=L===t;if(T&&a==="prefix_and_default")if(R)R&&g&&S&&(p.name+=`${n}${o}`);else{const y=N(I({},p),{path:E});if(S&&(y.name=`${p.name}${n}${o}`),c.children){y.children=[];for(const w of c.children)y.children=y.children.concat(h(w,[L],!0,!0))}u.push(y)}const j=R&&!E.startsWith("/"),k=!j&&!(T&&a==="prefix_except_default");return k&&(E=`/${L}${E}`),E&&(E=Se(E,l,j)),k&&T&&a==="prefix"&&r&&u.push(I({},c)),p.path=E,u.push(p),u},[])}return e.reduce((c,_)=>[...c,...h(_,s||[])],[])}function $e(e,{locales:t=[],localeCodes:a=[],baseUrl:l=le}={}){if(!M(e.global,e.mode))throw new Error("TODO:");const n=m.ref(t),o=m.ref(a);e.global.locales=m.computed(()=>n.value),e.global.localeCodes=m.computed(()=>o.value),e.global.__baseUrl=Ae(l,{})}function be(e){return new RegExp(`^/(${e.join("|")})(?:/|$)`,"i")}function se(e,t,a){const l=`(${e.join("|")})`,n=`(?:${t}${a})?`,o=new RegExp(`${t}${l}${n}$`,"i"),r=be(e);return f=>{if(f.name){const h=(F(f.name)?f.name:f.name.toString()).match(o);if(h&&h.length>1)return h[1]}else if(f.path){const s=f.path.match(r);if(s&&s.length>1)return s[1]}return""}}function Ue(e){var t,a,l,n,o,r,i,f,s,h;return e.version=(t=e.version)!=null?t:4,e.defaultLocale=(a=e.defaultLocale)!=null?a:$,e.strategy=(l=e.strategy)!=null?l:b,e.trailingSlash=(n=e.trailingSlash)!=null?n:ae,e.routesNameSeparator=(o=e.routesNameSeparator)!=null?o:U,e.defaultLocaleRouteNameSuffix=(r=e.defaultLocaleRouteNameSuffix)!=null?r:q,e.locales=(i=e.locales)!=null?i:[],e.defaultDirection=(f=e.defaultDirection)!=null?f:ye,e.baseUrl=(s=e.baseUrl)!=null?s:le,e.routes=(h=e.routes)!=null?h:[],e}function Oe(e,t={}){const{version:a,defaultLocale:l,locales:n,strategy:o,trailingSlash:r,routesNameSeparator:i,defaultLocaleRouteNameSuffix:f,defaultDirection:s,baseUrl:h,routes:c,routeOptionsResolver:_}=Ue(t),R=K(n),g=R.map(L=>L.code),d=se(g,i,f);$e(e,{locales:R,baseUrl:h,localeCodes:g});const v=ce(c,{locales:n,defaultLocale:l,strategy:o,trailingSlash:r,routesNameSeparator:i,defaultLocaleRouteNameSuffix:f,optionsResolver:_});t.routes=v;let u=null;if(m.isVue3&&a===4)u=A.createRouter(t);else if(m.isVue2&&a===3)u=new he.default(t);else throw new Error("TODO:");return u.__defaultLocale=l,u.__localeCodes=g,u.__strategy=o,u.__trailingSlash=r,u.__routesNameSeparator=i,u.__defaultLocaleRouteNameSuffix=f,u.__defaultDirection=s,u.beforeEach((L,S,E)=>{const p=x(e),T=d(L)||p||l||"";p!==T&&ee(e,T),E()}),u}const we="0.0.0";exports.VERSION=we;exports.createLocaleFromRouteGetter=se;exports.createRouter=Oe;exports.getLocale=x;exports.getRouteBaseName=O;exports.localeLocation=Te;exports.localePath=oe;exports.localeRoute=ne;exports.localizeRoutes=ce;exports.setLocale=ee;exports.switchLocalePath=V;exports.useI18nHead=Fe; |
@@ -9,2 +9,3 @@ import { Composer } from '@intlify/vue-i18n-bridge'; | ||
import type { RouteLocation } from '@intlify/vue-router-bridge'; | ||
import type { RouteLocationNormalized } from '@intlify/vue-router-bridge'; | ||
import type { RouteLocationNormalizedLoaded } from '@intlify/vue-router-bridge'; | ||
@@ -27,2 +28,15 @@ import type { RouteLocationRaw } from '@intlify/vue-router-bridge'; | ||
/** | ||
* Options to compute route localizing | ||
* | ||
* @remarks | ||
* The route options that is compute the route to be localized on {@link localizeRoutes} | ||
*/ | ||
export declare type ComputedRouteOptions = { | ||
locales: readonly string[]; | ||
paths: Record<string, string>; | ||
}; | ||
export declare function createLocaleFromRouteGetter(localeCodes: string[], routesNameSeparator: string, defaultLocaleRouteNameSuffix: string): (route: Route_2 | RouteLocationNormalizedLoaded | RouteLocationNormalized) => string; | ||
/** | ||
* Create a Vue Router instance | ||
@@ -41,2 +55,4 @@ * | ||
* At the Vue 2 will return a [Vue Router v3 instance](https://router.vuejs.org/api/#router-construction-options), and at the Vue 3 will return a [Vue Router v4 instance](https://next.router.vuejs.org/api/#createrouter). | ||
* | ||
* @public | ||
*/ | ||
@@ -50,2 +66,4 @@ export declare function createRouter<Options extends VueI18nRoutingOptions = VueI18nRoutingOptions>(i18n: I18n, options?: Options): Options['version'] extends 4 ? Router : VueRouter; | ||
export declare function getLocale(i18n: I18n | Composer): Locale; | ||
/** | ||
@@ -142,4 +160,15 @@ * Get route base name | ||
export declare function localizeRoutes(routes: VueI18nRoute[], { defaultLocale, strategy, trailingSlash, routesNameSeparator, defaultLocaleRouteNameSuffix, includeUprefixedFallback, locales }?: Pick<VueI18nRoutingOptions, 'defaultLocale' | 'strategy' | 'locales' | 'routesNameSeparator' | 'trailingSlash' | 'defaultLocaleRouteNameSuffix'> & { | ||
/** | ||
* Localize routes | ||
* | ||
* @param routes - Some routes | ||
* @param options - An options | ||
* | ||
* @returns Localized routes | ||
* | ||
* @public | ||
*/ | ||
export declare function localizeRoutes(routes: VueI18nRoute[], { defaultLocale, strategy, trailingSlash, routesNameSeparator, defaultLocaleRouteNameSuffix, includeUprefixedFallback, optionsResolver, locales }?: Pick<VueI18nRoutingOptions, 'defaultLocale' | 'strategy' | 'locales' | 'routesNameSeparator' | 'trailingSlash' | 'defaultLocaleRouteNameSuffix'> & { | ||
includeUprefixedFallback?: boolean; | ||
optionsResolver?: RouteOptionsResolver; | ||
}): VueI18nRoute[]; | ||
@@ -172,2 +201,7 @@ | ||
/** | ||
* Resolver for route localizing options | ||
*/ | ||
export declare type RouteOptionsResolver = (route: VueI18nRoute, allowedLocaleCodes: string[]) => ComputedRouteOptions | null; | ||
/** | ||
* SEO Attribute options | ||
@@ -184,2 +218,4 @@ */ | ||
export declare function setLocale(i18n: I18n | Composer, locale: Locale): void; | ||
declare const STRATEGIES: { | ||
@@ -265,3 +301,4 @@ readonly PREFIX: "prefix"; | ||
* | ||
* @remarks TODO: | ||
* @remarks | ||
* Can either be an array of string codes (e.g. `['en', 'fr']`) or an array of {@link LocaleObject} for more complex configurations | ||
* | ||
@@ -307,7 +344,7 @@ * @defaultValue [] | ||
/** | ||
* Default detection direction | ||
* Default direction direction | ||
* | ||
* @defaultValue 'ltr' | ||
*/ | ||
defaultDetection?: Directions; | ||
defaultDirection?: Directions; | ||
/** | ||
@@ -326,10 +363,28 @@ * The fallback base URL to use as a prefix for alternate URLs in hreflang tags. | ||
baseUrl?: string | BaseUrl; | ||
/** | ||
* Route options resolver | ||
* | ||
* @defaultValue undefined | ||
*/ | ||
routeOptionsResolver?: RouteOptionsResolver; | ||
} & RouterOptions; | ||
export { } | ||
import type { ComputedRef } from 'vue-demi' | ||
declare module 'vue-i18n' { | ||
export interface ComposerCustom { | ||
locales: ComputedRef<string[] | LocaleObject[]> | ||
__baseUrl: string | ||
/** | ||
* List of locales | ||
* | ||
* @defaultValue `undefined` | ||
*/ | ||
locales?: ComputedRef<string[] | LocaleObject[]> | ||
/** | ||
* List of locale codes | ||
* | ||
* @defaultValue `undefined` | ||
*/ | ||
localeCodes?: ComputedRef<string[]> | ||
__baseUrl?: string | ||
} | ||
@@ -339,5 +394,16 @@ } | ||
export interface ComposerCustom { | ||
locales: ComputedRef<string[] | LocaleObject[]> | ||
__baseUrl: string | ||
/** | ||
* List of locales | ||
* | ||
* @defaultValue `undefined` | ||
*/ | ||
locales?: ComputedRef<string[] | LocaleObject[]> | ||
/** | ||
* List of locale codes | ||
* | ||
* @defaultValue `undefined` | ||
*/ | ||
localeCodes?: ComputedRef<string[]> | ||
__baseUrl?: string | ||
} | ||
} |
@@ -36,3 +36,3 @@ var __defProp = Object.defineProperty; | ||
/*! | ||
* shared v9.2.0-beta.28 | ||
* shared v9.2.0-beta.30 | ||
* (c) 2022 kazuya kawaguchi | ||
@@ -151,3 +151,3 @@ * Released under the MIT License. | ||
const DEFAULT_BASE_URL = ""; | ||
const RESOLVED_PREFIXED = new Set([STRATEGIES.PREFIX_AND_DEFAULT, STRATEGIES.PREFIX_EXCEPT_DEFAULT]); | ||
const RESOLVED_PREFIXED = /* @__PURE__ */ new Set([STRATEGIES.PREFIX_AND_DEFAULT, STRATEGIES.PREFIX_EXCEPT_DEFAULT]); | ||
function getRouteBaseName(givenRoute = useRoute(), { router = useRouter(), routesNameSeparator = DEFAULT_ROUTES_NAME_SEPARATOR } = {}) { | ||
@@ -280,2 +280,5 @@ const _routesNameSeparator = routesNameSeparator || router.__routesNameSeparator; | ||
function updateMeta(_route) { | ||
if (i18n.locales == null || i18n.__baseUrl == null) { | ||
return; | ||
} | ||
const locale = getLocale(i18n); | ||
@@ -286,3 +289,3 @@ const currentLocale = getNormalizedLocales(i18n.locales.value).find((l) => l.code === locale) || { | ||
const currentLocaleIso = currentLocale.iso; | ||
const currentLocaleDir = currentLocale.dir || router.__defaultDetection; | ||
const currentLocaleDir = currentLocale.dir || router.__defaultDirection; | ||
if (addDirAttribute) { | ||
@@ -319,3 +322,3 @@ metaObject.value.htmlAttrs.dir = currentLocaleDir; | ||
} | ||
const localeMap = new Map(); | ||
const localeMap = /* @__PURE__ */ new Map(); | ||
for (const locale of locales) { | ||
@@ -430,2 +433,3 @@ const localeIso = locale.iso; | ||
includeUprefixedFallback = false, | ||
optionsResolver = void 0, | ||
locales = [] | ||
@@ -441,2 +445,9 @@ } = {}) { | ||
} | ||
let routeOptions = null; | ||
if (optionsResolver != null) { | ||
routeOptions = optionsResolver(route, allowedLocaleCodes); | ||
if (routeOptions == null) { | ||
return [route]; | ||
} | ||
} | ||
const targetLocales = allowedLocaleCodes; | ||
@@ -489,3 +500,3 @@ return targetLocales.reduce((_routes, locale) => { | ||
} | ||
function extendI18n(i18n, { locales = [], baseUrl = DEFAULT_BASE_URL } = {}) { | ||
function extendI18n(i18n, { locales = [], localeCodes = [], baseUrl = DEFAULT_BASE_URL } = {}) { | ||
if (!isComposer(i18n.global, i18n.mode)) { | ||
@@ -495,3 +506,5 @@ throw new Error("TODO:"); | ||
const _locales = ref(locales); | ||
const _localeCodes = ref(localeCodes); | ||
i18n.global.locales = computed(() => _locales.value); | ||
i18n.global.localeCodes = computed(() => _localeCodes.value); | ||
i18n.global.__baseUrl = resolveBaseUrl(baseUrl, {}); | ||
@@ -533,3 +546,3 @@ } | ||
options.locales = (_g = options.locales) != null ? _g : []; | ||
options.defaultDetection = (_h = options.defaultDetection) != null ? _h : DEFAULT_DETECTION_DIRECTION; | ||
options.defaultDirection = (_h = options.defaultDirection) != null ? _h : DEFAULT_DETECTION_DIRECTION; | ||
options.baseUrl = (_i = options.baseUrl) != null ? _i : DEFAULT_BASE_URL; | ||
@@ -548,5 +561,6 @@ options.routes = (_j = options.routes) != null ? _j : []; | ||
defaultLocaleRouteNameSuffix, | ||
defaultDetection, | ||
defaultDirection, | ||
baseUrl, | ||
routes | ||
routes, | ||
routeOptionsResolver: optionsResolver | ||
} = asDefaultVueI18nRouterOptions(options); | ||
@@ -556,3 +570,3 @@ const normalizedLocaleCodes = getNormalizedLocales(locales); | ||
const getLocaleFromRoute = createLocaleFromRouteGetter(localeCodes, routesNameSeparator, defaultLocaleRouteNameSuffix); | ||
extendI18n(i18n, { locales: normalizedLocaleCodes, baseUrl }); | ||
extendI18n(i18n, { locales: normalizedLocaleCodes, baseUrl, localeCodes }); | ||
const localizedRoutes = localizeRoutes(routes, { | ||
@@ -564,3 +578,4 @@ locales, | ||
routesNameSeparator, | ||
defaultLocaleRouteNameSuffix | ||
defaultLocaleRouteNameSuffix, | ||
optionsResolver | ||
}); | ||
@@ -582,3 +597,3 @@ options.routes = localizedRoutes; | ||
router.__defaultLocaleRouteNameSuffix = defaultLocaleRouteNameSuffix; | ||
router.__defaultDetection = defaultDetection; | ||
router.__defaultDirection = defaultDirection; | ||
router.beforeEach((to, from, next) => { | ||
@@ -595,2 +610,2 @@ const currentLocale = getLocale(i18n); | ||
const VERSION = "0.0.0"; | ||
export { VERSION, createRouter, getRouteBaseName, localeLocation, localePath, localeRoute, localizeRoutes, switchLocalePath, useI18nHead }; | ||
export { VERSION, createLocaleFromRouteGetter, createRouter, getLocale, getRouteBaseName, localeLocation, localePath, localeRoute, localizeRoutes, setLocale, switchLocalePath, useI18nHead }; |
@@ -1,5 +0,5 @@ | ||
var Oe=Object.defineProperty,we=Object.defineProperties;var xe=Object.getOwnPropertyDescriptors;var w=Object.getOwnPropertySymbols;var ae=Object.prototype.hasOwnProperty,ne=Object.prototype.propertyIsEnumerable;var le=(f,s,_)=>s in f?Oe(f,s,{enumerable:!0,configurable:!0,writable:!0,value:_}):f[s]=_,P=(f,s)=>{for(var _ in s||(s={}))ae.call(s,_)&&le(f,_,s[_]);if(w)for(var _ of w(s))ne.call(s,_)&&le(f,_,s[_]);return f},x=(f,s)=>we(f,xe(s));var oe=(f,s)=>{var _={};for(var p in f)ae.call(f,p)&&s.indexOf(p)<0&&(_[p]=f[p]);if(f!=null&&w)for(var p of w(f))s.indexOf(p)<0&&ne.call(f,p)&&(_[p]=f[p]);return _};var VueI18nRouting=function(f,s,_,p){"use strict";function ce(e){return e&&typeof e=="object"&&"default"in e?e:{default:e}}var re=ce(_);/*! | ||
* shared v9.2.0-beta.28 | ||
var Ce=Object.defineProperty,xe=Object.defineProperties;var De=Object.getOwnPropertyDescriptors;var x=Object.getOwnPropertySymbols;var re=Object.prototype.hasOwnProperty,se=Object.prototype.propertyIsEnumerable;var ce=(s,r,_)=>r in s?Ce(s,r,{enumerable:!0,configurable:!0,writable:!0,value:_}):s[r]=_,P=(s,r)=>{for(var _ in r||(r={}))re.call(r,_)&&ce(s,_,r[_]);if(x)for(var _ of x(r))se.call(r,_)&&ce(s,_,r[_]);return s},D=(s,r)=>xe(s,De(r));var ue=(s,r)=>{var _={};for(var p in s)re.call(s,p)&&r.indexOf(p)<0&&(_[p]=s[p]);if(s!=null&&x)for(var p of x(s))r.indexOf(p)<0&&se.call(s,p)&&(_[p]=s[p]);return _};var VueI18nRouting=function(s,r,_,p){"use strict";function fe(e){return e&&typeof e=="object"&&"default"in e?e:{default:e}}var ie=fe(_);/*! | ||
* shared v9.2.0-beta.30 | ||
* (c) 2022 kazuya kawaguchi | ||
* Released under the MIT License. | ||
*/const q=Object.assign,se=Array.isArray,ue=e=>typeof e=="function",F=e=>typeof e=="string",fe=e=>typeof e=="boolean",ie=e=>typeof e=="symbol",de=/\/$|\/\?/;function C(e="",t=!1){return t?de.test(e):e.endsWith("/")}function he(e="",t=!1){if(!t)return(C(e)?e.slice(0,-1):e)||"/";if(!C(e,!0))return e||"/";const[a,...n]=e.split("?");return(a.slice(0,-1)||"/")+(n.length?`?${n.join("?")}`:"")}function _e(e="",t=!1){if(!t)return e.endsWith("/")?e:e+"/";if(C(e,!0))return e||"/";const[a,...n]=e.split("?");return a+"/"+(n.length?`?${n.join("?")}`:"")}function me(e,t){typeof console!="undefined"&&(console.warn("[vue-i18n-routing] "+e),t&&console.warn(t.stack))}function G(e){e=e||[];const t=[];for(const a of e)F(a)?t.push({code:a}):t.push(a);return t}function D(e,t){return s.isRef(e.locale)&&t==="composition"}function H(e){return"global"in e&&"mode"in e}function X(e){return H(e)?D(e.global,e.mode)?e.global.locale.value:e.global.locale:e.locale.value}function Le(e,t){H(e)?D(e.global,e.mode)?e.global.locale.value=t:e.global.locale=t:s.isRef(e.locale)&&(e.locale.value=t)}function ge(e,t,a){return e.replace(/\/+$/,"")+(t?"/":"")||(a?"":"/")}function W(e){return F(e)?e:ie(e)?e.toString():"(null)"}function B(e,t,{defaultLocale:a,strategy:n,routesNameSeparator:o,defaultLocaleRouteNameSuffix:l}){let c=W(e)+(n==="no_prefix"?"":o+t);return t===a&&n==="prefix_and_default"&&(c+=o+l),c}function Re(e,t){return ue(e)?e(t):e}const $={PREFIX:"prefix",PREFIX_EXCEPT_DEFAULT:"prefix_except_default",PREFIX_AND_DEFAULT:"prefix_and_default",NO_PREFIX:"no_prefix"},U="",b=$.PREFIX_EXCEPT_DEFAULT,Q=!1,v="___",M="default",Ee="ltr",Y="",Se=new Set([$.PREFIX_AND_DEFAULT,$.PREFIX_EXCEPT_DEFAULT]);function O(e=_.useRoute(),{router:t=_.useRouter(),routesNameSeparator:a=v}={}){const n=a||t.__routesNameSeparator,o=s.unref(e);return o.name?W(o.name).split(n)[0]:null}function J(e,t,a){const n=V(e,t,a);return n==null?"":s.isVue3?n.redirectedFrom||n.fullPath:n.route.redirectedFrom||n.route.fullPath}function K(e,t,a){const n=V(e,t,a);return n==null?void 0:s.isVue3?n:n.route}function pe(e,t,a){const n=V(e,t,a);return n==null?void 0:s.isVue3?n:n.location}function V(e,t,{router:a=_.useRouter(),i18n:n=p.useI18n(),defaultLocale:o=U,defaultLocaleRouteNameSuffix:l=M,routesNameSeparator:c=v,strategy:i=b,trailingSlash:d=!1}={}){const u=a.__defaultLocaleRouteNameSuffix||l,r=a.__defaultLocale||o,R=a.__routesNameSeparator||c,g=a.__strategy||i,E=t||X(n);let I=e;F(e)&&(I[0]==="/"?I={path:e}:I={name:e});let h=q({},I);if(h.path&&!h.name){const L=a.resolve(h),S=s.isVue3?L:L.route,A=O(S);F(A)?h={name:B(A,E,{defaultLocale:r,strategy:g,routesNameSeparator:R,defaultLocaleRouteNameSuffix:u}),params:S.params,query:S.query,hash:S.hash}:(!(E===o&&Se.has(g))&&g!==$.NO_PREFIX&&(h.path=`/${E}${h.path}`),h.path=d?_e(h.path,!0):he(h.path,!0))}else{h.name=B(h.name,E,{defaultLocale:r,strategy:g,routesNameSeparator:R,defaultLocaleRouteNameSuffix:u});const{params:L}=h;L&&L["0"]===void 0&&L.pathMatch&&(L["0"]=L.pathMatch)}const m=a.resolve(h);return(s.isVue3?m.name:m.route.name)?m:a.resolve(e)}function z(e,t){const a=t&&t.route||_.useRoute(),n=O(a,t);if(!n)return"";const u=!s.isVue3&&s.isRef(a)?a.value:a,{params:o}=u,l=oe(u,["params"]),c={},i=q({},l,{name:n,params:x(P(P({},o),c),{0:o.pathMatch})});return J(i,e,t)}function Ae({addDirAttribute:e=!1,addSeoAttributes:t=!1,strategy:a=b,defaultLocale:n=U,route:o=_.useRoute(),router:l=_.useRouter(),i18n:c=p.useI18n()}={}){const i=n||l.__defaultLocale,d=a||l.__strategy,u=s.ref({htmlAttrs:{},link:[],meta:[]});function r(){u.value={htmlAttrs:{},link:[],meta:[]}}function R(g){const E=X(c),I=G(c.locales.value).find(L=>L.code===E)||{code:E},h=I.iso,m=I.dir||l.__defaultDetection;if(e&&(u.value.htmlAttrs.dir=m),t&&E&&c.locales){h&&(u.value.htmlAttrs.lang=h);const L=c.locales.value;Ie(L,c.__baseUrl,u.value.link,{defaultLocale:i,strategy:d,route:o,router:l,i18n:c}),Te(c.__baseUrl,u.value.link,t,{route:g,router:l,i18n:c}),ye(I,h,u.value.meta),Pe(L,h,u.value.meta)}}return s.watch(l.currentRoute,g=>{r(),R(g)}),R(o),u}function Ie(e,t,a,n){if(n.strategy===$.NO_PREFIX)return;const o=new Map;for(const l of e){const c=l.iso;if(!c){me("Locale ISO code is required to generate alternate link");continue}const[i,d]=c.split("-");i&&d&&(l.isCatchallLocale||!o.has(i))&&o.set(i,l),o.set(c,l)}for(const[l,c]of o.entries()){const i=z(c.code,n);i&&a.push({hid:`i18n-alt-${l}`,rel:"alternate",href:j(i,t),hreflang:l})}if(n.defaultLocale){const l=z(n.defaultLocale,n);l&&a.push({hid:"i18n-xd",rel:"alternate",href:j(l,t),hreflang:"x-default"})}}function Te(e,t,a,n){const{route:o}=n,l=K(x(P({},o),{name:O(o,n)}),void 0,n);if(l){let c=j(l.path,e);const i=!fe(a)&&a.canonicalQueries||[];if(i.length){const d=l.query,u=new URLSearchParams;for(const R of i)if(R in d){const g=d[R];se(g)?g.forEach(E=>u.append(R,E||"")):u.append(R,g||"")}const r=u.toString();r&&(c=`${c}?${r}`)}t.push({hid:"i18n-can",rel:"canonical",href:c})}}function ye(e,t,a){!(e&&t)||a.push({hid:"i18n-og",property:"og:locale",content:Z(t)})}function Pe(e,t,a){const n=e.filter(o=>{const l=o.iso;return l&&l!==t});if(n.length){const o=n.map(l=>({hid:`i18n-og-alt-${l.iso}`,property:"og:locale:alternate",content:Z(l.iso)}));a.push(...o)}}function Z(e){return(e||"").replace(/-/g,"_")}function j(e,t){return e.match(/^https?:\/\//)?e:t+e}function ee(e,{defaultLocale:t=U,strategy:a=b,trailingSlash:n=Q,routesNameSeparator:o=v,defaultLocaleRouteNameSuffix:l=M,includeUprefixedFallback:c=!1,locales:i=[]}={}){if(a==="no_prefix")return e;const d=i.map(r=>F(r)?r:r.code);function u(r,R,g=!1,E=!1){return r.redirect&&(!r.component||!r.file)?[r]:R.reduce((h,m)=>{const{name:L}=r;let{path:S}=r;const A=P({},r);L&&(A.name=`${L}${o}${m}`),r.children&&(A.children=r.children.reduce((y,k)=>[...y,...u(k,[m],!0,E)],[]));const T=m===t;if(T&&a==="prefix_and_default")if(g)g&&E&&L&&(A.name+=`${o}${l}`);else{const y=x(P({},A),{path:S});if(L&&(y.name=`${A.name}${o}${l}`),r.children){y.children=[];for(const k of r.children)y.children=y.children.concat(u(k,[m],!0,!0))}h.push(y)}const N=g&&!S.startsWith("/"),te=!N&&!(T&&a==="prefix_except_default");return te&&(S=`/${m}${S}`),S&&(S=ge(S,n,N)),te&&T&&a==="prefix"&&c&&h.push(P({},r)),A.path=S,h.push(A),h},[])}return e.reduce((r,R)=>[...r,...u(R,d||[])],[])}function Fe(e,{locales:t=[],baseUrl:a=Y}={}){if(!D(e.global,e.mode))throw new Error("TODO:");const n=s.ref(t);e.global.locales=s.computed(()=>n.value),e.global.__baseUrl=Re(a,{})}function Ne(e){return new RegExp(`^/(${e.join("|")})(?:/|$)`,"i")}function $e(e,t,a){const n=`(${e.join("|")})`,o=`(?:${t}${a})?`,l=new RegExp(`${t}${n}${o}$`,"i"),c=Ne(e);return d=>{if(d.name){const r=(F(d.name)?d.name:d.name.toString()).match(l);if(r&&r.length>1)return r[1]}else if(d.path){const u=d.path.match(c);if(u&&u.length>1)return u[1]}return""}}function Ue(e){var t,a,n,o,l,c,i,d,u,r;return e.version=(t=e.version)!=null?t:4,e.defaultLocale=(a=e.defaultLocale)!=null?a:U,e.strategy=(n=e.strategy)!=null?n:b,e.trailingSlash=(o=e.trailingSlash)!=null?o:Q,e.routesNameSeparator=(l=e.routesNameSeparator)!=null?l:v,e.defaultLocaleRouteNameSuffix=(c=e.defaultLocaleRouteNameSuffix)!=null?c:M,e.locales=(i=e.locales)!=null?i:[],e.defaultDetection=(d=e.defaultDetection)!=null?d:Ee,e.baseUrl=(u=e.baseUrl)!=null?u:Y,e.routes=(r=e.routes)!=null?r:[],e}function be(e,t={}){const{version:a,defaultLocale:n,locales:o,strategy:l,trailingSlash:c,routesNameSeparator:i,defaultLocaleRouteNameSuffix:d,defaultDetection:u,baseUrl:r,routes:R}=Ue(t),g=G(o),E=g.map(L=>L.code),I=$e(E,i,d);Fe(e,{locales:g,baseUrl:r});const h=ee(R,{locales:o,defaultLocale:n,strategy:l,trailingSlash:c,routesNameSeparator:i,defaultLocaleRouteNameSuffix:d});t.routes=h;let m=null;if(s.isVue3&&a===4)m=_.createRouter(t);else if(s.isVue2&&a===3)m=new re.default(t);else throw new Error("TODO:");return m.__defaultLocale=n,m.__localeCodes=E,m.__strategy=l,m.__trailingSlash=c,m.__routesNameSeparator=i,m.__defaultLocaleRouteNameSuffix=d,m.__defaultDetection=u,m.beforeEach((L,S,A)=>{const T=X(e),N=I(L)||T||n||"";T!==N&&Le(e,N),A()}),m}const ve="0.0.0";return f.VERSION=ve,f.createRouter=be,f.getRouteBaseName=O,f.localeLocation=pe,f.localePath=J,f.localeRoute=K,f.localizeRoutes=ee,f.switchLocalePath=z,f.useI18nHead=Ae,Object.defineProperty(f,"__esModule",{value:!0}),f[Symbol.toStringTag]="Module",f}({},VueDemi,VueRouter,VueI18n); | ||
*/const G=Object.assign,de=Array.isArray,he=e=>typeof e=="function",N=e=>typeof e=="string",_e=e=>typeof e=="boolean",me=e=>typeof e=="symbol",Le=/\/$|\/\?/;function X(e="",t=!1){return t?Le.test(e):e.endsWith("/")}function ge(e="",t=!1){if(!t)return(X(e)?e.slice(0,-1):e)||"/";if(!X(e,!0))return e||"/";const[a,...l]=e.split("?");return(a.slice(0,-1)||"/")+(l.length?`?${l.join("?")}`:"")}function Re(e="",t=!1){if(!t)return e.endsWith("/")?e:e+"/";if(X(e,!0))return e||"/";const[a,...l]=e.split("?");return a+"/"+(l.length?`?${l.join("?")}`:"")}function Ee(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 M(e,t){return r.isRef(e.locale)&&t==="composition"}function W(e){return"global"in e&&"mode"in e}function U(e){return W(e)?M(e.global,e.mode)?e.global.locale.value:e.global.locale:e.locale.value}function B(e,t){W(e)?M(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 Q(e){return N(e)?e:me(e)?e.toString():"(null)"}function Y(e,t,{defaultLocale:a,strategy:l,routesNameSeparator:o,defaultLocaleRouteNameSuffix:n}){let c=Q(e)+(l==="no_prefix"?"":o+t);return t===a&&l==="prefix_and_default"&&(c+=o+n),c}function pe(e,t){return he(e)?e(t):e}const b={PREFIX:"prefix",PREFIX_EXCEPT_DEFAULT:"prefix_except_default",PREFIX_AND_DEFAULT:"prefix_and_default",NO_PREFIX:"no_prefix"},v="",O=b.PREFIX_EXCEPT_DEFAULT,J=!1,w="___",V="default",Ae="ltr",K="",Ie=new Set([b.PREFIX_AND_DEFAULT,b.PREFIX_EXCEPT_DEFAULT]);function C(e=_.useRoute(),{router:t=_.useRouter(),routesNameSeparator:a=w}={}){const l=a||t.__routesNameSeparator,o=r.unref(e);return o.name?Q(o.name).split(l)[0]:null}function Z(e,t,a){const l=z(e,t,a);return l==null?"":r.isVue3?l.redirectedFrom||l.fullPath:l.route.redirectedFrom||l.route.fullPath}function ee(e,t,a){const l=z(e,t,a);return l==null?void 0:r.isVue3?l:l.route}function Te(e,t,a){const l=z(e,t,a);return l==null?void 0:r.isVue3?l:l.location}function z(e,t,{router:a=_.useRouter(),i18n:l=p.useI18n(),defaultLocale:o=v,defaultLocaleRouteNameSuffix:n=V,routesNameSeparator:c=w,strategy:d=O,trailingSlash:h=!1}={}){const f=a.__defaultLocaleRouteNameSuffix||n,L=a.__defaultLocale||o,u=a.__routesNameSeparator||c,g=a.__strategy||d,R=t||U(l);let E=e;N(e)&&(E[0]==="/"?E={path:e}:E={name:e});let m=G({},E);if(m.path&&!m.name){const i=a.resolve(m),S=r.isVue3?i:i.route,y=C(S);N(y)?m={name:Y(y,R,{defaultLocale:L,strategy:g,routesNameSeparator:u,defaultLocaleRouteNameSuffix:f}),params:S.params,query:S.query,hash:S.hash}:(!(R===o&&Ie.has(g))&&g!==b.NO_PREFIX&&(m.path=`/${R}${m.path}`),m.path=h?Re(m.path,!0):ge(m.path,!0))}else{m.name=Y(m.name,R,{defaultLocale:L,strategy:g,routesNameSeparator:u,defaultLocaleRouteNameSuffix:f});const{params:i}=m;i&&i["0"]===void 0&&i.pathMatch&&(i["0"]=i.pathMatch)}const T=a.resolve(m);return(r.isVue3?T.name:T.route.name)?T:a.resolve(e)}function j(e,t){const a=t&&t.route||_.useRoute(),l=C(a,t);if(!l)return"";const f=!r.isVue3&&r.isRef(a)?a.value:a,{params:o}=f,n=ue(f,["params"]),c={},d=G({},n,{name:l,params:D(P(P({},o),c),{0:o.pathMatch})});return Z(d,e,t)}function ye({addDirAttribute:e=!1,addSeoAttributes:t=!1,strategy:a=O,defaultLocale:l=v,route:o=_.useRoute(),router:n=_.useRouter(),i18n:c=p.useI18n()}={}){const d=l||n.__defaultLocale,h=a||n.__strategy,f=r.ref({htmlAttrs:{},link:[],meta:[]});function L(){f.value={htmlAttrs:{},link:[],meta:[]}}function u(g){if(c.locales==null||c.__baseUrl==null)return;const R=U(c),E=H(c.locales.value).find(i=>i.code===R)||{code:R},m=E.iso,T=E.dir||n.__defaultDirection;if(e&&(f.value.htmlAttrs.dir=T),t&&R&&c.locales){m&&(f.value.htmlAttrs.lang=m);const i=c.locales.value;Fe(i,c.__baseUrl,f.value.link,{defaultLocale:d,strategy:h,route:o,router:n,i18n:c}),Pe(c.__baseUrl,f.value.link,t,{route:g,router:n,i18n:c}),Ne(E,m,f.value.meta),$e(i,m,f.value.meta)}}return r.watch(n.currentRoute,g=>{L(),u(g)}),u(o),f}function Fe(e,t,a,l){if(l.strategy===b.NO_PREFIX)return;const o=new Map;for(const n of e){const c=n.iso;if(!c){Ee("Locale ISO code is required to generate alternate link");continue}const[d,h]=c.split("-");d&&h&&(n.isCatchallLocale||!o.has(d))&&o.set(d,n),o.set(c,n)}for(const[n,c]of o.entries()){const d=j(c.code,l);d&&a.push({hid:`i18n-alt-${n}`,rel:"alternate",href:k(d,t),hreflang:n})}if(l.defaultLocale){const n=j(l.defaultLocale,l);n&&a.push({hid:"i18n-xd",rel:"alternate",href:k(n,t),hreflang:"x-default"})}}function Pe(e,t,a,l){const{route:o}=l,n=ee(D(P({},o),{name:C(o,l)}),void 0,l);if(n){let c=k(n.path,e);const d=!_e(a)&&a.canonicalQueries||[];if(d.length){const h=n.query,f=new URLSearchParams;for(const u of d)if(u in h){const g=h[u];de(g)?g.forEach(R=>f.append(u,R||"")):f.append(u,g||"")}const L=f.toString();L&&(c=`${c}?${L}`)}t.push({hid:"i18n-can",rel:"canonical",href:c})}}function Ne(e,t,a){!(e&&t)||a.push({hid:"i18n-og",property:"og:locale",content:te(t)})}function $e(e,t,a){const l=e.filter(o=>{const n=o.iso;return n&&n!==t});if(l.length){const o=l.map(n=>({hid:`i18n-og-alt-${n.iso}`,property:"og:locale:alternate",content:te(n.iso)}));a.push(...o)}}function te(e){return(e||"").replace(/-/g,"_")}function k(e,t){return e.match(/^https?:\/\//)?e:t+e}function ae(e,{defaultLocale:t=v,strategy:a=O,trailingSlash:l=J,routesNameSeparator:o=w,defaultLocaleRouteNameSuffix:n=V,includeUprefixedFallback:c=!1,optionsResolver:d=void 0,locales:h=[]}={}){if(a==="no_prefix")return e;const f=h.map(u=>N(u)?u:u.code);function L(u,g,R=!1,E=!1){if(u.redirect&&(!u.component||!u.file))return[u];let m=null;return d!=null&&(m=d(u,g),m==null)?[u]:g.reduce((i,S)=>{const{name:y}=u;let{path:A}=u;const I=P({},u);y&&(I.name=`${y}${o}${S}`),u.children&&(I.children=u.children.reduce((F,q)=>[...F,...L(q,[S],!0,E)],[]));const $=S===t;if($&&a==="prefix_and_default")if(R)R&&E&&y&&(I.name+=`${o}${n}`);else{const F=D(P({},I),{path:A});if(y&&(F.name=`${I.name}${o}${n}`),u.children){F.children=[];for(const q of u.children)F.children=F.children.concat(L(q,[S],!0,!0))}i.push(F)}const ne=R&&!A.startsWith("/"),oe=!ne&&!($&&a==="prefix_except_default");return oe&&(A=`/${S}${A}`),A&&(A=Se(A,l,ne)),oe&&$&&a==="prefix"&&c&&i.push(P({},u)),I.path=A,i.push(I),i},[])}return e.reduce((u,g)=>[...u,...L(g,f||[])],[])}function be(e,{locales:t=[],localeCodes:a=[],baseUrl:l=K}={}){if(!M(e.global,e.mode))throw new Error("TODO:");const o=r.ref(t),n=r.ref(a);e.global.locales=r.computed(()=>o.value),e.global.localeCodes=r.computed(()=>n.value),e.global.__baseUrl=pe(l,{})}function Ue(e){return new RegExp(`^/(${e.join("|")})(?:/|$)`,"i")}function le(e,t,a){const l=`(${e.join("|")})`,o=`(?:${t}${a})?`,n=new RegExp(`${t}${l}${o}$`,"i"),c=Ue(e);return h=>{if(h.name){const L=(N(h.name)?h.name:h.name.toString()).match(n);if(L&&L.length>1)return L[1]}else if(h.path){const f=h.path.match(c);if(f&&f.length>1)return f[1]}return""}}function ve(e){var t,a,l,o,n,c,d,h,f,L;return e.version=(t=e.version)!=null?t:4,e.defaultLocale=(a=e.defaultLocale)!=null?a:v,e.strategy=(l=e.strategy)!=null?l:O,e.trailingSlash=(o=e.trailingSlash)!=null?o:J,e.routesNameSeparator=(n=e.routesNameSeparator)!=null?n:w,e.defaultLocaleRouteNameSuffix=(c=e.defaultLocaleRouteNameSuffix)!=null?c:V,e.locales=(d=e.locales)!=null?d:[],e.defaultDirection=(h=e.defaultDirection)!=null?h:Ae,e.baseUrl=(f=e.baseUrl)!=null?f:K,e.routes=(L=e.routes)!=null?L:[],e}function Oe(e,t={}){const{version:a,defaultLocale:l,locales:o,strategy:n,trailingSlash:c,routesNameSeparator:d,defaultLocaleRouteNameSuffix:h,defaultDirection:f,baseUrl:L,routes:u,routeOptionsResolver:g}=ve(t),R=H(o),E=R.map(S=>S.code),m=le(E,d,h);be(e,{locales:R,baseUrl:L,localeCodes:E});const T=ae(u,{locales:o,defaultLocale:l,strategy:n,trailingSlash:c,routesNameSeparator:d,defaultLocaleRouteNameSuffix:h,optionsResolver:g});t.routes=T;let i=null;if(r.isVue3&&a===4)i=_.createRouter(t);else if(r.isVue2&&a===3)i=new ie.default(t);else throw new Error("TODO:");return i.__defaultLocale=l,i.__localeCodes=E,i.__strategy=n,i.__trailingSlash=c,i.__routesNameSeparator=d,i.__defaultLocaleRouteNameSuffix=h,i.__defaultDirection=f,i.beforeEach((S,y,A)=>{const I=U(e),$=m(S)||I||l||"";I!==$&&B(e,$),A()}),i}const we="0.0.0";return s.VERSION=we,s.createLocaleFromRouteGetter=le,s.createRouter=Oe,s.getLocale=U,s.getRouteBaseName=C,s.localeLocation=Te,s.localePath=Z,s.localeRoute=ee,s.localizeRoutes=ae,s.setLocale=B,s.switchLocalePath=j,s.useI18nHead=ye,Object.defineProperty(s,"__esModule",{value:!0}),s[Symbol.toStringTag]="Module",s}({},VueDemi,VueRouter,VueI18n); |
{ | ||
"name": "vue-i18n-routing", | ||
"description": "The i18n routing with using vue-i18n", | ||
"version": "0.0.0-8a8e08f", | ||
"version": "0.0.0-8fbb24d", | ||
"dependencies": { | ||
"@intlify/shared": "beta", | ||
"@intlify/vue-i18n-bridge": "^0.3.4", | ||
"@intlify/vue-router-bridge": "^0.3.4", | ||
"@intlify/vue-i18n-bridge": "^0.3.5", | ||
"@intlify/vue-router-bridge": "^0.3.5", | ||
"ufo": "^0.7.9", | ||
@@ -18,11 +18,12 @@ "vue-demi": "^0.12.1" | ||
"typescript": "^4.5.4", | ||
"vite": "^2.7.4", | ||
"vite": "latest", | ||
"vite-plugin-dts": "^0.9.6", | ||
"vitest": "^0.2.8", | ||
"vue": "^3.2.23", | ||
"vue-i18n": "npm:vue-i18n@next", | ||
"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@3", | ||
"vue-template-compiler": "^2.6.14", | ||
"vue-router": "^4.0.12", | ||
"vue-router3": "npm:vue-router@latest", | ||
"vue2": "npm:vue@2" | ||
@@ -33,4 +34,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" | ||
@@ -97,5 +98,7 @@ }, | ||
"typecheck": "tsc -p . --noEmit", | ||
"test": "vitest run", | ||
"test:watch": "vitest", | ||
"test:cover": "vitest --coverage", | ||
"build:docs": "api-docs-gen ./temp/vue-i18n-routing.api.json -c ./docsgen.config.js -o ./ -g noprefix" | ||
}, | ||
"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)" | ||
} | ||
} |
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
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
58855
1044
0
16