New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.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

to
0.0.0-e9e5447

6

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 C=(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)&&C(e,o,t[o]);if(A)for(var o of A(t))X.call(t,o)&&C(e,o,t[o]);return e},T=(e,t)=>Y(e,J(t));var M=(e,t)=>{var o={};for(var r in e)N.call(e,r)&&t.indexOf(r)<0&&(o[r]=e[r]);if(e!=null&&A)for(var r of A(e))t.indexOf(r)<0&&X.call(e,r)&&(o[r]=e[r]);return o};Object.defineProperty(exports,"__esModule",{value:!0});exports[Symbol.toStringTag]="Module";var E=require("vue-demi"),j=require("@intlify/vue-router-composable"),K=require("@intlify/vue-i18n-bridge");/*!
* shared v9.2.0-beta.25
"use strict";var W=Object.defineProperty,k=Object.defineProperties;var H=Object.getOwnPropertyDescriptors;var A=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(A)for(var a of A(t))D.call(t,a)&&O(e,a,t[a]);return e},T=(e,t)=>k(e,H(t));var V=(e,t)=>{var a={};for(var n in e)y.call(e,n)&&t.indexOf(n)<0&&(a[n]=e[n]);if(e!=null&&A)for(var n of A(e))t.indexOf(n)<0&&D.call(e,n)&&(a[n]=e[n]);return a};Object.defineProperty(exports,"__esModule",{value:!0});exports[Symbol.toStringTag]="Module";var m=require("vue-demi"),N=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(N);/*!
* shared v9.2.0-beta.26
* (c) 2021 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 G(e){return"global"in e&&"mode"in e}function O(e){return G(e)?y(e.global,e.mode)?e.global.locale.value:e.global.locale:I(e.locale)?e.locale.value:e.locale}function B(e,t){G(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:r=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,p,L=!1,h=!1){return n.redirect&&(!n.component||!n.file)?[n]:p.reduce((l,s)=>{const{name:c}=n;let{path:u}=n;const a=F({},n);c&&(a.name=`${c}${f}${s}`),n.children&&(a.children=n.children.reduce((b,S)=>[...b,...m(S,[s],!0,h)],[]));const x=s===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,[s],!0,!0))}l.push(b)}const R=L&&!u.startsWith("/"),v=!R&&!(x&&o==="prefix_except_default");return v&&(u=`/${s}${u}`),u&&(u=oe(u,r,R)),v&&x&&o==="prefix"&&i&&l.push(F({},n)),a.path=u,l.push(a),l},[])}return e.reduce((n,p)=>[...n,...m(p,_||[])],[])}function ce(e){return new RegExp(`^/(${e.join("|")})(?:/|$)`,"i")}function le(e,t,o){const r=`(${e.join("|")})`,f=`(?:${t}${o})?`,d=new RegExp(`${t}${r}${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 se({router:e,i18n:t,defaultLocale:o=w,strategy:r=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,p=n.constructor,L=n.options.routes||[],h=V(L,{localeCodes:$,defaultLocale:o,strategy:r,trailingSlash:f,routesNameSeparator:d,defaultLocaleRouteNameSuffix:i});console.log("vue2 routes",L,h);const g=new p({mode:"history",base:n.options.base,routes:h});return g.__defaultLocale=o,g.__strategy=r,g.__trailingSlash=f,g.__routesNameSeparator=d,g.__defaultLocaleRouteNameSuffix=i,g.beforeEach((l,s,c)=>{console.log("beforeEach",l,s);const u=O(t),a=m(l)||u||o||"";console.log("currentLocale",u,"finalLocale",a),u!==a&&B(t,a),c()}),g}else{const n=e,p=n.options.routes||[],L=V(p,{localeCodes:$,defaultLocale:o,strategy:r,trailingSlash:f,routesNameSeparator:d,defaultLocaleRouteNameSuffix:i});return console.log("vue3 routes",p,L,n),p.forEach(h=>n.removeRoute(h.name)),L.forEach(h=>n.addRoute(h)),n.__defaultLocale=o,n.__strategy=r,n.__trailingSlash=f,n.__routesNameSeparator=d,n.__defaultLocaleRouteNameSuffix=i,n.beforeEach((h,g,l)=>{console.log("beforeEach",h,g);const s=O(t),c=m(h)||s||o||"";console.log("currentLocale",s,"finalLocale",c),s!==c&&B(t,c),l()}),n}}function re(e={}){const t=K.useI18n(),o=j.useRouter(),r=j.useRoute(),f=e.defaultLocaleRouteNameSuffix||o.__defaultLocaleRouteNameSuffix,d=e.defaultLocale||o.__defaultLocale,i=e.routesNameSeparator||o.__routesNameSeparator,$=e.strategy||o.__strategy;function _(l){const s=l!=null?l:E.isRef(r)?r.value:r;return s.name?k(s.name).split(i)[0]:void 0}function m(l,s){let c=k(l)+($==="no_prefix"?"":i+s);return s===d&&$==="prefix_and_default"&&(c+=i+f),c}function n(l,s){const c=s||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 p(l,s){const c=n(l,s);return c==null?"":E.isVue2?c.route.redirectedFrom||c.route.fullPath:c.redirectedFrom||c.fullPath}function L(l,s){const c=n(l,s);return c==null?void 0:E.isVue2?c.route:c}function h(l,s){const c=n(l,s);return c==null?void 0:E.isVue2?c.location:c.href}function g(l){const s=_();if(!s)return"";const v=E.isVue2&&E.isRef(r)?r.value:r,{params:c}=v,u=M(v,["params"]),a={},x=q({},u,{name:s,params:T(F(F({},c),a),{0:c.pathMatch})}),R=p(x,l);return console.log("switchLocalePath",t.locale.value,l,R),R}return{localePath:p,localeRoute:L,localeLocation:h,switchLocalePath:g}}function k(e){return P(e)?e:Q(e)?e.toString():""}function ae({router:e,i18n:t,defaultLocale:o=w,trailingSlash:r=D,routesNameSeparator:f=z,defaultLocaleRouteNameSuffix:d=U,localeCodes:i=[]}={}){if(e==null)throw new Error("TODO");return se({router:e,i18n:t,defaultLocale:o,trailingSlash:r,routesNameSeparator:f,defaultLocaleRouteNameSuffix:d,localeCodes:i})}const ue="";exports.VERSION=ue;exports.extendRouting=ae;exports.localizeRoutes=V;exports.useI18nRouting=re;
*/const U=Object.assign,b=e=>typeof e=="string",Q=e=>typeof e=="symbol";function Z(e){e=e||[];const t=[];for(const a of e)b(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=N.useRouter(),n=N.useRoute(),R=e.defaultLocaleRouteNameSuffix||a.__defaultLocaleRouteNameSuffix,g=e.defaultLocale||a.__defaultLocale,h=e.routesNameSeparator||a.__routesNameSeparator,L=e.strategy||a.__strategy;function u(r){const c=r!=null?r:m.isRef(n)?n.value:n;return c.name?X(c.name).split(h)[0]:void 0}function _(r,c){let o=X(r)+(L==="no_prefix"?"":h+c);return c===g&&L==="prefix_and_default"&&(o+=h+R),o}function l(r,c){const o=c||z(t);let s=r;b(r)&&(r[0]==="/"?s={path:r}:s={name:r});let f=U({},s);if(f.path&&!f.name){const d=a.resolve(f),v=m.isVue2?d.route:d,E=u(v);b(E)&&(f={name:_(E,o),params:v.params,query:v.query,hash:v.hash})}else{f.name=_(f.name,o);const{params:d}=f;d&&d["0"]===void 0&&d.pathMatch&&(d["0"]=d.pathMatch)}const p=a.resolve(f);return(m.isVue2?p.route.name:p.name)?p:a.resolve(r)}function S(r,c){const o=l(r,c);return o==null?"":m.isVue2?o.route.redirectedFrom||o.route.fullPath:o.redirectedFrom||o.fullPath}function x(r,c){const o=l(r,c);return o==null?void 0:m.isVue2?o.route:o}function i(r,c){const o=l(r,c);return o==null?void 0:m.isVue2?o.location:o.href}function $(r){const c=u();if(!c)return"";const v=m.isVue2&&m.isRef(n)?n.value:n,{params:o}=v,s=V(v,["params"]),f={},p=U({},s,{name:c,params:T(F(F({},o),f),{0:o.pathMatch})}),d=S(p,r);return console.log("switchLocalePath",t.locale.value,r,d),d}return{getRouteBaseName:u,localePath:S,localeRoute:x,localeLocation:i,switchLocalePath:$}}function X(e){return b(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"},M="",j=oe.PREFIX_EXCEPT_DEFAULT,C=!1,q="___",G="default";function B(e,{defaultLocale:t=M,strategy:a=j,trailingSlash:n=C,routesNameSeparator:R=q,defaultLocaleRouteNameSuffix:g=G,includeUprefixedFallback:h=!1,locales:L=[]}={}){if(a==="no_prefix")return e;const u=L.map(l=>b(l)?l:l.code);function _(l,S,x=!1,i=!1){return l.redirect&&(!l.component||!l.file)?[l]:S.reduce((r,c)=>{const{name:o}=l;let{path:s}=l;const f=F({},l);o&&(f.name=`${o}${R}${c}`),l.children&&(f.children=l.children.reduce((E,P)=>[...E,..._(P,[c],!0,i)],[]));const p=c===t;if(p&&a==="prefix_and_default")if(x)x&&i&&o&&(f.name+=`${R}${g}`);else{const E=T(F({},f),{path:s});if(o&&(E.name=`${f.name}${R}${g}`),l.children){E.children=[];for(const P of l.children)E.children=E.children.concat(_(P,[c],!0,!0))}r.push(E)}const d=x&&!s.startsWith("/"),v=!d&&!(p&&a==="prefix_except_default");return v&&(s=`/${c}${s}`),s&&(s=te(s,n,d)),v&&p&&a==="prefix"&&h&&r.push(F({},l)),f.path=s,r.push(f),r},[])}return e.reduce((l,S)=>[...l,..._(S,u||[])],[])}function le(e,{locales:t=[]}={}){if(!I(e.global,e.mode))throw new Error("");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 n=`(${e.join("|")})`,R=`(?:${t}${a})?`,g=new RegExp(`${t}${n}${R}$`,"i"),h=ne(e);return u=>{if(u.name){const l=(b(u.name)?u.name:u.name.toString()).match(g);if(l&&l.length>1)return l[1]}else if(u.path){const _=u.path.match(h);if(_&&_.length>1)return _[1]}return""}}function ce(e){var t,a,n,R,g,h,L,u;return e.version=(t=e.version)!=null?t:4,e.defaultLocale=(a=e.defaultLocale)!=null?a:M,e.strategy=(n=e.strategy)!=null?n:j,e.trailingSlash=(R=e.trailingSlash)!=null?R:C,e.routesNameSeparator=(g=e.routesNameSeparator)!=null?g:q,e.defaultLocaleRouteNameSuffix=(h=e.defaultLocaleRouteNameSuffix)!=null?h:G,e.locales=(L=e.locales)!=null?L:[],e.routes=(u=e.routes)!=null?u:[],e}function ue(e,t={}){const{version:a,defaultLocale:n,locales:R,strategy:g,trailingSlash:h,routesNameSeparator:L,defaultLocaleRouteNameSuffix:u,routes:_}=ce(t),l=Z(R),S=re(l.map($=>$.code),L,u);le(e,{locales:l});const x=B(_,{locales:R,defaultLocale:n,strategy:g,trailingSlash:h,routesNameSeparator:L,defaultLocaleRouteNameSuffix:u});t.routes=x;let i=null;if(m.isVue3&&a===4)i=N.createRouter(t);else if(m.isVue2&&a===3)i=new K.default(t);else throw new Error("TODO:");return i.__defaultLocale=n,i.__strategy=g,i.__trailingSlash=h,i.__routesNameSeparator=L,i.__defaultLocaleRouteNameSuffix=u,i.beforeEach(($,r,c)=>{console.log("beforeEach",$,r);const o=z(e),s=S($)||o||n||"";console.log("currentLocale",o,"finalLocale",s),o!==s&&ee(e,s),c()}),console.log("create router",i),i}const se="";exports.VERSION=se;exports.createRouter=ue;exports.localizeRoutes=B;exports.useI18nRouting=ae;

@@ -1,11 +0,28 @@

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 type { I18n } from '@intlify/vue-i18n-bridge';
import { Locale } from '@intlify/vue-i18n-bridge';
import type { Route as Route_2 } from '@intlify/vue-router-bridge';
import type { RouteConfig } from '@intlify/vue-router-bridge';
import type { RouteLocationNormalizedLoaded } from '@intlify/vue-router-bridge';
import type { Router } from '@intlify/vue-router-bridge';
import type { RouterOptions } from '@intlify/vue-router-bridge';
import type { VueRouter } from '@intlify/vue-router-bridge';
/**
* 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,9 +32,3 @@ */

export declare function extendRouting<TRouter extends VueRouter | Router>({ router, i18n, defaultLocale, trailingSlash, routesNameSeparator, defaultLocaleRouteNameSuffix, localeCodes }?: VueI18nRoutingOptions): TRouter;
export declare type I18nRoutingOptions = Pick<VueI18nRoutingOptions, 'defaultLocale' | 'strategy' | 'defaultLocaleRouteNameSuffix' | 'trailingSlash' | 'localeCodes'> & {
routesNameSeparator?: string;
};
export declare interface I18nRoutingReturn {
export declare interface I18nRouting {
getRouteBaseName(givenRoute?: Route_2 | RouteLocationNormalizedLoaded): string;

@@ -30,2 +41,6 @@ localePath(route: any, locale?: Locale): string;

export declare type I18nRoutingOptions = Pick<VueI18nRoutingOptions, 'defaultLocale' | 'strategy' | 'defaultLocaleRouteNameSuffix' | 'trailingSlash' | 'locales'> & {
routesNameSeparator?: string;
};
/**

@@ -44,3 +59,3 @@ * Locale object

export declare function localizeRoutes(routes: VueI18nRoute[], { defaultLocale, strategy, trailingSlash, routesNameSeparator, defaultLocaleRouteNameSuffix, includeUprefixedFallback, localeCodes }?: Pick<VueI18nRoutingOptions, 'defaultLocale' | 'strategy' | 'localeCodes' | 'routesNameSeparator' | 'trailingSlash' | 'defaultLocaleRouteNameSuffix'> & {
export declare function localizeRoutes(routes: VueI18nRoute[], { defaultLocale, strategy, trailingSlash, routesNameSeparator, defaultLocaleRouteNameSuffix, includeUprefixedFallback, locales }?: Pick<VueI18nRoutingOptions, 'defaultLocale' | 'strategy' | 'locales' | 'routesNameSeparator' | 'trailingSlash' | 'defaultLocaleRouteNameSuffix'> & {
includeUprefixedFallback?: boolean;

@@ -85,3 +100,3 @@ }): VueI18nRoute[];

export declare function useI18nRouting<Legacy extends boolean = false>(options?: I18nRoutingOptions): I18nRoutingReturn;
export declare function useI18nRouting<Legacy extends boolean = false>(options?: I18nRoutingOptions): I18nRouting;

@@ -104,23 +119,76 @@ /**

/**
* 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 = {
/**
* 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;
}
} & RouterOptions;
export { }
import type { ComputedRef } from 'vue'

@@ -132,1 +200,6 @@ declare module 'vue-i18n' {

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

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

};
import { ref, computed, isVue2, isRef as isRef$1 } from "vue-demi";
import { useRouter, useRoute } from "@intlify/vue-router-composable";
import { isRef, isVue2, ref, computed, isVue3 } from "vue-demi";
import VueRouter3, { useRouter, useRoute, createRouter as createRouter$1 } from "@intlify/vue-router-bridge";
import { useI18n } from "@intlify/vue-i18n-bridge";
/*!
* shared v9.2.0-beta.25
* shared v9.2.0-beta.26
* (c) 2021 kazuya kawaguchi

@@ -43,9 +43,3 @@ * Released under the MIT License.

const isString = (val) => typeof val === "string";
const isSymbol$1 = (val) => typeof val === "symbol";
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);
}
Promise.resolve();
function getNormalizedLocales(locales) {

@@ -70,3 +64,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;
}

@@ -87,10 +81,101 @@ function setLocale(i18n, locale) {

}
function extendI18n(i18n, { localeCodes = [] } = {}) {
if (!isComposer(i18n.global, i18n.mode)) {
throw new Error("");
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];
}
const _localeCodes = ref(localeCodes);
i18n.global.locales = computed(() => _localeCodes.value);
console.log("... extends i18n done");
function getLocaleRouteName(routeName, locale) {
let name = getRouteName(routeName) + (strategy === "no_prefix" ? "" : routesNameSeparator + locale);
if (locale === defaultLocale && strategy === "prefix_and_default") {
name += routesNameSeparator + defaultLocaleRouteNameSuffix;
}
return name;
}
function resolveRoute(route, locale) {
const _locale = locale || getLocale($i18n);
let _route = route;
if (isString(route)) {
if (route[0] === "/") {
_route = { path: route };
} else {
_route = { name: route };
}
}
let localizedRoute = assign({}, _route);
if (localizedRoute.path && !localizedRoute.name) {
const _resolvedRoute = $router.resolve(localizedRoute);
const resolvedRoute2 = !isVue2 ? _resolvedRoute : _resolvedRoute.route;
const resolvedRouteName = getRouteBaseName(resolvedRoute2);
if (isString(resolvedRouteName)) {
localizedRoute = {
name: getLocaleRouteName(resolvedRouteName, _locale),
params: resolvedRoute2.params,
query: resolvedRoute2.query,
hash: resolvedRoute2.hash
};
}
} else {
localizedRoute.name = getLocaleRouteName(localizedRoute.name, _locale);
const { params } = localizedRoute;
if (params && params["0"] === void 0 && params.pathMatch) {
params["0"] = params.pathMatch;
}
}
const resolvedRoute = $router.resolve(localizedRoute);
if (isVue2 ? resolvedRoute.route.name : resolvedRoute.name) {
return resolvedRoute;
}
return $router.resolve(route);
}
function localePath(route, locale) {
const localizedRoute = resolveRoute(route, locale);
return localizedRoute == null ? "" : isVue2 ? localizedRoute.route.redirectedFrom || localizedRoute.route.fullPath : localizedRoute.redirectedFrom || localizedRoute.fullPath;
}
function localeRoute(route, locale) {
const resolved = resolveRoute(route, locale);
return resolved == null ? void 0 : isVue2 ? resolved.route : resolved;
}
function localeLocation(route, locale) {
const resolved = resolveRoute(route, locale);
return resolved == null ? void 0 : isVue2 ? resolved.location : resolved.href;
}
function switchLocalePath(locale) {
const name = getRouteBaseName();
if (!name) {
return "";
}
const _a = isVue2 && isRef($route) ? $route.value : $route, { params } = _a, routeCopy = __objRest(_a, ["params"]);
const langSwitchParams = {};
const baseRoute = assign({}, routeCopy, {
name,
params: __spreadProps(__spreadValues(__spreadValues({}, params), langSwitchParams), {
0: params.pathMatch
})
});
const path = localePath(baseRoute, locale);
console.log("switchLocalePath", $i18n.locale.value, locale, path);
return path;
}
return {
getRouteBaseName,
localePath,
localeRoute,
localeLocation,
switchLocalePath
};
}
function getRouteName(routeName) {
return isString(routeName) ? routeName : isSymbol(routeName) ? routeName.toString() : "(null)";
}
const STRATEGIES = {

@@ -114,3 +199,3 @@ PREFIX: "prefix",

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

@@ -120,3 +205,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 +258,10 @@ if (route.redirect && (!route.component || !route.file)) {

}
function extendI18n(i18n, { locales = [] } = {}) {
if (!isComposer(i18n.global, i18n.mode)) {
throw new Error("");
}
const _locales = ref(locales);
i18n.global.locales = computed(() => _locales.value);
console.log("... extends i18n done");
}
function getLocalesRegex(localeCodes) {

@@ -199,202 +292,64 @@ 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;
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.routes = (_h = options.routes) != null ? _h : [];
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
routes
} = asDefaultVueI18nRouterOptions(options);
const normalizedLocaleCodes = getNormalizedLocales(locales);
const getLocaleFromRoute = createLocaleFromRouteGetter(normalizedLocaleCodes.map((l) => l.code), routesNameSeparator, defaultLocaleRouteNameSuffix);
extendI18n(i18n, { locales: normalizedLocaleCodes });
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.__strategy = strategy;
router.__trailingSlash = trailingSlash;
router.__routesNameSeparator = routesNameSeparator;
router.__defaultLocaleRouteNameSuffix = defaultLocaleRouteNameSuffix;
router.beforeEach((to, from, next) => {
console.log("beforeEach", to, from);
const currentLocale = getLocale(i18n);
const finalLocale = getLocaleFromRoute(to) || currentLocale || defaultLocale || "";
console.log("currentLocale", currentLocale, "finalLocale", finalLocale);
if (currentLocale !== finalLocale) {
setLocale(i18n, finalLocale);
}
next();
});
console.log("create router", router);
return router;
}
const VERSION = "";
export { VERSION, extendRouting, localizeRoutes, useI18nRouting };
export { VERSION, createRouter, localizeRoutes, useI18nRouting };

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

var re=Object.defineProperty,ue=Object.defineProperties;var ie=Object.getOwnPropertyDescriptors;var x=Object.getOwnPropertySymbols;var W=Object.prototype.hasOwnProperty,k=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={}))W.call(s,f)&&H(r,f,s[f]);if(x)for(var f of x(s))k.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)W.call(r,$)&&s.indexOf($)<0&&(f[$]=r[$]);if(r!=null&&x)for(var $ of x(r))s.indexOf($)<0&&k.call(r,$)&&(f[$]=r[$]);return f};var VueI18nRouting=function(r,s,f,$){"use strict";/*!
* shared v9.2.0-beta.25
var ue=Object.defineProperty,se=Object.defineProperties;var fe=Object.getOwnPropertyDescriptors;var b=Object.getOwnPropertySymbols;var W=Object.prototype.hasOwnProperty,k=Object.prototype.propertyIsEnumerable;var B=(r,a,s)=>a in r?ue(r,a,{enumerable:!0,configurable:!0,writable:!0,value:s}):r[a]=s,T=(r,a)=>{for(var s in a||(a={}))W.call(a,s)&&B(r,s,a[s]);if(b)for(var s of b(a))k.call(a,s)&&B(r,s,a[s]);return r},O=(r,a)=>se(r,fe(a));var D=(r,a)=>{var s={};for(var p in r)W.call(r,p)&&a.indexOf(p)<0&&(s[p]=r[p]);if(r!=null&&b)for(var p of b(r))a.indexOf(p)<0&&k.call(r,p)&&(s[p]=r[p]);return s};var VueI18nRouting=function(r,a,s,p){"use strict";function H(e){return e&&typeof e=="object"&&"default"in e?e:{default:e}}var Y=H(s);/*!
* shared v9.2.0-beta.26
* (c) 2021 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="",B=oe.PREFIX_EXCEPT_DEFAULT,z=!1,U="___",N="default";function X(e,{defaultLocale:l=w,strategy:n=B,trailingSlash:_=z,routesNameSeparator:h=U,defaultLocaleRouteNameSuffix:R=N,includeUprefixedFallback:d=!1,localeCodes:S=[]}={}){if(n==="no_prefix")return e;const m=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}${R}`);else{const A=j(v({},u),{path:i});if(t&&(A.name=`${u.name}${h}${R}`),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,m||[])],[])}function te(e){return new RegExp(`^/(${e.join("|")})(?:/|$)`,"i")}function ne(e,l,n){const _=`(${e.join("|")})`,h=`(?:${l}${n})?`,R=new RegExp(`${l}${_}${h}$`,"i"),d=te(e);return m=>{if(m.name){const o=(I(m.name)?m.name:m.name.toString()).match(R);if(o&&o.length>1)return o[1]}else if(m.path){const g=m.path.match(d);if(g&&g.length>1)return g[1]}return""}}function ce({router:e,i18n:l,defaultLocale:n=w,strategy:_=B,trailingSlash:h=z,routesNameSeparator:R=U,defaultLocaleRouteNameSuffix:d=N,localeCodes:S=[]}={}){const m=Q(S),g=ne(m.map(o=>o.code),R,d);if(ee(l,{localeCodes:m}),s.isVue2){const o=e,E=o.constructor,F=o.options.routes||[],p=X(F,{localeCodes:S,defaultLocale:n,strategy:_,trailingSlash:h,routesNameSeparator:R,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=R,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:R,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=R,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,R=e.defaultLocale||n.__defaultLocale,d=e.routesNameSeparator||n.__routesNameSeparator,S=e.strategy||n.__strategy;function m(c){const a=c!=null?c:s.isRef(_)?_.value:_;return a.name?D(a.name).split(d)[0]:void 0}function g(c,a){let t=D(c)+(S==="no_prefix"?"":d+a);return a===R&&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=m(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=m();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 D(e){return I(e)?e:J(e)?e.toString():""}function ae({router:e,i18n:l,defaultLocale:n=w,trailingSlash:_=z,routesNameSeparator:h=U,defaultLocaleRouteNameSuffix:R=N,localeCodes:d=[]}={}){if(e==null)throw new Error("TODO");return ce({router:e,i18n:l,defaultLocale:n,trailingSlash:_,routesNameSeparator:h,defaultLocaleRouteNameSuffix:R,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 V=Object.assign,P=e=>typeof e=="string",J=e=>typeof e=="symbol";function K(e){e=e||[];const o=[];for(const l of e)P(l)?o.push({code:l}):o.push(l);return o}function y(e,o){return a.isRef(e.locale)&&o==="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,o){U(e)?y(e.global,e.mode)?e.global.locale.value=o:e.global.locale=o:a.isRef(e.locale)&&(e.locale.value=o)}function Z(e,o,l){return e.replace(/\/+$/,"")+(o?"/":"")||(l?"":"/")}function ee(e={}){const o=p.useI18n(),l=s.useRouter(),h=s.useRoute(),m=e.defaultLocaleRouteNameSuffix||l.__defaultLocaleRouteNameSuffix,E=e.defaultLocale||l.__defaultLocale,g=e.routesNameSeparator||l.__routesNameSeparator,S=e.strategy||l.__strategy;function f(c){const u=c!=null?c:a.isRef(h)?h.value:h;return u.name?z(u.name).split(g)[0]:void 0}function L(c,u){let t=z(c)+(S==="no_prefix"?"":g+u);return u===E&&S==="prefix_and_default"&&(t+=g+m),t}function n(c,u){const t=u||w(o);let i=c;P(c)&&(c[0]==="/"?i={path:c}:i={name:c});let d=V({},i);if(d.path&&!d.name){const _=l.resolve(d),$=a.isVue2?_.route:_,F=f($);P(F)&&(d={name:L(F,t),params:$.params,query:$.query,hash:$.hash})}else{d.name=L(d.name,t);const{params:_}=d;_&&_["0"]===void 0&&_.pathMatch&&(_["0"]=_.pathMatch)}const x=l.resolve(d);return(a.isVue2?x.route.name:x.name)?x:l.resolve(c)}function A(c,u){const t=n(c,u);return t==null?"":a.isVue2?t.route.redirectedFrom||t.route.fullPath:t.redirectedFrom||t.fullPath}function I(c,u){const t=n(c,u);return t==null?void 0:a.isVue2?t.route:t}function R(c,u){const t=n(c,u);return t==null?void 0:a.isVue2?t.location:t.href}function N(c){const u=f();if(!u)return"";const $=a.isVue2&&a.isRef(h)?h.value:h,{params:t}=$,i=D($,["params"]),d={},x=V({},i,{name:u,params:O(T(T({},t),d),{0:t.pathMatch})}),_=A(x,c);return console.log("switchLocalePath",o.locale.value,c,_),_}return{getRouteBaseName:f,localePath:A,localeRoute:I,localeLocation:R,switchLocalePath:N}}function z(e){return P(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"},X="",M=te.PREFIX_EXCEPT_DEFAULT,j=!1,C="___",G="default";function q(e,{defaultLocale:o=X,strategy:l=M,trailingSlash:h=j,routesNameSeparator:m=C,defaultLocaleRouteNameSuffix:E=G,includeUprefixedFallback:g=!1,locales:S=[]}={}){if(l==="no_prefix")return e;const f=S.map(n=>P(n)?n:n.code);function L(n,A,I=!1,R=!1){return n.redirect&&(!n.component||!n.file)?[n]:A.reduce((c,u)=>{const{name:t}=n;let{path:i}=n;const d=T({},n);t&&(d.name=`${t}${m}${u}`),n.children&&(d.children=n.children.reduce((F,v)=>[...F,...L(v,[u],!0,R)],[]));const x=u===o;if(x&&l==="prefix_and_default")if(I)I&&R&&t&&(d.name+=`${m}${E}`);else{const F=O(T({},d),{path:i});if(t&&(F.name=`${d.name}${m}${E}`),n.children){F.children=[];for(const v of n.children)F.children=F.children.concat(L(v,[u],!0,!0))}c.push(F)}const _=I&&!i.startsWith("/"),$=!_&&!(x&&l==="prefix_except_default");return $&&(i=`/${u}${i}`),i&&(i=Z(i,h,_)),$&&x&&l==="prefix"&&g&&c.push(T({},n)),d.path=i,c.push(d),c},[])}return e.reduce((n,A)=>[...n,...L(A,f||[])],[])}function ae(e,{locales:o=[]}={}){if(!y(e.global,e.mode))throw new Error("");const l=a.ref(o);e.global.locales=a.computed(()=>l.value),console.log("... extends i18n done")}function oe(e){return new RegExp(`^/(${e.join("|")})(?:/|$)`,"i")}function ne(e,o,l){const h=`(${e.join("|")})`,m=`(?:${o}${l})?`,E=new RegExp(`${o}${h}${m}$`,"i"),g=oe(e);return f=>{if(f.name){const n=(P(f.name)?f.name:f.name.toString()).match(E);if(n&&n.length>1)return n[1]}else if(f.path){const L=f.path.match(g);if(L&&L.length>1)return L[1]}return""}}function le(e){var o,l,h,m,E,g,S,f;return e.version=(o=e.version)!=null?o:4,e.defaultLocale=(l=e.defaultLocale)!=null?l:X,e.strategy=(h=e.strategy)!=null?h:M,e.trailingSlash=(m=e.trailingSlash)!=null?m:j,e.routesNameSeparator=(E=e.routesNameSeparator)!=null?E:C,e.defaultLocaleRouteNameSuffix=(g=e.defaultLocaleRouteNameSuffix)!=null?g:G,e.locales=(S=e.locales)!=null?S:[],e.routes=(f=e.routes)!=null?f:[],e}function ce(e,o={}){const{version:l,defaultLocale:h,locales:m,strategy:E,trailingSlash:g,routesNameSeparator:S,defaultLocaleRouteNameSuffix:f,routes:L}=le(o),n=K(m),A=ne(n.map(N=>N.code),S,f);ae(e,{locales:n});const I=q(L,{locales:m,defaultLocale:h,strategy:E,trailingSlash:g,routesNameSeparator:S,defaultLocaleRouteNameSuffix:f});o.routes=I;let R=null;if(a.isVue3&&l===4)R=s.createRouter(o);else if(a.isVue2&&l===3)R=new Y.default(o);else throw new Error("TODO:");return R.__defaultLocale=h,R.__strategy=E,R.__trailingSlash=g,R.__routesNameSeparator=S,R.__defaultLocaleRouteNameSuffix=f,R.beforeEach((N,c,u)=>{console.log("beforeEach",N,c);const t=w(e),i=A(N)||t||h||"";console.log("currentLocale",t,"finalLocale",i),t!==i&&Q(e,i),u()}),console.log("create router",R),R}const re="";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);
{
"name": "vue-i18n-routing",
"description": "The i18n routing with using vue-i18n",
"version": "0.0.0-e1405ae",
"version": "0.0.0-e9e5447",
"dependencies": {
"@intlify/shared": "beta",
"@intlify/vue-router-composable": "0.0.0-e1405ae",
"@intlify/vue-i18n-bridge": "0.0.0-e1405ae",
"vue-demi": "*"
"@intlify/vue-i18n-bridge": "^0.3.4",
"@intlify/vue-router-bridge": "^0.3.4",
"vue-demi": "^0.12.1"
},

@@ -15,2 +15,3 @@ "devDependencies": {

"rimraf": "^3.0.2",
"typescript": "^4.5.4",
"vite": "^2.7.4",

@@ -29,5 +30,5 @@ "vite-plugin-dts": "^0.9.6",

"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 +35,0 @@ "peerDependenciesMeta": {