vue-i18n-routing
Advanced tools
Comparing version 0.0.0-5165052 to 0.0.0-6058846
@@ -1,5 +0,5 @@ | ||
"use strict";var Q=Object.defineProperty,Z=Object.defineProperties;var ee=Object.getOwnPropertyDescriptors;var y=Object.getOwnPropertySymbols;var w=Object.prototype.hasOwnProperty,z=Object.prototype.propertyIsEnumerable;var C=(e,t,a)=>t in e?Q(e,t,{enumerable:!0,configurable:!0,writable:!0,value:a}):e[t]=a,P=(e,t)=>{for(var a in t||(t={}))w.call(t,a)&&C(e,a,t[a]);if(y)for(var a of y(t))z.call(t,a)&&C(e,a,t[a]);return e},O=(e,t)=>Z(e,ee(t));var X=(e,t)=>{var a={};for(var o in e)w.call(e,o)&&t.indexOf(o)<0&&(a[o]=e[o]);if(e!=null&&y)for(var o of y(e))t.indexOf(o)<0&&z.call(e,o)&&(a[o]=e[o]);return a};Object.defineProperty(exports,"__esModule",{value:!0});exports[Symbol.toStringTag]="Module";var h=require("vue-demi"),D=require("@intlify/vue-router-bridge"),te=require("@intlify/vue-i18n-bridge");function ae(e){return e&&typeof e=="object"&&"default"in e?e:{default:e}}var oe=ae(D);/*! | ||
* shared v9.2.0-beta.28 | ||
"use strict";var De=Object.defineProperty,be=Object.defineProperties;var xe=Object.getOwnPropertyDescriptors;var $=Object.getOwnPropertySymbols;var ie=Object.prototype.hasOwnProperty,ue=Object.prototype.propertyIsEnumerable;var ce=(e,t,o)=>t in e?De(e,t,{enumerable:!0,configurable:!0,writable:!0,value:o}):e[t]=o,I=(e,t)=>{for(var o in t||(t={}))ie.call(t,o)&&ce(e,o,t[o]);if($)for(var o of $(t))ue.call(t,o)&&ce(e,o,t[o]);return e},V=(e,t)=>be(e,xe(t));var fe=(e,t)=>{var o={};for(var n in e)ie.call(e,n)&&t.indexOf(n)<0&&(o[n]=e[n]);if(e!=null&&$)for(var n of $(e))t.indexOf(n)<0&&ue.call(e,n)&&(o[n]=e[n]);return o};Object.defineProperties(exports,{__esModule:{value:!0},[Symbol.toStringTag]:{value:"Module"}});var d=require("vue-demi"),p=require("@intlify/vue-router-bridge"),U=require("@intlify/vue-i18n-bridge");function Ce(e){return e&&typeof e=="object"&&"default"in e?e:{default:e}}var Oe=Ce(p);const D={PREFIX:"prefix",PREFIX_EXCEPT_DEFAULT:"prefix_except_default",PREFIX_AND_DEFAULT:"prefix_and_default",NO_PREFIX:"no_prefix"},B="",j=D.PREFIX_EXCEPT_DEFAULT,G=!1,X="___",M="default",te="ltr",oe="";/*! | ||
* shared v9.2.0-beta.35 | ||
* (c) 2022 kazuya kawaguchi | ||
* Released under the MIT License. | ||
*/const M=Object.assign,I=e=>typeof e=="string",le=e=>typeof e=="symbol";function ne(e){e=e||[];const t=[];for(const a of e)I(a)?t.push({code:a}):t.push(a);return t}function V(e,t){return h.isRef(e.locale)&&t==="composition"}function j(e){return"global"in e&&"mode"in e}function q(e){return j(e)?V(e.global,e.mode)?e.global.locale.value:e.global.locale:e.locale.value}function re(e,t){j(e)?V(e.global,e.mode)?e.global.locale.value=t:e.global.locale=t:h.isRef(e.locale)&&(e.locale.value=t)}function ce(e,t,a){return e.replace(/\/+$/,"")+(t?"/":"")||(a?"":"/")}function G(e){return I(e)?e:le(e)?e.toString():"(null)"}function B(e,t,{defaultLocale:a,strategy:o,routesNameSeparator:u,defaultLocaleRouteNameSuffix:i}){let s=G(e)+(o==="no_prefix"?"":u+t);return t===a&&o==="prefix_and_default"&&(s+=u+i),s}function ue(e={}){var d,L,E,p,m,_,A;const t=(d=e.i18n)!=null?d:te.useI18n(),a=(L=e.router)!=null?L:D.useRouter(),o=(E=e.route)!=null?E:D.useRoute(),u=(p=e.defaultLocaleRouteNameSuffix)!=null?p:a.__defaultLocaleRouteNameSuffix,i=(m=e.defaultLocale)!=null?m:a.__defaultLocale,s=(_=e.routesNameSeparator)!=null?_:a.__routesNameSeparator,g=(A=e.strategy)!=null?A:a.__strategy;function c(r){const f=r!=null?r:h.isRef(o)?o.value:o;return f.name?G(f.name).split(s)[0]:null}function R(r,f){const n=f||q(t);let x=r;I(r)&&(r[0]==="/"?x={path:r}:x={name:r});let S=M({},x);if(S.path&&!S.name){const v=a.resolve(S),T=h.isVue2?v.route:v,U=c(T);I(U)&&(S={name:B(U,n,{defaultLocale:i,strategy:g,routesNameSeparator:s,defaultLocaleRouteNameSuffix:u}),params:T.params,query:T.query,hash:T.hash})}else{S.name=B(S.name,n,{defaultLocale:i,strategy:g,routesNameSeparator:s,defaultLocaleRouteNameSuffix:u});const{params:v}=S;v&&v["0"]===void 0&&v.pathMatch&&(v["0"]=v.pathMatch)}const N=a.resolve(S);return(h.isVue2?N.route.name:N.name)?N:a.resolve(r)}function l(r,f){const n=R(r,f);return n==null?"":h.isVue2?n.route.redirectedFrom||n.route.fullPath:n.redirectedFrom||n.fullPath}function $(r,f){const n=R(r,f);return n==null?void 0:h.isVue2?n.route:n}function F(r,f){const n=R(r,f);return n==null?void 0:h.isVue2?n.location:n}function b(r){const f=c();if(!f)return"";const T=h.isVue2&&h.isRef(o)?o.value:o,{params:n}=T,x=X(T,["params"]),S={},N=M({},x,{name:f,params:O(P(P({},n),S),{0:n.pathMatch})}),v=l(N,r);return console.log("switchLocalePath",t.locale.value,r,v),v}return{getRouteBaseName:c,localePath:l,localeRoute:$,localeLocation:F,switchLocalePath:b}}const se={PREFIX:"prefix",PREFIX_EXCEPT_DEFAULT:"prefix_except_default",PREFIX_AND_DEFAULT:"prefix_and_default",NO_PREFIX:"no_prefix"},W="",k=se.PREFIX_EXCEPT_DEFAULT,H=!1,Y="___",J="default";function K(e,{defaultLocale:t=W,strategy:a=k,trailingSlash:o=H,routesNameSeparator:u=Y,defaultLocaleRouteNameSuffix:i=J,includeUprefixedFallback:s=!1,locales:g=[]}={}){if(a==="no_prefix")return e;const c=g.map(l=>I(l)?l:l.code);function R(l,$,F=!1,b=!1){return l.redirect&&(!l.component||!l.file)?[l]:$.reduce((L,E)=>{const{name:p}=l;let{path:m}=l;const _=P({},l);p&&(_.name=`${p}${u}${E}`),l.children&&(_.children=l.children.reduce((n,x)=>[...n,...R(x,[E],!0,b)],[]));const A=E===t;if(A&&a==="prefix_and_default")if(F)F&&b&&p&&(_.name+=`${u}${i}`);else{const n=O(P({},_),{path:m});if(p&&(n.name=`${_.name}${u}${i}`),l.children){n.children=[];for(const x of l.children)n.children=n.children.concat(R(x,[E],!0,!0))}L.push(n)}const r=F&&!m.startsWith("/"),f=!r&&!(A&&a==="prefix_except_default");return f&&(m=`/${E}${m}`),m&&(m=ce(m,o,r)),f&&A&&a==="prefix"&&s&&L.push(P({},l)),_.path=m,L.push(_),L},[])}return e.reduce((l,$)=>[...l,...R($,c||[])],[])}function fe(e,{locales:t=[]}={}){if(!V(e.global,e.mode))throw new Error("TODO:");const a=h.ref(t);e.global.locales=h.computed(()=>a.value),console.log("... extends i18n done")}function ie(e){return new RegExp(`^/(${e.join("|")})(?:/|$)`,"i")}function de(e,t,a){const o=`(${e.join("|")})`,u=`(?:${t}${a})?`,i=new RegExp(`${t}${o}${u}$`,"i"),s=ie(e);return c=>{if(c.name){const l=(I(c.name)?c.name:c.name.toString()).match(i);if(l&&l.length>1)return l[1]}else if(c.path){const R=c.path.match(s);if(R&&R.length>1)return R[1]}return""}}function me(e){var t,a,o,u,i,s,g,c;return e.version=(t=e.version)!=null?t:4,e.defaultLocale=(a=e.defaultLocale)!=null?a:W,e.strategy=(o=e.strategy)!=null?o:k,e.trailingSlash=(u=e.trailingSlash)!=null?u:H,e.routesNameSeparator=(i=e.routesNameSeparator)!=null?i:Y,e.defaultLocaleRouteNameSuffix=(s=e.defaultLocaleRouteNameSuffix)!=null?s:J,e.locales=(g=e.locales)!=null?g:[],e.routes=(c=e.routes)!=null?c:[],e}function Re(e,t={}){const{version:a,defaultLocale:o,locales:u,strategy:i,trailingSlash:s,routesNameSeparator:g,defaultLocaleRouteNameSuffix:c,routes:R}=me(t),l=ne(u),$=l.map(L=>L.code),F=de($,g,c);fe(e,{locales:l});const b=K(R,{locales:u,defaultLocale:o,strategy:i,trailingSlash:s,routesNameSeparator:g,defaultLocaleRouteNameSuffix:c});t.routes=b;let d=null;if(h.isVue3&&a===4)d=D.createRouter(t);else if(h.isVue2&&a===3)d=new oe.default(t);else throw new Error("TODO:");return d.__defaultLocale=o,d.__localeCodes=$,d.__strategy=i,d.__trailingSlash=s,d.__routesNameSeparator=g,d.__defaultLocaleRouteNameSuffix=c,d.beforeEach((L,E,p)=>{console.log("beforeEach",L,E);const m=q(e),_=F(L)||m||o||"";console.log("currentLocale",m,"finalLocale",_),m!==_&&re(e,_),p()}),console.log("create router",d),d}const _e="0.0.0";exports.VERSION=_e;exports.createRouter=Re;exports.localizeRoutes=K;exports.useI18nRouting=ue; | ||
*/const Ue=typeof Symbol=="function"&&typeof Symbol.toStringTag=="symbol",Fe=e=>Ue?Symbol(e):e,me=Object.assign,Ne=Array.isArray,we=e=>typeof e=="function",T=e=>typeof e=="string",$e=e=>typeof e=="boolean",Ve=e=>typeof e=="symbol",ne=e=>e!==null&&typeof e=="object",Be=/\/$|\/\?/;function K(e="",t=!1){return t?Be.test(e):e.endsWith("/")}function je(e="",t=!1){if(!t)return(K(e)?e.slice(0,-1):e)||"/";if(!K(e,!0))return e||"/";const[o,...n]=e.split("?");return(o.slice(0,-1)||"/")+(n.length?`?${n.join("?")}`:"")}function Ge(e="",t=!1){if(!t)return e.endsWith("/")?e:e+"/";if(K(e,!0))return e||"/";const[o,...n]=e.split("?");return o+"/"+(n.length?`?${n.join("?")}`:"")}const Xe=typeof window!="undefined";function pe(e,t){typeof console!="undefined"&&(console.warn("[vue-i18n-routing] "+e),t&&console.warn(t.stack))}function Le(e){e=e||[];const t=[];for(const o of e)T(o)?t.push({code:o}):t.push(o);return t}function F(e){return e!=null&&"global"in e&&"mode"in e}function N(e){return e!=null&&!("__composer"in e)&&d.isRef(e.locale)}function b(e){return e!=null&&"__composer"in e}function k(e){return e!=null&&!("__composer"in e)&&!d.isRef(e.locale)}function y(e){return e!=null&&("__VUE_I18N_BRIDGE__"in e||"_sync"in e)}function Re(e){return F(e)?N(e.global)?e.global:e.global.__composer:b(e)?e.__composer:e}function z(e){const t=F(e)?e.global:e;return N(t)?d.isVue2&&y(e)?e.locale:t.locale.value:(k(t)||b(t)||y(t),t.locale)}function Me(e){const t=F(e)?e.global:e;return N(t)?d.isVue2&&y(e)?e.locales:t.locales.value:(k(t)||b(t)||y(t),t.locales)}function ge(e,t){const o=F(e)?e.global:e;if(N(o))d.isVue2&&y(e)?e.locale=t:o.locale.value=t;else if(k(o)||b(o)||y(o))o.locale=t;else throw new Error("TODO:")}function ke(e,t,o){return e.replace(/\/+$/,"")+(t?"/":"")||(o?"":"/")}function de(e){return p.isVueRouter4,d.isRef(e)?e.value:e}function _e(e){return T(e)?e:Ve(e)?e.toString():"(null)"}function he(e,t,{defaultLocale:o,strategy:n,routesNameSeparator:l,defaultLocaleRouteNameSuffix:a}){let r=_e(e)+(n==="no_prefix"?"":l+t);return t===o&&n==="prefix_and_default"&&(r+=l+a),r}function Ee(e,t){return we(e)?e(t):e}function ze(e,t){const o=[];for(const[n,l]of t.entries()){const a=e.find(r=>r.iso.toLowerCase()===l.toLowerCase());if(a){o.push({code:a.code,score:1-n/t.length});break}}for(const[n,l]of t.entries()){const a=l.split("-")[0].toLowerCase(),r=e.find(s=>s.iso.split("-")[0].toLowerCase()===a);if(r){o.push({code:r.code,score:.999-n/t.length});break}}return o}const He=ze;function qe(e,t){return e.score===t.score?t.code.length-e.code.length:t.score-e.score}const We=qe;function Qe(e,t,{matcher:o=He,comparer:n=We}={}){const l=[];for(const r of e){const{code:s}=r,c=r.iso||s;l.push({code:s,iso:c})}const a=o(l,t);return a.length>1&&a.sort(n),a.length?a[0].code:""}function S(e){return function(){return Reflect.apply(e,{getRouteBaseName:this.getRouteBaseName,localePath:this.localePath,localeRoute:this.localeRoute,localeLocation:this.localeLocation,resolveRoute:this.resolveRoute,switchLocalePath:this.switchLocalePath,localeHead:this.localeHead,i18n:this.$i18n,route:this.$route,router:this.$router},arguments)}}function Se(e,{locales:t=[],localeCodes:o=[],baseUrl:n=oe,hooks:l={}}={}){const a=d.effectScope(),r=e.install;return e.install=(s,...c)=>{Reflect.apply(r,e,[s,...c]);const u=Re(e);a.run(()=>Ye(u,{locales:t,localeCodes:o,baseUrl:n,hooks:l})),b(e.global)&&Ke(e.global,l.onExtendVueI18n);const f=s,i=e.mode==="composition"?d.isVue3?f.config.globalProperties.$i18n:e:d.isVue2?e:null;if(i&&Je(i,u,l.onExtendExportedGlobal),(Ze(c[0])?c[0]:{inject:!0}).inject&&s.mixin({methods:{resolveRoute:S(w),localePath:S(q),localeRoute:S(W),localeLocation:S(ae),switchLocalePath:S(O),getRouteBaseName:S(x),localeHead:S(le)}}),f.unmount){const h=f.unmount;f.unmount=()=>{a.stop(),h()}}},a}function Ye(e,t){const{locales:o,localeCodes:n,baseUrl:l}=t,a=d.ref(o),r=d.ref(n);e.locales=d.computed(()=>a.value),e.localeCodes=d.computed(()=>r.value),e.__baseUrl=Ee(l,{}),t.hooks&&t.hooks.onExtendComposer&&t.hooks.onExtendComposer(e)}function Je(e,t,o){const n=[{locales:{get(){return t.locales.value}},localeCodes:{get(){return t.localeCodes.value}},__baseUrl:{get(){return t.__baseUrl}}}];o&&n.push(o(t));for(const l of n)for(const[a,r]of Object.entries(l))Object.defineProperty(e,a,r)}function Ke(e,t){const o=Re(e),n=[{locales:{get(){return o.locales.value}},localeCodes:{get(){return o.localeCodes.value}},__baseUrl:{get(){return o.__baseUrl}}}];t&&n.push(t(o));for(const l of n)for(const[a,r]of Object.entries(l))Object.defineProperty(e,a,r)}function Ze(e){return ne(e)&&"inject"in e&&$e(e.inject)}function ve(e,{defaultLocale:t=B,strategy:o=j,trailingSlash:n=G,routesNameSeparator:l=X,defaultLocaleRouteNameSuffix:a=M,includeUprefixedFallback:r=!1,optionsResolver:s=void 0,locales:c=[]}={}){if(o==="no_prefix")return e;const u=c.map(i=>T(i)?i:i.code);function f(i,m,h=!1,L=!1){if(i.redirect&&(!i.component||!i.file))return[i];let v=null;return s!=null&&(v=s(i,m),v==null)?[i]:m.reduce((_,E)=>{const{name:C}=i;let{path:R}=i;const g=I({},i);C&&(g.name=`${C}${l}${E}`),i.children&&(g.children=i.children.reduce((A,J)=>[...A,...f(J,[E],!0,L)],[]));const P=E===t;if(P&&o==="prefix_and_default")if(h)h&&L&&C&&(g.name+=`${l}${a}`);else{const A=V(I({},g),{path:R});if(C&&(A.name=`${g.name}${l}${a}`),i.children){A.children=[];for(const J of i.children)A.children=A.children.concat(f(J,[E],!0,!0))}_.push(A)}const re=h&&!R.startsWith("/"),se=!re&&!(P&&o==="prefix_except_default");return se&&(R=`/${E}${R}`),R&&(R=ke(R,n,re)),se&&P&&o==="prefix"&&r&&_.push(I({},i)),g.path=R,_.push(g),_},[])}return e.reduce((i,m)=>[...i,...f(m,u||[])],[])}const Z=Fe("vue-i18n-routing-gor");function Ae(e,t){e[Z]?pe("already registered global options"):e[Z]=t}function Ie(e){var t;return(t=e[Z])!=null?t:{}}function et(e,t={}){const{version:o,defaultLocale:n,locales:l,strategy:a,trailingSlash:r,routesNameSeparator:s,defaultLocaleRouteNameSuffix:c,defaultDirection:u,baseUrl:f,routes:i,routeOptionsResolver:m}=ot(t),h=Le(l),L=h.map(E=>E.code),v=ye(L,s,c);Se(e,{locales:h,baseUrl:f,localeCodes:L});const Y=ve(i,{locales:l,defaultLocale:n,strategy:a,trailingSlash:r,routesNameSeparator:s,defaultLocaleRouteNameSuffix:c,optionsResolver:m});t.routes=Y;const _=tt(t,o);return Ae(_,{defaultLocale:n,localeCodes:L,strategy:a,trailingSlash:r,routesNameSeparator:s,defaultLocaleRouteNameSuffix:c,defaultDirection:u}),_.beforeEach((E,C,R)=>{const g=z(e),P=v(E)||g||n||"";g!==P&&ge(e,P),R()}),_}function tt(e,t){if(d.isVue3&&t===4)return p.createRouter(e);if(d.isVue2&&t===3)return new Oe.default(e);throw new Error("TODO:")}function Te(e){return new RegExp(`^/(${e.join("|")})(?:/|$)`,"i")}function ye(e,t,o){const n=`(${e.join("|")})`,l=`(?:${t}${o})?`,a=new RegExp(`${t}${n}${l}$`,"i"),r=Te(e);return c=>{if(ne(c)){if(c.name){const f=(T(c.name)?c.name:c.name.toString()).match(a);if(f&&f.length>1)return f[1]}else if(c.path){const u=c.path.match(r);if(u&&u.length>1)return u[1]}}else if(T(c)){const u=c.match(r);if(u&&u.length>1)return u[1]}return""}}function ot(e){var t,o,n,l,a,r,s,c,u,f;return e.version=(t=e.version)!=null?t:4,e.defaultLocale=(o=e.defaultLocale)!=null?o:B,e.strategy=(n=e.strategy)!=null?n:j,e.trailingSlash=(l=e.trailingSlash)!=null?l:G,e.routesNameSeparator=(a=e.routesNameSeparator)!=null?a:X,e.defaultLocaleRouteNameSuffix=(r=e.defaultLocaleRouteNameSuffix)!=null?r:M,e.locales=(s=e.locales)!=null?s:[],e.defaultDirection=(c=e.defaultDirection)!=null?c:te,e.baseUrl=(u=e.baseUrl)!=null?u:oe,e.routes=(f=e.routes)!=null?f:[],e}function H(e,t,{defaultLocale:o=B,defaultDirection:n=te,defaultLocaleRouteNameSuffix:l=M,routesNameSeparator:a=X,strategy:r=j,trailingSlash:s=G,localeCodes:c=[]}={}){const u=Ie(e);return{defaultLocale:t.defaultLocale||u.defaultLocale||o,defaultDirection:t.defaultDirection||u.defaultDirection||n,defaultLocaleRouteNameSuffix:t.defaultLocaleRouteNameSuffix||u.defaultLocaleRouteNameSuffix||l,routesNameSeparator:t.routesNameSeparator||u.routesNameSeparator||a,strategy:t.strategy||u.strategy||r,trailingSlash:t.trailingSlash||u.trailingSlash||s,localeCodes:t.localeCodes||u.localeCodes||c}}const nt=new Set([D.PREFIX_AND_DEFAULT,D.PREFIX_EXCEPT_DEFAULT]);function x(e){const t=this.router,{routesNameSeparator:o}=H(t,this),n=e!=null?d.isRef(e)?d.unref(e):e:this.route;return n.name?_e(n.name).split(o)[0]:void 0}function q(e,t){const o=w.call(this,e,t);return o==null?"":d.isVue3?o.redirectedFrom||o.fullPath:o.route.redirectedFrom||o.route.fullPath}function W(e,t){const o=w.call(this,e,t);return o==null?void 0:d.isVue3?o:o.route}function ae(e,t){const o=w.call(this,e,t);return o==null?void 0:d.isVue3?o:o.location}function w(e,t){const o=this.router,n=this.i18n,l=t||z(n),{routesNameSeparator:a,defaultLocale:r,defaultLocaleRouteNameSuffix:s,strategy:c,trailingSlash:u}=H(o,this);let f=e;T(e)&&(f[0]==="/"?f={path:e}:f={name:e});let i=me({},f);if(i.path&&!i.name){const h=o.resolve(i),L=d.isVue3?h:h.route,v=x.call(this,L);T(v)?i={name:he(v,l,{defaultLocale:r,strategy:c,routesNameSeparator:a,defaultLocaleRouteNameSuffix:s}),params:L.params,query:L.query,hash:L.hash}:(!(l===r&&nt.has(c))&&c!==D.NO_PREFIX&&(i.path=`/${l}${i.path}`),i.path=u?Ge(i.path,!0):je(i.path,!0))}else{i.name=he(i.name,l,{defaultLocale:r,strategy:c,routesNameSeparator:a,defaultLocaleRouteNameSuffix:s});const{params:h}=i;h&&h["0"]===void 0&&h.pathMatch&&(h["0"]=h.pathMatch)}const m=o.resolve(i);return(d.isVue3?m.name:m.route.name)?m:o.resolve(e)}function O(e){const t=this.route,o=x.call(this,t);if(!o)return"";const c=!d.isVue3&&d.isRef(t)?t.value:t,{params:n}=c,l=fe(c,["params"]),a={},r=me({},l,{name:o,params:V(I(I({},n),a),{0:n.pathMatch})});return q.call(this,r,e)}function le({addDirAttribute:e=!1,addSeoAttributes:t=!1}={}){const o=this.router,n=this.i18n,{defaultDirection:l}=H(o,this),a={htmlAttrs:{},link:[],meta:[]};if(n.locales==null||n.__baseUrl==null)return a;const r=z(n),s=Me(n),c=Le(s).find(i=>i.code===r)||{code:r},u=c.iso,f=c.dir||l;return e&&(a.htmlAttrs.dir=f),t&&r&&n.locales&&(u&&(a.htmlAttrs.lang=u),at.call(this,s,n.__baseUrl,a.link),lt.call(this,n.__baseUrl,a.link,t),rt(c,u,a.meta),st(s,u,a.meta)),a}function at(e,t,o){const n=this.router,{defaultLocale:l,strategy:a}=H(n,this);if(a===D.NO_PREFIX)return;const r=new Map;for(const s of e){const c=s.iso;if(!c){pe("Locale ISO code is required to generate alternate link");continue}const[u,f]=c.split("-");u&&f&&(s.isCatchallLocale||!r.has(u))&&r.set(u,s),r.set(c,s)}for(const[s,c]of r.entries()){const u=O.call(this,c.code);u&&o.push({hid:`i18n-alt-${s}`,rel:"alternate",href:ee(u,t),hreflang:s})}if(l){const s=O.call(this,l);s&&o.push({hid:"i18n-xd",rel:"alternate",href:ee(s,t),hreflang:"x-default"})}}function lt(e,t,o){const n=this.route,l=W.call(this,V(I({},n),{name:x.call(this,n)}));if(l){let a=ee(l.path,e);const r=ne(o)&&o.canonicalQueries||[];if(r.length){const s=l.query,c=new URLSearchParams;for(const f of r)if(f in s){const i=s[f];Ne(i)?i.forEach(m=>c.append(f,m||"")):c.append(f,i||"")}const u=c.toString();u&&(a=`${a}?${u}`)}t.push({hid:"i18n-can",rel:"canonical",href:a})}}function rt(e,t,o){!(e&&t)||o.push({hid:"i18n-og",property:"og:locale",content:Pe(t)})}function st(e,t,o){const n=e.filter(l=>{const a=l.iso;return a&&a!==t});if(n.length){const l=n.map(a=>({hid:`i18n-og-alt-${a.iso}`,property:"og:locale:alternate",content:Pe(a.iso)}));o.push(...l)}}function Pe(e){return(e||"").replace(/-/g,"_")}function ee(e,t){return e.match(/^https?:\/\//)?e:t+e}function Q(e,t){const{router:o,route:n,i18n:l,defaultLocale:a,strategy:r,defaultLocaleRouteNameSuffix:s,trailingSlash:c,routesNameSeparator:u}=e;return function(...f){return Reflect.apply(t,{router:o,route:n,i18n:l,defaultLocale:a,strategy:r,defaultLocaleRouteNameSuffix:s,trailingSlash:c,routesNameSeparator:u},f)}}function ct(e=p.useRoute(),{router:t=p.useRouter(),routesNameSeparator:o=void 0}={}){const n={router:t,route:e,routesNameSeparator:o};return x.call(n,e)}function it({router:e=p.useRouter(),route:t=p.useRoute(),i18n:o=U.useI18n(),defaultLocale:n=void 0,defaultLocaleRouteNameSuffix:l=void 0,routesNameSeparator:a=void 0,strategy:r=void 0,trailingSlash:s=void 0}={}){return Q({router:e,route:t,i18n:o,defaultLocale:n,defaultLocaleRouteNameSuffix:l,routesNameSeparator:a,strategy:r,trailingSlash:s},q)}function ut({router:e=p.useRouter(),route:t=p.useRoute(),i18n:o=U.useI18n(),defaultLocale:n=void 0,defaultLocaleRouteNameSuffix:l=void 0,routesNameSeparator:a=void 0,strategy:r=void 0,trailingSlash:s=void 0}={}){return Q({router:e,route:t,i18n:o,defaultLocale:n,defaultLocaleRouteNameSuffix:l,routesNameSeparator:a,strategy:r,trailingSlash:s},W)}function ft({router:e=p.useRouter(),route:t=p.useRoute(),i18n:o=U.useI18n(),defaultLocale:n=void 0,defaultLocaleRouteNameSuffix:l=void 0,routesNameSeparator:a=void 0,strategy:r=void 0,trailingSlash:s=void 0}={}){return Q({router:e,route:t,i18n:o,defaultLocale:n,defaultLocaleRouteNameSuffix:l,routesNameSeparator:a,strategy:r,trailingSlash:s},ae)}function dt({router:e=p.useRouter(),route:t=p.useRoute(),i18n:o=U.useI18n(),defaultLocale:n=void 0,defaultLocaleRouteNameSuffix:l=void 0,routesNameSeparator:a=void 0,strategy:r=void 0,trailingSlash:s=void 0}={}){return Q({router:e,route:t,i18n:o,defaultLocale:n,defaultLocaleRouteNameSuffix:l,routesNameSeparator:a,strategy:r,trailingSlash:s},O)}function ht({addDirAttribute:e=!1,addSeoAttributes:t=!1,strategy:o=void 0,defaultLocale:n=void 0,route:l=p.useRoute(),router:a=p.useRouter(),i18n:r=U.useI18n()}={}){const s=a,c=d.ref({htmlAttrs:{},link:[],meta:[]});function u(){c.value={htmlAttrs:{},link:[],meta:[]}}function f(i){c.value=Reflect.apply(le,{router:a,route:i,i18n:r,defaultLocale:n,strategy:o},[{addDirAttribute:e,addSeoAttributes:t}])}if(Xe)if(d.isVue3){const i=d.watchEffect(()=>{u(),f(de(s.currentRoute))});d.onUnmounted(()=>i())}else{const i=s.afterEach((m,h)=>{u(),f(m)});d.onUnmounted(()=>i()),f(l)}else f(de(s.currentRoute));return c}const mt="0.0.0";exports.DEFAULT_BASE_URL=oe;exports.DEFAULT_DETECTION_DIRECTION=te;exports.DEFAULT_LOCALE=B;exports.DEFAULT_LOCALE_ROUTE_NAME_SUFFIX=M;exports.DEFAULT_ROUTES_NAME_SEPARATOR=X;exports.DEFAULT_STRATEGY=j;exports.DEFAULT_TRAILING_SLASH=G;exports.STRATEGIES=D;exports.VERSION=mt;exports.createLocaleFromRouteGetter=ye;exports.createRouter=et;exports.extendI18n=Se;exports.findBrowserLocale=Qe;exports.getGlobalOptions=Ie;exports.getLocale=z;exports.getLocalesRegex=Te;exports.getRouteBaseName=x;exports.isComposer=N;exports.isExportedGlobalComposer=k;exports.isI18nInstance=F;exports.isLegacyVueI18n=y;exports.isVueI18n=b;exports.localeHead=le;exports.localeLocation=ae;exports.localePath=q;exports.localeRoute=W;exports.localizeRoutes=ve;exports.proxyVueInstance=S;exports.registerGlobalOptions=Ae;exports.resolveBaseUrl=Ee;exports.resolveRoute=w;exports.setLocale=ge;exports.switchLocalePath=O;exports.useLocaleHead=ht;exports.useLocaleLocation=ft;exports.useLocalePath=it;exports.useLocaleRoute=ut;exports.useRouteBaseName=ct;exports.useSwitchLocalePath=dt; |
@@ -0,22 +1,80 @@ | ||
import type { Composer } from '@intlify/vue-i18n-bridge'; | ||
import { EffectScope } from 'vue-demi'; | ||
import type { ExportedGlobalComposer } from '@intlify/vue-i18n-bridge'; | ||
import type { I18n } from '@intlify/vue-i18n-bridge'; | ||
import { Locale } from '@intlify/vue-i18n-bridge'; | ||
import type { Location as Location_2 } from '@intlify/vue-router-bridge'; | ||
import type { Locale } from '@intlify/vue-i18n-bridge'; | ||
import type { RawLocation } from '@intlify/vue-router-bridge'; | ||
import type { Route as Route_2 } from '@intlify/vue-router-bridge'; | ||
import type { Ref } from 'vue-demi'; | ||
import { Route } from '@intlify/vue-router-bridge'; | ||
import type { RouteConfig } from '@intlify/vue-router-bridge'; | ||
import type { RouteLocation } from '@intlify/vue-router-bridge'; | ||
import type { RouteLocationNormalizedLoaded } from '@intlify/vue-router-bridge'; | ||
import { RouteLocationNormalized } from '@intlify/vue-router-bridge'; | ||
import { RouteLocationNormalizedLoaded } from '@intlify/vue-router-bridge'; | ||
import type { RouteLocationRaw } from '@intlify/vue-router-bridge'; | ||
import type { Router } from '@intlify/vue-router-bridge'; | ||
import type { RouterOptions } from '@intlify/vue-router-bridge'; | ||
import { useI18n } from '@intlify/vue-i18n-bridge'; | ||
import { useRoute } from '@intlify/vue-router-bridge'; | ||
import { useRouter } from '@intlify/vue-router-bridge'; | ||
import type { VueI18n } from '@intlify/vue-i18n-bridge'; | ||
import type { VueRouter } from '@intlify/vue-router-bridge'; | ||
export declare type BaseUrlResolveHandler<Context = unknown> = (context: Context) => string; | ||
/** | ||
* The browser locale info | ||
* | ||
* @remarks | ||
* This type is used by {@link FindBrowserLocaleOptions#sorter | sorter} in {@link findBrowserLocale} function | ||
*/ | ||
export declare type BrowserLocale = { | ||
/** | ||
* The locale code, such as BCP 47 (e.g `en-US`), or `ja` | ||
*/ | ||
code: string; | ||
/** | ||
* The score number | ||
* | ||
* @remarks | ||
* The score number that is used by `sorter` of {@link FindBrowserLocaleOptions} | ||
*/ | ||
score: number; | ||
}; | ||
/** | ||
* The browser locale matcher | ||
* | ||
* @remarks | ||
* This matcher is used by {@link findBrowserLocale} function | ||
* | ||
* @param locales - The target {@link LocaleObject | locale} list | ||
* @param browserLocales - The locale code list that is used in browser | ||
* | ||
* @returns The matched {@link BrowserLocale | locale info} | ||
*/ | ||
export declare type BrowserLocaleMatcher = (locales: TargetLocale[], browserLocales: string[]) => BrowserLocale[]; | ||
export declare type ComposableOptions = { | ||
route?: ReturnType<typeof useRoute>; | ||
router?: ReturnType<typeof useRouter>; | ||
i18n?: Composer; | ||
}; | ||
/** | ||
* Options to compute route localizing | ||
* | ||
* @remarks | ||
* The route options that is compute the route to be localized on {@link localizeRoutes} | ||
*/ | ||
export declare type ComputedRouteOptions = { | ||
locales: readonly string[]; | ||
paths: Record<string, string>; | ||
}; | ||
export declare function createLocaleFromRouteGetter(localeCodes: string[], routesNameSeparator: string, defaultLocaleRouteNameSuffix: string): (route: Route | RouteLocationNormalizedLoaded | RouteLocationNormalized | string) => string; | ||
/** | ||
* Create a Vue Router instance | ||
* | ||
* @param i18n - A Vue I18n instance, see [Vue I18n API docs](https://vue-i18n.intlify.dev/api/general.html#i18n) | ||
* @param options - An options, see {@link VueI18nRoutingOptions} | ||
* @param options - An options, see {@link I18nRoutingOptions} | ||
* | ||
@@ -31,5 +89,21 @@ * @returns A Vue Router instance | ||
* At the Vue 2 will return a [Vue Router v3 instance](https://router.vuejs.org/api/#router-construction-options), and at the Vue 3 will return a [Vue Router v4 instance](https://next.router.vuejs.org/api/#createrouter). | ||
* | ||
* @public | ||
*/ | ||
export declare function createRouter<Options extends VueI18nRoutingOptions = VueI18nRoutingOptions>(i18n: I18n, options?: Options): Options['version'] extends 4 ? Router : VueRouter; | ||
export declare function createRouter<Options extends I18nRoutingOptions = I18nRoutingOptions>(i18n: I18n, options?: Options): Options['version'] extends 4 ? Router : VueRouter; | ||
export declare const DEFAULT_BASE_URL = ""; | ||
export declare const DEFAULT_DETECTION_DIRECTION = "ltr"; | ||
export declare const DEFAULT_LOCALE = ""; | ||
export declare const DEFAULT_LOCALE_ROUTE_NAME_SUFFIX = "default"; | ||
export declare const DEFAULT_ROUTES_NAME_SEPARATOR = "___"; | ||
export declare const DEFAULT_STRATEGY: "prefix_except_default"; | ||
export declare const DEFAULT_TRAILING_SLASH = false; | ||
/** | ||
@@ -40,83 +114,96 @@ * Direction | ||
export declare interface I18nRouting { | ||
getRouteBaseName(givenRoute?: Route_2 | RouteLocationNormalizedLoaded): string | null; | ||
localePath(route: RawLocation | RouteLocationRaw, locale?: Locale): string; | ||
localeRoute(route: RawLocation | RouteLocationRaw, locale?: Locale): Route_2 | ReturnType<Router['resolve']>; | ||
localeLocation(route: RawLocation | RouteLocationRaw, locale?: Locale): Location_2 | RouteLocation; | ||
switchLocalePath(locale: Locale): void; | ||
export declare type ExtendComposerHook = (compser: Composer) => void; | ||
export declare type ExtendExportedGlobalHook = (global: Composer) => ExtendProperyDescripters; | ||
export declare interface ExtendHooks { | ||
onExtendComposer?: ExtendComposerHook; | ||
onExtendExportedGlobal?: ExtendExportedGlobalHook; | ||
onExtendVueI18n?: ExtendVueI18nHook; | ||
} | ||
export declare type I18nRoutingOptions = Pick<VueI18nRoutingOptions, 'defaultLocale' | 'strategy' | 'defaultLocaleRouteNameSuffix' | 'trailingSlash' | 'locales' | 'routesNameSeparator'> & { | ||
route?: ReturnType<typeof useRoute>; | ||
router?: ReturnType<typeof useRouter>; | ||
i18n?: ReturnType<typeof useI18n>; | ||
export declare function extendI18n<TI18n extends I18n>(i18n: TI18n, { locales, localeCodes, baseUrl, hooks }?: VueI18nExtendOptions): EffectScope; | ||
export declare type ExtendProperyDescripters = { | ||
[key: string]: Pick<PropertyDescriptor, 'get'>; | ||
}; | ||
export declare type ExtendVueI18nHook = (composer: Composer) => ExtendProperyDescripters; | ||
/** | ||
* Locale object | ||
* Find the browser locale | ||
* | ||
* @param locales - The target {@link LocaleObject | locale} list | ||
* @param browserLocales - The locale code list that is used in browser | ||
* @param options - The options for {@link findBrowserLocale} function | ||
* | ||
* @returns The matched the locale code | ||
*/ | ||
export declare interface LocaleObject extends Record<string, any> { | ||
code: Locale; | ||
name?: string; | ||
dir?: Directions; | ||
domain?: string; | ||
file?: string; | ||
isCatchallLocale?: boolean; | ||
iso?: string; | ||
} | ||
export declare function findBrowserLocale(locales: LocaleObject[], browserLocales: string[], { matcher, comparer }?: FindBrowserLocaleOptions): string | ''; | ||
export declare function localizeRoutes(routes: VueI18nRoute[], { defaultLocale, strategy, trailingSlash, routesNameSeparator, defaultLocaleRouteNameSuffix, includeUprefixedFallback, locales }?: Pick<VueI18nRoutingOptions, 'defaultLocale' | 'strategy' | 'locales' | 'routesNameSeparator' | 'trailingSlash' | 'defaultLocaleRouteNameSuffix'> & { | ||
includeUprefixedFallback?: boolean; | ||
}): VueI18nRoute[]; | ||
/** | ||
* Route config for vue-router v4 | ||
* The options for {@link findBrowserLocale} function | ||
*/ | ||
export declare interface Route { | ||
name?: string; | ||
path: string; | ||
file?: string; | ||
children?: Route[]; | ||
} | ||
export declare type FindBrowserLocaleOptions = { | ||
matcher?: BrowserLocaleMatcher; | ||
comparer?: (a: BrowserLocale, b: BrowserLocale) => number; | ||
}; | ||
declare type _Route = UnionToIntersection<RouteConfig>; | ||
/** | ||
* Route config for lagacy vue-router v3 | ||
* Get global i18n routing options | ||
* | ||
* @param router - A router instance, about router type | ||
* | ||
* @returns - {@link I18nRoutingGlobalOptions | global options} from i18n routing options registory, if registered, return it, else empty object | ||
*/ | ||
export declare interface RouteLegacy extends Pick<_Route, Exclude<keyof _Route, 'children' | 'component'>> { | ||
chunkName?: string; | ||
chunkNames?: Record<string, string>; | ||
component?: _Route['component'] | string; | ||
children?: RouteLegacy[]; | ||
} | ||
export declare function getGlobalOptions(router: Router | VueRouter): I18nRoutingGlobalOptions; | ||
declare const STRATEGIES: { | ||
readonly PREFIX: "prefix"; | ||
readonly PREFIX_EXCEPT_DEFAULT: "prefix_except_default"; | ||
readonly PREFIX_AND_DEFAULT: "prefix_and_default"; | ||
readonly NO_PREFIX: "no_prefix"; | ||
}; | ||
/** | ||
* Routing strategy | ||
* Get a locale | ||
* | ||
* @param i18n - An [I18n](https://vue-i18n.intlify.dev/api/general.html#i18n) instance or a [Composer](https://vue-i18n.intlify.dev/api/composition.html#composer) instance | ||
* | ||
* @returns A locale | ||
*/ | ||
export declare type Strategies = typeof STRATEGIES[keyof typeof STRATEGIES]; | ||
export declare function getLocale(i18n: I18n | Composer | VueI18n): Locale; | ||
declare type UnionToIntersection<T> = (T extends any ? (k: T) => void : never) extends (k: infer U) => void ? U : never; | ||
export declare function getLocalesRegex(localeCodes: string[]): RegExp; | ||
export declare function useI18nRouting(options?: I18nRoutingOptions): I18nRouting; | ||
export declare function getRouteBaseName(this: RoutingProxy, givenRoute?: Route | RouteLocationNormalizedLoaded): string | undefined; | ||
export declare type I18nCommonRoutingOptions = Pick<I18nRoutingOptions, 'defaultLocale' | 'strategy' | 'defaultLocaleRouteNameSuffix' | 'trailingSlash' | 'locales' | 'routesNameSeparator'>; | ||
export declare type I18nCommonRoutingOptionsWithComposable = I18nCommonRoutingOptions & ComposableOptions; | ||
/** | ||
* Vue I18n Routing Version | ||
* | ||
* @remarks | ||
* Semver format. Same format as the package.json `version` field. | ||
* I18n header meta info | ||
*/ | ||
export declare const VERSION: string; | ||
export declare interface I18nHeadMetaInfo { | ||
htmlAttrs?: MetaAttrs; | ||
meta?: MetaAttrs[]; | ||
link?: MetaAttrs[]; | ||
} | ||
/** | ||
* Options for {@link localeHead} function | ||
*/ | ||
export declare interface I18nHeadOptions { | ||
/** | ||
* Adds a `dir` attribute to the HTML element. | ||
* | ||
* @defaultValue false | ||
*/ | ||
addDirAttribute?: boolean; | ||
/** | ||
* Adds various SEO attributes. | ||
* | ||
* @defaultValue false | ||
*/ | ||
addSeoAttributes?: boolean | SeoAttributesOptions; | ||
} | ||
/** | ||
* Route config for vue-i18n-routing | ||
*/ | ||
export declare type VueI18nRoute = Route & RouteLegacy & { | ||
export declare type I18nRoute = Route_2 & RouteLegacy & { | ||
redirect?: string; | ||
@@ -126,2 +213,9 @@ }; | ||
/** | ||
* Global options for i18n routing | ||
*/ | ||
export declare type I18nRoutingGlobalOptions<BaseUrl extends BaseUrlResolveHandler = BaseUrlResolveHandler> = Pick<I18nRoutingOptions<BaseUrl>, 'defaultLocale' | 'defaultDirection' | 'defaultLocaleRouteNameSuffix' | 'trailingSlash' | 'routesNameSeparator' | 'strategy'> & { | ||
localeCodes?: string[]; | ||
}; | ||
/** | ||
* Options to initialize a VueRouter instance | ||
@@ -132,3 +226,3 @@ * | ||
*/ | ||
export declare type VueI18nRoutingOptions = { | ||
export declare type I18nRoutingOptions<BaseUrl extends BaseUrlResolveHandler = BaseUrlResolveHandler> = { | ||
/** | ||
@@ -159,3 +253,4 @@ * Vue Router version | ||
* | ||
* @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 | ||
* | ||
@@ -200,15 +295,356 @@ * @defaultValue [] | ||
defaultLocaleRouteNameSuffix?: string; | ||
/** | ||
* Default direction direction | ||
* | ||
* @defaultValue 'ltr' | ||
*/ | ||
defaultDirection?: Directions; | ||
/** | ||
* The fallback base URL to use as a prefix for alternate URLs in hreflang tags. | ||
* | ||
* @remarks | ||
* By default VueRouter's base URL will be used and only if that is not available, fallback URL will be used. | ||
* | ||
* Can also be a function (will be passed a Nuxt Context as a parameter) that returns a string. | ||
* | ||
* Useful to make base URL dynamic based on request headers. | ||
* | ||
* @defaultValue '' | ||
*/ | ||
baseUrl?: string | BaseUrl; | ||
/** | ||
* Route options resolver | ||
* | ||
* @defaultValue undefined | ||
*/ | ||
routeOptionsResolver?: RouteOptionsResolver; | ||
} & RouterOptions; | ||
export declare function isComposer(target: any): target is Composer; | ||
export declare function isExportedGlobalComposer(target: any): target is ExportedGlobalComposer; | ||
export declare function isI18nInstance(i18n: any): i18n is I18n; | ||
export declare function isLegacyVueI18n(target: any): target is Pick<VueI18n, 'locale'>; | ||
export declare function isVueI18n(target: any): target is VueI18n; | ||
export declare function localeHead(this: RoutingProxy, { addDirAttribute, addSeoAttributes }?: I18nHeadOptions): I18nHeadMetaInfo; | ||
export declare function localeLocation(this: RoutingProxy, route: RawLocation | RouteLocationRaw, locale?: Locale): Location | RouteLocation | undefined; | ||
/** | ||
* Resolve locale location function | ||
* | ||
* @param route - A route location. The path or name of the route or an object for more complex routes | ||
* @param locale - A locale code, if not specified, uses the current locale | ||
* | ||
* @returns Returns the location object for a given route, the location object is resolved by vue-router rather than just a full route path. | ||
* | ||
* @see {@link useLocaleLocation} | ||
*/ | ||
export declare type LocaleLocationFunction = (route: RawLocation | RouteLocationRaw, locale?: Locale) => Location | RouteLocation | undefined; | ||
/** | ||
* Locale object | ||
*/ | ||
export declare interface LocaleObject extends Record<string, any> { | ||
code: Locale; | ||
name?: string; | ||
dir?: Directions; | ||
domain?: string; | ||
file?: string; | ||
isCatchallLocale?: boolean; | ||
iso?: string; | ||
} | ||
export declare function localePath(this: RoutingProxy, route: RawLocation | RouteLocationRaw, locale?: Locale): string; | ||
/** | ||
* Resolve locale path function | ||
* | ||
* @param route - A route location. The path or name of the route or an object for more complex routes | ||
* @param locale - A locale code, if not specified, uses the current locale | ||
* | ||
* @returns Returns the localized URL for a given route | ||
* | ||
* @see {@link useLocalePath} | ||
*/ | ||
export declare type LocalePathFunction = (route: RawLocation | RouteLocation, locale?: Locale) => string; | ||
export declare function localeRoute(this: RoutingProxy, route: RawLocation | RouteLocationRaw, locale?: Locale): Route | ReturnType<Router['resolve']> | undefined; | ||
/** | ||
* Resolve route fucntion | ||
* | ||
* @param route - A route location. The path or name of the route or an object for more complex routes | ||
* @param locale - A locale code, if not specified, uses the current locale | ||
* | ||
* @returns Returns the route object for a given route, the route object is resolved by vue-router rather than just a full route path. | ||
* | ||
* @see {@link useLocaleRoute} | ||
*/ | ||
export declare type LocaleRouteFunction = (route: RawLocation | RouteLocationRaw, locale?: Locale) => Route | ReturnType<Router['resolve']> | undefined; | ||
/** | ||
* Localize routes | ||
* | ||
* @param routes - Some routes | ||
* @param options - An options | ||
* | ||
* @returns Localized routes | ||
* | ||
* @public | ||
*/ | ||
export declare function localizeRoutes(routes: I18nRoute[], { defaultLocale, strategy, trailingSlash, routesNameSeparator, defaultLocaleRouteNameSuffix, includeUprefixedFallback, optionsResolver, locales }?: Pick<I18nRoutingOptions, 'defaultLocale' | 'strategy' | 'locales' | 'routesNameSeparator' | 'trailingSlash' | 'defaultLocaleRouteNameSuffix'> & { | ||
includeUprefixedFallback?: boolean; | ||
optionsResolver?: RouteOptionsResolver; | ||
}): I18nRoute[]; | ||
export declare type MetaAttrs = Record<string, any>; | ||
export declare function proxyVueInstance(target: Function): Function; | ||
/** | ||
* Register global i18n routing option registory | ||
* | ||
* @param router - A router instance, about router type | ||
* @param options - A global options, about options type, see {@link I18nRoutingGlobalOptions} | ||
*/ | ||
export declare function registerGlobalOptions<BaseUrl extends BaseUrlResolveHandler = BaseUrlResolveHandler>(router: Router | VueRouter, options: I18nRoutingGlobalOptions<BaseUrl>): void; | ||
/** | ||
* Resolve base url | ||
* | ||
* @param baseUrl - A base url to resolve on SEO and domain. if you want to resolve with dynamically, you can spacify {@link BaseUrlResolveHandler} | ||
* @param context - A context to resolve base url, if you want to resolve base url with {@link BaseUrlResolveHandler} | ||
* | ||
* @returns A resolved base url | ||
*/ | ||
export declare function resolveBaseUrl<Context = unknown>(baseUrl: string | BaseUrlResolveHandler<Context>, context: Context): string; | ||
export declare function resolveRoute(this: RoutingProxy, route: any, locale?: Locale): any; | ||
export { Route } | ||
declare type _Route = UnionToIntersection<RouteConfig>; | ||
/** | ||
* Route config for vue-router v4 | ||
*/ | ||
declare interface Route_2 { | ||
name?: string; | ||
path: string; | ||
file?: string; | ||
children?: Route_2[]; | ||
} | ||
/** | ||
* Route config for lagacy vue-router v3 | ||
*/ | ||
export declare interface RouteLegacy extends Pick<_Route, Exclude<keyof _Route, 'children' | 'component'>> { | ||
chunkName?: string; | ||
chunkNames?: Record<string, string>; | ||
component?: _Route['component'] | string; | ||
children?: RouteLegacy[]; | ||
} | ||
export { RouteLocationNormalized } | ||
export { RouteLocationNormalizedLoaded } | ||
/** | ||
* Resolver for route localizing options | ||
*/ | ||
export declare type RouteOptionsResolver = (route: I18nRoute, allowedLocaleCodes: string[]) => ComputedRouteOptions | null; | ||
/** | ||
* Routing Proxy | ||
*/ | ||
export declare type RoutingProxy = { | ||
i18n: any; | ||
getRouteBaseName: any; | ||
localePath: any; | ||
localeRoute: any; | ||
localeLocation: any; | ||
resolveRoute: any; | ||
switchLocalePath: any; | ||
localeHead: any; | ||
route: Route | RouteLocationNormalizedLoaded; | ||
router: Router | VueRouter; | ||
defaultLocale?: string; | ||
localeCodes?: string[]; | ||
strategy?: Strategies; | ||
defaultDirection?: Directions; | ||
defaultLocaleRouteNameSuffix?: string; | ||
trailingSlash?: boolean; | ||
routesNameSeparator?: string; | ||
}; | ||
/** | ||
* SEO Attribute options | ||
*/ | ||
export declare interface SeoAttributesOptions { | ||
/** | ||
* An array of strings corresponding to query params you would like to include in your canonical URL. | ||
* | ||
* @defaultValue [] | ||
*/ | ||
canonicalQueries?: string[]; | ||
} | ||
/** | ||
* Set a locale | ||
* | ||
* @param i18n - An [I18n](https://vue-i18n.intlify.dev/api/general.html#i18n) instance or a [Composer](https://vue-i18n.intlify.dev/api/composition.html#composer) instance | ||
* @param locale - A target locale | ||
*/ | ||
export declare function setLocale(i18n: I18n | Composer, locale: Locale): void; | ||
export declare const STRATEGIES: { | ||
readonly PREFIX: "prefix"; | ||
readonly PREFIX_EXCEPT_DEFAULT: "prefix_except_default"; | ||
readonly PREFIX_AND_DEFAULT: "prefix_and_default"; | ||
readonly NO_PREFIX: "no_prefix"; | ||
}; | ||
/** | ||
* Routing strategy | ||
*/ | ||
export declare type Strategies = typeof STRATEGIES[keyof typeof STRATEGIES]; | ||
export declare function switchLocalePath(this: RoutingProxy, locale: Locale): string; | ||
/** | ||
* Swtich locale path function | ||
* | ||
* @param locale - A locale code, if not specified, uses the current locale | ||
* | ||
* @returns Returns a link to the current route in another language | ||
* | ||
* @see {@link useSwitchLocalePath} | ||
*/ | ||
export declare type SwitchLocalePathFunction = (locale?: Locale) => string; | ||
/** | ||
* The target locale info | ||
* | ||
* @remarks | ||
* This type is used by {@link BrowserLocaleMatcher} first argument | ||
*/ | ||
export declare type TargetLocale = Required<Pick<LocaleObject, 'code' | 'iso'>>; | ||
declare type UnionToIntersection<T> = (T extends any ? (k: T) => void : never) extends (k: infer U) => void ? U : never; | ||
/** | ||
* Use localize head meta | ||
* | ||
* @param options - An options, see about details {@link I18nHeadOptions}, {@link ComposableOptions}, {@link I18nCommonRoutingOptions} | ||
* | ||
* @returns Genereated SEO head meta information | ||
*/ | ||
export declare function useLocaleHead({ addDirAttribute, addSeoAttributes, strategy, defaultLocale, route, router, i18n }?: Pick<I18nCommonRoutingOptionsWithComposable, 'strategy' | 'defaultLocale' | 'route' | 'router' | 'i18n'> & I18nHeadOptions): Ref<I18nHeadMetaInfo>; | ||
/** | ||
* Use resolve locale location | ||
* | ||
* @param options - An options, see about details {@link I18nRoutingOptions} | ||
* | ||
* @returns Returns a {@link LocaleLocationFunction} | ||
*/ | ||
export declare function useLocaleLocation({ router, route, i18n, defaultLocale, defaultLocaleRouteNameSuffix, routesNameSeparator, strategy, trailingSlash }?: I18nCommonRoutingOptionsWithComposable): LocaleLocationFunction; | ||
/** | ||
* Use resolve locale path | ||
* | ||
* @param options - An options, see about details {@link I18nRoutingOptions} | ||
* | ||
* @returns Returns a {@link LocalePathFunction} | ||
*/ | ||
export declare function useLocalePath({ router, route, i18n, defaultLocale, defaultLocaleRouteNameSuffix, routesNameSeparator, strategy, trailingSlash }?: I18nCommonRoutingOptionsWithComposable): LocalePathFunction; | ||
/** | ||
* Use resolve locale route | ||
* | ||
* @param options - An options, see about details {@link I18nRoutingOptions} | ||
* | ||
* @returns Returns a {@link LocaleRouteFunction} | ||
*/ | ||
export declare function useLocaleRoute({ router, route, i18n, defaultLocale, defaultLocaleRouteNameSuffix, routesNameSeparator, strategy, trailingSlash }?: I18nCommonRoutingOptionsWithComposable): LocaleRouteFunction; | ||
/** | ||
* Use route base name | ||
* | ||
* @param givenRoute - A route object, if not provided, the route is returned with `useRoute` will be used | ||
* @param options - An options, see about details {@link I18nRoutingOptions} | ||
* | ||
* @returns The route base name, if route name is not defined, return null | ||
*/ | ||
export declare function useRouteBaseName(givenRoute?: Route | RouteLocationNormalizedLoaded, { router, routesNameSeparator }?: I18nCommonRoutingOptionsWithComposable): string | undefined; | ||
/** | ||
* Use swtich locale path | ||
* | ||
* @param options - An options, see about details {@link I18nRoutingOptions} | ||
* | ||
* @returns Returns a {@link SwitchLocalePathFunction} | ||
*/ | ||
export declare function useSwitchLocalePath({ router, route, i18n, defaultLocale, defaultLocaleRouteNameSuffix, routesNameSeparator, strategy, trailingSlash }?: I18nCommonRoutingOptionsWithComposable): SwitchLocalePathFunction; | ||
/** | ||
* Vue I18n Routing Version | ||
* | ||
* @remarks | ||
* Semver format. Same format as the package.json `version` field. | ||
*/ | ||
export declare const VERSION: string; | ||
export declare type VueI18nExtendOptions = Pick<I18nRoutingOptions, 'baseUrl'> & { | ||
locales?: string[] | LocaleObject[]; | ||
localeCodes?: string[]; | ||
hooks?: ExtendHooks; | ||
}; | ||
/** | ||
* An options of Vue I18n Routing Plugin | ||
*/ | ||
export declare interface VueI18nRoutingPluginOptions { | ||
/** | ||
* Whether to inject some option APIs style methods into Vue instance | ||
* | ||
* @defaultValue `true` | ||
*/ | ||
inject?: boolean; | ||
} | ||
export { } | ||
import type { ComputedRef } from 'vue-demi' | ||
export interface ComposerCustomProperties { | ||
/** | ||
* List of locales | ||
* | ||
* @remarks | ||
* Can either be an array of string codes (e.g. `['en', 'fr']`) or an array of {@link LocaleObject} for more complex configurations | ||
*/ | ||
locales: ComputedRef<string[] | LocaleObject[]> | ||
/** | ||
* List of locale codes | ||
*/ | ||
localeCodes: ComputedRef<string[]> | ||
__baseUrl: string | ||
} | ||
declare module 'vue-i18n' { | ||
export interface ComposerCustom { | ||
locales: ComputedRef<LocaleObject[]> | ||
} | ||
// eslint-disable-next-line @typescript-eslint/no-empty-interface | ||
export interface ComposerCustom extends ComposerCustomProperties {} | ||
} | ||
declare module 'vue-i18n-bridge' { | ||
export interface ComposerCustom { | ||
locales: ComputedRef<LocaleObject[]> | ||
} | ||
// eslint-disable-next-line @typescript-eslint/no-empty-interface | ||
export interface ComposerCustom extends ComposerCustomProperties {} | ||
} | ||
declare module '@intlify/vue-i18n-bridge' { | ||
// eslint-disable-next-line @typescript-eslint/no-empty-interface | ||
export interface ComposerCustom extends ComposerCustomProperties {} | ||
} |
@@ -32,13 +32,68 @@ 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, isVue2, effectScope, isVue3, ref, computed, unref, watchEffect, onUnmounted } from "vue-demi"; | ||
import VueRouter3, { isVueRouter4, createRouter as createRouter$1, useRoute, useRouter } from "@intlify/vue-router-bridge"; | ||
import { useI18n } from "@intlify/vue-i18n-bridge"; | ||
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 = ""; | ||
/*! | ||
* shared v9.2.0-beta.28 | ||
* shared v9.2.0-beta.35 | ||
* (c) 2022 kazuya kawaguchi | ||
* Released under the MIT License. | ||
*/ | ||
const hasSymbol = typeof Symbol === "function" && typeof Symbol.toStringTag === "symbol"; | ||
const makeSymbol = (name) => hasSymbol ? Symbol(name) : name; | ||
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 isObject = (val) => val !== null && typeof val === "object"; | ||
const TRAILING_SLASH_RE = /\/$|\/\?/; | ||
function hasTrailingSlash(input = "", queryParams = false) { | ||
if (!queryParams) { | ||
return input.endsWith("/"); | ||
} | ||
return TRAILING_SLASH_RE.test(input); | ||
} | ||
function withoutTrailingSlash(input = "", queryParams = false) { | ||
if (!queryParams) { | ||
return (hasTrailingSlash(input) ? input.slice(0, -1) : input) || "/"; | ||
} | ||
if (!hasTrailingSlash(input, true)) { | ||
return input || "/"; | ||
} | ||
const [s0, ...s] = input.split("?"); | ||
return (s0.slice(0, -1) || "/") + (s.length ? `?${s.join("?")}` : ""); | ||
} | ||
function withTrailingSlash(input = "", queryParams = false) { | ||
if (!queryParams) { | ||
return input.endsWith("/") ? input : input + "/"; | ||
} | ||
if (hasTrailingSlash(input, true)) { | ||
return input || "/"; | ||
} | ||
const [s0, ...s] = input.split("?"); | ||
return s0 + "/" + (s.length ? `?${s.join("?")}` : ""); | ||
} | ||
const inBrowser = typeof window !== "undefined"; | ||
function warn(msg, err) { | ||
if (typeof console !== "undefined") { | ||
console.warn(`[vue-i18n-routing] ` + msg); | ||
if (err) { | ||
console.warn(err.stack); | ||
} | ||
} | ||
} | ||
function getNormalizedLocales(locales) { | ||
@@ -56,20 +111,40 @@ locales = locales || []; | ||
} | ||
function isComposer(target, mode) { | ||
return isRef(target.locale) && mode === "composition"; | ||
} | ||
function isI18nInstance(i18n) { | ||
return "global" in i18n && "mode" in i18n; | ||
return i18n != null && "global" in i18n && "mode" in i18n; | ||
} | ||
function isComposer(target) { | ||
return target != null && !("__composer" in target) && isRef(target.locale); | ||
} | ||
function isVueI18n(target) { | ||
return target != null && "__composer" in target; | ||
} | ||
function isExportedGlobalComposer(target) { | ||
return target != null && !("__composer" in target) && !isRef(target.locale); | ||
} | ||
function isLegacyVueI18n(target) { | ||
return target != null && ("__VUE_I18N_BRIDGE__" in target || "_sync" in target); | ||
} | ||
function getComposer(i18n) { | ||
return isI18nInstance(i18n) ? isComposer(i18n.global) ? i18n.global : i18n.global.__composer : isVueI18n(i18n) ? i18n.__composer : i18n; | ||
} | ||
function getLocale(i18n) { | ||
return isI18nInstance(i18n) ? isComposer(i18n.global, i18n.mode) ? i18n.global.locale.value : i18n.global.locale : i18n.locale.value; | ||
const target = isI18nInstance(i18n) ? i18n.global : i18n; | ||
return isComposer(target) ? isVue2 && isLegacyVueI18n(i18n) ? i18n.locale : target.locale.value : isExportedGlobalComposer(target) || isVueI18n(target) || isLegacyVueI18n(target) ? target.locale : target.locale; | ||
} | ||
function getLocales(i18n) { | ||
const target = isI18nInstance(i18n) ? i18n.global : i18n; | ||
return isComposer(target) ? isVue2 && isLegacyVueI18n(i18n) ? i18n.locales : target.locales.value : isExportedGlobalComposer(target) || isVueI18n(target) || isLegacyVueI18n(target) ? target.locales : target.locales; | ||
} | ||
function setLocale(i18n, locale) { | ||
if (isI18nInstance(i18n)) { | ||
if (isComposer(i18n.global, i18n.mode)) { | ||
i18n.global.locale.value = locale; | ||
const target = isI18nInstance(i18n) ? i18n.global : i18n; | ||
if (isComposer(target)) { | ||
if (isVue2 && isLegacyVueI18n(i18n)) { | ||
i18n.locale = locale; | ||
} else { | ||
i18n.global.locale = locale; | ||
target.locale.value = locale; | ||
} | ||
} else if (isRef(i18n.locale)) { | ||
i18n.locale.value = locale; | ||
} else if (isExportedGlobalComposer(target) || isVueI18n(target) || isLegacyVueI18n(target)) { | ||
target.locale = locale; | ||
} else { | ||
throw new Error("TODO:"); | ||
} | ||
@@ -80,2 +155,5 @@ } | ||
} | ||
function toRawRoute(maybeRoute) { | ||
return isVueRouter4 ? isRef(maybeRoute) ? maybeRoute.value : maybeRoute : isRef(maybeRoute) ? maybeRoute.value : maybeRoute; | ||
} | ||
function getRouteName(routeName) { | ||
@@ -96,113 +174,172 @@ return isString(routeName) ? routeName : isSymbol(routeName) ? routeName.toString() : "(null)"; | ||
} | ||
function useI18nRouting(options = {}) { | ||
var _a, _b, _c, _d, _e, _f, _g; | ||
const $i18n = (_a = options.i18n) != null ? _a : useI18n(); | ||
const $router = (_b = options.router) != null ? _b : useRouter(); | ||
const $route = (_c = options.route) != null ? _c : useRoute(); | ||
const defaultLocaleRouteNameSuffix = (_d = options.defaultLocaleRouteNameSuffix) != null ? _d : $router.__defaultLocaleRouteNameSuffix; | ||
const defaultLocale = (_e = options.defaultLocale) != null ? _e : $router.__defaultLocale; | ||
const routesNameSeparator = (_f = options.routesNameSeparator) != null ? _f : $router.__routesNameSeparator; | ||
const strategy = (_g = options.strategy) != null ? _g : $router.__strategy; | ||
function getRouteBaseName(givenRoute) { | ||
const route = givenRoute != null ? givenRoute : isRef($route) ? $route.value : $route; | ||
if (!route.name) { | ||
return null; | ||
function resolveBaseUrl(baseUrl, context) { | ||
if (isFunction(baseUrl)) { | ||
return baseUrl(context); | ||
} | ||
return baseUrl; | ||
} | ||
function matchBrowserLocale(locales, browserLocales) { | ||
const matchedLocales = []; | ||
for (const [index, browserCode] of browserLocales.entries()) { | ||
const matchedLocale = locales.find((l) => l.iso.toLowerCase() === browserCode.toLowerCase()); | ||
if (matchedLocale) { | ||
matchedLocales.push({ code: matchedLocale.code, score: 1 - index / browserLocales.length }); | ||
break; | ||
} | ||
const name = getRouteName(route.name); | ||
return name.split(routesNameSeparator)[0]; | ||
} | ||
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 }; | ||
} | ||
for (const [index, browserCode] of browserLocales.entries()) { | ||
const languageCode = browserCode.split("-")[0].toLowerCase(); | ||
const matchedLocale = locales.find((l) => l.iso.split("-")[0].toLowerCase() === languageCode); | ||
if (matchedLocale) { | ||
matchedLocales.push({ code: matchedLocale.code, score: 0.999 - index / browserLocales.length }); | ||
break; | ||
} | ||
let localizedRoute = assign({}, _route); | ||
if (localizedRoute.path && !localizedRoute.name) { | ||
const _resolvedRoute = $router.resolve(localizedRoute); | ||
const resolvedRoute2 = !isVue2 ? _resolvedRoute : _resolvedRoute.route; | ||
const resolvedRouteName = getRouteBaseName(resolvedRoute2); | ||
if (isString(resolvedRouteName)) { | ||
localizedRoute = { | ||
name: getLocaleRouteName(resolvedRouteName, _locale, { | ||
defaultLocale, | ||
strategy, | ||
routesNameSeparator, | ||
defaultLocaleRouteNameSuffix | ||
}), | ||
params: resolvedRoute2.params, | ||
query: resolvedRoute2.query, | ||
hash: resolvedRoute2.hash | ||
}; | ||
} | ||
} else { | ||
localizedRoute.name = getLocaleRouteName(localizedRoute.name, _locale, { | ||
defaultLocale, | ||
strategy, | ||
routesNameSeparator, | ||
defaultLocaleRouteNameSuffix | ||
} | ||
return matchedLocales; | ||
} | ||
const DefaultBrowserLocaleMatcher = matchBrowserLocale; | ||
function compareBrowserLocale(a, b) { | ||
if (a.score === b.score) { | ||
return b.code.length - a.code.length; | ||
} | ||
return b.score - a.score; | ||
} | ||
const DefaultBrowerLocaleComparer = compareBrowserLocale; | ||
function findBrowserLocale(locales, browserLocales, { matcher = DefaultBrowserLocaleMatcher, comparer = DefaultBrowerLocaleComparer } = {}) { | ||
const normalizedLocales = []; | ||
for (const l of locales) { | ||
const { code } = l; | ||
const iso = l.iso || code; | ||
normalizedLocales.push({ code, iso }); | ||
} | ||
const matchedLocales = matcher(normalizedLocales, browserLocales); | ||
if (matchedLocales.length > 1) { | ||
matchedLocales.sort(comparer); | ||
} | ||
return matchedLocales.length ? matchedLocales[0].code : ""; | ||
} | ||
function proxyVueInstance(target) { | ||
return function() { | ||
return Reflect.apply(target, { | ||
getRouteBaseName: this.getRouteBaseName, | ||
localePath: this.localePath, | ||
localeRoute: this.localeRoute, | ||
localeLocation: this.localeLocation, | ||
resolveRoute: this.resolveRoute, | ||
switchLocalePath: this.switchLocalePath, | ||
localeHead: this.localeHead, | ||
i18n: this.$i18n, | ||
route: this.$route, | ||
router: this.$router | ||
}, arguments); | ||
}; | ||
} | ||
function extendI18n(i18n, { locales = [], localeCodes = [], baseUrl = DEFAULT_BASE_URL, hooks = {} } = {}) { | ||
const scope = effectScope(); | ||
const orgInstall = i18n.install; | ||
i18n.install = (vue, ...options) => { | ||
Reflect.apply(orgInstall, i18n, [vue, ...options]); | ||
const composer = getComposer(i18n); | ||
scope.run(() => extendComposer(composer, { locales, localeCodes, baseUrl, hooks })); | ||
if (isVueI18n(i18n.global)) { | ||
extendVueI18n(i18n.global, hooks.onExtendVueI18n); | ||
} | ||
const app = vue; | ||
const exported = i18n.mode === "composition" ? isVue3 ? app.config.globalProperties.$i18n : i18n : isVue2 ? i18n : null; | ||
if (exported) { | ||
extendExportedGlobal(exported, composer, hooks.onExtendExportedGlobal); | ||
} | ||
const pluginOptions = isPluginOptions(options[0]) ? options[0] : { inject: true }; | ||
if (pluginOptions.inject) { | ||
vue.mixin({ | ||
methods: { | ||
resolveRoute: proxyVueInstance(resolveRoute), | ||
localePath: proxyVueInstance(localePath), | ||
localeRoute: proxyVueInstance(localeRoute), | ||
localeLocation: proxyVueInstance(localeLocation), | ||
switchLocalePath: proxyVueInstance(switchLocalePath), | ||
getRouteBaseName: proxyVueInstance(getRouteBaseName), | ||
localeHead: proxyVueInstance(localeHead) | ||
} | ||
}); | ||
const { params } = localizedRoute; | ||
if (params && params["0"] === void 0 && params.pathMatch) { | ||
params["0"] = params.pathMatch; | ||
} | ||
if (app.unmount) { | ||
const unmountApp = app.unmount; | ||
app.unmount = () => { | ||
scope.stop(); | ||
unmountApp(); | ||
}; | ||
} | ||
}; | ||
return scope; | ||
} | ||
function extendComposer(composer, options) { | ||
const { locales, localeCodes, baseUrl } = options; | ||
const _locales = ref(locales); | ||
const _localeCodes = ref(localeCodes); | ||
composer.locales = computed(() => _locales.value); | ||
composer.localeCodes = computed(() => _localeCodes.value); | ||
composer.__baseUrl = resolveBaseUrl(baseUrl, {}); | ||
if (options.hooks && options.hooks.onExtendComposer) { | ||
options.hooks.onExtendComposer(composer); | ||
} | ||
} | ||
function extendExportedGlobal(exported, global, hook) { | ||
const properties = [ | ||
{ | ||
locales: { | ||
get() { | ||
return global.locales.value; | ||
} | ||
}, | ||
localeCodes: { | ||
get() { | ||
return global.localeCodes.value; | ||
} | ||
}, | ||
__baseUrl: { | ||
get() { | ||
return global.__baseUrl; | ||
} | ||
} | ||
} | ||
const resolvedRoute = $router.resolve(localizedRoute); | ||
if (isVue2 ? resolvedRoute.route.name : resolvedRoute.name) { | ||
return resolvedRoute; | ||
]; | ||
hook && properties.push(hook(global)); | ||
for (const property of properties) { | ||
for (const [key, descriptor] of Object.entries(property)) { | ||
Object.defineProperty(exported, key, descriptor); | ||
} | ||
return $router.resolve(route); | ||
} | ||
function localePath(route, locale) { | ||
const localizedRoute = resolveRoute(route, locale); | ||
return localizedRoute == null ? "" : isVue2 ? localizedRoute.route.redirectedFrom || localizedRoute.route.fullPath : localizedRoute.redirectedFrom || localizedRoute.fullPath; | ||
} | ||
function localeRoute(route, locale) { | ||
const resolved = resolveRoute(route, locale); | ||
return resolved == null ? void 0 : isVue2 ? resolved.route : resolved; | ||
} | ||
function localeLocation(route, locale) { | ||
const resolved = resolveRoute(route, locale); | ||
return resolved == null ? void 0 : isVue2 ? resolved.location : resolved; | ||
} | ||
function switchLocalePath(locale) { | ||
const name = getRouteBaseName(); | ||
if (!name) { | ||
return ""; | ||
} | ||
function extendVueI18n(vueI18n, hook) { | ||
const composer = getComposer(vueI18n); | ||
const properties = [ | ||
{ | ||
locales: { | ||
get() { | ||
return composer.locales.value; | ||
} | ||
}, | ||
localeCodes: { | ||
get() { | ||
return composer.localeCodes.value; | ||
} | ||
}, | ||
__baseUrl: { | ||
get() { | ||
return composer.__baseUrl; | ||
} | ||
} | ||
} | ||
const _a2 = isVue2 && isRef($route) ? $route.value : $route, { params } = _a2, routeCopy = __objRest(_a2, ["params"]); | ||
const langSwitchParams = {}; | ||
const baseRoute = assign({}, routeCopy, { | ||
name, | ||
params: __spreadProps(__spreadValues(__spreadValues({}, params), langSwitchParams), { | ||
0: params.pathMatch | ||
}) | ||
}); | ||
const path = localePath(baseRoute, locale); | ||
console.log("switchLocalePath", $i18n.locale.value, locale, path); | ||
return path; | ||
]; | ||
hook && properties.push(hook(composer)); | ||
for (const property of properties) { | ||
for (const [key, descriptor] of Object.entries(property)) { | ||
Object.defineProperty(vueI18n, key, descriptor); | ||
} | ||
} | ||
return { | ||
getRouteBaseName, | ||
localePath, | ||
localeRoute, | ||
localeLocation, | ||
switchLocalePath | ||
}; | ||
} | ||
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 isPluginOptions(options) { | ||
return isObject(options) && "inject" in options && isBoolean(options.inject); | ||
} | ||
function localizeRoutes(routes, { | ||
@@ -215,2 +352,3 @@ defaultLocale = DEFAULT_LOCALE, | ||
includeUprefixedFallback = false, | ||
optionsResolver = void 0, | ||
locales = [] | ||
@@ -226,2 +364,9 @@ } = {}) { | ||
} | ||
let routeOptions = null; | ||
if (optionsResolver != null) { | ||
routeOptions = optionsResolver(route, allowedLocaleCodes); | ||
if (routeOptions == null) { | ||
return [route]; | ||
} | ||
} | ||
const targetLocales = allowedLocaleCodes; | ||
@@ -274,9 +419,71 @@ return targetLocales.reduce((_routes, locale) => { | ||
} | ||
function extendI18n(i18n, { locales = [] } = {}) { | ||
if (!isComposer(i18n.global, i18n.mode)) { | ||
const GlobalOptionsRegistory = makeSymbol("vue-i18n-routing-gor"); | ||
function registerGlobalOptions(router, options) { | ||
const _options = router[GlobalOptionsRegistory]; | ||
if (_options) { | ||
warn("already registered global options"); | ||
} else { | ||
router[GlobalOptionsRegistory] = options; | ||
} | ||
} | ||
function getGlobalOptions(router) { | ||
var _a; | ||
return (_a = router[GlobalOptionsRegistory]) != null ? _a : {}; | ||
} | ||
function createRouter(i18n, options = {}) { | ||
const { | ||
version, | ||
defaultLocale, | ||
locales, | ||
strategy, | ||
trailingSlash, | ||
routesNameSeparator, | ||
defaultLocaleRouteNameSuffix, | ||
defaultDirection, | ||
baseUrl, | ||
routes, | ||
routeOptionsResolver: optionsResolver | ||
} = asDefaultVueI18nRouterOptions(options); | ||
const normalizedLocaleCodes = getNormalizedLocales(locales); | ||
const localeCodes = normalizedLocaleCodes.map((l) => l.code); | ||
const getLocaleFromRoute = createLocaleFromRouteGetter(localeCodes, routesNameSeparator, defaultLocaleRouteNameSuffix); | ||
extendI18n(i18n, { locales: normalizedLocaleCodes, baseUrl, localeCodes }); | ||
const localizedRoutes = localizeRoutes(routes, { | ||
locales, | ||
defaultLocale, | ||
strategy, | ||
trailingSlash, | ||
routesNameSeparator, | ||
defaultLocaleRouteNameSuffix, | ||
optionsResolver | ||
}); | ||
options.routes = localizedRoutes; | ||
const router = createVueRouter(options, version); | ||
registerGlobalOptions(router, { | ||
defaultLocale, | ||
localeCodes, | ||
strategy, | ||
trailingSlash, | ||
routesNameSeparator, | ||
defaultLocaleRouteNameSuffix, | ||
defaultDirection | ||
}); | ||
router.beforeEach((to, from, next) => { | ||
const currentLocale = getLocale(i18n); | ||
const finalLocale = getLocaleFromRoute(to) || currentLocale || defaultLocale || ""; | ||
if (currentLocale !== finalLocale) { | ||
setLocale(i18n, finalLocale); | ||
} | ||
next(); | ||
}); | ||
return router; | ||
} | ||
function createVueRouter(options, version) { | ||
if (isVue3 && version === 4) { | ||
return createRouter$1(options); | ||
} else if (isVue2 && version === 3) { | ||
return new VueRouter3(options); | ||
} else { | ||
throw new Error("TODO:"); | ||
} | ||
const _locales = ref(locales); | ||
i18n.global.locales = computed(() => _locales.value); | ||
console.log("... extends i18n done"); | ||
} | ||
@@ -292,10 +499,17 @@ function getLocalesRegex(localeCodes) { | ||
const getLocaleFromRoute = (route) => { | ||
if (route.name) { | ||
const name = isString(route.name) ? route.name : route.name.toString(); | ||
const matches = name.match(regexpName); | ||
if (matches && matches.length > 1) { | ||
return matches[1]; | ||
if (isObject(route)) { | ||
if (route.name) { | ||
const name = isString(route.name) ? route.name : route.name.toString(); | ||
const matches = name.match(regexpName); | ||
if (matches && matches.length > 1) { | ||
return matches[1]; | ||
} | ||
} else if (route.path) { | ||
const matches = route.path.match(regexpPath); | ||
if (matches && matches.length > 1) { | ||
return matches[1]; | ||
} | ||
} | ||
} else if (route.path) { | ||
const matches = route.path.match(regexpPath); | ||
} else if (isString(route)) { | ||
const matches = route.match(regexpPath); | ||
if (matches && matches.length > 1) { | ||
@@ -310,3 +524,3 @@ return matches[1]; | ||
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; | ||
@@ -319,57 +533,424 @@ 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; | ||
} | ||
function createRouter(i18n, options = {}) { | ||
function getI18nRoutingOptions(router, proxy, { | ||
defaultLocale = DEFAULT_LOCALE, | ||
defaultDirection = DEFAULT_DETECTION_DIRECTION, | ||
defaultLocaleRouteNameSuffix = DEFAULT_LOCALE_ROUTE_NAME_SUFFIX, | ||
routesNameSeparator = DEFAULT_ROUTES_NAME_SEPARATOR, | ||
strategy = DEFAULT_STRATEGY, | ||
trailingSlash = DEFAULT_TRAILING_SLASH, | ||
localeCodes = [] | ||
} = {}) { | ||
const options = getGlobalOptions(router); | ||
return { | ||
defaultLocale: proxy.defaultLocale || options.defaultLocale || defaultLocale, | ||
defaultDirection: proxy.defaultDirection || options.defaultDirection || defaultDirection, | ||
defaultLocaleRouteNameSuffix: proxy.defaultLocaleRouteNameSuffix || options.defaultLocaleRouteNameSuffix || defaultLocaleRouteNameSuffix, | ||
routesNameSeparator: proxy.routesNameSeparator || options.routesNameSeparator || routesNameSeparator, | ||
strategy: proxy.strategy || options.strategy || strategy, | ||
trailingSlash: proxy.trailingSlash || options.trailingSlash || trailingSlash, | ||
localeCodes: proxy.localeCodes || options.localeCodes || localeCodes | ||
}; | ||
} | ||
const RESOLVED_PREFIXED = /* @__PURE__ */ new Set([STRATEGIES.PREFIX_AND_DEFAULT, STRATEGIES.PREFIX_EXCEPT_DEFAULT]); | ||
function getRouteBaseName(givenRoute) { | ||
const router = this.router; | ||
const { routesNameSeparator } = getI18nRoutingOptions(router, this); | ||
const route = givenRoute != null ? isRef(givenRoute) ? unref(givenRoute) : givenRoute : this.route; | ||
if (!route.name) { | ||
return; | ||
} | ||
const name = getRouteName(route.name); | ||
return name.split(routesNameSeparator)[0]; | ||
} | ||
function localePath(route, locale) { | ||
const localizedRoute = resolveRoute.call(this, route, locale); | ||
return localizedRoute == null ? "" : isVue3 ? localizedRoute.redirectedFrom || localizedRoute.fullPath : localizedRoute.route.redirectedFrom || localizedRoute.route.fullPath; | ||
} | ||
function localeRoute(route, locale) { | ||
const resolved = resolveRoute.call(this, route, locale); | ||
return resolved == null ? void 0 : isVue3 ? resolved : resolved.route; | ||
} | ||
function localeLocation(route, locale) { | ||
const resolved = resolveRoute.call(this, route, locale); | ||
return resolved == null ? void 0 : isVue3 ? resolved : resolved.location; | ||
} | ||
function resolveRoute(route, locale) { | ||
const router = this.router; | ||
const i18n = this.i18n; | ||
const _locale = locale || getLocale(i18n); | ||
const { routesNameSeparator, defaultLocale, defaultLocaleRouteNameSuffix, strategy, trailingSlash } = getI18nRoutingOptions(router, this); | ||
let _route = route; | ||
if (isString(route)) { | ||
if (_route[0] === "/") { | ||
_route = { path: route }; | ||
} else { | ||
_route = { name: route }; | ||
} | ||
} | ||
let localizedRoute = assign({}, _route); | ||
if (localizedRoute.path && !localizedRoute.name) { | ||
const _resolvedRoute = router.resolve(localizedRoute); | ||
const resolvedRoute2 = isVue3 ? _resolvedRoute : _resolvedRoute.route; | ||
const resolvedRouteName = getRouteBaseName.call(this, resolvedRoute2); | ||
if (isString(resolvedRouteName)) { | ||
localizedRoute = { | ||
name: getLocaleRouteName(resolvedRouteName, _locale, { | ||
defaultLocale, | ||
strategy, | ||
routesNameSeparator, | ||
defaultLocaleRouteNameSuffix | ||
}), | ||
params: resolvedRoute2.params, | ||
query: resolvedRoute2.query, | ||
hash: resolvedRoute2.hash | ||
}; | ||
} else { | ||
const isDefaultLocale = _locale === defaultLocale; | ||
const isPrefixed = !(isDefaultLocale && RESOLVED_PREFIXED.has(strategy)) && !(strategy === STRATEGIES.NO_PREFIX); | ||
if (isPrefixed) { | ||
localizedRoute.path = `/${_locale}${localizedRoute.path}`; | ||
} | ||
localizedRoute.path = trailingSlash ? withTrailingSlash(localizedRoute.path, true) : withoutTrailingSlash(localizedRoute.path, true); | ||
} | ||
} else { | ||
localizedRoute.name = getLocaleRouteName(localizedRoute.name, _locale, { | ||
defaultLocale, | ||
strategy, | ||
routesNameSeparator, | ||
defaultLocaleRouteNameSuffix | ||
}); | ||
const { params } = localizedRoute; | ||
if (params && params["0"] === void 0 && params.pathMatch) { | ||
params["0"] = params.pathMatch; | ||
} | ||
} | ||
const resolvedRoute = router.resolve(localizedRoute); | ||
if (isVue3 ? resolvedRoute.name : resolvedRoute.route.name) { | ||
return resolvedRoute; | ||
} | ||
return router.resolve(route); | ||
} | ||
function switchLocalePath(locale) { | ||
const route = this.route; | ||
const name = getRouteBaseName.call(this, route); | ||
if (!name) { | ||
return ""; | ||
} | ||
const _a = !isVue3 && isRef(route) ? route.value : route, { params } = _a, routeCopy = __objRest(_a, ["params"]); | ||
const langSwitchParams = {}; | ||
const baseRoute = assign({}, routeCopy, { | ||
name, | ||
params: __spreadProps(__spreadValues(__spreadValues({}, params), langSwitchParams), { | ||
0: params.pathMatch | ||
}) | ||
}); | ||
const path = localePath.call(this, baseRoute, locale); | ||
return path; | ||
} | ||
function localeHead({ addDirAttribute = false, addSeoAttributes = false } = {}) { | ||
const router = this.router; | ||
const i18n = this.i18n; | ||
const { defaultDirection } = getI18nRoutingOptions(router, this); | ||
const metaObject = { | ||
htmlAttrs: {}, | ||
link: [], | ||
meta: [] | ||
}; | ||
if (i18n.locales == null || i18n.__baseUrl == null) { | ||
return metaObject; | ||
} | ||
const locale = getLocale(i18n); | ||
const locales = getLocales(i18n); | ||
const currentLocale = getNormalizedLocales(locales).find((l) => l.code === locale) || { | ||
code: locale | ||
}; | ||
const currentLocaleIso = currentLocale.iso; | ||
const currentLocaleDir = currentLocale.dir || defaultDirection; | ||
if (addDirAttribute) { | ||
metaObject.htmlAttrs.dir = currentLocaleDir; | ||
} | ||
if (addSeoAttributes && locale && i18n.locales) { | ||
if (currentLocaleIso) { | ||
metaObject.htmlAttrs.lang = currentLocaleIso; | ||
} | ||
addHreflangLinks.call(this, locales, i18n.__baseUrl, metaObject.link); | ||
addCanonicalLinks.call(this, i18n.__baseUrl, metaObject.link, addSeoAttributes); | ||
addCurrentOgLocale(currentLocale, currentLocaleIso, metaObject.meta); | ||
addAlternateOgLocales(locales, currentLocaleIso, metaObject.meta); | ||
} | ||
return metaObject; | ||
} | ||
function addHreflangLinks(locales, baseUrl, link) { | ||
const router = this.router; | ||
const { defaultLocale, strategy } = getI18nRoutingOptions(router, this); | ||
if (strategy === STRATEGIES.NO_PREFIX) { | ||
return; | ||
} | ||
const localeMap = /* @__PURE__ */ 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.call(this, mapLocale.code); | ||
if (localePath2) { | ||
link.push({ | ||
hid: `i18n-alt-${iso}`, | ||
rel: "alternate", | ||
href: toAbsoluteUrl(localePath2, baseUrl), | ||
hreflang: iso | ||
}); | ||
} | ||
} | ||
if (defaultLocale) { | ||
const localePath2 = switchLocalePath.call(this, defaultLocale); | ||
if (localePath2) { | ||
link.push({ | ||
hid: "i18n-xd", | ||
rel: "alternate", | ||
href: toAbsoluteUrl(localePath2, baseUrl), | ||
hreflang: "x-default" | ||
}); | ||
} | ||
} | ||
} | ||
function addCanonicalLinks(baseUrl, link, seoAttributesOptions) { | ||
const route = this.route; | ||
const currentRoute = localeRoute.call(this, __spreadProps(__spreadValues({}, route), { | ||
name: getRouteBaseName.call(this, route) | ||
})); | ||
if (currentRoute) { | ||
let href = toAbsoluteUrl(currentRoute.path, baseUrl); | ||
const canonicalQueries = isObject(seoAttributesOptions) && seoAttributesOptions.canonicalQueries || []; | ||
if (canonicalQueries.length) { | ||
const currentRouteQueryParams = currentRoute.query; | ||
const params = new URLSearchParams(); | ||
for (const queryParamName of canonicalQueries) { | ||
if (queryParamName in currentRouteQueryParams) { | ||
const queryParamValue = currentRouteQueryParams[queryParamName]; | ||
if (isArray(queryParamValue)) { | ||
queryParamValue.forEach((v) => params.append(queryParamName, v || "")); | ||
} else { | ||
params.append(queryParamName, queryParamValue || ""); | ||
} | ||
} | ||
} | ||
const queryString = params.toString(); | ||
if (queryString) { | ||
href = `${href}?${queryString}`; | ||
} | ||
} | ||
link.push({ | ||
hid: "i18n-can", | ||
rel: "canonical", | ||
href | ||
}); | ||
} | ||
} | ||
function addCurrentOgLocale(currentLocale, currentLocaleIso, meta) { | ||
const hasCurrentLocaleAndIso = currentLocale && currentLocaleIso; | ||
if (!hasCurrentLocaleAndIso) { | ||
return; | ||
} | ||
meta.push({ | ||
hid: "i18n-og", | ||
property: "og:locale", | ||
content: hypenToUnderscore(currentLocaleIso) | ||
}); | ||
} | ||
function addAlternateOgLocales(locales, currentLocaleIso, meta) { | ||
const localesWithoutCurrent = locales.filter((locale) => { | ||
const localeIso = locale.iso; | ||
return localeIso && localeIso !== currentLocaleIso; | ||
}); | ||
if (localesWithoutCurrent.length) { | ||
const alternateLocales = localesWithoutCurrent.map((locale) => ({ | ||
hid: `i18n-og-alt-${locale.iso}`, | ||
property: "og:locale:alternate", | ||
content: hypenToUnderscore(locale.iso) | ||
})); | ||
meta.push(...alternateLocales); | ||
} | ||
} | ||
function hypenToUnderscore(str) { | ||
return (str || "").replace(/-/g, "_"); | ||
} | ||
function toAbsoluteUrl(urlOrPath, baseUrl) { | ||
if (urlOrPath.match(/^https?:\/\//)) { | ||
return urlOrPath; | ||
} | ||
return baseUrl + urlOrPath; | ||
} | ||
function proxyForComposable(options, target) { | ||
const { | ||
version, | ||
router, | ||
route, | ||
i18n, | ||
defaultLocale, | ||
locales, | ||
strategy, | ||
defaultLocaleRouteNameSuffix, | ||
trailingSlash, | ||
routesNameSeparator | ||
} = options; | ||
return function(...args) { | ||
return Reflect.apply(target, { | ||
router, | ||
route, | ||
i18n, | ||
defaultLocale, | ||
strategy, | ||
defaultLocaleRouteNameSuffix, | ||
trailingSlash, | ||
routesNameSeparator | ||
}, args); | ||
}; | ||
} | ||
function useRouteBaseName(givenRoute = useRoute(), { router = useRouter(), routesNameSeparator = void 0 } = {}) { | ||
const proxy = { | ||
router, | ||
route: givenRoute, | ||
routesNameSeparator | ||
}; | ||
return getRouteBaseName.call(proxy, givenRoute); | ||
} | ||
function useLocalePath({ | ||
router = useRouter(), | ||
route = useRoute(), | ||
i18n = useI18n(), | ||
defaultLocale = void 0, | ||
defaultLocaleRouteNameSuffix = void 0, | ||
routesNameSeparator = void 0, | ||
strategy = void 0, | ||
trailingSlash = void 0 | ||
} = {}) { | ||
return proxyForComposable({ router, route, i18n, defaultLocale, defaultLocaleRouteNameSuffix, routesNameSeparator, strategy, trailingSlash }, localePath); | ||
} | ||
function useLocaleRoute({ | ||
router = useRouter(), | ||
route = useRoute(), | ||
i18n = useI18n(), | ||
defaultLocale = void 0, | ||
defaultLocaleRouteNameSuffix = void 0, | ||
routesNameSeparator = void 0, | ||
strategy = void 0, | ||
trailingSlash = void 0 | ||
} = {}) { | ||
return proxyForComposable({ | ||
router, | ||
route, | ||
i18n, | ||
defaultLocale, | ||
defaultLocaleRouteNameSuffix, | ||
routesNameSeparator, | ||
strategy, | ||
trailingSlash | ||
}, localeRoute); | ||
} | ||
function useLocaleLocation({ | ||
router = useRouter(), | ||
route = useRoute(), | ||
i18n = useI18n(), | ||
defaultLocale = void 0, | ||
defaultLocaleRouteNameSuffix = void 0, | ||
routesNameSeparator = void 0, | ||
strategy = void 0, | ||
trailingSlash = void 0 | ||
} = {}) { | ||
return proxyForComposable({ | ||
router, | ||
route, | ||
i18n, | ||
defaultLocale, | ||
defaultLocaleRouteNameSuffix, | ||
routes | ||
} = asDefaultVueI18nRouterOptions(options); | ||
const normalizedLocaleCodes = getNormalizedLocales(locales); | ||
const localeCodes = normalizedLocaleCodes.map((l) => l.code); | ||
const getLocaleFromRoute = createLocaleFromRouteGetter(localeCodes, routesNameSeparator, defaultLocaleRouteNameSuffix); | ||
extendI18n(i18n, { locales: normalizedLocaleCodes }); | ||
const localizedRoutes = localizeRoutes(routes, { | ||
locales, | ||
routesNameSeparator, | ||
strategy, | ||
trailingSlash | ||
}, localeLocation); | ||
} | ||
function useSwitchLocalePath({ | ||
router = useRouter(), | ||
route = useRoute(), | ||
i18n = useI18n(), | ||
defaultLocale = void 0, | ||
defaultLocaleRouteNameSuffix = void 0, | ||
routesNameSeparator = void 0, | ||
strategy = void 0, | ||
trailingSlash = void 0 | ||
} = {}) { | ||
return proxyForComposable({ | ||
router, | ||
route, | ||
i18n, | ||
defaultLocale, | ||
defaultLocaleRouteNameSuffix, | ||
routesNameSeparator, | ||
strategy, | ||
trailingSlash, | ||
routesNameSeparator, | ||
defaultLocaleRouteNameSuffix | ||
trailingSlash | ||
}, switchLocalePath); | ||
} | ||
function useLocaleHead({ | ||
addDirAttribute = false, | ||
addSeoAttributes = false, | ||
strategy = void 0, | ||
defaultLocale = void 0, | ||
route = useRoute(), | ||
router = useRouter(), | ||
i18n = useI18n() | ||
} = {}) { | ||
const _router = router; | ||
const metaObject = ref({ | ||
htmlAttrs: {}, | ||
link: [], | ||
meta: [] | ||
}); | ||
options.routes = localizedRoutes; | ||
let router = null; | ||
if (isVue3 && version === 4) { | ||
router = createRouter$1(options); | ||
} else if (isVue2 && version === 3) { | ||
router = new VueRouter3(options); | ||
function cleanMeta() { | ||
metaObject.value = { | ||
htmlAttrs: {}, | ||
link: [], | ||
meta: [] | ||
}; | ||
} | ||
function updateMeta(_route) { | ||
metaObject.value = Reflect.apply(localeHead, { | ||
router, | ||
route: _route, | ||
i18n, | ||
defaultLocale, | ||
strategy | ||
}, [{ addDirAttribute, addSeoAttributes }]); | ||
} | ||
if (inBrowser) { | ||
if (isVue3) { | ||
const stop = watchEffect(() => { | ||
cleanMeta(); | ||
updateMeta(toRawRoute(_router.currentRoute)); | ||
}); | ||
onUnmounted(() => stop()); | ||
} else { | ||
const handler = _router.afterEach((to, from) => { | ||
cleanMeta(); | ||
updateMeta(to); | ||
}); | ||
onUnmounted(() => handler()); | ||
updateMeta(route); | ||
} | ||
} else { | ||
throw new Error("TODO:"); | ||
updateMeta(toRawRoute(_router.currentRoute)); | ||
} | ||
router.__defaultLocale = defaultLocale; | ||
router.__localeCodes = localeCodes; | ||
router.__strategy = strategy; | ||
router.__trailingSlash = trailingSlash; | ||
router.__routesNameSeparator = routesNameSeparator; | ||
router.__defaultLocaleRouteNameSuffix = defaultLocaleRouteNameSuffix; | ||
router.beforeEach((to, from, next) => { | ||
console.log("beforeEach", to, from); | ||
const currentLocale = getLocale(i18n); | ||
const finalLocale = getLocaleFromRoute(to) || currentLocale || defaultLocale || ""; | ||
console.log("currentLocale", currentLocale, "finalLocale", finalLocale); | ||
if (currentLocale !== finalLocale) { | ||
setLocale(i18n, finalLocale); | ||
} | ||
next(); | ||
}); | ||
console.log("create router", router); | ||
return router; | ||
return metaObject; | ||
} | ||
const VERSION = "0.0.0"; | ||
export { VERSION, createRouter, localizeRoutes, useI18nRouting }; | ||
export { DEFAULT_BASE_URL, DEFAULT_DETECTION_DIRECTION, DEFAULT_LOCALE, DEFAULT_LOCALE_ROUTE_NAME_SUFFIX, DEFAULT_ROUTES_NAME_SEPARATOR, DEFAULT_STRATEGY, DEFAULT_TRAILING_SLASH, STRATEGIES, VERSION, createLocaleFromRouteGetter, createRouter, extendI18n, findBrowserLocale, getGlobalOptions, getLocale, getLocalesRegex, getRouteBaseName, isComposer, isExportedGlobalComposer, isI18nInstance, isLegacyVueI18n, isVueI18n, localeHead, localeLocation, localePath, localeRoute, localizeRoutes, proxyVueInstance, registerGlobalOptions, resolveBaseUrl, resolveRoute, setLocale, switchLocalePath, useLocaleHead, useLocaleLocation, useLocalePath, useLocaleRoute, useRouteBaseName, useSwitchLocalePath }; |
@@ -1,5 +0,5 @@ | ||
var he=Object.defineProperty,Re=Object.defineProperties;var me=Object.getOwnPropertyDescriptors;var U=Object.getOwnPropertySymbols;var J=Object.prototype.hasOwnProperty,K=Object.prototype.propertyIsEnumerable;var Q=(c,a,s)=>a in c?he(c,a,{enumerable:!0,configurable:!0,writable:!0,value:s}):c[a]=s,y=(c,a)=>{for(var s in a||(a={}))J.call(a,s)&&Q(c,s,a[s]);if(U)for(var s of U(a))K.call(a,s)&&Q(c,s,a[s]);return c},z=(c,a)=>Re(c,me(a));var Z=(c,a)=>{var s={};for(var p in c)J.call(c,p)&&a.indexOf(p)<0&&(s[p]=c[p]);if(c!=null&&U)for(var p of U(c))a.indexOf(p)<0&&K.call(c,p)&&(s[p]=c[p]);return s};var VueI18nRouting=function(c,a,s,p){"use strict";function ee(e){return e&&typeof e=="object"&&"default"in e?e:{default:e}}var te=ee(s);/*! | ||
* shared v9.2.0-beta.28 | ||
var VueI18nRouting=function(s,d,L,_){"use strict";var ht=Object.defineProperty,Lt=Object.defineProperties;var gt=Object.getOwnPropertyDescriptors;var Q=Object.getOwnPropertySymbols;var ye=Object.prototype.hasOwnProperty,Ce=Object.prototype.propertyIsEnumerable;var Pe=(s,d,L)=>d in s?ht(s,d,{enumerable:!0,configurable:!0,writable:!0,value:L}):s[d]=L,O=(s,d)=>{for(var L in d||(d={}))ye.call(d,L)&&Pe(s,L,d[L]);if(Q)for(var L of Q(d))Ce.call(d,L)&&Pe(s,L,d[L]);return s},Y=(s,d)=>Lt(s,gt(d));var Oe=(s,d)=>{var L={};for(var _ in s)ye.call(s,_)&&d.indexOf(_)<0&&(L[_]=s[_]);if(s!=null&&Q)for(var _ of Q(s))d.indexOf(_)<0&&Ce.call(s,_)&&(L[_]=s[_]);return L};function Ue(e){return e&&typeof e=="object"&&"default"in e?e:{default:e}}var be=Ue(L);const U={PREFIX:"prefix",PREFIX_EXCEPT_DEFAULT:"prefix_except_default",PREFIX_AND_DEFAULT:"prefix_and_default",NO_PREFIX:"no_prefix"},G="",D=U.PREFIX_EXCEPT_DEFAULT,B=!1,X="___",M="default",J="ltr",K="";/*! | ||
* shared v9.2.0-beta.35 | ||
* (c) 2022 kazuya kawaguchi | ||
* Released under the MIT License. | ||
*/const C=Object.assign,b=e=>typeof e=="string",ae=e=>typeof e=="symbol";function oe(e){e=e||[];const t=[];for(const o of e)b(o)?t.push({code:o}):t.push(o);return t}function w(e,t){return a.isRef(e.locale)&&t==="composition"}function X(e){return"global"in e&&"mode"in e}function M(e){return X(e)?w(e.global,e.mode)?e.global.locale.value:e.global.locale:e.locale.value}function le(e,t){X(e)?w(e.global,e.mode)?e.global.locale.value=t:e.global.locale=t:a.isRef(e.locale)&&(e.locale.value=t)}function ne(e,t,o){return e.replace(/\/+$/,"")+(t?"/":"")||(o?"":"/")}function j(e){return b(e)?e:ae(e)?e.toString():"(null)"}function G(e,t,{defaultLocale:o,strategy:u,routesNameSeparator:i,defaultLocaleRouteNameSuffix:h}){let d=j(e)+(u==="no_prefix"?"":i+t);return t===o&&u==="prefix_and_default"&&(d+=i+h),d}function ce(e={}){var R,S,F,x,m,L,v;const t=(R=e.i18n)!=null?R:p.useI18n(),o=(S=e.router)!=null?S:s.useRouter(),u=(F=e.route)!=null?F:s.useRoute(),i=(x=e.defaultLocaleRouteNameSuffix)!=null?x:o.__defaultLocaleRouteNameSuffix,h=(m=e.defaultLocale)!=null?m:o.__defaultLocale,d=(L=e.routesNameSeparator)!=null?L:o.__routesNameSeparator,E=(v=e.strategy)!=null?v:o.__strategy;function f(r){const _=r!=null?r:a.isRef(u)?u.value:u;return _.name?j(_.name).split(d)[0]:null}function g(r,_){const n=_||M(t);let A=r;b(r)&&(r[0]==="/"?A={path:r}:A={name:r});let T=C({},A);if(T.path&&!T.name){const $=o.resolve(T),N=a.isVue2?$.route:$,Y=f(N);b(Y)&&(T={name:G(Y,n,{defaultLocale:h,strategy:E,routesNameSeparator:d,defaultLocaleRouteNameSuffix:i}),params:N.params,query:N.query,hash:N.hash})}else{T.name=G(T.name,n,{defaultLocale:h,strategy:E,routesNameSeparator:d,defaultLocaleRouteNameSuffix:i});const{params:$}=T;$&&$["0"]===void 0&&$.pathMatch&&($["0"]=$.pathMatch)}const V=o.resolve(T);return(a.isVue2?V.route.name:V.name)?V:o.resolve(r)}function l(r,_){const n=g(r,_);return n==null?"":a.isVue2?n.route.redirectedFrom||n.route.fullPath:n.redirectedFrom||n.fullPath}function I(r,_){const n=g(r,_);return n==null?void 0:a.isVue2?n.route:n}function P(r,_){const n=g(r,_);return n==null?void 0:a.isVue2?n.location:n}function O(r){const _=f();if(!_)return"";const N=a.isVue2&&a.isRef(u)?u.value:u,{params:n}=N,A=Z(N,["params"]),T={},V=C({},A,{name:_,params:z(y(y({},n),T),{0:n.pathMatch})}),$=l(V,r);return console.log("switchLocalePath",t.locale.value,r,$),$}return{getRouteBaseName:f,localePath:l,localeRoute:I,localeLocation:P,switchLocalePath:O}}const re={PREFIX:"prefix",PREFIX_EXCEPT_DEFAULT:"prefix_except_default",PREFIX_AND_DEFAULT:"prefix_and_default",NO_PREFIX:"no_prefix"},q="",D=re.PREFIX_EXCEPT_DEFAULT,W=!1,k="___",B="default";function H(e,{defaultLocale:t=q,strategy:o=D,trailingSlash:u=W,routesNameSeparator:i=k,defaultLocaleRouteNameSuffix:h=B,includeUprefixedFallback:d=!1,locales:E=[]}={}){if(o==="no_prefix")return e;const f=E.map(l=>b(l)?l:l.code);function g(l,I,P=!1,O=!1){return l.redirect&&(!l.component||!l.file)?[l]:I.reduce((S,F)=>{const{name:x}=l;let{path:m}=l;const L=y({},l);x&&(L.name=`${x}${i}${F}`),l.children&&(L.children=l.children.reduce((n,A)=>[...n,...g(A,[F],!0,O)],[]));const v=F===t;if(v&&o==="prefix_and_default")if(P)P&&O&&x&&(L.name+=`${i}${h}`);else{const n=z(y({},L),{path:m});if(x&&(n.name=`${L.name}${i}${h}`),l.children){n.children=[];for(const A of l.children)n.children=n.children.concat(g(A,[F],!0,!0))}S.push(n)}const r=P&&!m.startsWith("/"),_=!r&&!(v&&o==="prefix_except_default");return _&&(m=`/${F}${m}`),m&&(m=ne(m,u,r)),_&&v&&o==="prefix"&&d&&S.push(y({},l)),L.path=m,S.push(L),S},[])}return e.reduce((l,I)=>[...l,...g(I,f||[])],[])}function ue(e,{locales:t=[]}={}){if(!w(e.global,e.mode))throw new Error("TODO:");const o=a.ref(t);e.global.locales=a.computed(()=>o.value),console.log("... extends i18n done")}function se(e){return new RegExp(`^/(${e.join("|")})(?:/|$)`,"i")}function fe(e,t,o){const u=`(${e.join("|")})`,i=`(?:${t}${o})?`,h=new RegExp(`${t}${u}${i}$`,"i"),d=se(e);return f=>{if(f.name){const l=(b(f.name)?f.name:f.name.toString()).match(h);if(l&&l.length>1)return l[1]}else if(f.path){const g=f.path.match(d);if(g&&g.length>1)return g[1]}return""}}function ie(e){var t,o,u,i,h,d,E,f;return e.version=(t=e.version)!=null?t:4,e.defaultLocale=(o=e.defaultLocale)!=null?o:q,e.strategy=(u=e.strategy)!=null?u:D,e.trailingSlash=(i=e.trailingSlash)!=null?i:W,e.routesNameSeparator=(h=e.routesNameSeparator)!=null?h:k,e.defaultLocaleRouteNameSuffix=(d=e.defaultLocaleRouteNameSuffix)!=null?d:B,e.locales=(E=e.locales)!=null?E:[],e.routes=(f=e.routes)!=null?f:[],e}function de(e,t={}){const{version:o,defaultLocale:u,locales:i,strategy:h,trailingSlash:d,routesNameSeparator:E,defaultLocaleRouteNameSuffix:f,routes:g}=ie(t),l=oe(i),I=l.map(S=>S.code),P=fe(I,E,f);ue(e,{locales:l});const O=H(g,{locales:i,defaultLocale:u,strategy:h,trailingSlash:d,routesNameSeparator:E,defaultLocaleRouteNameSuffix:f});t.routes=O;let R=null;if(a.isVue3&&o===4)R=s.createRouter(t);else if(a.isVue2&&o===3)R=new te.default(t);else throw new Error("TODO:");return R.__defaultLocale=u,R.__localeCodes=I,R.__strategy=h,R.__trailingSlash=d,R.__routesNameSeparator=E,R.__defaultLocaleRouteNameSuffix=f,R.beforeEach((S,F,x)=>{console.log("beforeEach",S,F);const m=M(e),L=P(S)||m||u||"";console.log("currentLocale",m,"finalLocale",L),m!==L&&le(e,L),x()}),console.log("create router",R),R}const _e="0.0.0";return c.VERSION=_e,c.createRouter=de,c.localizeRoutes=H,c.useI18nRouting=ce,Object.defineProperty(c,"__esModule",{value:!0}),c[Symbol.toStringTag]="Module",c}({},VueDemi,VueRouter,VueI18n); | ||
*/const Fe=typeof Symbol=="function"&&typeof Symbol.toStringTag=="symbol",Ne=e=>Fe?Symbol(e):e,se=Object.assign,we=Array.isArray,$e=e=>typeof e=="function",T=e=>typeof e=="string",ve=e=>typeof e=="boolean",Ve=e=>typeof e=="symbol",Z=e=>e!==null&&typeof e=="object",je=/\/$|\/\?/;function ee(e="",t=!1){return t?je.test(e):e.endsWith("/")}function Ge(e="",t=!1){if(!t)return(ee(e)?e.slice(0,-1):e)||"/";if(!ee(e,!0))return e||"/";const[o,...n]=e.split("?");return(o.slice(0,-1)||"/")+(n.length?`?${n.join("?")}`:"")}function De(e="",t=!1){if(!t)return e.endsWith("/")?e:e+"/";if(ee(e,!0))return e||"/";const[o,...n]=e.split("?");return o+"/"+(n.length?`?${n.join("?")}`:"")}const Be=typeof window!="undefined";function re(e,t){typeof console!="undefined"&&(console.warn("[vue-i18n-routing] "+e),t&&console.warn(t.stack))}function ie(e){e=e||[];const t=[];for(const o of e)T(o)?t.push({code:o}):t.push(o);return t}function w(e){return e!=null&&"global"in e&&"mode"in e}function $(e){return e!=null&&!("__composer"in e)&&d.isRef(e.locale)}function b(e){return e!=null&&"__composer"in e}function k(e){return e!=null&&!("__composer"in e)&&!d.isRef(e.locale)}function P(e){return e!=null&&("__VUE_I18N_BRIDGE__"in e||"_sync"in e)}function ue(e){return w(e)?$(e.global)?e.global:e.global.__composer:b(e)?e.__composer:e}function z(e){const t=w(e)?e.global:e;return $(t)?d.isVue2&&P(e)?e.locale:t.locale.value:(k(t)||b(t)||P(t),t.locale)}function Xe(e){const t=w(e)?e.global:e;return $(t)?d.isVue2&&P(e)?e.locales:t.locales.value:(k(t)||b(t)||P(t),t.locales)}function fe(e,t){const o=w(e)?e.global:e;if($(o))d.isVue2&&P(e)?e.locale=t:o.locale.value=t;else if(k(o)||b(o)||P(o))o.locale=t;else throw new Error("TODO:")}function Me(e,t,o){return e.replace(/\/+$/,"")+(t?"/":"")||(o?"":"/")}function de(e){return L.isVueRouter4,d.isRef(e)?e.value:e}function he(e){return T(e)?e:Ve(e)?e.toString():"(null)"}function Le(e,t,{defaultLocale:o,strategy:n,routesNameSeparator:l,defaultLocaleRouteNameSuffix:a}){let c=he(e)+(n==="no_prefix"?"":l+t);return t===o&&n==="prefix_and_default"&&(c+=l+a),c}function ge(e,t){return $e(e)?e(t):e}function ke(e,t){const o=[];for(const[n,l]of t.entries()){const a=e.find(c=>c.iso.toLowerCase()===l.toLowerCase());if(a){o.push({code:a.code,score:1-n/t.length});break}}for(const[n,l]of t.entries()){const a=l.split("-")[0].toLowerCase(),c=e.find(r=>r.iso.split("-")[0].toLowerCase()===a);if(c){o.push({code:c.code,score:.999-n/t.length});break}}return o}const ze=ke;function He(e,t){return e.score===t.score?t.code.length-e.code.length:t.score-e.score}const qe=He;function xe(e,t,{matcher:o=ze,comparer:n=qe}={}){const l=[];for(const c of e){const{code:r}=c,i=c.iso||r;l.push({code:r,iso:i})}const a=o(l,t);return a.length>1&&a.sort(n),a.length?a[0].code:""}function I(e){return function(){return Reflect.apply(e,{getRouteBaseName:this.getRouteBaseName,localePath:this.localePath,localeRoute:this.localeRoute,localeLocation:this.localeLocation,resolveRoute:this.resolveRoute,switchLocalePath:this.switchLocalePath,localeHead:this.localeHead,i18n:this.$i18n,route:this.$route,router:this.$router},arguments)}}function _e(e,{locales:t=[],localeCodes:o=[],baseUrl:n=K,hooks:l={}}={}){const a=d.effectScope(),c=e.install;return e.install=(r,...i)=>{Reflect.apply(c,e,[r,...i]);const f=ue(e);a.run(()=>We(f,{locales:t,localeCodes:o,baseUrl:n,hooks:l})),b(e.global)&&Ye(e.global,l.onExtendVueI18n);const h=r,u=e.mode==="composition"?d.isVue3?h.config.globalProperties.$i18n:e:d.isVue2?e:null;if(u&&Qe(u,f,l.onExtendExportedGlobal),(Je(i[0])?i[0]:{inject:!0}).inject&&r.mixin({methods:{resolveRoute:I(v),localePath:I(q),localeRoute:I(x),localeLocation:I(oe),switchLocalePath:I(V),getRouteBaseName:I(F),localeHead:I(ne)}}),h.unmount){const g=h.unmount;h.unmount=()=>{a.stop(),g()}}},a}function We(e,t){const{locales:o,localeCodes:n,baseUrl:l}=t,a=d.ref(o),c=d.ref(n);e.locales=d.computed(()=>a.value),e.localeCodes=d.computed(()=>c.value),e.__baseUrl=ge(l,{}),t.hooks&&t.hooks.onExtendComposer&&t.hooks.onExtendComposer(e)}function Qe(e,t,o){const n=[{locales:{get(){return t.locales.value}},localeCodes:{get(){return t.localeCodes.value}},__baseUrl:{get(){return t.__baseUrl}}}];o&&n.push(o(t));for(const l of n)for(const[a,c]of Object.entries(l))Object.defineProperty(e,a,c)}function Ye(e,t){const o=ue(e),n=[{locales:{get(){return o.locales.value}},localeCodes:{get(){return o.localeCodes.value}},__baseUrl:{get(){return o.__baseUrl}}}];t&&n.push(t(o));for(const l of n)for(const[a,c]of Object.entries(l))Object.defineProperty(e,a,c)}function Je(e){return Z(e)&&"inject"in e&&ve(e.inject)}function me(e,{defaultLocale:t=G,strategy:o=D,trailingSlash:n=B,routesNameSeparator:l=X,defaultLocaleRouteNameSuffix:a=M,includeUprefixedFallback:c=!1,optionsResolver:r=void 0,locales:i=[]}={}){if(o==="no_prefix")return e;const f=i.map(u=>T(u)?u:u.code);function h(u,m,g=!1,R=!1){if(u.redirect&&(!u.component||!u.file))return[u];let y=null;return r!=null&&(y=r(u,m),y==null)?[u]:m.reduce((S,A)=>{const{name:j}=u;let{path:E}=u;const p=O({},u);j&&(p.name=`${j}${l}${A}`),u.children&&(p.children=u.children.reduce((C,ce)=>[...C,...h(ce,[A],!0,R)],[]));const N=A===t;if(N&&o==="prefix_and_default")if(g)g&&R&&j&&(p.name+=`${l}${a}`);else{const C=Y(O({},p),{path:E});if(j&&(C.name=`${p.name}${l}${a}`),u.children){C.children=[];for(const ce of u.children)C.children=C.children.concat(h(ce,[A],!0,!0))}S.push(C)}const Ie=g&&!E.startsWith("/"),Te=!Ie&&!(N&&o==="prefix_except_default");return Te&&(E=`/${A}${E}`),E&&(E=Me(E,n,Ie)),Te&&N&&o==="prefix"&&c&&S.push(O({},u)),p.path=E,S.push(p),S},[])}return e.reduce((u,m)=>[...u,...h(m,f||[])],[])}const te=Ne("vue-i18n-routing-gor");function Re(e,t){e[te]?re("already registered global options"):e[te]=t}function Ee(e){var t;return(t=e[te])!=null?t:{}}function Ke(e,t={}){const{version:o,defaultLocale:n,locales:l,strategy:a,trailingSlash:c,routesNameSeparator:r,defaultLocaleRouteNameSuffix:i,defaultDirection:f,baseUrl:h,routes:u,routeOptionsResolver:m}=et(t),g=ie(l),R=g.map(A=>A.code),y=Se(R,r,i);_e(e,{locales:g,baseUrl:h,localeCodes:R});const le=me(u,{locales:l,defaultLocale:n,strategy:a,trailingSlash:c,routesNameSeparator:r,defaultLocaleRouteNameSuffix:i,optionsResolver:m});t.routes=le;const S=Ze(t,o);return Re(S,{defaultLocale:n,localeCodes:R,strategy:a,trailingSlash:c,routesNameSeparator:r,defaultLocaleRouteNameSuffix:i,defaultDirection:f}),S.beforeEach((A,j,E)=>{const p=z(e),N=y(A)||p||n||"";p!==N&&fe(e,N),E()}),S}function Ze(e,t){if(d.isVue3&&t===4)return L.createRouter(e);if(d.isVue2&&t===3)return new be.default(e);throw new Error("TODO:")}function pe(e){return new RegExp(`^/(${e.join("|")})(?:/|$)`,"i")}function Se(e,t,o){const n=`(${e.join("|")})`,l=`(?:${t}${o})?`,a=new RegExp(`${t}${n}${l}$`,"i"),c=pe(e);return i=>{if(Z(i)){if(i.name){const h=(T(i.name)?i.name:i.name.toString()).match(a);if(h&&h.length>1)return h[1]}else if(i.path){const f=i.path.match(c);if(f&&f.length>1)return f[1]}}else if(T(i)){const f=i.match(c);if(f&&f.length>1)return f[1]}return""}}function et(e){var t,o,n,l,a,c,r,i,f,h;return e.version=(t=e.version)!=null?t:4,e.defaultLocale=(o=e.defaultLocale)!=null?o:G,e.strategy=(n=e.strategy)!=null?n:D,e.trailingSlash=(l=e.trailingSlash)!=null?l:B,e.routesNameSeparator=(a=e.routesNameSeparator)!=null?a:X,e.defaultLocaleRouteNameSuffix=(c=e.defaultLocaleRouteNameSuffix)!=null?c:M,e.locales=(r=e.locales)!=null?r:[],e.defaultDirection=(i=e.defaultDirection)!=null?i:J,e.baseUrl=(f=e.baseUrl)!=null?f:K,e.routes=(h=e.routes)!=null?h:[],e}function H(e,t,{defaultLocale:o=G,defaultDirection:n=J,defaultLocaleRouteNameSuffix:l=M,routesNameSeparator:a=X,strategy:c=D,trailingSlash:r=B,localeCodes:i=[]}={}){const f=Ee(e);return{defaultLocale:t.defaultLocale||f.defaultLocale||o,defaultDirection:t.defaultDirection||f.defaultDirection||n,defaultLocaleRouteNameSuffix:t.defaultLocaleRouteNameSuffix||f.defaultLocaleRouteNameSuffix||l,routesNameSeparator:t.routesNameSeparator||f.routesNameSeparator||a,strategy:t.strategy||f.strategy||c,trailingSlash:t.trailingSlash||f.trailingSlash||r,localeCodes:t.localeCodes||f.localeCodes||i}}const tt=new Set([U.PREFIX_AND_DEFAULT,U.PREFIX_EXCEPT_DEFAULT]);function F(e){const t=this.router,{routesNameSeparator:o}=H(t,this),n=e!=null?d.isRef(e)?d.unref(e):e:this.route;return n.name?he(n.name).split(o)[0]:void 0}function q(e,t){const o=v.call(this,e,t);return o==null?"":d.isVue3?o.redirectedFrom||o.fullPath:o.route.redirectedFrom||o.route.fullPath}function x(e,t){const o=v.call(this,e,t);return o==null?void 0:d.isVue3?o:o.route}function oe(e,t){const o=v.call(this,e,t);return o==null?void 0:d.isVue3?o:o.location}function v(e,t){const o=this.router,n=this.i18n,l=t||z(n),{routesNameSeparator:a,defaultLocale:c,defaultLocaleRouteNameSuffix:r,strategy:i,trailingSlash:f}=H(o,this);let h=e;T(e)&&(h[0]==="/"?h={path:e}:h={name:e});let u=se({},h);if(u.path&&!u.name){const g=o.resolve(u),R=d.isVue3?g:g.route,y=F.call(this,R);T(y)?u={name:Le(y,l,{defaultLocale:c,strategy:i,routesNameSeparator:a,defaultLocaleRouteNameSuffix:r}),params:R.params,query:R.query,hash:R.hash}:(!(l===c&&tt.has(i))&&i!==U.NO_PREFIX&&(u.path=`/${l}${u.path}`),u.path=f?De(u.path,!0):Ge(u.path,!0))}else{u.name=Le(u.name,l,{defaultLocale:c,strategy:i,routesNameSeparator:a,defaultLocaleRouteNameSuffix:r});const{params:g}=u;g&&g["0"]===void 0&&g.pathMatch&&(g["0"]=g.pathMatch)}const m=o.resolve(u);return(d.isVue3?m.name:m.route.name)?m:o.resolve(e)}function V(e){const t=this.route,o=F.call(this,t);if(!o)return"";const i=!d.isVue3&&d.isRef(t)?t.value:t,{params:n}=i,l=Oe(i,["params"]),a={},c=se({},l,{name:o,params:Y(O(O({},n),a),{0:n.pathMatch})});return q.call(this,c,e)}function ne({addDirAttribute:e=!1,addSeoAttributes:t=!1}={}){const o=this.router,n=this.i18n,{defaultDirection:l}=H(o,this),a={htmlAttrs:{},link:[],meta:[]};if(n.locales==null||n.__baseUrl==null)return a;const c=z(n),r=Xe(n),i=ie(r).find(u=>u.code===c)||{code:c},f=i.iso,h=i.dir||l;return e&&(a.htmlAttrs.dir=h),t&&c&&n.locales&&(f&&(a.htmlAttrs.lang=f),ot.call(this,r,n.__baseUrl,a.link),nt.call(this,n.__baseUrl,a.link,t),at(i,f,a.meta),lt(r,f,a.meta)),a}function ot(e,t,o){const n=this.router,{defaultLocale:l,strategy:a}=H(n,this);if(a===U.NO_PREFIX)return;const c=new Map;for(const r of e){const i=r.iso;if(!i){re("Locale ISO code is required to generate alternate link");continue}const[f,h]=i.split("-");f&&h&&(r.isCatchallLocale||!c.has(f))&&c.set(f,r),c.set(i,r)}for(const[r,i]of c.entries()){const f=V.call(this,i.code);f&&o.push({hid:`i18n-alt-${r}`,rel:"alternate",href:ae(f,t),hreflang:r})}if(l){const r=V.call(this,l);r&&o.push({hid:"i18n-xd",rel:"alternate",href:ae(r,t),hreflang:"x-default"})}}function nt(e,t,o){const n=this.route,l=x.call(this,Y(O({},n),{name:F.call(this,n)}));if(l){let a=ae(l.path,e);const c=Z(o)&&o.canonicalQueries||[];if(c.length){const r=l.query,i=new URLSearchParams;for(const h of c)if(h in r){const u=r[h];we(u)?u.forEach(m=>i.append(h,m||"")):i.append(h,u||"")}const f=i.toString();f&&(a=`${a}?${f}`)}t.push({hid:"i18n-can",rel:"canonical",href:a})}}function at(e,t,o){!(e&&t)||o.push({hid:"i18n-og",property:"og:locale",content:Ae(t)})}function lt(e,t,o){const n=e.filter(l=>{const a=l.iso;return a&&a!==t});if(n.length){const l=n.map(a=>({hid:`i18n-og-alt-${a.iso}`,property:"og:locale:alternate",content:Ae(a.iso)}));o.push(...l)}}function Ae(e){return(e||"").replace(/-/g,"_")}function ae(e,t){return e.match(/^https?:\/\//)?e:t+e}function W(e,t){const{router:o,route:n,i18n:l,defaultLocale:a,strategy:c,defaultLocaleRouteNameSuffix:r,trailingSlash:i,routesNameSeparator:f}=e;return function(...h){return Reflect.apply(t,{router:o,route:n,i18n:l,defaultLocale:a,strategy:c,defaultLocaleRouteNameSuffix:r,trailingSlash:i,routesNameSeparator:f},h)}}function ct(e=L.useRoute(),{router:t=L.useRouter(),routesNameSeparator:o=void 0}={}){const n={router:t,route:e,routesNameSeparator:o};return F.call(n,e)}function st({router:e=L.useRouter(),route:t=L.useRoute(),i18n:o=_.useI18n(),defaultLocale:n=void 0,defaultLocaleRouteNameSuffix:l=void 0,routesNameSeparator:a=void 0,strategy:c=void 0,trailingSlash:r=void 0}={}){return W({router:e,route:t,i18n:o,defaultLocale:n,defaultLocaleRouteNameSuffix:l,routesNameSeparator:a,strategy:c,trailingSlash:r},q)}function rt({router:e=L.useRouter(),route:t=L.useRoute(),i18n:o=_.useI18n(),defaultLocale:n=void 0,defaultLocaleRouteNameSuffix:l=void 0,routesNameSeparator:a=void 0,strategy:c=void 0,trailingSlash:r=void 0}={}){return W({router:e,route:t,i18n:o,defaultLocale:n,defaultLocaleRouteNameSuffix:l,routesNameSeparator:a,strategy:c,trailingSlash:r},x)}function it({router:e=L.useRouter(),route:t=L.useRoute(),i18n:o=_.useI18n(),defaultLocale:n=void 0,defaultLocaleRouteNameSuffix:l=void 0,routesNameSeparator:a=void 0,strategy:c=void 0,trailingSlash:r=void 0}={}){return W({router:e,route:t,i18n:o,defaultLocale:n,defaultLocaleRouteNameSuffix:l,routesNameSeparator:a,strategy:c,trailingSlash:r},oe)}function ut({router:e=L.useRouter(),route:t=L.useRoute(),i18n:o=_.useI18n(),defaultLocale:n=void 0,defaultLocaleRouteNameSuffix:l=void 0,routesNameSeparator:a=void 0,strategy:c=void 0,trailingSlash:r=void 0}={}){return W({router:e,route:t,i18n:o,defaultLocale:n,defaultLocaleRouteNameSuffix:l,routesNameSeparator:a,strategy:c,trailingSlash:r},V)}function ft({addDirAttribute:e=!1,addSeoAttributes:t=!1,strategy:o=void 0,defaultLocale:n=void 0,route:l=L.useRoute(),router:a=L.useRouter(),i18n:c=_.useI18n()}={}){const r=a,i=d.ref({htmlAttrs:{},link:[],meta:[]});function f(){i.value={htmlAttrs:{},link:[],meta:[]}}function h(u){i.value=Reflect.apply(ne,{router:a,route:u,i18n:c,defaultLocale:n,strategy:o},[{addDirAttribute:e,addSeoAttributes:t}])}if(Be)if(d.isVue3){const u=d.watchEffect(()=>{f(),h(de(r.currentRoute))});d.onUnmounted(()=>u())}else{const u=r.afterEach((m,g)=>{f(),h(m)});d.onUnmounted(()=>u()),h(l)}else h(de(r.currentRoute));return i}const dt="0.0.0";return s.DEFAULT_BASE_URL=K,s.DEFAULT_DETECTION_DIRECTION=J,s.DEFAULT_LOCALE=G,s.DEFAULT_LOCALE_ROUTE_NAME_SUFFIX=M,s.DEFAULT_ROUTES_NAME_SEPARATOR=X,s.DEFAULT_STRATEGY=D,s.DEFAULT_TRAILING_SLASH=B,s.STRATEGIES=U,s.VERSION=dt,s.createLocaleFromRouteGetter=Se,s.createRouter=Ke,s.extendI18n=_e,s.findBrowserLocale=xe,s.getGlobalOptions=Ee,s.getLocale=z,s.getLocalesRegex=pe,s.getRouteBaseName=F,s.isComposer=$,s.isExportedGlobalComposer=k,s.isI18nInstance=w,s.isLegacyVueI18n=P,s.isVueI18n=b,s.localeHead=ne,s.localeLocation=oe,s.localePath=q,s.localeRoute=x,s.localizeRoutes=me,s.proxyVueInstance=I,s.registerGlobalOptions=Re,s.resolveBaseUrl=ge,s.resolveRoute=v,s.setLocale=fe,s.switchLocalePath=V,s.useLocaleHead=ft,s.useLocaleLocation=it,s.useLocalePath=st,s.useLocaleRoute=rt,s.useRouteBaseName=ct,s.useSwitchLocalePath=ut,Object.defineProperties(s,{__esModule:{value:!0},[Symbol.toStringTag]:{value:"Module"}}),s}({},VueDemi,VueRouter,VueI18n); |
{ | ||
"name": "vue-i18n-routing", | ||
"description": "The i18n routing with using vue-i18n", | ||
"version": "0.0.0-5165052", | ||
"version": "0.0.0-6058846", | ||
"dependencies": { | ||
"@intlify/shared": "beta", | ||
"@intlify/vue-i18n-bridge": "^0.3.4", | ||
"@intlify/vue-router-bridge": "^0.3.4", | ||
"@intlify/shared": "next", | ||
"@intlify/vue-i18n-bridge": "^0.3.5", | ||
"@intlify/vue-router-bridge": "^0.3.5", | ||
"ufo": "^0.7.9", | ||
"vue-demi": "^0.12.1" | ||
@@ -16,12 +17,13 @@ }, | ||
"rimraf": "^3.0.2", | ||
"typescript": "^4.5.4", | ||
"vite": "^2.7.4", | ||
"typescript": "^4.6.3", | ||
"vite": "^2.9.8", | ||
"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-bridge": "next", | ||
"vue-i18n-legacy": "npm:vue-i18n@8", | ||
"vue-router": "^4.0.15", | ||
"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" | ||
@@ -32,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.35", | ||
"vue-i18n-bridge": "^9.2.0-beta.35", | ||
"vue-router": "^3.5.3 || ^4.0.0" | ||
@@ -51,2 +53,3 @@ }, | ||
"index.mjs", | ||
"types.d.ts", | ||
"LICENSE", | ||
@@ -66,4 +69,10 @@ "README.md" | ||
}, | ||
"require": "./dist/vue-i18n-routing.cjs.js" | ||
} | ||
"require": "./dist/vue-i18n-routing.cjs.js", | ||
"types": "./dist/vue-i18n-routing.d.ts" | ||
}, | ||
"./types": { | ||
"types": "./types.d.ts" | ||
}, | ||
"./package.json": "./package.json", | ||
"./dist/*": "./dist/*" | ||
}, | ||
@@ -95,4 +104,7 @@ "license": "MIT", | ||
"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" | ||
} | ||
} |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
96392
11
1750
10
16
1
+ Addedufo@^0.7.9
+ Added@intlify/shared@11.0.0-rc.1(transitive)
+ Addedufo@0.7.11(transitive)
- Removed@intlify/shared@9.3.0-beta.27(transitive)
Updated@intlify/shared@next