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-50f6b19 to 0.0.0-5735bda

8

dist/vue-i18n-routing.cjs.js

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

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

@@ -1,11 +0,59 @@

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) => string;
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 +63,66 @@ */

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

@@ -43,7 +140,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(baseUrl: string | BaseUrlResolveHandler, context: unknown): string;
/**
* Route config for vue-router v4

@@ -70,2 +214,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 +252,22 @@ readonly PREFIX: "prefix";

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

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

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

@@ -105,20 +291,100 @@ /**

/**
* 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;

@@ -130,3 +396,15 @@ export { }

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
}

@@ -136,4 +414,16 @@ }

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
}
}

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

};
import { isRef, ref, computed, isVue2 } from "vue-demi";
import { useRouter, useRoute } from "@intlify/vue-router-bridge";
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.26
* (c) 2021 kazuya kawaguchi
* shared v9.2.0-beta.30
* (c) 2022 kazuya kawaguchi
* Released under the MIT License.
*/
const assign = Object.assign;
const isArray = Array.isArray;
const isFunction = (val) => typeof val === "function";
const isString = (val) => typeof val === "string";
const isBoolean = (val) => typeof val === "boolean";
const isSymbol = (val) => typeof val === "symbol";
const 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) {

@@ -79,10 +119,26 @@ locales = locales || [];

}
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;
}
const STRATEGIES = {

@@ -99,2 +155,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, {

@@ -107,3 +450,4 @@ defaultLocale = DEFAULT_LOCALE,

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

@@ -113,3 +457,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) {

@@ -119,2 +463,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;

@@ -167,2 +518,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) {

@@ -177,10 +593,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) {

@@ -194,203 +617,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;
}
function useI18nRouting(options = {}) {
const $i18n = useI18n();
const $router = useRouter();
const $route = useRoute();
const defaultLocaleRouteNameSuffix = options.defaultLocaleRouteNameSuffix || $router.__defaultLocaleRouteNameSuffix;
const defaultLocale = options.defaultLocale || $router.__defaultLocale;
const routesNameSeparator = options.routesNameSeparator || $router.__routesNameSeparator;
const strategy = options.strategy || $router.__strategy;
function getRouteBaseName(givenRoute) {
const route = givenRoute != null ? givenRoute : isRef($route) ? $route.value : $route;
if (!route.name) {
return;
}
const name = getRouteName(route.name);
return name.split(routesNameSeparator)[0];
}
function 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($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 {
getRouteBaseName,
localePath,
localeRoute,
localeLocation,
switchLocalePath
};
}
function getRouteName(routeName) {
return isString(routeName) ? routeName : isSymbol(routeName) ? routeName.toString() : "(null)";
}
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, getLocale, getRouteBaseName, localeLocation, localePath, localeRoute, localizeRoutes, resolveBaseUrl, setLocale, switchLocalePath, useI18nHead };

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

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

@@ -13,14 +14,17 @@ },

"@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",
"vue2": "npm:vue@2",
"typescript": "^4.5.4"
"vue-router3": "npm:vue-router@3",
"vue-template-compiler": "^2.6.14",
"vue2": "npm:vue@2"
},

@@ -30,4 +34,4 @@ "peerDependencies": {

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

@@ -63,4 +67,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"
},

@@ -92,4 +99,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"
}
}

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