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

vue-i18n-routing

Package Overview
Dependencies
Maintainers
1
Versions
239
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

vue-i18n-routing - npm Package Compare versions

Comparing version 0.0.0-9f94af5 to 0.0.0-ab35914

8

dist/vue-i18n-routing.cjs.js

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

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

@@ -1,11 +0,92 @@

import type { I18n } from 'vue-i18n';
import { Locale } from 'vue-i18n';
import type { Route as Route_2 } from 'vue-router3';
import type { RouteConfig } from 'vue-router3';
import type { RouteLocationNormalizedLoaded } from 'vue-router';
import type { Router } from 'vue-router';
import VueI18n from 'vue-i18n-legacy';
import VueRouter from 'vue-router3';
import { Composer } from '@intlify/vue-i18n-bridge';
import type { I18n } from '@intlify/vue-i18n-bridge';
import type { Locale } from '@intlify/vue-i18n-bridge';
import type { RawLocation } from '@intlify/vue-router-bridge';
import type { Ref } from 'vue-demi';
import type { Route as Route_2 } from '@intlify/vue-router-bridge';
import type { RouteConfig } from '@intlify/vue-router-bridge';
import type { RouteLocation } from '@intlify/vue-router-bridge';
import type { RouteLocationNormalized } from '@intlify/vue-router-bridge';
import type { RouteLocationNormalizedLoaded } from '@intlify/vue-router-bridge';
import type { RouteLocationRaw } from '@intlify/vue-router-bridge';
import type { Router } from '@intlify/vue-router-bridge';
import type { RouterOptions } from '@intlify/vue-router-bridge';
import { useRoute } from '@intlify/vue-router-bridge';
import { useRouter } from '@intlify/vue-router-bridge';
import type { VueRouter } from '@intlify/vue-router-bridge';
export declare type BaseUrlResolveHandler<Context = unknown> = (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_2 | 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}
*
* @returns A Vue Router instance
*
* @remakrs
* You can create a vue router instance to be used by the Vue app.
*
* The routes of the created router instance are handled with i18n routing.
*
* At the Vue 2 will return a [Vue Router v3 instance](https://router.vuejs.org/api/#router-construction-options), and at the Vue 3 will return a [Vue Router v4 instance](https://next.router.vuejs.org/api/#createrouter).
*
* @public
*/
export declare function createRouter<Options extends VueI18nRoutingOptions = VueI18nRoutingOptions>(i18n: I18n, options?: Options): Options['version'] extends 4 ? Router : VueRouter;
/**
* Direction

@@ -15,17 +96,85 @@ */

export declare function extendRouting<TRouter extends VueRouter | Router>({ router, i18n, defaultLocale, trailingSlash, routesNameSeparator, defaultLocaleRouteNameSuffix, localeCodes }?: VueI18nRoutingOptions): TRouter;
/**
* 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 function findBrowserLocale(locales: LocaleObject[], browserLocales: string[], { matcher, comparer }?: FindBrowserLocaleOptions): string | '';
export declare type I18nRoutingOptions = Pick<VueI18nRoutingOptions, 'defaultLocale' | 'strategy' | 'defaultLocaleRouteNameSuffix' | 'trailingSlash' | 'localeCodes'> & {
routesNameSeparator?: string;
/**
* The options for {@link findBrowserLocale} function
*/
export declare type FindBrowserLocaleOptions = {
matcher?: BrowserLocaleMatcher;
comparer?: (a: BrowserLocale, b: BrowserLocale) => number;
};
export declare interface I18nRoutingReturn {
getRouteBaseName(givenRoute?: Route_2 | RouteLocationNormalizedLoaded): string;
localePath(route: any, locale?: Locale): string;
localeRoute(route: any, locale?: Locale): any;
localeLocation(route: any, locale?: Locale): any;
switchLocalePath(locale: Locale): void;
/**
* 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 function getLocale(i18n: I18n | Composer): Locale;
/**
* Get route base name
*
* @param givenRoute - A route object, if not provided, the route is returned with `useRoute` will be used
* @param options - An options, see about details {@link I18nRoutingOptions}
*
* @returns The route base name, if route name is not defined, return null
*/
export declare function getRouteBaseName(givenRoute?: Route_2 | RouteLocationNormalizedLoaded, { router, routesNameSeparator }?: I18nRoutingOptions): string | null;
/**
* I18n header meta info
*/
export declare interface I18nHeadMetaInfo {
htmlAttrs?: MetaAttrs;
meta?: MetaAttrs[];
link?: MetaAttrs[];
}
/**
* Options for {@link useI18nHead} function
*/
export declare interface I18nHeadOptions {
/**
* Adds a `dir` attribute to the HTML element.
*
* @defaultValue false
*/
addDirAttribute?: boolean;
/**
* Adds various SEO attributes.
*
* @defaultValue false
*/
addSeoAttributes?: boolean | SeoAttributesOptions;
}
/**
* Options for vue-i18n-routing common
*/
export declare type I18nRoutingOptions = Pick<VueI18nRoutingOptions, 'defaultLocale' | 'strategy' | 'defaultLocaleRouteNameSuffix' | 'trailingSlash' | 'locales' | 'routesNameSeparator'> & ComposableOptions;
/**
* Resolve locale location
*
* @param route - A route location. The path or name of the route or an object for more complex routes
* @param locale - A locale code, if not specified, uses the current locale
* @param options - An options, see about details {@link I18nRoutingOptions}
*
* @returns Returns the location object for a given route, the location object is resolved by vue-router rather than just a full route path.
*/
export declare function localeLocation(route: RawLocation | RouteLocationRaw, locale?: Locale, // TODO: locale should be more type inference (completion)
options?: I18nRoutingOptions): Location | RouteLocation | undefined;
/**
* Locale object

@@ -43,7 +192,54 @@ */

export declare function localizeRoutes(routes: VueI18nRoute[], { defaultLocale, strategy, trailingSlash, routesNameSeparator, defaultLocaleRouteNameSuffix, includeUprefixedFallback, localeCodes }?: Pick<VueI18nRoutingOptions, 'defaultLocale' | 'strategy' | 'localeCodes' | 'routesNameSeparator' | 'trailingSlash' | 'defaultLocaleRouteNameSuffix'> & {
/**
* Resolve locale path
*
* @param route - A route location. The path or name of the route or an object for more complex routes
* @param locale - A locale code, if not specified, uses the current locale
* @param options - An options, see about details {@link I18nRoutingOptions}
*
* @returns Returns the localized URL for a given route
*/
export declare function localePath(route: RawLocation | RouteLocationRaw, locale?: Locale, // TODO: locale should be more type inference (completion)
options?: I18nRoutingOptions): string;
/**
* Resolve locale route
*
* @param route - A route location. The path or name of the route or an object for more complex routes
* @param locale - A locale code, if not specified, uses the current locale
* @param options - An options, see about details {@link I18nRoutingOptions}
*
* @returns Returns the route object for a given route, the route object is resolved by vue-router rather than just a full route path.
*/
export declare function localeRoute(route: RawLocation | RouteLocationRaw, locale?: Locale, // TODO: locale should be more type inference (completion)
options?: I18nRoutingOptions): Route_2 | ReturnType<Router['resolve']> | undefined;
/**
* Localize routes
*
* @param routes - Some routes
* @param options - An options
*
* @returns Localized routes
*
* @public
*/
export declare function localizeRoutes(routes: VueI18nRoute[], { defaultLocale, strategy, trailingSlash, routesNameSeparator, defaultLocaleRouteNameSuffix, includeUprefixedFallback, optionsResolver, locales }?: Pick<VueI18nRoutingOptions, 'defaultLocale' | 'strategy' | 'locales' | 'routesNameSeparator' | 'trailingSlash' | 'defaultLocaleRouteNameSuffix'> & {
includeUprefixedFallback?: boolean;
optionsResolver?: RouteOptionsResolver;
}): VueI18nRoute[];
export declare type MetaAttrs = Record<string, any>;
/**
* 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;
/**
* Route config for vue-router v4

@@ -70,2 +266,27 @@ */

/**
* Resolver for route localizing options
*/
export declare type RouteOptionsResolver = (route: VueI18nRoute, allowedLocaleCodes: string[]) => ComputedRouteOptions | null;
/**
* SEO Attribute options
*/
export declare interface SeoAttributesOptions {
/**
* An array of strings corresponding to query params you would like to include in your canonical URL.
*
* @defaultValue []
*/
canonicalQueries?: string[];
}
/**
* 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;
declare const STRATEGIES: {

@@ -83,5 +304,30 @@ readonly PREFIX: "prefix";

/**
* Switch locale path
*
* @param locale - A locale code, if not specified, uses the current locale
* @param options - An options, see about details {@link I18nRoutingOptions}
*
* @returns Returns a link to the current route in another language
*/
export declare function switchLocalePath(locale: Locale, options?: I18nRoutingOptions): string;
/**
* 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;
export declare function useI18nRouting<Legacy extends boolean = false>(options?: I18nRoutingOptions): I18nRoutingReturn;
/**
* Generate SEO head meta information
*
* @param options - An options, see about details {@link I18nHeadOptions}
*
* @returns Genereated SEO head meta information
*/
export declare function useI18nHead({ addDirAttribute, addSeoAttributes, strategy, defaultLocale, route, router, i18n }?: Pick<I18nRoutingOptions, 'strategy' | 'defaultLocale'> & ComposableOptions & I18nHeadOptions): Ref<I18nHeadMetaInfo>;

@@ -94,3 +340,3 @@ /**

*/
export declare const VERSION = "";
export declare const VERSION: string;

@@ -105,28 +351,137 @@ /**

/**
* Vue I18n routing options
* Options to initialize a VueRouter instance
*
* @remarks
* This options is extended from Vue Router `RouterOptioins`, so you can specify those options.
*/
export declare interface VueI18nRoutingOptions {
export declare type VueI18nRoutingOptions<BaseUrl extends BaseUrlResolveHandler = BaseUrlResolveHandler> = {
/**
* Vue Router instance
* Vue Router version
*
* @remarks
* You can choice between vue-router v3 and v4.
*
* If you specify `3`, this function return Vue Router v3 instance, else specify `4`, this function return Vue Router v4 instance.
*
* @defaultValue 4
*/
router?: VueRouter | Router;
version?: 3 | 4;
/**
* Vue I18n instance
* The app's default locale
*
* @remarks
* When using `prefix_except_default` strategy, URLs for locale specified here won't have a prefix.
*
* It's recommended to set this to some locale regardless of chosen strategy, as it will be used as a fallback locale when navigating to a non-existent route
*
* @defaultValue '' (emputy string)
*/
i18n?: VueI18n | I18n;
defaultLocale?: string;
localeCodes?: string[] | LocaleObject[];
/**
* List of locales supported by your app
*
* @remarks
* Can either be an array of string codes (e.g. `['en', 'fr']`) or an array of {@link LocaleObject} for more complex configurations
*
* @defaultValue []
*/
locales?: string[] | LocaleObject[];
/**
* Routes strategy
*
* @remarks
* Can be set to one of the following:
*
* - `no_prefix`: routes won't have a locale prefix
* - `prefix_except_default`: locale prefix added for every locale except default
* - `prefix`: locale prefix added for every locale
* - `prefix_and_default`: locale prefix added for every locale and default
*
* @defaultValue 'prefix_except_default'
*/
strategy?: Strategies;
/**
* Whether to use trailing slash
*
* @defaultValue false
*/
trailingSlash?: boolean;
/**
* Internal separator used for generated route names for each locale. You shouldn't need to change this
*
* @defaultValue '___'
*/
routesNameSeparator?: string;
/**
* Internal suffix added to generated route names for default locale
*
* @remarks
* if strategy is prefix_and_default. You shouldn't need to change this.
*
* @defaultValue 'default'
*/
defaultLocaleRouteNameSuffix?: string;
}
/**
* Default 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 { }
import type { ComputedRef } from 'vue'
import type { ComputedRef } from 'vue-demi'
declare module 'vue-i18n' {
export interface ComposerCustom {
locales: ComputedRef<string[] | LocaleObject[]>
/**
* List of locales
*
* @defaultValue `undefined`
*/
locales?: ComputedRef<string[] | LocaleObject[]>
/**
* List of locale codes
*
* @defaultValue `undefined`
*/
localeCodes?: ComputedRef<string[]>
__baseUrl?: string
}
}
declare module 'vue-i18n-bridge' {
export interface ComposerCustom {
/**
* List of locales
*
* @defaultValue `undefined`
*/
locales?: ComputedRef<string[] | LocaleObject[]>
/**
* List of locale codes
*
* @defaultValue `undefined`
*/
localeCodes?: ComputedRef<string[]>
__baseUrl?: string
}
}

@@ -32,19 +32,53 @@ var __defProp = Object.defineProperty;

};
import { ref, computed, isVue2, getCurrentInstance, isRef as isRef$1 } from "vue-demi";
import { useRouter as useRouter$1, useRoute as useRoute$1 } from "vue-router";
import { useI18n as useI18n$1 } from "vue-i18n";
import { isRef, unref, isVue3, ref, watchEffect, onUnmounted, computed, isVue2 } from "vue-demi";
import VueRouter3, { isVueRouter4, useRoute, useRouter, createRouter as createRouter$1 } from "@intlify/vue-router-bridge";
import { useI18n } from "@intlify/vue-i18n-bridge";
/*!
* shared v9.2.0-beta.25
* (c) 2021 kazuya kawaguchi
* shared v9.2.0-beta.30
* (c) 2022 kazuya kawaguchi
* Released under the MIT License.
*/
const assign = Object.assign;
const isArray = Array.isArray;
const isFunction = (val) => typeof val === "function";
const isString = (val) => typeof val === "string";
const isSymbol$1 = (val) => typeof val === "symbol";
const isBoolean = (val) => typeof val === "boolean";
const isSymbol = (val) => typeof val === "symbol";
new Set(Object.getOwnPropertyNames(Symbol).map((key) => Symbol[key]).filter(isSymbol));
function isRef(r) {
return Boolean(r && r.__v_isRef === true);
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);
}
Promise.resolve();
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) {

@@ -69,3 +103,3 @@ locales = locales || [];

function getLocale(i18n) {
return isI18nInstance(i18n) ? isComposer(i18n.global, i18n.mode) ? i18n.global.locale.value : i18n.global.locale : isRef(i18n.locale) ? i18n.locale.value : i18n.locale;
return isI18nInstance(i18n) ? isComposer(i18n.global, i18n.mode) ? i18n.global.locale.value : i18n.global.locale : i18n.locale.value;
}

@@ -86,10 +120,66 @@ function setLocale(i18n, locale) {

}
function extendI18n(i18n, { localeCodes = [] } = {}) {
if (!isComposer(i18n.global, i18n.mode)) {
throw new Error("");
function toRawRoute(maybeRoute) {
return isVueRouter4 ? isRef(maybeRoute) ? maybeRoute.value : maybeRoute : isRef(maybeRoute) ? maybeRoute.value : maybeRoute;
}
function getRouteName(routeName) {
return isString(routeName) ? routeName : isSymbol(routeName) ? routeName.toString() : "(null)";
}
function getLocaleRouteName(routeName, locale, {
defaultLocale,
strategy,
routesNameSeparator,
defaultLocaleRouteNameSuffix
}) {
let name = getRouteName(routeName) + (strategy === "no_prefix" ? "" : routesNameSeparator + locale);
if (locale === defaultLocale && strategy === "prefix_and_default") {
name += routesNameSeparator + defaultLocaleRouteNameSuffix;
}
const _localeCodes = ref(localeCodes);
i18n.global.locales = computed(() => _localeCodes.value);
console.log("... extends i18n done");
return name;
}
function 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;
}
}
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;
}
}
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 : "";
}
const STRATEGIES = {

@@ -106,2 +196,289 @@ PREFIX: "prefix",

const DEFAULT_LOCALE_ROUTE_NAME_SUFFIX = "default";
const DEFAULT_DETECTION_DIRECTION = "ltr";
const DEFAULT_BASE_URL = "";
const RESOLVED_PREFIXED = /* @__PURE__ */ new Set([STRATEGIES.PREFIX_AND_DEFAULT, STRATEGIES.PREFIX_EXCEPT_DEFAULT]);
function getRouteBaseName(givenRoute = useRoute(), { router = useRouter(), routesNameSeparator = DEFAULT_ROUTES_NAME_SEPARATOR } = {}) {
const _routesNameSeparator = routesNameSeparator || router.__routesNameSeparator;
const _route = unref(givenRoute);
if (!_route.name) {
return null;
}
const name = getRouteName(_route.name);
return name.split(_routesNameSeparator)[0];
}
function localePath(route, locale, options) {
const localizedRoute = resolveRoute(route, locale, options);
return localizedRoute == null ? "" : isVue3 ? localizedRoute.redirectedFrom || localizedRoute.fullPath : localizedRoute.route.redirectedFrom || localizedRoute.route.fullPath;
}
function localeRoute(route, locale, options) {
const resolved = resolveRoute(route, locale, options);
return resolved == null ? void 0 : isVue3 ? resolved : resolved.route;
}
function localeLocation(route, locale, options) {
const resolved = resolveRoute(route, locale, options);
return resolved == null ? void 0 : isVue3 ? resolved : resolved.location;
}
function resolveRoute(route, locale, {
router = useRouter(),
i18n = useI18n(),
defaultLocale = DEFAULT_LOCALE,
defaultLocaleRouteNameSuffix = DEFAULT_LOCALE_ROUTE_NAME_SUFFIX,
routesNameSeparator = DEFAULT_ROUTES_NAME_SEPARATOR,
strategy = DEFAULT_STRATEGY,
trailingSlash = false
} = {}) {
const _defaultLocaleRouteNameSuffix = router.__defaultLocaleRouteNameSuffix || defaultLocaleRouteNameSuffix;
const _defaultLocale = router.__defaultLocale || defaultLocale;
const _routesNameSeparator = router.__routesNameSeparator || routesNameSeparator;
const _strategy = router.__strategy || strategy;
const _locale = locale || getLocale(i18n);
let _route = route;
if (isString(route)) {
if (_route[0] === "/") {
_route = { path: route };
} else {
_route = { name: route };
}
}
let localizedRoute = assign({}, _route);
if (localizedRoute.path && !localizedRoute.name) {
const _resolvedRoute = router.resolve(localizedRoute);
const resolvedRoute2 = isVue3 ? _resolvedRoute : _resolvedRoute.route;
const resolvedRouteName = getRouteBaseName(resolvedRoute2);
if (isString(resolvedRouteName)) {
localizedRoute = {
name: getLocaleRouteName(resolvedRouteName, _locale, {
defaultLocale: _defaultLocale,
strategy: _strategy,
routesNameSeparator: _routesNameSeparator,
defaultLocaleRouteNameSuffix: _defaultLocaleRouteNameSuffix
}),
params: resolvedRoute2.params,
query: resolvedRoute2.query,
hash: resolvedRoute2.hash
};
} else {
const isDefaultLocale = _locale === defaultLocale;
const isPrefixed = !(isDefaultLocale && RESOLVED_PREFIXED.has(_strategy)) && !(_strategy === STRATEGIES.NO_PREFIX);
if (isPrefixed) {
localizedRoute.path = `/${_locale}${localizedRoute.path}`;
}
localizedRoute.path = trailingSlash ? withTrailingSlash(localizedRoute.path, true) : withoutTrailingSlash(localizedRoute.path, true);
}
} else {
localizedRoute.name = getLocaleRouteName(localizedRoute.name, _locale, {
defaultLocale: _defaultLocale,
strategy: _strategy,
routesNameSeparator: _routesNameSeparator,
defaultLocaleRouteNameSuffix: _defaultLocaleRouteNameSuffix
});
const { params } = localizedRoute;
if (params && params["0"] === void 0 && params.pathMatch) {
params["0"] = params.pathMatch;
}
}
const resolvedRoute = router.resolve(localizedRoute);
if (isVue3 ? resolvedRoute.name : resolvedRoute.route.name) {
return resolvedRoute;
}
return router.resolve(route);
}
function switchLocalePath(locale, options) {
const route = options && options.route || useRoute();
const name = getRouteBaseName(route, options);
if (!name) {
return "";
}
const _a = !isVue3 && isRef(route) ? route.value : route, { params } = _a, routeCopy = __objRest(_a, ["params"]);
const langSwitchParams = {};
const baseRoute = assign({}, routeCopy, {
name,
params: __spreadProps(__spreadValues(__spreadValues({}, params), langSwitchParams), {
0: params.pathMatch
})
});
const path = localePath(baseRoute, locale, options);
return path;
}
function useI18nHead({
addDirAttribute = false,
addSeoAttributes = false,
strategy = DEFAULT_STRATEGY,
defaultLocale = DEFAULT_LOCALE,
route = useRoute(),
router = useRouter(),
i18n = useI18n()
} = {}) {
const _router = router;
const _defaultLocale = defaultLocale || _router.__defaultLocale;
const _strategy = strategy || _router.__strategy;
const metaObject = ref({
htmlAttrs: {},
link: [],
meta: []
});
function cleanMeta() {
metaObject.value = {
htmlAttrs: {},
link: [],
meta: []
};
}
function updateMeta(_route) {
if (i18n.locales == null || i18n.__baseUrl == null) {
return;
}
const locale = getLocale(i18n);
const currentLocale = getNormalizedLocales(i18n.locales.value).find((l) => l.code === locale) || {
code: locale
};
const currentLocaleIso = currentLocale.iso;
const currentLocaleDir = currentLocale.dir || router.__defaultDirection;
if (addDirAttribute) {
metaObject.value.htmlAttrs.dir = currentLocaleDir;
}
if (addSeoAttributes && locale && i18n.locales) {
if (currentLocaleIso) {
metaObject.value.htmlAttrs.lang = currentLocaleIso;
}
const locales = i18n.locales.value;
addHreflangLinks(locales, i18n.__baseUrl, metaObject.value.link, {
defaultLocale: _defaultLocale,
strategy: _strategy,
route,
router,
i18n
});
addCanonicalLinks(i18n.__baseUrl, metaObject.value.link, addSeoAttributes, { route: _route, router, i18n });
addCurrentOgLocale(currentLocale, currentLocaleIso, metaObject.value.meta);
addAlternateOgLocales(locales, currentLocaleIso, metaObject.value.meta);
}
}
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 {
updateMeta(toRawRoute(_router.currentRoute));
}
return metaObject;
}
function addHreflangLinks(locales, baseUrl, link, options) {
if (options.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(mapLocale.code, options);
if (localePath2) {
link.push({
hid: `i18n-alt-${iso}`,
rel: "alternate",
href: toAbsoluteUrl(localePath2, baseUrl),
hreflang: iso
});
}
}
if (options.defaultLocale) {
const localePath2 = switchLocalePath(options.defaultLocale, options);
if (localePath2) {
link.push({
hid: "i18n-xd",
rel: "alternate",
href: toAbsoluteUrl(localePath2, baseUrl),
hreflang: "x-default"
});
}
}
}
function addCanonicalLinks(baseUrl, link, seoAttributesOptions, options) {
const { route } = options;
const currentRoute = localeRoute(__spreadProps(__spreadValues({}, route), {
name: getRouteBaseName(route, options)
}), void 0, options);
if (currentRoute) {
let href = toAbsoluteUrl(currentRoute.path, baseUrl);
const canonicalQueries = !isBoolean(seoAttributesOptions) && seoAttributesOptions.canonicalQueries || [];
if (canonicalQueries.length) {
const currentRouteQueryParams = currentRoute.query;
const params = new URLSearchParams();
for (const queryParamName of canonicalQueries) {
if (queryParamName in currentRouteQueryParams) {
const queryParamValue = currentRouteQueryParams[queryParamName];
if (isArray(queryParamValue)) {
queryParamValue.forEach((v) => params.append(queryParamName, v || ""));
} else {
params.append(queryParamName, queryParamValue || "");
}
}
}
const queryString = params.toString();
if (queryString) {
href = `${href}?${queryString}`;
}
}
link.push({
hid: "i18n-can",
rel: "canonical",
href
});
}
}
function addCurrentOgLocale(currentLocale, currentLocaleIso, meta) {
const hasCurrentLocaleAndIso = currentLocale && currentLocaleIso;
if (!hasCurrentLocaleAndIso) {
return;
}
meta.push({
hid: "i18n-og",
property: "og:locale",
content: hypenToUnderscore(currentLocaleIso)
});
}
function addAlternateOgLocales(locales, currentLocaleIso, meta) {
const localesWithoutCurrent = locales.filter((locale) => {
const localeIso = locale.iso;
return localeIso && localeIso !== currentLocaleIso;
});
if (localesWithoutCurrent.length) {
const alternateLocales = localesWithoutCurrent.map((locale) => ({
hid: `i18n-og-alt-${locale.iso}`,
property: "og:locale:alternate",
content: hypenToUnderscore(locale.iso)
}));
meta.push(...alternateLocales);
}
}
function hypenToUnderscore(str) {
return (str || "").replace(/-/g, "_");
}
function toAbsoluteUrl(urlOrPath, baseUrl) {
if (urlOrPath.match(/^https?:\/\//)) {
return urlOrPath;
}
return baseUrl + urlOrPath;
}
function localizeRoutes(routes, {

@@ -114,3 +491,4 @@ defaultLocale = DEFAULT_LOCALE,

includeUprefixedFallback = false,
localeCodes = []
optionsResolver = void 0,
locales = []
} = {}) {

@@ -120,3 +498,3 @@ if (strategy === "no_prefix") {

}
const _localeCodes = localeCodes.map((locale) => isString(locale) ? locale : locale.code);
const _localeCodes = locales.map((locale) => isString(locale) ? locale : locale.code);
function makeLocalizedRoutes(route, allowedLocaleCodes, isChild = false, isExtraPageTree = false) {

@@ -126,2 +504,9 @@ if (route.redirect && (!route.component || !route.file)) {

}
let routeOptions = null;
if (optionsResolver != null) {
routeOptions = optionsResolver(route, allowedLocaleCodes);
if (routeOptions == null) {
return [route];
}
}
const targetLocales = allowedLocaleCodes;

@@ -174,2 +559,67 @@ return targetLocales.reduce((_routes, locale) => {

}
function extendI18n(i18n, { locales = [], localeCodes = [], baseUrl = DEFAULT_BASE_URL } = {}) {
if (!isComposer(i18n.global, i18n.mode)) {
throw new Error("TODO:");
}
const _locales = ref(locales);
const _localeCodes = ref(localeCodes);
i18n.global.locales = computed(() => _locales.value);
i18n.global.localeCodes = computed(() => _localeCodes.value);
i18n.global.__baseUrl = resolveBaseUrl(baseUrl, {});
}
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);
router.__defaultLocale = defaultLocale;
router.__localeCodes = localeCodes;
router.__strategy = strategy;
router.__trailingSlash = trailingSlash;
router.__routesNameSeparator = routesNameSeparator;
router.__defaultLocaleRouteNameSuffix = defaultLocaleRouteNameSuffix;
router.__defaultDirection = 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:");
}
}
function getLocalesRegex(localeCodes) {

@@ -184,10 +634,17 @@ return new RegExp(`^/(${localeCodes.join("|")})(?:/|$)`, "i");

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) {

@@ -201,225 +658,17 @@ return matches[1];

}
function extendRouter({
router,
i18n,
defaultLocale = DEFAULT_LOCALE,
strategy = DEFAULT_STRATEGY,
trailingSlash = DEFAULT_TRAILING_SLASH,
routesNameSeparator = DEFAULT_ROUTES_NAME_SEPARATOR,
defaultLocaleRouteNameSuffix = DEFAULT_LOCALE_ROUTE_NAME_SUFFIX,
localeCodes = []
} = {}) {
const normalizedLocaleCodes = getNormalizedLocales(localeCodes);
const getLocaleFromRoute = createLocaleFromRouteGetter(normalizedLocaleCodes.map((l) => l.code), routesNameSeparator, defaultLocaleRouteNameSuffix);
extendI18n(i18n, { localeCodes: normalizedLocaleCodes });
if (isVue2) {
const _router = router;
const _VueRouter = _router.constructor;
const routes = _router.options.routes || [];
const localizedRoutes = localizeRoutes(routes, {
localeCodes,
defaultLocale,
strategy,
trailingSlash,
routesNameSeparator,
defaultLocaleRouteNameSuffix
});
console.log("vue2 routes", routes, localizedRoutes);
const newRouter = new _VueRouter({
mode: "history",
base: _router.options.base,
routes: localizedRoutes
});
newRouter.__defaultLocale = defaultLocale;
newRouter.__strategy = strategy;
newRouter.__trailingSlash = trailingSlash;
newRouter.__routesNameSeparator = routesNameSeparator;
newRouter.__defaultLocaleRouteNameSuffix = defaultLocaleRouteNameSuffix;
newRouter.beforeEach((to, from, next) => {
console.log("beforeEach", to, from);
const currentLocale = getLocale(i18n);
const finalLocale = getLocaleFromRoute(to) || currentLocale || defaultLocale || "";
console.log("currentLocale", currentLocale, "finalLocale", finalLocale);
if (currentLocale !== finalLocale) {
setLocale(i18n, finalLocale);
}
next();
});
return newRouter;
} else {
const _router = router;
const routes = _router.options.routes || [];
const localizedRoutes = localizeRoutes(routes, {
localeCodes,
defaultLocale,
strategy,
trailingSlash,
routesNameSeparator,
defaultLocaleRouteNameSuffix
});
console.log("vue3 routes", routes, localizedRoutes, _router);
routes.forEach((r) => _router.removeRoute(r.name));
localizedRoutes.forEach((route) => _router.addRoute(route));
_router.__defaultLocale = defaultLocale;
_router.__strategy = strategy;
_router.__trailingSlash = trailingSlash;
_router.__routesNameSeparator = routesNameSeparator;
_router.__defaultLocaleRouteNameSuffix = defaultLocaleRouteNameSuffix;
_router.beforeEach((to, from, next) => {
console.log("beforeEach", to, from);
const currentLocale = getLocale(i18n);
const finalLocale = getLocaleFromRoute(to) || currentLocale || defaultLocale || "";
console.log("currentLocale", currentLocale, "finalLocale", finalLocale);
if (currentLocale !== finalLocale) {
setLocale(i18n, finalLocale);
}
next();
});
return _router;
}
function asDefaultVueI18nRouterOptions(options) {
var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j;
options.version = (_a = options.version) != null ? _a : 4;
options.defaultLocale = (_b = options.defaultLocale) != null ? _b : DEFAULT_LOCALE;
options.strategy = (_c = options.strategy) != null ? _c : DEFAULT_STRATEGY;
options.trailingSlash = (_d = options.trailingSlash) != null ? _d : DEFAULT_TRAILING_SLASH;
options.routesNameSeparator = (_e = options.routesNameSeparator) != null ? _e : DEFAULT_ROUTES_NAME_SEPARATOR;
options.defaultLocaleRouteNameSuffix = (_f = options.defaultLocaleRouteNameSuffix) != null ? _f : DEFAULT_LOCALE_ROUTE_NAME_SUFFIX;
options.locales = (_g = options.locales) != null ? _g : [];
options.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;
}
const useLegacyRouter = () => {
const vm = getCurrentInstance();
if (vm == null) {
throw new Error(`should be used in setup`);
}
return vm.$router;
};
const useLegacyRoute = () => {
const vm = getCurrentInstance();
if (vm == null) {
throw new Error(`should be used in setup`);
}
return computed(() => vm.$route);
};
function useRoute() {
return isVue2 ? useLegacyRoute() : useRoute$1();
}
function useRouter() {
return isVue2 ? useLegacyRouter() : useRouter$1();
}
function useI18n() {
return useI18n$1();
}
function useI18nRouting(options = {}) {
const $i18n = useI18n();
const $router = useRouter();
const $route = useRoute();
const defaultLocaleRouteNameSuffix = options.defaultLocaleRouteNameSuffix || $router.__defaultLocaleRouteNameSuffix;
const defaultLocale = options.defaultLocale || $router.__defaultLocale;
const routesNameSeparator = options.routesNameSeparator || $router.__routesNameSeparator;
const strategy = options.strategy || $router.__strategy;
function getRouteBaseName(givenRoute) {
const route = givenRoute != null ? givenRoute : isRef$1($route) ? $route.value : $route;
if (!route.name) {
return;
}
const name = getRouteName(route.name);
return name.split(routesNameSeparator)[0];
}
function getLocaleRouteName(routeName, locale) {
let name = getRouteName(routeName) + (strategy === "no_prefix" ? "" : routesNameSeparator + locale);
if (locale === defaultLocale && strategy === "prefix_and_default") {
name += routesNameSeparator + defaultLocaleRouteNameSuffix;
}
return name;
}
function resolveRoute(route, locale) {
const _locale = locale || getLocale($i18n);
let _route = route;
if (isString(route)) {
if (route[0] === "/") {
_route = { path: route };
} else {
_route = { name: route };
}
}
let localizedRoute = assign({}, _route);
if (localizedRoute.path && !localizedRoute.name) {
const _resolvedRoute = $router.resolve(localizedRoute);
const resolvedRoute2 = !isVue2 ? _resolvedRoute : _resolvedRoute.route;
const resolvedRouteName = getRouteBaseName(resolvedRoute2);
if (isString(resolvedRouteName)) {
localizedRoute = {
name: getLocaleRouteName(resolvedRouteName, _locale),
params: resolvedRoute2.params,
query: resolvedRoute2.query,
hash: resolvedRoute2.hash
};
}
} else {
localizedRoute.name = getLocaleRouteName(localizedRoute.name, _locale);
const { params } = localizedRoute;
if (params && params["0"] === void 0 && params.pathMatch) {
params["0"] = params.pathMatch;
}
}
const resolvedRoute = $router.resolve(localizedRoute);
if (isVue2 ? resolvedRoute.route.name : resolvedRoute.name) {
return resolvedRoute;
}
return $router.resolve(route);
}
function localePath(route, locale) {
const localizedRoute = resolveRoute(route, locale);
return localizedRoute == null ? "" : isVue2 ? localizedRoute.route.redirectedFrom || localizedRoute.route.fullPath : localizedRoute.redirectedFrom || localizedRoute.fullPath;
}
function localeRoute(route, locale) {
const resolved = resolveRoute(route, locale);
return resolved == null ? void 0 : isVue2 ? resolved.route : resolved;
}
function localeLocation(route, locale) {
const resolved = resolveRoute(route, locale);
return resolved == null ? void 0 : isVue2 ? resolved.location : resolved.href;
}
function switchLocalePath(locale) {
const name = getRouteBaseName();
if (!name) {
return "";
}
const _a = isVue2 && isRef$1($route) ? $route.value : $route, { params } = _a, routeCopy = __objRest(_a, ["params"]);
const langSwitchParams = {};
const baseRoute = assign({}, routeCopy, {
name,
params: __spreadProps(__spreadValues(__spreadValues({}, params), langSwitchParams), {
0: params.pathMatch
})
});
const path = localePath(baseRoute, locale);
console.log("switchLocalePath", $i18n.locale.value, locale, path);
return path;
}
return {
localePath,
localeRoute,
localeLocation,
switchLocalePath
};
}
function getRouteName(routeName) {
return isString(routeName) ? routeName : isSymbol$1(routeName) ? routeName.toString() : "";
}
function extendRouting({
router,
i18n,
defaultLocale = DEFAULT_LOCALE,
trailingSlash = DEFAULT_TRAILING_SLASH,
routesNameSeparator = DEFAULT_ROUTES_NAME_SEPARATOR,
defaultLocaleRouteNameSuffix = DEFAULT_LOCALE_ROUTE_NAME_SUFFIX,
localeCodes = []
} = {}) {
if (router == null) {
throw new Error("TODO");
}
return extendRouter({
router,
i18n,
defaultLocale,
trailingSlash,
routesNameSeparator,
defaultLocaleRouteNameSuffix,
localeCodes
});
}
const VERSION = "";
export { VERSION, extendRouting, localizeRoutes, useI18nRouting };
const VERSION = "0.0.0";
export { VERSION, createLocaleFromRouteGetter, createRouter, findBrowserLocale, getLocale, getRouteBaseName, localeLocation, localePath, localeRoute, localizeRoutes, resolveBaseUrl, setLocale, switchLocalePath, useI18nHead };

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

var _e=Object.defineProperty,he=Object.defineProperties;var Re=Object.getOwnPropertyDescriptors;var x=Object.getOwnPropertySymbols;var k=Object.prototype.hasOwnProperty,H=Object.prototype.propertyIsEnumerable;var Y=(a,n,f)=>n in a?_e(a,n,{enumerable:!0,configurable:!0,writable:!0,value:f}):a[n]=f,w=(a,n)=>{for(var f in n||(n={}))k.call(n,f)&&Y(a,f,n[f]);if(x)for(var f of x(n))H.call(n,f)&&Y(a,f,n[f]);return a},M=(a,n)=>he(a,Re(n));var J=(a,n)=>{var f={};for(var $ in a)k.call(a,$)&&n.indexOf($)<0&&(f[$]=a[$]);if(a!=null&&x)for(var $ of x(a))n.indexOf($)<0&&H.call(a,$)&&(f[$]=a[$]);return f};var VueI18nRouting=function(a,n,f,$){"use strict";/*!
* shared v9.2.0-beta.25
* (c) 2021 kazuya kawaguchi
var ke=Object.defineProperty,qe=Object.defineProperties;var Ge=Object.getOwnPropertyDescriptors;var x=Object.getOwnPropertySymbols;var ue=Object.prototype.hasOwnProperty,fe=Object.prototype.propertyIsEnumerable;var se=(s,r,L)=>r in s?ke(s,r,{enumerable:!0,configurable:!0,writable:!0,value:L}):s[r]=L,N=(s,r)=>{for(var L in r||(r={}))ue.call(r,L)&&se(s,L,r[L]);if(x)for(var L of x(r))fe.call(r,L)&&se(s,L,r[L]);return s},X=(s,r)=>qe(s,Ge(r));var ie=(s,r)=>{var L={};for(var p in s)ue.call(s,p)&&r.indexOf(p)<0&&(L[p]=s[p]);if(s!=null&&x)for(var p of x(s))r.indexOf(p)<0&&fe.call(s,p)&&(L[p]=s[p]);return L};var VueI18nRouting=function(s,r,L,p){"use strict";function de(e){return e&&typeof e=="object"&&"default"in e?e:{default:e}}var he=de(L);/*!
* shared v9.2.0-beta.30
* (c) 2022 kazuya kawaguchi
* Released under the MIT License.
*/const j=Object.assign,T=e=>typeof e=="string",K=e=>typeof e=="symbol",Q=e=>typeof e=="symbol";new Set(Object.getOwnPropertyNames(Symbol).map(e=>Symbol[e]).filter(Q));function y(e){return Boolean(e&&e.__v_isRef===!0)}Promise.resolve();function Z(e){e=e||[];const r=[];for(const c of e)T(c)?r.push({code:c}):r.push(c);return r}function V(e,r){return y(e.locale)&&r==="composition"}function G(e){return"global"in e&&"mode"in e}function v(e){return G(e)?V(e.global,e.mode)?e.global.locale.value:e.global.locale:y(e.locale)?e.locale.value:e.locale}function q(e,r){G(e)?V(e.global,e.mode)?e.global.locale.value=r:e.global.locale=r:y(e.locale)&&(e.locale.value=r)}function D(e,r,c){return e.replace(/\/+$/,"")+(r?"/":"")||(c?"":"/")}function ee(e,{localeCodes:r=[]}={}){if(!V(e.global,e.mode))throw new Error("");const c=n.ref(r);e.global.locales=n.computed(()=>c.value),console.log("... extends i18n done")}const oe={PREFIX:"prefix",PREFIX_EXCEPT_DEFAULT:"prefix_except_default",PREFIX_AND_DEFAULT:"prefix_and_default",NO_PREFIX:"no_prefix"},O="",B=oe.PREFIX_EXCEPT_DEFAULT,z=!1,U="___",N="default";function C(e,{defaultLocale:r=O,strategy:c=B,trailingSlash:d=z,routesNameSeparator:h=U,defaultLocaleRouteNameSuffix:R=N,includeUprefixedFallback:_=!1,localeCodes:A=[]}={}){if(c==="no_prefix")return e;const m=A.map(o=>T(o)?o:o.code);function g(o,E,F=!1,p=!1){return o.redirect&&(!o.component||!o.file)?[o]:E.reduce((s,l)=>{const{name:t}=o;let{path:i}=o;const u=w({},o);t&&(u.name=`${t}${h}${l}`),o.children&&(u.children=o.children.reduce((P,X)=>[...P,...g(X,[l],!0,p)],[]));const S=l===r;if(S&&c==="prefix_and_default")if(F)F&&p&&t&&(u.name+=`${h}${R}`);else{const P=M(w({},u),{path:i});if(t&&(P.name=`${u.name}${h}${R}`),o.children){P.children=[];for(const X of o.children)P.children=P.children.concat(g(X,[l],!0,!0))}s.push(P)}const L=F&&!i.startsWith("/"),I=!L&&!(S&&c==="prefix_except_default");return I&&(i=`/${l}${i}`),i&&(i=D(i,d,L)),I&&S&&c==="prefix"&&_&&s.push(w({},o)),u.path=i,s.push(u),s},[])}return e.reduce((o,E)=>[...o,...g(E,m||[])],[])}function te(e){return new RegExp(`^/(${e.join("|")})(?:/|$)`,"i")}function ne(e,r,c){const d=`(${e.join("|")})`,h=`(?:${r}${c})?`,R=new RegExp(`${r}${d}${h}$`,"i"),_=te(e);return m=>{if(m.name){const o=(T(m.name)?m.name:m.name.toString()).match(R);if(o&&o.length>1)return o[1]}else if(m.path){const g=m.path.match(_);if(g&&g.length>1)return g[1]}return""}}function ce({router:e,i18n:r,defaultLocale:c=O,strategy:d=B,trailingSlash:h=z,routesNameSeparator:R=U,defaultLocaleRouteNameSuffix:_=N,localeCodes:A=[]}={}){const m=Z(A),g=ne(m.map(o=>o.code),R,_);if(ee(r,{localeCodes:m}),n.isVue2){const o=e,E=o.constructor,F=o.options.routes||[],p=C(F,{localeCodes:A,defaultLocale:c,strategy:d,trailingSlash:h,routesNameSeparator:R,defaultLocaleRouteNameSuffix:_});console.log("vue2 routes",F,p);const b=new E({mode:"history",base:o.options.base,routes:p});return b.__defaultLocale=c,b.__strategy=d,b.__trailingSlash=h,b.__routesNameSeparator=R,b.__defaultLocaleRouteNameSuffix=_,b.beforeEach((s,l,t)=>{console.log("beforeEach",s,l);const i=v(r),u=g(s)||i||c||"";console.log("currentLocale",i,"finalLocale",u),i!==u&&q(r,u),t()}),b}else{const o=e,E=o.options.routes||[],F=C(E,{localeCodes:A,defaultLocale:c,strategy:d,trailingSlash:h,routesNameSeparator:R,defaultLocaleRouteNameSuffix:_});return console.log("vue3 routes",E,F,o),E.forEach(p=>o.removeRoute(p.name)),F.forEach(p=>o.addRoute(p)),o.__defaultLocale=c,o.__strategy=d,o.__trailingSlash=h,o.__routesNameSeparator=R,o.__defaultLocaleRouteNameSuffix=_,o.beforeEach((p,b,s)=>{console.log("beforeEach",p,b);const l=v(r),t=g(p)||l||c||"";console.log("currentLocale",l,"finalLocale",t),l!==t&&q(r,t),s()}),o}}const se=()=>{const e=n.getCurrentInstance();if(e==null)throw new Error("should be used in setup");return e.$router},re=()=>{const e=n.getCurrentInstance();if(e==null)throw new Error("should be used in setup");return n.computed(()=>e.$route)};function le(){return n.isVue2?re():f.useRoute()}function ae(){return n.isVue2?se():f.useRouter()}function ue(){return $.useI18n()}function ie(e={}){const r=ue(),c=ae(),d=le(),h=e.defaultLocaleRouteNameSuffix||c.__defaultLocaleRouteNameSuffix,R=e.defaultLocale||c.__defaultLocale,_=e.routesNameSeparator||c.__routesNameSeparator,A=e.strategy||c.__strategy;function m(s){const l=s!=null?s:n.isRef(d)?d.value:d;return l.name?W(l.name).split(_)[0]:void 0}function g(s,l){let t=W(s)+(A==="no_prefix"?"":_+l);return l===R&&A==="prefix_and_default"&&(t+=_+h),t}function o(s,l){const t=l||v(r);let i=s;T(s)&&(s[0]==="/"?i={path:s}:i={name:s});let u=j({},i);if(u.path&&!u.name){const L=c.resolve(u),I=n.isVue2?L.route:L,P=m(I);T(P)&&(u={name:g(P,t),params:I.params,query:I.query,hash:I.hash})}else{u.name=g(u.name,t);const{params:L}=u;L&&L["0"]===void 0&&L.pathMatch&&(L["0"]=L.pathMatch)}const S=c.resolve(u);return(n.isVue2?S.route.name:S.name)?S:c.resolve(s)}function E(s,l){const t=o(s,l);return t==null?"":n.isVue2?t.route.redirectedFrom||t.route.fullPath:t.redirectedFrom||t.fullPath}function F(s,l){const t=o(s,l);return t==null?void 0:n.isVue2?t.route:t}function p(s,l){const t=o(s,l);return t==null?void 0:n.isVue2?t.location:t.href}function b(s){const l=m();if(!l)return"";const I=n.isVue2&&n.isRef(d)?d.value:d,{params:t}=I,i=J(I,["params"]),u={},S=j({},i,{name:l,params:M(w(w({},t),u),{0:t.pathMatch})}),L=E(S,s);return console.log("switchLocalePath",r.locale.value,s,L),L}return{localePath:E,localeRoute:F,localeLocation:p,switchLocalePath:b}}function W(e){return T(e)?e:K(e)?e.toString():""}function fe({router:e,i18n:r,defaultLocale:c=O,trailingSlash:d=z,routesNameSeparator:h=U,defaultLocaleRouteNameSuffix:R=N,localeCodes:_=[]}={}){if(e==null)throw new Error("TODO");return ce({router:e,i18n:r,defaultLocale:c,trailingSlash:d,routesNameSeparator:h,defaultLocaleRouteNameSuffix:R,localeCodes:_})}const de="";return a.VERSION=de,a.extendRouting=fe,a.localizeRoutes=C,a.useI18nRouting=ie,Object.defineProperty(a,"__esModule",{value:!0}),a[Symbol.toStringTag]="Module",a}({},VueDemi,VueRouter,VueI18n);
*/const q=Object.assign,_e=Array.isArray,Le=e=>typeof e=="function",P=e=>typeof e=="string",ge=e=>typeof e=="boolean",me=e=>typeof e=="symbol",Re=e=>e!==null&&typeof e=="object",Ee=/\/$|\/\?/;function V(e="",t=!1){return t?Ee.test(e):e.endsWith("/")}function Se(e="",t=!1){if(!t)return(V(e)?e.slice(0,-1):e)||"/";if(!V(e,!0))return e||"/";const[a,...o]=e.split("?");return(a.slice(0,-1)||"/")+(o.length?`?${o.join("?")}`:"")}function pe(e="",t=!1){if(!t)return e.endsWith("/")?e:e+"/";if(V(e,!0))return e||"/";const[a,...o]=e.split("?");return a+"/"+(o.length?`?${o.join("?")}`:"")}const Ae=typeof window!="undefined";function Ie(e,t){typeof console!="undefined"&&(console.warn("[vue-i18n-routing] "+e),t&&console.warn(t.stack))}function G(e){e=e||[];const t=[];for(const a of e)P(a)?t.push({code:a}):t.push(a);return t}function B(e,t){return r.isRef(e.locale)&&t==="composition"}function H(e){return"global"in e&&"mode"in e}function U(e){return H(e)?B(e.global,e.mode)?e.global.locale.value:e.global.locale:e.locale.value}function W(e,t){H(e)?B(e.global,e.mode)?e.global.locale.value=t:e.global.locale=t:r.isRef(e.locale)&&(e.locale.value=t)}function Te(e,t,a){return e.replace(/\/+$/,"")+(t?"/":"")||(a?"":"/")}function Q(e){return L.isVueRouter4,r.isRef(e)?e.value:e}function Y(e){return P(e)?e:me(e)?e.toString():"(null)"}function J(e,t,{defaultLocale:a,strategy:o,routesNameSeparator:l,defaultLocaleRouteNameSuffix:n}){let c=Y(e)+(o==="no_prefix"?"":l+t);return t===a&&o==="prefix_and_default"&&(c+=l+n),c}function K(e,t){return Le(e)?e(t):e}function Fe(e,t){const a=[];for(const[o,l]of t.entries()){const n=e.find(c=>c.iso.toLowerCase()===l.toLowerCase());if(n){a.push({code:n.code,score:1-o/t.length});break}}for(const[o,l]of t.entries()){const n=l.split("-")[0].toLowerCase(),c=e.find(u=>u.iso.split("-")[0].toLowerCase()===n);if(c){a.push({code:c.code,score:.999-o/t.length});break}}return a}const Pe=Fe;function we(e,t){return e.score===t.score?t.code.length-e.code.length:t.score-e.score}const Ne=we;function ye(e,t,{matcher:a=Pe,comparer:o=Ne}={}){const l=[];for(const c of e){const{code:u}=c,i=c.iso||u;l.push({code:u,iso:i})}const n=a(l,t);return n.length>1&&n.sort(o),n.length?n[0].code:""}const $={PREFIX:"prefix",PREFIX_EXCEPT_DEFAULT:"prefix_except_default",PREFIX_AND_DEFAULT:"prefix_and_default",NO_PREFIX:"no_prefix"},C="",O=$.PREFIX_EXCEPT_DEFAULT,Z=!1,b="___",D="default",$e="ltr",ee="",Ue=new Set([$.PREFIX_AND_DEFAULT,$.PREFIX_EXCEPT_DEFAULT]);function v(e=L.useRoute(),{router:t=L.useRouter(),routesNameSeparator:a=b}={}){const o=a||t.__routesNameSeparator,l=r.unref(e);return l.name?Y(l.name).split(o)[0]:null}function te(e,t,a){const o=M(e,t,a);return o==null?"":r.isVue3?o.redirectedFrom||o.fullPath:o.route.redirectedFrom||o.route.fullPath}function ae(e,t,a){const o=M(e,t,a);return o==null?void 0:r.isVue3?o:o.route}function Ce(e,t,a){const o=M(e,t,a);return o==null?void 0:r.isVue3?o:o.location}function M(e,t,{router:a=L.useRouter(),i18n:o=p.useI18n(),defaultLocale:l=C,defaultLocaleRouteNameSuffix:n=D,routesNameSeparator:c=b,strategy:u=O,trailingSlash:i=!1}={}){const d=a.__defaultLocaleRouteNameSuffix||n,h=a.__defaultLocale||l,f=a.__routesNameSeparator||c,m=a.__strategy||u,R=t||U(o);let S=e;P(e)&&(S[0]==="/"?S={path:e}:S={name:e});let g=q({},S);if(g.path&&!g.name){const _=a.resolve(g),E=r.isVue3?_:_.route,F=v(E);P(F)?g={name:J(F,R,{defaultLocale:h,strategy:m,routesNameSeparator:f,defaultLocaleRouteNameSuffix:d}),params:E.params,query:E.query,hash:E.hash}:(!(R===l&&Ue.has(m))&&m!==$.NO_PREFIX&&(g.path=`/${R}${g.path}`),g.path=i?pe(g.path,!0):Se(g.path,!0))}else{g.name=J(g.name,R,{defaultLocale:h,strategy:m,routesNameSeparator:f,defaultLocaleRouteNameSuffix:d});const{params:_}=g;_&&_["0"]===void 0&&_.pathMatch&&(_["0"]=_.pathMatch)}const A=a.resolve(g);return(r.isVue3?A.name:A.route.name)?A:a.resolve(e)}function j(e,t){const a=t&&t.route||L.useRoute(),o=v(a,t);if(!o)return"";const d=!r.isVue3&&r.isRef(a)?a.value:a,{params:l}=d,n=ie(d,["params"]),c={},u=q({},n,{name:o,params:X(N(N({},l),c),{0:l.pathMatch})});return te(u,e,t)}function Oe({addDirAttribute:e=!1,addSeoAttributes:t=!1,strategy:a=O,defaultLocale:o=C,route:l=L.useRoute(),router:n=L.useRouter(),i18n:c=p.useI18n()}={}){const u=n,i=o||u.__defaultLocale,d=a||u.__strategy,h=r.ref({htmlAttrs:{},link:[],meta:[]});function f(){h.value={htmlAttrs:{},link:[],meta:[]}}function m(R){if(c.locales==null||c.__baseUrl==null)return;const S=U(c),g=G(c.locales.value).find(E=>E.code===S)||{code:S},A=g.iso,_=g.dir||n.__defaultDirection;if(e&&(h.value.htmlAttrs.dir=_),t&&S&&c.locales){A&&(h.value.htmlAttrs.lang=A);const E=c.locales.value;be(E,c.__baseUrl,h.value.link,{defaultLocale:i,strategy:d,route:l,router:n,i18n:c}),ve(c.__baseUrl,h.value.link,t,{route:R,router:n,i18n:c}),xe(g,A,h.value.meta),Xe(E,A,h.value.meta)}}if(Ae)if(r.isVue3){const R=r.watchEffect(()=>{f(),m(Q(u.currentRoute))});r.onUnmounted(()=>R())}else{const R=u.afterEach((S,g)=>{f(),m(S)});r.onUnmounted(()=>R()),m(l)}else m(Q(u.currentRoute));return h}function be(e,t,a,o){if(o.strategy===$.NO_PREFIX)return;const l=new Map;for(const n of e){const c=n.iso;if(!c){Ie("Locale ISO code is required to generate alternate link");continue}const[u,i]=c.split("-");u&&i&&(n.isCatchallLocale||!l.has(u))&&l.set(u,n),l.set(c,n)}for(const[n,c]of l.entries()){const u=j(c.code,o);u&&a.push({hid:`i18n-alt-${n}`,rel:"alternate",href:z(u,t),hreflang:n})}if(o.defaultLocale){const n=j(o.defaultLocale,o);n&&a.push({hid:"i18n-xd",rel:"alternate",href:z(n,t),hreflang:"x-default"})}}function ve(e,t,a,o){const{route:l}=o,n=ae(X(N({},l),{name:v(l,o)}),void 0,o);if(n){let c=z(n.path,e);const u=!ge(a)&&a.canonicalQueries||[];if(u.length){const i=n.query,d=new URLSearchParams;for(const f of u)if(f in i){const m=i[f];_e(m)?m.forEach(R=>d.append(f,R||"")):d.append(f,m||"")}const h=d.toString();h&&(c=`${c}?${h}`)}t.push({hid:"i18n-can",rel:"canonical",href:c})}}function xe(e,t,a){!(e&&t)||a.push({hid:"i18n-og",property:"og:locale",content:oe(t)})}function Xe(e,t,a){const o=e.filter(l=>{const n=l.iso;return n&&n!==t});if(o.length){const l=o.map(n=>({hid:`i18n-og-alt-${n.iso}`,property:"og:locale:alternate",content:oe(n.iso)}));a.push(...l)}}function oe(e){return(e||"").replace(/-/g,"_")}function z(e,t){return e.match(/^https?:\/\//)?e:t+e}function ne(e,{defaultLocale:t=C,strategy:a=O,trailingSlash:o=Z,routesNameSeparator:l=b,defaultLocaleRouteNameSuffix:n=D,includeUprefixedFallback:c=!1,optionsResolver:u=void 0,locales:i=[]}={}){if(a==="no_prefix")return e;const d=i.map(f=>P(f)?f:f.code);function h(f,m,R=!1,S=!1){if(f.redirect&&(!f.component||!f.file))return[f];let g=null;return u!=null&&(g=u(f,m),g==null)?[f]:m.reduce((_,E)=>{const{name:F}=f;let{path:I}=f;const T=N({},f);F&&(T.name=`${F}${l}${E}`),f.children&&(T.children=f.children.reduce((w,k)=>[...w,...h(k,[E],!0,S)],[]));const y=E===t;if(y&&a==="prefix_and_default")if(R)R&&S&&F&&(T.name+=`${l}${n}`);else{const w=X(N({},T),{path:I});if(F&&(w.name=`${T.name}${l}${n}`),f.children){w.children=[];for(const k of f.children)w.children=w.children.concat(h(k,[E],!0,!0))}_.push(w)}const ce=R&&!I.startsWith("/"),re=!ce&&!(y&&a==="prefix_except_default");return re&&(I=`/${E}${I}`),I&&(I=Te(I,o,ce)),re&&y&&a==="prefix"&&c&&_.push(N({},f)),T.path=I,_.push(T),_},[])}return e.reduce((f,m)=>[...f,...h(m,d||[])],[])}function Ve(e,{locales:t=[],localeCodes:a=[],baseUrl:o=ee}={}){if(!B(e.global,e.mode))throw new Error("TODO:");const l=r.ref(t),n=r.ref(a);e.global.locales=r.computed(()=>l.value),e.global.localeCodes=r.computed(()=>n.value),e.global.__baseUrl=K(o,{})}function Be(e,t={}){const{version:a,defaultLocale:o,locales:l,strategy:n,trailingSlash:c,routesNameSeparator:u,defaultLocaleRouteNameSuffix:i,defaultDirection:d,baseUrl:h,routes:f,routeOptionsResolver:m}=je(t),R=G(l),S=R.map(E=>E.code),g=le(S,u,i);Ve(e,{locales:R,baseUrl:h,localeCodes:S});const A=ne(f,{locales:l,defaultLocale:o,strategy:n,trailingSlash:c,routesNameSeparator:u,defaultLocaleRouteNameSuffix:i,optionsResolver:m});t.routes=A;const _=De(t,a);return _.__defaultLocale=o,_.__localeCodes=S,_.__strategy=n,_.__trailingSlash=c,_.__routesNameSeparator=u,_.__defaultLocaleRouteNameSuffix=i,_.__defaultDirection=d,_.beforeEach((E,F,I)=>{const T=U(e),y=g(E)||T||o||"";T!==y&&W(e,y),I()}),_}function De(e,t){if(r.isVue3&&t===4)return L.createRouter(e);if(r.isVue2&&t===3)return new he.default(e);throw new Error("TODO:")}function Me(e){return new RegExp(`^/(${e.join("|")})(?:/|$)`,"i")}function le(e,t,a){const o=`(${e.join("|")})`,l=`(?:${t}${a})?`,n=new RegExp(`${t}${o}${l}$`,"i"),c=Me(e);return i=>{if(Re(i)){if(i.name){const h=(P(i.name)?i.name:i.name.toString()).match(n);if(h&&h.length>1)return h[1]}else if(i.path){const d=i.path.match(c);if(d&&d.length>1)return d[1]}}else if(P(i)){const d=i.match(c);if(d&&d.length>1)return d[1]}return""}}function je(e){var t,a,o,l,n,c,u,i,d,h;return e.version=(t=e.version)!=null?t:4,e.defaultLocale=(a=e.defaultLocale)!=null?a:C,e.strategy=(o=e.strategy)!=null?o:O,e.trailingSlash=(l=e.trailingSlash)!=null?l:Z,e.routesNameSeparator=(n=e.routesNameSeparator)!=null?n:b,e.defaultLocaleRouteNameSuffix=(c=e.defaultLocaleRouteNameSuffix)!=null?c:D,e.locales=(u=e.locales)!=null?u:[],e.defaultDirection=(i=e.defaultDirection)!=null?i:$e,e.baseUrl=(d=e.baseUrl)!=null?d:ee,e.routes=(h=e.routes)!=null?h:[],e}const ze="0.0.0";return s.VERSION=ze,s.createLocaleFromRouteGetter=le,s.createRouter=Be,s.findBrowserLocale=ye,s.getLocale=U,s.getRouteBaseName=v,s.localeLocation=Ce,s.localePath=te,s.localeRoute=ae,s.localizeRoutes=ne,s.resolveBaseUrl=K,s.setLocale=W,s.switchLocalePath=j,s.useI18nHead=Oe,Object.defineProperty(s,"__esModule",{value:!0}),s[Symbol.toStringTag]="Module",s}({},VueDemi,VueRouter,VueI18n);
{
"name": "vue-i18n-routing",
"description": "The i18n routing with using vue-i18n",
"version": "0.0.0-9f94af5",
"version": "0.0.0-ab35914",
"dependencies": {
"@intlify/shared": "beta",
"vue-demi": "*"
"@intlify/vue-i18n-bridge": "^0.3.5",
"@intlify/vue-router-bridge": "^0.3.5",
"ufo": "^0.7.9",
"vue-demi": "^0.12.1"
},
"devDependencies": {
"@microsoft/api-extractor": "^7.18.20",
"@vue/test-utils": "^1.3.0",
"api-docs-gen": "^0.4.0",
"rimraf": "^3.0.2",
"vite": "^2.7.4",
"typescript": "^4.5.4",
"vite": "latest",
"vite-plugin-dts": "^0.9.6",
"vitest": "^0.2.8",
"vue": "^3.2.23",
"vue-i18n": "npm:vue-i18n@next",
"vue-i18n-bridge": "beta",
"vue-i18n-legacy": "npm:vue-i18n@latest",
"vue-i18n-legacy": "npm:vue-i18n@8",
"vue-router": "^4.0.12",
"vue-router3": "npm:vue-router@latest",
"vue-router3": "npm:vue-router@3",
"vue-template-compiler": "^2.6.14",
"vue2": "npm:vue@2"

@@ -26,2 +33,4 @@ },

"vue": "^2.6.14 || ^3.2.0",
"vue-i18n": "^8.26.1 || ^9.2.0-beta.30",
"vue-i18n-bridge": "^9.2.0-beta.30",
"vue-router": "^3.5.3 || ^4.0.0"

@@ -57,4 +66,7 @@ },

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

@@ -86,5 +98,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"
},
"readme": "# vue-i18n-routing\n\nThe i18n routing with using vue-i18n\n\nWIP: 👷\n\n## 🤝 API\n\nAbout details, See the [API References]('./api.md)\n\n## Šī¸ License\n\n[MIT](http://opensource.org/licenses/MIT)"
}
}

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

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

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡ī¸ by Socket Inc