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-2ade018 to 0.0.0-2adf43f

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

@@ -1,11 +0,42 @@

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 { Route as Route_2 } from '@intlify/vue-router-bridge';
import type { RouteConfig } from '@intlify/vue-router-bridge';
import type { RouteLocation } from '@intlify/vue-router-bridge';
import type { RouteLocationNormalizedLoaded } from '@intlify/vue-router-bridge';
import type { RouteLocationRaw } from '@intlify/vue-router-bridge';
import type { Router } from '@intlify/vue-router-bridge';
import type { RouterOptions } from '@intlify/vue-router-bridge';
import { useRoute } from '@intlify/vue-router-bridge';
import { useRouter } from '@intlify/vue-router-bridge';
import type { VueRouter } from '@intlify/vue-router-bridge';
export declare type BaseUrlResolveHandler = (context: unknown) => string;
export declare type ComposableOptions = {
route?: ReturnType<typeof useRoute>;
router?: ReturnType<typeof useRouter>;
i18n?: Composer;
};
/**
* 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).
*/
export declare function createRouter<Options extends VueI18nRoutingOptions = VueI18nRoutingOptions>(i18n: I18n, options?: Options): Options['version'] extends 4 ? Router : VueRouter;
/**
* Direction

@@ -15,17 +46,57 @@ */

export declare function extendRouting<TRouter extends VueRouter | Router>({ router, i18n, defaultLocale, trailingSlash, routesNameSeparator, defaultLocaleRouteNameSuffix, localeCodes }?: VueI18nRoutingOptions): TRouter;
/**
* Get route base name
*
* @param givenRoute - A route object, if not provided, the route is returned with `useRoute` will be used
* @param routesNameSeparator - A route name separator, if not provided, default separator is `routesNameSeparator` option of {@link VueI18nRoutingOptions} will be used
*
* @returns The route base name, if route name is not defined, return null
*/
export declare function getRouteBaseName(givenRoute?: Route_2 | RouteLocationNormalizedLoaded, routesNameSeparator?: string): string | null;
export declare type I18nRoutingOptions = Pick<VueI18nRoutingOptions, 'defaultLocale' | 'strategy' | 'defaultLocaleRouteNameSuffix' | 'trailingSlash' | 'localeCodes'> & {
routesNameSeparator?: string;
};
/**
* I18n header meta info
*/
export declare interface I18nHeadMetaInfo {
htmlAttrs?: MetaAttrs;
meta?: MetaAttrs;
link?: MetaAttrs;
}
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;
/**
* 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,6 +114,32 @@ */

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;
export declare function localizeRoutes(routes: VueI18nRoute[], { defaultLocale, strategy, trailingSlash, routesNameSeparator, defaultLocaleRouteNameSuffix, includeUprefixedFallback, locales }?: Pick<VueI18nRoutingOptions, 'defaultLocale' | 'strategy' | 'locales' | 'routesNameSeparator' | 'trailingSlash' | 'defaultLocaleRouteNameSuffix'> & {
includeUprefixedFallback?: boolean;
}): VueI18nRoute[];
export declare type MetaAttrs = Record<string, any>;
/**

@@ -70,2 +167,14 @@ * Route config for vue-router v4

/**
* SEO Attribute options
*/
export declare interface SeoAttributesOptions {
/**
* An array of strings corresponding to query params you would like to include in your canonical URL.
*
* @defaultValue []
*/
canonicalQueries?: string[];
}
declare const STRATEGIES: {

@@ -83,5 +192,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, { route, i18n }?: 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): 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): I18nHeadMetaInfo;

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

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

@@ -105,23 +231,95 @@ /**

/**
* 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 TODO:
*
* @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 detection direction
*
* @defaultValue 'ltr'
*/
defaultDetection?: Directions;
/**
* The fallback base URL to use as a prefix for alternate URLs in hreflang tags.
*
* @remarks
* By default VueRouter's base URL will be used and only if that is not available, fallback URL will be used.
*
* Can also be a function (will be passed a Nuxt Context as a parameter) that returns a string.
*
* Useful to make base URL dynamic based on request headers.
*
* @defaultValue ''
*/
baseUrl?: string | BaseUrl;
} & RouterOptions;
export { }
import type { ComputedRef } from 'vue'

@@ -131,3 +329,10 @@ declare module 'vue-i18n' {

locales: ComputedRef<string[] | LocaleObject[]>
__baseUrl: string
}
}
declare module 'vue-i18n-bridge' {
export interface ComposerCustom {
locales: ComputedRef<string[] | LocaleObject[]>
__baseUrl: string
}
}

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

};
import { ref, computed, isVue2, isRef as isRef$1 } from "vue-demi";
import { useRouter, useRoute } from "@intlify/vue-router-bridge";
import { isRef, unref, isVue3, ref, computed, isVue2 } from "vue-demi";
import VueRouter3, { useRoute, useRouter, createRouter as createRouter$1 } from "@intlify/vue-router-bridge";
import { useI18n } from "@intlify/vue-i18n-bridge";
/*!
* shared v9.2.0-beta.26
* (c) 2021 kazuya kawaguchi
* shared v9.2.0-beta.28
* (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 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("?")}` : "");
}
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 +101,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 +118,23 @@ function setLocale(i18n, locale) {

}
function extendI18n(i18n, { localeCodes = [] } = {}) {
if (!isComposer(i18n.global, i18n.mode)) {
throw new Error("");
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 = {

@@ -106,2 +151,254 @@ PREFIX: "prefix",

const DEFAULT_LOCALE_ROUTE_NAME_SUFFIX = "default";
const DEFAULT_DETECTION_DIRECTION = "ltr";
const DEFAULT_BASE_URL = "";
function getRouteBaseName(givenRoute = useRoute(), routesNameSeparator = useRouter().__routesNameSeparator || DEFAULT_ROUTES_NAME_SEPARATOR) {
const _route = unref(givenRoute);
if (!_route.name) {
return null;
}
const name = getRouteName(_route.name);
return name.split(routesNameSeparator)[0];
}
const RESOLVED_PREFIXED = new Set([STRATEGIES.PREFIX_AND_DEFAULT, STRATEGIES.PREFIX_EXCEPT_DEFAULT]);
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, { route = useRoute(), i18n = useI18n() } = {}) {
const name = getRouteBaseName();
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, { route, i18n });
return path;
}
function useI18nHead({
addDirAttribute = false,
addSeoAttributes = false,
strategy = DEFAULT_STRATEGY,
defaultLocale = DEFAULT_LOCALE,
route = useRoute(),
router = useRouter(),
i18n = useI18n()
} = {}) {
const _defaultLocale = defaultLocale || router.__defaultLocale;
const _strategy = strategy || router.__strategy;
const metaObject = {
htmlAttrs: {},
link: [],
meta: []
};
const locale = getLocale(i18n);
const currentLocale = router.__localeProperties || { code: locale };
const currentLocaleIso = currentLocale.iso;
const currentLocaleDir = currentLocale.dir || router.__defaultDetection;
if (addDirAttribute) {
metaObject.htmlAttrs.dir = currentLocaleDir;
}
if (addSeoAttributes && locale && i18n.locales) {
if (currentLocaleIso) {
metaObject.htmlAttrs.lang = currentLocaleIso;
}
const locales = i18n.locales.value;
addHreflangLinks(locales, i18n.__baseUrl, metaObject.link, {
defaultLocale: _defaultLocale,
strategy: _strategy,
route,
router,
i18n
});
addCanonicalLinks(i18n.__baseUrl, metaObject.link, addSeoAttributes, { route, router, i18n });
addCurrentOgLocale(currentLocale, currentLocaleIso, metaObject.meta);
addAlternateOgLocales(locales, currentLocaleIso, metaObject.meta);
}
return metaObject;
}
function addHreflangLinks(locales, baseUrl, link, options) {
if (options.strategy === STRATEGIES.NO_PREFIX) {
return;
}
const localeMap = new Map();
for (const locale of locales) {
const localeIso = locale.iso;
if (!localeIso) {
warn("Locale ISO code is required to generate alternate link");
continue;
}
const [language, region] = localeIso.split("-");
if (language && region && (locale.isCatchallLocale || !localeMap.has(language))) {
localeMap.set(language, locale);
}
localeMap.set(localeIso, locale);
}
for (const [iso, mapLocale] of localeMap.entries()) {
const localePath2 = switchLocalePath(mapLocale.code, options);
if (localePath2) {
link.push({
hid: `i18n-alt-${iso}`,
rel: "alternate",
href: toAbsoluteUrl(localePath2, baseUrl),
hreflang: iso
});
}
}
if (options.defaultLocale) {
const localePath2 = switchLocalePath(options.defaultLocale, options);
if (localePath2) {
link.push({
hid: "i18n-xd",
rel: "alternate",
href: toAbsoluteUrl(localePath2, baseUrl),
hreflang: "x-default"
});
}
}
}
function addCanonicalLinks(baseUrl, link, seoAttributesOptions, options) {
const { route } = options;
const currentRoute = localeRoute(__spreadProps(__spreadValues({}, route), {
name: getRouteBaseName()
}), 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 +411,3 @@ defaultLocale = DEFAULT_LOCALE,

includeUprefixedFallback = false,
localeCodes = []
locales = []
} = {}) {

@@ -120,3 +417,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) {

@@ -173,2 +470,10 @@ if (route.redirect && (!route.component || !route.file)) {

}
function extendI18n(i18n, { locales = [], baseUrl = DEFAULT_BASE_URL } = {}) {
if (!isComposer(i18n.global, i18n.mode)) {
throw new Error("TODO:");
}
const _locales = ref(locales);
i18n.global.locales = computed(() => _locales.value);
i18n.global.__baseUrl = resolveBaseUrl(baseUrl, {});
}
function getLocalesRegex(localeCodes) {

@@ -199,202 +504,70 @@ return new RegExp(`^/(${localeCodes.join("|")})(?:/|$)`, "i");

}
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.defaultDetection = (_h = options.defaultDetection) != 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$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,
function createRouter(i18n, options = {}) {
const {
version,
defaultLocale,
locales,
strategy,
trailingSlash,
routesNameSeparator,
defaultLocaleRouteNameSuffix,
localeCodes
defaultDetection,
baseUrl,
routes
} = asDefaultVueI18nRouterOptions(options);
const locale = getLocale(i18n);
const normalizedLocaleCodes = getNormalizedLocales(locales);
const localeCodes = normalizedLocaleCodes.map((l) => l.code);
const getLocaleFromRoute = createLocaleFromRouteGetter(localeCodes, routesNameSeparator, defaultLocaleRouteNameSuffix);
extendI18n(i18n, { locales: normalizedLocaleCodes, baseUrl });
const localizedRoutes = localizeRoutes(routes, {
locales,
defaultLocale,
strategy,
trailingSlash,
routesNameSeparator,
defaultLocaleRouteNameSuffix
});
options.routes = localizedRoutes;
let router = null;
if (isVue3 && version === 4) {
router = createRouter$1(options);
} else if (isVue2 && version === 3) {
router = new VueRouter3(options);
} else {
throw new Error("TODO:");
}
router.__defaultLocale = defaultLocale;
router.__localeCodes = localeCodes;
router.__localeProperties = normalizedLocaleCodes.find((l) => l.code === locale) || { code: locale };
router.__strategy = strategy;
router.__trailingSlash = trailingSlash;
router.__routesNameSeparator = routesNameSeparator;
router.__defaultLocaleRouteNameSuffix = defaultLocaleRouteNameSuffix;
router.__defaultDetection = defaultDetection;
router.beforeEach((to, from, next) => {
const currentLocale = getLocale(i18n);
const finalLocale = getLocaleFromRoute(to) || currentLocale || defaultLocale || "";
if (currentLocale !== finalLocale) {
setLocale(i18n, finalLocale);
}
next();
});
return router;
}
const VERSION = "";
export { VERSION, extendRouting, localizeRoutes, useI18nRouting };
const VERSION = "0.0.0";
export { VERSION, createRouter, getRouteBaseName, localeLocation, localePath, localeRoute, localizeRoutes, switchLocalePath, useI18nHead };

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

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

@@ -21,2 +24,3 @@ "vite-plugin-dts": "^0.9.6",

"vue-i18n-legacy": "npm:vue-i18n@latest",
"vue-template-compiler": "^2.6.14",
"vue-router": "^4.0.12",

@@ -29,5 +33,5 @@ "vue-router3": "npm:vue-router@latest",

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

@@ -34,0 +38,0 @@ "peerDependenciesMeta": {

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