vue-i18n-routing
Advanced tools
Comparing version 0.0.0-44f5c85 to 0.0.0-46a6e19
@@ -1,5 +0,5 @@ | ||
"use strict";var W=Object.defineProperty,k=Object.defineProperties;var H=Object.getOwnPropertyDescriptors;var b=Object.getOwnPropertySymbols;var y=Object.prototype.hasOwnProperty,D=Object.prototype.propertyIsEnumerable;var O=(e,t,a)=>t in e?W(e,t,{enumerable:!0,configurable:!0,writable:!0,value:a}):e[t]=a,F=(e,t)=>{for(var a in t||(t={}))y.call(t,a)&&O(e,a,t[a]);if(b)for(var a of b(t))D.call(t,a)&&O(e,a,t[a]);return e},P=(e,t)=>k(e,H(t));var V=(e,t)=>{var a={};for(var r in e)y.call(e,r)&&t.indexOf(r)<0&&(a[r]=e[r]);if(e!=null&&b)for(var r of b(e))t.indexOf(r)<0&&D.call(e,r)&&(a[r]=e[r]);return a};Object.defineProperty(exports,"__esModule",{value:!0});exports[Symbol.toStringTag]="Module";var m=require("vue-demi"),A=require("@intlify/vue-router-bridge"),Y=require("@intlify/vue-i18n-bridge");function J(e){return e&&typeof e=="object"&&"default"in e?e:{default:e}}var K=J(A);/*! | ||
* shared v9.2.0-beta.26 | ||
* (c) 2021 kazuya kawaguchi | ||
"use strict";var ce=Object.defineProperty,se=Object.defineProperties;var ue=Object.getOwnPropertyDescriptors;var F=Object.getOwnPropertySymbols;var G=Object.prototype.hasOwnProperty,H=Object.prototype.propertyIsEnumerable;var B=(e,t,a)=>t in e?ce(e,t,{enumerable:!0,configurable:!0,writable:!0,value:a}):e[t]=a,I=(e,t)=>{for(var a in t||(t={}))G.call(t,a)&&B(e,a,t[a]);if(F)for(var a of F(t))H.call(t,a)&&B(e,a,t[a]);return e},N=(e,t)=>se(e,ue(t));var W=(e,t)=>{var a={};for(var l in e)G.call(e,l)&&t.indexOf(l)<0&&(a[l]=e[l]);if(e!=null&&F)for(var l of F(e))t.indexOf(l)<0&&H.call(e,l)&&(a[l]=e[l]);return a};Object.defineProperty(exports,"__esModule",{value:!0});exports[Symbol.toStringTag]="Module";var R=require("vue-demi"),A=require("@intlify/vue-router-bridge"),Y=require("@intlify/vue-i18n-bridge");function ie(e){return e&&typeof e=="object"&&"default"in e?e:{default:e}}var fe=ie(A);/*! | ||
* shared v9.2.0-beta.30 | ||
* (c) 2022 kazuya kawaguchi | ||
* Released under the MIT License. | ||
*/const U=Object.assign,T=e=>typeof e=="string",Q=e=>typeof e=="symbol";function Z(e){e=e||[];const t=[];for(const a of e)T(a)?t.push({code:a}):t.push(a);return t}function I(e,t){return m.isRef(e.locale)&&t==="composition"}function w(e){return"global"in e&&"mode"in e}function z(e){return w(e)?I(e.global,e.mode)?e.global.locale.value:e.global.locale:e.locale.value}function ee(e,t){w(e)?I(e.global,e.mode)?e.global.locale.value=t:e.global.locale=t:m.isRef(e.locale)&&(e.locale.value=t)}function te(e,t,a){return e.replace(/\/+$/,"")+(t?"/":"")||(a?"":"/")}function ae(e={}){const t=Y.useI18n(),a=A.useRouter(),r=A.useRoute(),R=e.defaultLocaleRouteNameSuffix||a.__defaultLocaleRouteNameSuffix,g=e.defaultLocale||a.__defaultLocale,_=e.routesNameSeparator||a.__routesNameSeparator,L=e.strategy||a.__strategy;function s(o){const c=o!=null?o:m.isRef(r)?r.value:r;return c.name?C(c.name).split(_)[0]:void 0}function h(o,c){let l=C(o)+(L==="no_prefix"?"":_+c);return c===g&&L==="prefix_and_default"&&(l+=_+R),l}function n(o,c){const l=c||z(t);let f=o;T(o)&&(o[0]==="/"?f={path:o}:f={name:o});let u=U({},f);if(u.path&&!u.name){const d=a.resolve(u),v=m.isVue2?d.route:d,E=s(v);T(E)&&(u={name:h(E,l),params:v.params,query:v.query,hash:v.hash})}else{u.name=h(u.name,l);const{params:d}=u;d&&d["0"]===void 0&&d.pathMatch&&(d["0"]=d.pathMatch)}const S=a.resolve(u);return(m.isVue2?S.route.name:S.name)?S:a.resolve(o)}function p(o,c){const l=n(o,c);return l==null?"":m.isVue2?l.route.redirectedFrom||l.route.fullPath:l.redirectedFrom||l.fullPath}function x(o,c){const l=n(o,c);return l==null?void 0:m.isVue2?l.route:l}function $(o,c){const l=n(o,c);return l==null?void 0:m.isVue2?l.location:l.href}function i(o){const c=s();if(!c)return"";const v=m.isVue2&&m.isRef(r)?r.value:r,{params:l}=v,f=V(v,["params"]),u={},S=U({},f,{name:c,params:P(F(F({},l),u),{0:l.pathMatch})}),d=p(S,o);return console.log("switchLocalePath",t.locale.value,o,d),d}return{getRouteBaseName:s,localePath:p,localeRoute:x,localeLocation:$,switchLocalePath:i}}function C(e){return T(e)?e:Q(e)?e.toString():"(null)"}const oe={PREFIX:"prefix",PREFIX_EXCEPT_DEFAULT:"prefix_except_default",PREFIX_AND_DEFAULT:"prefix_and_default",NO_PREFIX:"no_prefix"},X="",M=oe.PREFIX_EXCEPT_DEFAULT,j=!1,q="___",G="default";function B(e,{defaultLocale:t=X,strategy:a=M,trailingSlash:r=j,routesNameSeparator:R=q,defaultLocaleRouteNameSuffix:g=G,includeUprefixedFallback:_=!1,locales:L=[]}={}){if(a==="no_prefix")return e;const s=L.map(n=>T(n)?n:n.code);function h(n,p,x=!1,$=!1){return n.redirect&&(!n.component||!n.file)?[n]:p.reduce((o,c)=>{const{name:l}=n;let{path:f}=n;const u=F({},n);l&&(u.name=`${l}${R}${c}`),n.children&&(u.children=n.children.reduce((E,N)=>[...E,...h(N,[c],!0,$)],[]));const S=c===t;if(S&&a==="prefix_and_default")if(x)x&&$&&l&&(u.name+=`${R}${g}`);else{const E=P(F({},u),{path:f});if(l&&(E.name=`${u.name}${R}${g}`),n.children){E.children=[];for(const N of n.children)E.children=E.children.concat(h(N,[c],!0,!0))}o.push(E)}const d=x&&!f.startsWith("/"),v=!d&&!(S&&a==="prefix_except_default");return v&&(f=`/${c}${f}`),f&&(f=te(f,r,d)),v&&S&&a==="prefix"&&_&&o.push(F({},n)),u.path=f,o.push(u),o},[])}return e.reduce((n,p)=>[...n,...h(p,s||[])],[])}function le(e,{locales:t=[]}={}){if(!I(e.global,e.mode))throw new Error("TODO:");const a=m.ref(t);e.global.locales=m.computed(()=>a.value),console.log("... extends i18n done")}function ne(e){return new RegExp(`^/(${e.join("|")})(?:/|$)`,"i")}function re(e,t,a){const r=`(${e.join("|")})`,R=`(?:${t}${a})?`,g=new RegExp(`${t}${r}${R}$`,"i"),_=ne(e);return s=>{if(s.name){const n=(T(s.name)?s.name:s.name.toString()).match(g);if(n&&n.length>1)return n[1]}else if(s.path){const h=s.path.match(_);if(h&&h.length>1)return h[1]}return""}}function ce(e){var t,a,r,R,g,_,L,s;return e.version=(t=e.version)!=null?t:4,e.defaultLocale=(a=e.defaultLocale)!=null?a:X,e.strategy=(r=e.strategy)!=null?r:M,e.trailingSlash=(R=e.trailingSlash)!=null?R:j,e.routesNameSeparator=(g=e.routesNameSeparator)!=null?g:q,e.defaultLocaleRouteNameSuffix=(_=e.defaultLocaleRouteNameSuffix)!=null?_:G,e.locales=(L=e.locales)!=null?L:[],e.routes=(s=e.routes)!=null?s:[],e}function ue(e,t={}){const{version:a,defaultLocale:r,locales:R,strategy:g,trailingSlash:_,routesNameSeparator:L,defaultLocaleRouteNameSuffix:s,routes:h}=ce(t),n=Z(R),p=n.map(o=>o.code),x=re(p,L,s);le(e,{locales:n});const $=B(h,{locales:R,defaultLocale:r,strategy:g,trailingSlash:_,routesNameSeparator:L,defaultLocaleRouteNameSuffix:s});t.routes=$;let i=null;if(m.isVue3&&a===4)i=A.createRouter(t);else if(m.isVue2&&a===3)i=new K.default(t);else throw new Error("TODO:");return i.__defaultLocale=r,i.__localeCodes=p,i.__strategy=g,i.__trailingSlash=_,i.__routesNameSeparator=L,i.__defaultLocaleRouteNameSuffix=s,i.beforeEach((o,c,l)=>{console.log("beforeEach",o,c);const f=z(e),u=x(o)||f||r||"";console.log("currentLocale",f,"finalLocale",u),f!==u&&ee(e,u),l()}),console.log("create router",i),i}const se="0.0.0";exports.VERSION=se;exports.createRouter=ue;exports.localizeRoutes=B;exports.useI18nRouting=ae; | ||
*/const J=Object.assign,de=Array.isArray,he=e=>typeof e=="function",P=e=>typeof e=="string",_e=e=>typeof e=="boolean",me=e=>typeof e=="symbol",Re=/\/$|\/\?/;function w(e="",t=!1){return t?Re.test(e):e.endsWith("/")}function ge(e="",t=!1){if(!t)return(w(e)?e.slice(0,-1):e)||"/";if(!w(e,!0))return e||"/";const[a,...l]=e.split("?");return(a.slice(0,-1)||"/")+(l.length?`?${l.join("?")}`:"")}function Le(e="",t=!1){if(!t)return e.endsWith("/")?e:e+"/";if(w(e,!0))return e||"/";const[a,...l]=e.split("?");return a+"/"+(l.length?`?${l.join("?")}`:"")}function Ee(e,t){typeof console!="undefined"&&(console.warn("[vue-i18n-routing] "+e),t&&console.warn(t.stack))}function K(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 Z(e){return"global"in e&&"mode"in e}function M(e){return Z(e)?X(e.global,e.mode)?e.global.locale.value:e.global.locale:e.locale.value}function pe(e,t){Z(e)?X(e.global,e.mode)?e.global.locale.value=t:e.global.locale=t:R.isRef(e.locale)&&(e.locale.value=t)}function ve(e,t,a){return e.replace(/\/+$/,"")+(t?"/":"")||(a?"":"/")}function ee(e){return P(e)?e:me(e)?e.toString():"(null)"}function Q(e,t,{defaultLocale:a,strategy:l,routesNameSeparator:o,defaultLocaleRouteNameSuffix:n}){let r=ee(e)+(l==="no_prefix"?"":o+t);return t===a&&l==="prefix_and_default"&&(r+=o+n),r}function Se(e,t){return he(e)?e(t):e}const D={PREFIX:"prefix",PREFIX_EXCEPT_DEFAULT:"prefix_except_default",PREFIX_AND_DEFAULT:"prefix_and_default",NO_PREFIX:"no_prefix"},x="",$=D.PREFIX_EXCEPT_DEFAULT,te=!1,b="___",q="default",Ae="ltr",ae="",ye=new Set([D.PREFIX_AND_DEFAULT,D.PREFIX_EXCEPT_DEFAULT]);function U(e=A.useRoute(),{router:t=A.useRouter(),routesNameSeparator:a=b}={}){const l=a||t.__routesNameSeparator,o=R.unref(e);return o.name?ee(o.name).split(l)[0]:null}function le(e,t,a){const l=z(e,t,a);return l==null?"":R.isVue3?l.redirectedFrom||l.fullPath:l.route.redirectedFrom||l.route.fullPath}function ne(e,t,a){const l=z(e,t,a);return l==null?void 0:R.isVue3?l:l.route}function Ie(e,t,a){const l=z(e,t,a);return l==null?void 0:R.isVue3?l:l.location}function z(e,t,{router:a=A.useRouter(),i18n:l=Y.useI18n(),defaultLocale:o=x,defaultLocaleRouteNameSuffix:n=q,routesNameSeparator:r=b,strategy:i=$,trailingSlash:f=!1}={}){const s=a.__defaultLocaleRouteNameSuffix||n,h=a.__defaultLocale||o,c=a.__routesNameSeparator||r,_=a.__strategy||i,m=t||M(l);let g=e;P(e)&&(g[0]==="/"?g={path:e}:g={name:e});let d=J({},g);if(d.path&&!d.name){const u=a.resolve(d),L=R.isVue3?u:u.route,S=U(L);P(S)?d={name:Q(S,m,{defaultLocale:h,strategy:_,routesNameSeparator:c,defaultLocaleRouteNameSuffix:s}),params:L.params,query:L.query,hash:L.hash}:(!(m===o&&ye.has(_))&&_!==D.NO_PREFIX&&(d.path=`/${m}${d.path}`),d.path=f?Le(d.path,!0):ge(d.path,!0))}else{d.name=Q(d.name,m,{defaultLocale:h,strategy:_,routesNameSeparator:c,defaultLocaleRouteNameSuffix:s});const{params:u}=d;u&&u["0"]===void 0&&u.pathMatch&&(u["0"]=u.pathMatch)}const v=a.resolve(d);return(R.isVue3?v.name:v.route.name)?v:a.resolve(e)}function C(e,t){const a=t&&t.route||A.useRoute(),l=U(a,t);if(!l)return"";const s=!R.isVue3&&R.isRef(a)?a.value:a,{params:o}=s,n=W(s,["params"]),r={},i=J({},n,{name:l,params:N(I(I({},o),r),{0:o.pathMatch})});return le(i,e,t)}function Te({addDirAttribute:e=!1,addSeoAttributes:t=!1,strategy:a=$,defaultLocale:l=x,route:o=A.useRoute(),router:n=A.useRouter(),i18n:r=Y.useI18n()}={}){const i=l||n.__defaultLocale,f=a||n.__strategy,s=R.ref({htmlAttrs:{},link:[],meta:[]});function h(){s.value={htmlAttrs:{},link:[],meta:[]}}function c(_){if(r.locales==null||r.__baseUrl==null)return;const m=M(r),g=K(r.locales.value).find(u=>u.code===m)||{code:m},d=g.iso,v=g.dir||n.__defaultDirection;if(e&&(s.value.htmlAttrs.dir=v),t&&m&&r.locales){d&&(s.value.htmlAttrs.lang=d);const u=r.locales.value;Pe(u,r.__baseUrl,s.value.link,{defaultLocale:i,strategy:f,route:o,router:n,i18n:r}),De(r.__baseUrl,s.value.link,t,{route:_,router:n,i18n:r}),Fe(g,d,s.value.meta),Ne(u,d,s.value.meta)}}return R.watch(n.currentRoute,_=>{h(),c(_)}),c(o),s}function Pe(e,t,a,l){if(l.strategy===D.NO_PREFIX)return;const o=new Map;for(const n of e){const r=n.iso;if(!r){Ee("Locale ISO code is required to generate alternate link");continue}const[i,f]=r.split("-");i&&f&&(n.isCatchallLocale||!o.has(i))&&o.set(i,n),o.set(r,n)}for(const[n,r]of o.entries()){const i=C(r.code,l);i&&a.push({hid:`i18n-alt-${n}`,rel:"alternate",href:V(i,t),hreflang:n})}if(l.defaultLocale){const n=C(l.defaultLocale,l);n&&a.push({hid:"i18n-xd",rel:"alternate",href:V(n,t),hreflang:"x-default"})}}function De(e,t,a,l){const{route:o}=l,n=ne(N(I({},o),{name:U(o,l)}),void 0,l);if(n){let r=V(n.path,e);const i=!_e(a)&&a.canonicalQueries||[];if(i.length){const f=n.query,s=new URLSearchParams;for(const c of i)if(c in f){const _=f[c];de(_)?_.forEach(m=>s.append(c,m||"")):s.append(c,_||"")}const h=s.toString();h&&(r=`${r}?${h}`)}t.push({hid:"i18n-can",rel:"canonical",href:r})}}function Fe(e,t,a){!(e&&t)||a.push({hid:"i18n-og",property:"og:locale",content:oe(t)})}function Ne(e,t,a){const l=e.filter(o=>{const n=o.iso;return n&&n!==t});if(l.length){const o=l.map(n=>({hid:`i18n-og-alt-${n.iso}`,property:"og:locale:alternate",content:oe(n.iso)}));a.push(...o)}}function oe(e){return(e||"").replace(/-/g,"_")}function V(e,t){return e.match(/^https?:\/\//)?e:t+e}function re(e,{defaultLocale:t=x,strategy:a=$,trailingSlash:l=te,routesNameSeparator:o=b,defaultLocaleRouteNameSuffix:n=q,includeUprefixedFallback:r=!1,optionsResolver:i=void 0,locales:f=[]}={}){if(a==="no_prefix")return e;const s=f.map(c=>P(c)?c:c.code);function h(c,_,m=!1,g=!1){if(c.redirect&&(!c.component||!c.file))return[c];let d=null;return i!=null&&(d=i(c,_),d==null)?[c]:_.reduce((u,L)=>{const{name:S}=c;let{path:E}=c;const p=I({},c);S&&(p.name=`${S}${o}${L}`),c.children&&(p.children=c.children.reduce((y,O)=>[...y,...h(O,[L],!0,g)],[]));const T=L===t;if(T&&a==="prefix_and_default")if(m)m&&g&&S&&(p.name+=`${o}${n}`);else{const y=N(I({},p),{path:E});if(S&&(y.name=`${p.name}${o}${n}`),c.children){y.children=[];for(const O of c.children)y.children=y.children.concat(h(O,[L],!0,!0))}u.push(y)}const j=m&&!E.startsWith("/"),k=!j&&!(T&&a==="prefix_except_default");return k&&(E=`/${L}${E}`),E&&(E=ve(E,l,j)),k&&T&&a==="prefix"&&r&&u.push(I({},c)),p.path=E,u.push(p),u},[])}return e.reduce((c,_)=>[...c,...h(_,s||[])],[])}function xe(e,{locales:t=[],baseUrl:a=ae}={}){if(!X(e.global,e.mode))throw new Error("TODO:");const l=R.ref(t);e.global.locales=R.computed(()=>l.value),e.global.__baseUrl=Se(a,{})}function $e(e){return new RegExp(`^/(${e.join("|")})(?:/|$)`,"i")}function be(e,t,a){const l=`(${e.join("|")})`,o=`(?:${t}${a})?`,n=new RegExp(`${t}${l}${o}$`,"i"),r=$e(e);return f=>{if(f.name){const h=(P(f.name)?f.name:f.name.toString()).match(n);if(h&&h.length>1)return h[1]}else if(f.path){const s=f.path.match(r);if(s&&s.length>1)return s[1]}return""}}function Ue(e){var t,a,l,o,n,r,i,f,s,h;return e.version=(t=e.version)!=null?t:4,e.defaultLocale=(a=e.defaultLocale)!=null?a:x,e.strategy=(l=e.strategy)!=null?l:$,e.trailingSlash=(o=e.trailingSlash)!=null?o:te,e.routesNameSeparator=(n=e.routesNameSeparator)!=null?n:b,e.defaultLocaleRouteNameSuffix=(r=e.defaultLocaleRouteNameSuffix)!=null?r:q,e.locales=(i=e.locales)!=null?i:[],e.defaultDirection=(f=e.defaultDirection)!=null?f:Ae,e.baseUrl=(s=e.baseUrl)!=null?s:ae,e.routes=(h=e.routes)!=null?h:[],e}function Oe(e,t={}){const{version:a,defaultLocale:l,locales:o,strategy:n,trailingSlash:r,routesNameSeparator:i,defaultLocaleRouteNameSuffix:f,defaultDirection:s,baseUrl:h,routes:c,routeOptionsResolver:_}=Ue(t),m=K(o),g=m.map(L=>L.code),d=be(g,i,f);xe(e,{locales:m,baseUrl:h});const v=re(c,{locales:o,defaultLocale:l,strategy:n,trailingSlash:r,routesNameSeparator:i,defaultLocaleRouteNameSuffix:f,optionsResolver:_});t.routes=v;let u=null;if(R.isVue3&&a===4)u=A.createRouter(t);else if(R.isVue2&&a===3)u=new fe.default(t);else throw new Error("TODO:");return u.__defaultLocale=l,u.__localeCodes=g,u.__strategy=n,u.__trailingSlash=r,u.__routesNameSeparator=i,u.__defaultLocaleRouteNameSuffix=f,u.__defaultDirection=s,u.beforeEach((L,S,E)=>{const p=M(e),T=d(L)||p||l||"";p!==T&&pe(e,T),E()}),u}const we="0.0.0";exports.VERSION=we;exports.createRouter=Oe;exports.getRouteBaseName=U;exports.localeLocation=Ie;exports.localePath=le;exports.localeRoute=ne;exports.localizeRoutes=re;exports.switchLocalePath=C;exports.useI18nHead=Te; |
@@ -0,11 +1,37 @@ | ||
import { Composer } from '@intlify/vue-i18n-bridge'; | ||
import type { I18n } from '@intlify/vue-i18n-bridge'; | ||
import { Locale } 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 { 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>; | ||
}; | ||
/** | ||
* Create a Vue Router instance | ||
@@ -24,2 +50,4 @@ * | ||
* At the Vue 2 will return a [Vue Router v3 instance](https://router.vuejs.org/api/#router-construction-options), and at the Vue 3 will return a [Vue Router v4 instance](https://next.router.vuejs.org/api/#createrouter). | ||
* | ||
* @public | ||
*/ | ||
@@ -33,13 +61,57 @@ export declare function createRouter<Options extends VueI18nRoutingOptions = VueI18nRoutingOptions>(i18n: I18n, options?: Options): Options['version'] extends 4 ? Router : VueRouter; | ||
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' | 'locales' | 'routesNameSeparator'>; | ||
/** | ||
* 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 | ||
@@ -57,6 +129,43 @@ */ | ||
export declare function localizeRoutes(routes: VueI18nRoute[], { defaultLocale, strategy, trailingSlash, routesNameSeparator, defaultLocaleRouteNameSuffix, includeUprefixedFallback, locales }?: Pick<VueI18nRoutingOptions, 'defaultLocale' | 'strategy' | 'locales' | '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>; | ||
/** | ||
@@ -84,2 +193,19 @@ * Route config for vue-router v4 | ||
/** | ||
* 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[]; | ||
} | ||
declare const STRATEGIES: { | ||
@@ -97,5 +223,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(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>; | ||
@@ -123,3 +266,3 @@ /** | ||
*/ | ||
export declare type VueI18nRoutingOptions = { | ||
export declare type VueI18nRoutingOptions<BaseUrl extends BaseUrlResolveHandler = BaseUrlResolveHandler> = { | ||
/** | ||
@@ -150,3 +293,4 @@ * Vue Router version | ||
* | ||
* @remarks TODO: | ||
* @remarks | ||
* Can either be an array of string codes (e.g. `['en', 'fr']`) or an array of {@link LocaleObject} for more complex configurations | ||
* | ||
@@ -191,9 +335,41 @@ * @defaultValue [] | ||
defaultLocaleRouteNameSuffix?: string; | ||
/** | ||
* Default direction direction | ||
* | ||
* @defaultValue 'ltr' | ||
*/ | ||
defaultDirection?: Directions; | ||
/** | ||
* The fallback base URL to use as a prefix for alternate URLs in hreflang tags. | ||
* | ||
* @remarks | ||
* By default VueRouter's base URL will be used and only if that is not available, fallback URL will be used. | ||
* | ||
* Can also be a function (will be passed a Nuxt Context as a parameter) that returns a string. | ||
* | ||
* Useful to make base URL dynamic based on request headers. | ||
* | ||
* @defaultValue '' | ||
*/ | ||
baseUrl?: string | BaseUrl; | ||
/** | ||
* Route options resolver | ||
* | ||
* @defaultValue undefined | ||
*/ | ||
routeOptionsResolver?: RouteOptionsResolver; | ||
} & RouterOptions; | ||
export { } | ||
import type { ComputedRef } from 'vue-demi' | ||
declare module 'vue-i18n' { | ||
export interface ComposerCustom { | ||
locales: ComputedRef<string[] | LocaleObject[]> | ||
/** | ||
* List of locales | ||
* | ||
* @defaultValue `undefined` | ||
*/ | ||
locales?: ComputedRef<string[] | LocaleObject[]> | ||
__baseUrl?: string | ||
} | ||
@@ -203,4 +379,10 @@ } | ||
export interface ComposerCustom { | ||
locales: ComputedRef<string[] | LocaleObject[]> | ||
/** | ||
* List of locales | ||
* | ||
* @defaultValue `undefined` | ||
*/ | ||
locales?: ComputedRef<string[] | LocaleObject[]> | ||
__baseUrl?: string | ||
} | ||
} |
@@ -32,13 +32,51 @@ var __defProp = Object.defineProperty; | ||
}; | ||
import { isRef, isVue2, ref, computed, isVue3 } from "vue-demi"; | ||
import VueRouter3, { useRouter, useRoute, createRouter as createRouter$1 } from "@intlify/vue-router-bridge"; | ||
import { isRef, unref, isVue3, ref, watch, 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.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 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("?")}` : ""); | ||
} | ||
function warn(msg, err) { | ||
if (typeof console !== "undefined") { | ||
console.warn(`[vue-i18n-routing] ` + msg); | ||
if (err) { | ||
console.warn(err.stack); | ||
} | ||
} | ||
} | ||
function getNormalizedLocales(locales) { | ||
@@ -79,112 +117,307 @@ locales = locales || []; | ||
} | ||
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 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; | ||
} | ||
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 resolveBaseUrl(baseUrl, context) { | ||
if (isFunction(baseUrl)) { | ||
return baseUrl(context); | ||
} | ||
return baseUrl; | ||
} | ||
const STRATEGIES = { | ||
PREFIX: "prefix", | ||
PREFIX_EXCEPT_DEFAULT: "prefix_except_default", | ||
PREFIX_AND_DEFAULT: "prefix_and_default", | ||
NO_PREFIX: "no_prefix" | ||
}; | ||
const DEFAULT_LOCALE = ""; | ||
const DEFAULT_STRATEGY = STRATEGIES.PREFIX_EXCEPT_DEFAULT; | ||
const DEFAULT_TRAILING_SLASH = false; | ||
const DEFAULT_ROUTES_NAME_SEPARATOR = "___"; | ||
const DEFAULT_LOCALE_ROUTE_NAME_SUFFIX = "default"; | ||
const DEFAULT_DETECTION_DIRECTION = "ltr"; | ||
const DEFAULT_BASE_URL = ""; | ||
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 }; | ||
} | ||
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 | ||
}; | ||
} | ||
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 { | ||
localizedRoute.name = getLocaleRouteName(localizedRoute.name, _locale); | ||
const { params } = localizedRoute; | ||
if (params && params["0"] === void 0 && params.pathMatch) { | ||
params["0"] = params.pathMatch; | ||
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); | ||
} | ||
const resolvedRoute = $router.resolve(localizedRoute); | ||
if (isVue2 ? resolvedRoute.route.name : resolvedRoute.name) { | ||
return resolvedRoute; | ||
} 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; | ||
} | ||
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; | ||
const resolvedRoute = router.resolve(localizedRoute); | ||
if (isVue3 ? resolvedRoute.name : resolvedRoute.route.name) { | ||
return resolvedRoute; | ||
} | ||
function localeRoute(route, locale) { | ||
const resolved = resolveRoute(route, locale); | ||
return resolved == null ? void 0 : isVue2 ? resolved.route : resolved; | ||
return router.resolve(route); | ||
} | ||
function switchLocalePath(locale, options) { | ||
const route = options && options.route || useRoute(); | ||
const name = getRouteBaseName(route, options); | ||
if (!name) { | ||
return ""; | ||
} | ||
function localeLocation(route, locale) { | ||
const resolved = resolveRoute(route, locale); | ||
return resolved == null ? void 0 : isVue2 ? resolved.location : resolved.href; | ||
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 _defaultLocale = defaultLocale || router.__defaultLocale; | ||
const _strategy = strategy || router.__strategy; | ||
const metaObject = ref({ | ||
htmlAttrs: {}, | ||
link: [], | ||
meta: [] | ||
}); | ||
function cleanMeta() { | ||
metaObject.value = { | ||
htmlAttrs: {}, | ||
link: [], | ||
meta: [] | ||
}; | ||
} | ||
function switchLocalePath(locale) { | ||
const name = getRouteBaseName(); | ||
if (!name) { | ||
return ""; | ||
function updateMeta(_route) { | ||
if (i18n.locales == null || i18n.__baseUrl == null) { | ||
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 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); | ||
} | ||
} | ||
watch(router.currentRoute, (val) => { | ||
cleanMeta(); | ||
updateMeta(val); | ||
}); | ||
updateMeta(route); | ||
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 | ||
}); | ||
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 addCurrentOgLocale(currentLocale, currentLocaleIso, meta) { | ||
const hasCurrentLocaleAndIso = currentLocale && currentLocaleIso; | ||
if (!hasCurrentLocaleAndIso) { | ||
return; | ||
} | ||
meta.push({ | ||
hid: "i18n-og", | ||
property: "og:locale", | ||
content: hypenToUnderscore(currentLocaleIso) | ||
}); | ||
} | ||
const STRATEGIES = { | ||
PREFIX: "prefix", | ||
PREFIX_EXCEPT_DEFAULT: "prefix_except_default", | ||
PREFIX_AND_DEFAULT: "prefix_and_default", | ||
NO_PREFIX: "no_prefix" | ||
}; | ||
const DEFAULT_LOCALE = ""; | ||
const DEFAULT_STRATEGY = STRATEGIES.PREFIX_EXCEPT_DEFAULT; | ||
const DEFAULT_TRAILING_SLASH = false; | ||
const DEFAULT_ROUTES_NAME_SEPARATOR = "___"; | ||
const DEFAULT_LOCALE_ROUTE_NAME_SUFFIX = "default"; | ||
function 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, { | ||
@@ -197,2 +430,3 @@ defaultLocale = DEFAULT_LOCALE, | ||
includeUprefixedFallback = false, | ||
optionsResolver = void 0, | ||
locales = [] | ||
@@ -208,2 +442,9 @@ } = {}) { | ||
} | ||
let routeOptions = null; | ||
if (optionsResolver != null) { | ||
routeOptions = optionsResolver(route, allowedLocaleCodes); | ||
if (routeOptions == null) { | ||
return [route]; | ||
} | ||
} | ||
const targetLocales = allowedLocaleCodes; | ||
@@ -256,3 +497,3 @@ return targetLocales.reduce((_routes, locale) => { | ||
} | ||
function extendI18n(i18n, { locales = [] } = {}) { | ||
function extendI18n(i18n, { locales = [], baseUrl = DEFAULT_BASE_URL } = {}) { | ||
if (!isComposer(i18n.global, i18n.mode)) { | ||
@@ -263,3 +504,3 @@ throw new Error("TODO:"); | ||
i18n.global.locales = computed(() => _locales.value); | ||
console.log("... extends i18n done"); | ||
i18n.global.__baseUrl = resolveBaseUrl(baseUrl, {}); | ||
} | ||
@@ -292,3 +533,3 @@ function getLocalesRegex(localeCodes) { | ||
function asDefaultVueI18nRouterOptions(options) { | ||
var _a, _b, _c, _d, _e, _f, _g, _h; | ||
var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j; | ||
options.version = (_a = options.version) != null ? _a : 4; | ||
@@ -301,3 +542,5 @@ options.defaultLocale = (_b = options.defaultLocale) != null ? _b : DEFAULT_LOCALE; | ||
options.locales = (_g = options.locales) != null ? _g : []; | ||
options.routes = (_h = options.routes) != null ? _h : []; | ||
options.defaultDirection = (_h = options.defaultDirection) != null ? _h : DEFAULT_DETECTION_DIRECTION; | ||
options.baseUrl = (_i = options.baseUrl) != null ? _i : DEFAULT_BASE_URL; | ||
options.routes = (_j = options.routes) != null ? _j : []; | ||
return options; | ||
@@ -314,3 +557,6 @@ } | ||
defaultLocaleRouteNameSuffix, | ||
routes | ||
defaultDirection, | ||
baseUrl, | ||
routes, | ||
routeOptionsResolver: optionsResolver | ||
} = asDefaultVueI18nRouterOptions(options); | ||
@@ -320,3 +566,3 @@ const normalizedLocaleCodes = getNormalizedLocales(locales); | ||
const getLocaleFromRoute = createLocaleFromRouteGetter(localeCodes, routesNameSeparator, defaultLocaleRouteNameSuffix); | ||
extendI18n(i18n, { locales: normalizedLocaleCodes }); | ||
extendI18n(i18n, { locales: normalizedLocaleCodes, baseUrl }); | ||
const localizedRoutes = localizeRoutes(routes, { | ||
@@ -328,3 +574,4 @@ locales, | ||
routesNameSeparator, | ||
defaultLocaleRouteNameSuffix | ||
defaultLocaleRouteNameSuffix, | ||
optionsResolver | ||
}); | ||
@@ -346,7 +593,6 @@ options.routes = localizedRoutes; | ||
router.__defaultLocaleRouteNameSuffix = defaultLocaleRouteNameSuffix; | ||
router.__defaultDirection = defaultDirection; | ||
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) { | ||
@@ -357,6 +603,5 @@ setLocale(i18n, finalLocale); | ||
}); | ||
console.log("create router", router); | ||
return router; | ||
} | ||
const VERSION = "0.0.0"; | ||
export { VERSION, createRouter, localizeRoutes, useI18nRouting }; | ||
export { VERSION, createRouter, getRouteBaseName, localeLocation, localePath, localeRoute, localizeRoutes, switchLocalePath, useI18nHead }; |
@@ -1,5 +0,5 @@ | ||
var ue=Object.defineProperty,se=Object.defineProperties;var fe=Object.getOwnPropertyDescriptors;var b=Object.getOwnPropertySymbols;var D=Object.prototype.hasOwnProperty,W=Object.prototype.propertyIsEnumerable;var k=(r,t,f)=>t in r?ue(r,t,{enumerable:!0,configurable:!0,writable:!0,value:f}):r[t]=f,P=(r,t)=>{for(var f in t||(t={}))D.call(t,f)&&k(r,f,t[f]);if(b)for(var f of b(t))W.call(t,f)&&k(r,f,t[f]);return r},v=(r,t)=>se(r,fe(t));var B=(r,t)=>{var f={};for(var p in r)D.call(r,p)&&t.indexOf(p)<0&&(f[p]=r[p]);if(r!=null&&b)for(var p of b(r))t.indexOf(p)<0&&W.call(r,p)&&(f[p]=r[p]);return f};var VueI18nRouting=function(r,t,f,p){"use strict";function H(e){return e&&typeof e=="object"&&"default"in e?e:{default:e}}var Y=H(f);/*! | ||
* shared v9.2.0-beta.26 | ||
* (c) 2021 kazuya kawaguchi | ||
var we=Object.defineProperty,De=Object.defineProperties;var Ce=Object.getOwnPropertyDescriptors;var w=Object.getOwnPropertySymbols;var oe=Object.prototype.hasOwnProperty,ce=Object.prototype.propertyIsEnumerable;var ne=(u,s,_)=>s in u?we(u,s,{enumerable:!0,configurable:!0,writable:!0,value:_}):u[s]=_,F=(u,s)=>{for(var _ in s||(s={}))oe.call(s,_)&&ne(u,_,s[_]);if(w)for(var _ of w(s))ce.call(s,_)&&ne(u,_,s[_]);return u},D=(u,s)=>De(u,Ce(s));var re=(u,s)=>{var _={};for(var p in u)oe.call(u,p)&&s.indexOf(p)<0&&(_[p]=u[p]);if(u!=null&&w)for(var p of w(u))s.indexOf(p)<0&&ce.call(u,p)&&(_[p]=u[p]);return _};var VueI18nRouting=function(u,s,_,p){"use strict";function se(e){return e&&typeof e=="object"&&"default"in e?e:{default:e}}var ue=se(_);/*! | ||
* shared v9.2.0-beta.30 | ||
* (c) 2022 kazuya kawaguchi | ||
* Released under the MIT License. | ||
*/const V=Object.assign,I=e=>typeof e=="string",J=e=>typeof e=="symbol";function K(e){e=e||[];const l=[];for(const c of e)I(c)?l.push({code:c}):l.push(c);return l}function y(e,l){return t.isRef(e.locale)&&l==="composition"}function U(e){return"global"in e&&"mode"in e}function w(e){return U(e)?y(e.global,e.mode)?e.global.locale.value:e.global.locale:e.locale.value}function Q(e,l){U(e)?y(e.global,e.mode)?e.global.locale.value=l:e.global.locale=l:t.isRef(e.locale)&&(e.locale.value=l)}function Z(e,l,c){return e.replace(/\/+$/,"")+(l?"/":"")||(c?"":"/")}function ee(e={}){const l=p.useI18n(),c=f.useRouter(),_=f.useRoute(),m=e.defaultLocaleRouteNameSuffix||c.__defaultLocaleRouteNameSuffix,E=e.defaultLocale||c.__defaultLocale,g=e.routesNameSeparator||c.__routesNameSeparator,S=e.strategy||c.__strategy;function i(a){const u=a!=null?a:t.isRef(_)?_.value:_;return u.name?z(u.name).split(g)[0]:void 0}function L(a,u){let o=z(a)+(S==="no_prefix"?"":g+u);return u===E&&S==="prefix_and_default"&&(o+=g+m),o}function n(a,u){const o=u||w(l);let d=a;I(a)&&(a[0]==="/"?d={path:a}:d={name:a});let s=V({},d);if(s.path&&!s.name){const R=c.resolve(s),$=t.isVue2?R.route:R,F=i($);I(F)&&(s={name:L(F,o),params:$.params,query:$.query,hash:$.hash})}else{s.name=L(s.name,o);const{params:R}=s;R&&R["0"]===void 0&&R.pathMatch&&(R["0"]=R.pathMatch)}const x=c.resolve(s);return(t.isVue2?x.route.name:x.name)?x:c.resolve(a)}function T(a,u){const o=n(a,u);return o==null?"":t.isVue2?o.route.redirectedFrom||o.route.fullPath:o.redirectedFrom||o.fullPath}function A(a,u){const o=n(a,u);return o==null?void 0:t.isVue2?o.route:o}function N(a,u){const o=n(a,u);return o==null?void 0:t.isVue2?o.location:o.href}function h(a){const u=i();if(!u)return"";const $=t.isVue2&&t.isRef(_)?_.value:_,{params:o}=$,d=B($,["params"]),s={},x=V({},d,{name:u,params:v(P(P({},o),s),{0:o.pathMatch})}),R=T(x,a);return console.log("switchLocalePath",l.locale.value,a,R),R}return{getRouteBaseName:i,localePath:T,localeRoute:A,localeLocation:N,switchLocalePath:h}}function z(e){return I(e)?e:J(e)?e.toString():"(null)"}const te={PREFIX:"prefix",PREFIX_EXCEPT_DEFAULT:"prefix_except_default",PREFIX_AND_DEFAULT:"prefix_and_default",NO_PREFIX:"no_prefix"},C="",X=te.PREFIX_EXCEPT_DEFAULT,M=!1,j="___",G="default";function q(e,{defaultLocale:l=C,strategy:c=X,trailingSlash:_=M,routesNameSeparator:m=j,defaultLocaleRouteNameSuffix:E=G,includeUprefixedFallback:g=!1,locales:S=[]}={}){if(c==="no_prefix")return e;const i=S.map(n=>I(n)?n:n.code);function L(n,T,A=!1,N=!1){return n.redirect&&(!n.component||!n.file)?[n]:T.reduce((a,u)=>{const{name:o}=n;let{path:d}=n;const s=P({},n);o&&(s.name=`${o}${m}${u}`),n.children&&(s.children=n.children.reduce((F,O)=>[...F,...L(O,[u],!0,N)],[]));const x=u===l;if(x&&c==="prefix_and_default")if(A)A&&N&&o&&(s.name+=`${m}${E}`);else{const F=v(P({},s),{path:d});if(o&&(F.name=`${s.name}${m}${E}`),n.children){F.children=[];for(const O of n.children)F.children=F.children.concat(L(O,[u],!0,!0))}a.push(F)}const R=A&&!d.startsWith("/"),$=!R&&!(x&&c==="prefix_except_default");return $&&(d=`/${u}${d}`),d&&(d=Z(d,_,R)),$&&x&&c==="prefix"&&g&&a.push(P({},n)),s.path=d,a.push(s),a},[])}return e.reduce((n,T)=>[...n,...L(T,i||[])],[])}function ae(e,{locales:l=[]}={}){if(!y(e.global,e.mode))throw new Error("TODO:");const c=t.ref(l);e.global.locales=t.computed(()=>c.value),console.log("... extends i18n done")}function oe(e){return new RegExp(`^/(${e.join("|")})(?:/|$)`,"i")}function le(e,l,c){const _=`(${e.join("|")})`,m=`(?:${l}${c})?`,E=new RegExp(`${l}${_}${m}$`,"i"),g=oe(e);return i=>{if(i.name){const n=(I(i.name)?i.name:i.name.toString()).match(E);if(n&&n.length>1)return n[1]}else if(i.path){const L=i.path.match(g);if(L&&L.length>1)return L[1]}return""}}function ne(e){var l,c,_,m,E,g,S,i;return e.version=(l=e.version)!=null?l:4,e.defaultLocale=(c=e.defaultLocale)!=null?c:C,e.strategy=(_=e.strategy)!=null?_:X,e.trailingSlash=(m=e.trailingSlash)!=null?m:M,e.routesNameSeparator=(E=e.routesNameSeparator)!=null?E:j,e.defaultLocaleRouteNameSuffix=(g=e.defaultLocaleRouteNameSuffix)!=null?g:G,e.locales=(S=e.locales)!=null?S:[],e.routes=(i=e.routes)!=null?i:[],e}function ce(e,l={}){const{version:c,defaultLocale:_,locales:m,strategy:E,trailingSlash:g,routesNameSeparator:S,defaultLocaleRouteNameSuffix:i,routes:L}=ne(l),n=K(m),T=n.map(a=>a.code),A=le(T,S,i);ae(e,{locales:n});const N=q(L,{locales:m,defaultLocale:_,strategy:E,trailingSlash:g,routesNameSeparator:S,defaultLocaleRouteNameSuffix:i});l.routes=N;let h=null;if(t.isVue3&&c===4)h=f.createRouter(l);else if(t.isVue2&&c===3)h=new Y.default(l);else throw new Error("TODO:");return h.__defaultLocale=_,h.__localeCodes=T,h.__strategy=E,h.__trailingSlash=g,h.__routesNameSeparator=S,h.__defaultLocaleRouteNameSuffix=i,h.beforeEach((a,u,o)=>{console.log("beforeEach",a,u);const d=w(e),s=A(a)||d||_||"";console.log("currentLocale",d,"finalLocale",s),d!==s&&Q(e,s),o()}),console.log("create router",h),h}const re="0.0.0";return r.VERSION=re,r.createRouter=ce,r.localizeRoutes=q,r.useI18nRouting=ee,Object.defineProperty(r,"__esModule",{value:!0}),r[Symbol.toStringTag]="Module",r}({},VueDemi,VueRouter,VueI18n); | ||
*/const G=Object.assign,fe=Array.isArray,ie=e=>typeof e=="function",N=e=>typeof e=="string",de=e=>typeof e=="boolean",he=e=>typeof e=="symbol",_e=/\/$|\/\?/;function C(e="",t=!1){return t?_e.test(e):e.endsWith("/")}function me(e="",t=!1){if(!t)return(C(e)?e.slice(0,-1):e)||"/";if(!C(e,!0))return e||"/";const[a,...l]=e.split("?");return(a.slice(0,-1)||"/")+(l.length?`?${l.join("?")}`:"")}function ge(e="",t=!1){if(!t)return e.endsWith("/")?e:e+"/";if(C(e,!0))return e||"/";const[a,...l]=e.split("?");return a+"/"+(l.length?`?${l.join("?")}`:"")}function Le(e,t){typeof console!="undefined"&&(console.warn("[vue-i18n-routing] "+e),t&&console.warn(t.stack))}function H(e){e=e||[];const t=[];for(const a of e)N(a)?t.push({code:a}):t.push(a);return t}function X(e,t){return s.isRef(e.locale)&&t==="composition"}function W(e){return"global"in e&&"mode"in e}function M(e){return W(e)?X(e.global,e.mode)?e.global.locale.value:e.global.locale:e.locale.value}function Re(e,t){W(e)?X(e.global,e.mode)?e.global.locale.value=t:e.global.locale=t:s.isRef(e.locale)&&(e.locale.value=t)}function Ee(e,t,a){return e.replace(/\/+$/,"")+(t?"/":"")||(a?"":"/")}function B(e){return N(e)?e:he(e)?e.toString():"(null)"}function Q(e,t,{defaultLocale:a,strategy:l,routesNameSeparator:o,defaultLocaleRouteNameSuffix:n}){let c=B(e)+(l==="no_prefix"?"":o+t);return t===a&&l==="prefix_and_default"&&(c+=o+n),c}function Se(e,t){return ie(e)?e(t):e}const v={PREFIX:"prefix",PREFIX_EXCEPT_DEFAULT:"prefix_except_default",PREFIX_AND_DEFAULT:"prefix_and_default",NO_PREFIX:"no_prefix"},U="",b=v.PREFIX_EXCEPT_DEFAULT,Y=!1,O="___",V="default",pe="ltr",J="",Ae=new Set([v.PREFIX_AND_DEFAULT,v.PREFIX_EXCEPT_DEFAULT]);function x(e=_.useRoute(),{router:t=_.useRouter(),routesNameSeparator:a=O}={}){const l=a||t.__routesNameSeparator,o=s.unref(e);return o.name?B(o.name).split(l)[0]:null}function K(e,t,a){const l=z(e,t,a);return l==null?"":s.isVue3?l.redirectedFrom||l.fullPath:l.route.redirectedFrom||l.route.fullPath}function Z(e,t,a){const l=z(e,t,a);return l==null?void 0:s.isVue3?l:l.route}function Ie(e,t,a){const l=z(e,t,a);return l==null?void 0:s.isVue3?l:l.location}function z(e,t,{router:a=_.useRouter(),i18n:l=p.useI18n(),defaultLocale:o=U,defaultLocaleRouteNameSuffix:n=V,routesNameSeparator:c=O,strategy:d=b,trailingSlash:h=!1}={}){const f=a.__defaultLocaleRouteNameSuffix||n,g=a.__defaultLocale||o,r=a.__routesNameSeparator||c,L=a.__strategy||d,R=t||M(l);let E=e;N(e)&&(E[0]==="/"?E={path:e}:E={name:e});let m=G({},E);if(m.path&&!m.name){const i=a.resolve(m),S=s.isVue3?i:i.route,y=x(S);N(y)?m={name:Q(y,R,{defaultLocale:g,strategy:L,routesNameSeparator:r,defaultLocaleRouteNameSuffix:f}),params:S.params,query:S.query,hash:S.hash}:(!(R===o&&Ae.has(L))&&L!==v.NO_PREFIX&&(m.path=`/${R}${m.path}`),m.path=h?ge(m.path,!0):me(m.path,!0))}else{m.name=Q(m.name,R,{defaultLocale:g,strategy:L,routesNameSeparator:r,defaultLocaleRouteNameSuffix:f});const{params:i}=m;i&&i["0"]===void 0&&i.pathMatch&&(i["0"]=i.pathMatch)}const T=a.resolve(m);return(s.isVue3?T.name:T.route.name)?T:a.resolve(e)}function j(e,t){const a=t&&t.route||_.useRoute(),l=x(a,t);if(!l)return"";const f=!s.isVue3&&s.isRef(a)?a.value:a,{params:o}=f,n=re(f,["params"]),c={},d=G({},n,{name:l,params:D(F(F({},o),c),{0:o.pathMatch})});return K(d,e,t)}function Te({addDirAttribute:e=!1,addSeoAttributes:t=!1,strategy:a=b,defaultLocale:l=U,route:o=_.useRoute(),router:n=_.useRouter(),i18n:c=p.useI18n()}={}){const d=l||n.__defaultLocale,h=a||n.__strategy,f=s.ref({htmlAttrs:{},link:[],meta:[]});function g(){f.value={htmlAttrs:{},link:[],meta:[]}}function r(L){if(c.locales==null||c.__baseUrl==null)return;const R=M(c),E=H(c.locales.value).find(i=>i.code===R)||{code:R},m=E.iso,T=E.dir||n.__defaultDirection;if(e&&(f.value.htmlAttrs.dir=T),t&&R&&c.locales){m&&(f.value.htmlAttrs.lang=m);const i=c.locales.value;ye(i,c.__baseUrl,f.value.link,{defaultLocale:d,strategy:h,route:o,router:n,i18n:c}),Pe(c.__baseUrl,f.value.link,t,{route:L,router:n,i18n:c}),Fe(E,m,f.value.meta),Ne(i,m,f.value.meta)}}return s.watch(n.currentRoute,L=>{g(),r(L)}),r(o),f}function ye(e,t,a,l){if(l.strategy===v.NO_PREFIX)return;const o=new Map;for(const n of e){const c=n.iso;if(!c){Le("Locale ISO code is required to generate alternate link");continue}const[d,h]=c.split("-");d&&h&&(n.isCatchallLocale||!o.has(d))&&o.set(d,n),o.set(c,n)}for(const[n,c]of o.entries()){const d=j(c.code,l);d&&a.push({hid:`i18n-alt-${n}`,rel:"alternate",href:k(d,t),hreflang:n})}if(l.defaultLocale){const n=j(l.defaultLocale,l);n&&a.push({hid:"i18n-xd",rel:"alternate",href:k(n,t),hreflang:"x-default"})}}function Pe(e,t,a,l){const{route:o}=l,n=Z(D(F({},o),{name:x(o,l)}),void 0,l);if(n){let c=k(n.path,e);const d=!de(a)&&a.canonicalQueries||[];if(d.length){const h=n.query,f=new URLSearchParams;for(const r of d)if(r in h){const L=h[r];fe(L)?L.forEach(R=>f.append(r,R||"")):f.append(r,L||"")}const g=f.toString();g&&(c=`${c}?${g}`)}t.push({hid:"i18n-can",rel:"canonical",href:c})}}function Fe(e,t,a){!(e&&t)||a.push({hid:"i18n-og",property:"og:locale",content:ee(t)})}function Ne(e,t,a){const l=e.filter(o=>{const n=o.iso;return n&&n!==t});if(l.length){const o=l.map(n=>({hid:`i18n-og-alt-${n.iso}`,property:"og:locale:alternate",content:ee(n.iso)}));a.push(...o)}}function ee(e){return(e||"").replace(/-/g,"_")}function k(e,t){return e.match(/^https?:\/\//)?e:t+e}function te(e,{defaultLocale:t=U,strategy:a=b,trailingSlash:l=Y,routesNameSeparator:o=O,defaultLocaleRouteNameSuffix:n=V,includeUprefixedFallback:c=!1,optionsResolver:d=void 0,locales:h=[]}={}){if(a==="no_prefix")return e;const f=h.map(r=>N(r)?r:r.code);function g(r,L,R=!1,E=!1){if(r.redirect&&(!r.component||!r.file))return[r];let m=null;return d!=null&&(m=d(r,L),m==null)?[r]:L.reduce((i,S)=>{const{name:y}=r;let{path:A}=r;const I=F({},r);y&&(I.name=`${y}${o}${S}`),r.children&&(I.children=r.children.reduce((P,q)=>[...P,...g(q,[S],!0,E)],[]));const $=S===t;if($&&a==="prefix_and_default")if(R)R&&E&&y&&(I.name+=`${o}${n}`);else{const P=D(F({},I),{path:A});if(y&&(P.name=`${I.name}${o}${n}`),r.children){P.children=[];for(const q of r.children)P.children=P.children.concat(g(q,[S],!0,!0))}i.push(P)}const ae=R&&!A.startsWith("/"),le=!ae&&!($&&a==="prefix_except_default");return le&&(A=`/${S}${A}`),A&&(A=Ee(A,l,ae)),le&&$&&a==="prefix"&&c&&i.push(F({},r)),I.path=A,i.push(I),i},[])}return e.reduce((r,L)=>[...r,...g(L,f||[])],[])}function $e(e,{locales:t=[],baseUrl:a=J}={}){if(!X(e.global,e.mode))throw new Error("TODO:");const l=s.ref(t);e.global.locales=s.computed(()=>l.value),e.global.__baseUrl=Se(a,{})}function ve(e){return new RegExp(`^/(${e.join("|")})(?:/|$)`,"i")}function Ue(e,t,a){const l=`(${e.join("|")})`,o=`(?:${t}${a})?`,n=new RegExp(`${t}${l}${o}$`,"i"),c=ve(e);return h=>{if(h.name){const g=(N(h.name)?h.name:h.name.toString()).match(n);if(g&&g.length>1)return g[1]}else if(h.path){const f=h.path.match(c);if(f&&f.length>1)return f[1]}return""}}function be(e){var t,a,l,o,n,c,d,h,f,g;return e.version=(t=e.version)!=null?t:4,e.defaultLocale=(a=e.defaultLocale)!=null?a:U,e.strategy=(l=e.strategy)!=null?l:b,e.trailingSlash=(o=e.trailingSlash)!=null?o:Y,e.routesNameSeparator=(n=e.routesNameSeparator)!=null?n:O,e.defaultLocaleRouteNameSuffix=(c=e.defaultLocaleRouteNameSuffix)!=null?c:V,e.locales=(d=e.locales)!=null?d:[],e.defaultDirection=(h=e.defaultDirection)!=null?h:pe,e.baseUrl=(f=e.baseUrl)!=null?f:J,e.routes=(g=e.routes)!=null?g:[],e}function Oe(e,t={}){const{version:a,defaultLocale:l,locales:o,strategy:n,trailingSlash:c,routesNameSeparator:d,defaultLocaleRouteNameSuffix:h,defaultDirection:f,baseUrl:g,routes:r,routeOptionsResolver:L}=be(t),R=H(o),E=R.map(S=>S.code),m=Ue(E,d,h);$e(e,{locales:R,baseUrl:g});const T=te(r,{locales:o,defaultLocale:l,strategy:n,trailingSlash:c,routesNameSeparator:d,defaultLocaleRouteNameSuffix:h,optionsResolver:L});t.routes=T;let i=null;if(s.isVue3&&a===4)i=_.createRouter(t);else if(s.isVue2&&a===3)i=new ue.default(t);else throw new Error("TODO:");return i.__defaultLocale=l,i.__localeCodes=E,i.__strategy=n,i.__trailingSlash=c,i.__routesNameSeparator=d,i.__defaultLocaleRouteNameSuffix=h,i.__defaultDirection=f,i.beforeEach((S,y,A)=>{const I=M(e),$=m(S)||I||l||"";I!==$&&Re(e,$),A()}),i}const xe="0.0.0";return u.VERSION=xe,u.createRouter=Oe,u.getRouteBaseName=x,u.localeLocation=Ie,u.localePath=K,u.localeRoute=Z,u.localizeRoutes=te,u.switchLocalePath=j,u.useI18nHead=Te,Object.defineProperty(u,"__esModule",{value:!0}),u[Symbol.toStringTag]="Module",u}({},VueDemi,VueRouter,VueI18n); |
{ | ||
"name": "vue-i18n-routing", | ||
"description": "The i18n routing with using vue-i18n", | ||
"version": "0.0.0-44f5c85", | ||
"version": "0.0.0-46a6e19", | ||
"dependencies": { | ||
"@intlify/shared": "beta", | ||
"@intlify/vue-i18n-bridge": "^0.3.4", | ||
"@intlify/vue-router-bridge": "^0.3.4", | ||
"@intlify/vue-i18n-bridge": "^0.3.5", | ||
"@intlify/vue-router-bridge": "^0.3.5", | ||
"ufo": "^0.7.9", | ||
"vue-demi": "^0.12.1" | ||
@@ -13,13 +14,16 @@ }, | ||
"@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", | ||
"vite": "latest", | ||
"vite-plugin-dts": "^0.9.6", | ||
"vitest": "^0.2.8", | ||
"vue": "^3.2.23", | ||
"vue-i18n": "npm:vue-i18n@next", | ||
"vue-i18n-bridge": "beta", | ||
"vue-i18n-legacy": "npm:vue-i18n@latest", | ||
"vue-i18n-legacy": "npm:vue-i18n@8", | ||
"vue-router": "^4.0.12", | ||
"vue-router3": "npm:vue-router@latest", | ||
"vue-router3": "npm:vue-router@3", | ||
"vue-template-compiler": "^2.6.14", | ||
"vue2": "npm:vue@2" | ||
@@ -30,4 +34,4 @@ }, | ||
"vue": "^2.6.14 || ^3.2.0", | ||
"vue-i18n": "^8.26.1 || ^9.2.0-beta.25", | ||
"vue-i18n-bridge": "^9.2.0-beta.25", | ||
"vue-i18n": "^8.26.1 || ^9.2.0-beta.30", | ||
"vue-i18n-bridge": "^9.2.0-beta.30", | ||
"vue-router": "^3.5.3 || ^4.0.0" | ||
@@ -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" | ||
} | ||
} |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
57644
1024
10
16
+ Addedufo@^0.7.9
+ Addedufo@0.7.11(transitive)