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

vue-i18n-routing

Package Overview
Dependencies
Maintainers
1
Versions
239
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

vue-i18n-routing - npm Package Compare versions

Comparing version 0.0.0-50f6b19 to 0.0.0-6956b1d

4

dist/vue-i18n-routing.cjs.js

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

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

export declare function extendRouting<TRouter extends VueRouter | Router>({ router, i18n, defaultLocale, trailingSlash, routesNameSeparator, defaultLocaleRouteNameSuffix, localeCodes }?: VueI18nRoutingOptions): TRouter;
export declare interface I18nRouting {

@@ -26,3 +41,3 @@ getRouteBaseName(givenRoute?: Route_2 | RouteLocationNormalizedLoaded): string;

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

@@ -44,3 +59,3 @@ };

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;

@@ -103,23 +118,76 @@ }): VueI18nRoute[];

/**
* 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-demi'

@@ -126,0 +194,0 @@ declare module 'vue-i18n' {

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

};
import { isRef, ref, computed, isVue2 } from "vue-demi";
import { useRouter, useRoute } from "@intlify/vue-router-bridge";
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";

@@ -79,189 +79,2 @@ /*!

}
function extendI18n(i18n, { localeCodes = [] } = {}) {
if (!isComposer(i18n.global, i18n.mode)) {
throw new Error("");
}
const _localeCodes = ref(localeCodes);
i18n.global.locales = computed(() => _localeCodes.value);
console.log("... extends i18n done");
}
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 localizeRoutes(routes, {
defaultLocale = DEFAULT_LOCALE,
strategy = DEFAULT_STRATEGY,
trailingSlash = DEFAULT_TRAILING_SLASH,
routesNameSeparator = DEFAULT_ROUTES_NAME_SEPARATOR,
defaultLocaleRouteNameSuffix = DEFAULT_LOCALE_ROUTE_NAME_SUFFIX,
includeUprefixedFallback = false,
localeCodes = []
} = {}) {
if (strategy === "no_prefix") {
return routes;
}
const _localeCodes = localeCodes.map((locale) => isString(locale) ? locale : locale.code);
function makeLocalizedRoutes(route, allowedLocaleCodes, isChild = false, isExtraPageTree = false) {
if (route.redirect && (!route.component || !route.file)) {
return [route];
}
const targetLocales = allowedLocaleCodes;
return targetLocales.reduce((_routes, locale) => {
const { name } = route;
let { path } = route;
const localizedRoute = __spreadValues({}, route);
if (name) {
localizedRoute.name = `${name}${routesNameSeparator}${locale}`;
}
if (route.children) {
localizedRoute.children = route.children.reduce((children, child) => [...children, ...makeLocalizedRoutes(child, [locale], true, isExtraPageTree)], []);
}
const isDefaultLocale = locale === defaultLocale;
if (isDefaultLocale && strategy === "prefix_and_default") {
if (!isChild) {
const defaultRoute = __spreadProps(__spreadValues({}, localizedRoute), { path });
if (name) {
defaultRoute.name = `${localizedRoute.name}${routesNameSeparator}${defaultLocaleRouteNameSuffix}`;
}
if (route.children) {
defaultRoute.children = [];
for (const childRoute of route.children) {
defaultRoute.children = defaultRoute.children.concat(makeLocalizedRoutes(childRoute, [locale], true, true));
}
}
_routes.push(defaultRoute);
} else if (isChild && isExtraPageTree && name) {
localizedRoute.name += `${routesNameSeparator}${defaultLocaleRouteNameSuffix}`;
}
}
const isChildWithRelativePath = isChild && !path.startsWith("/");
const shouldAddPrefix = !isChildWithRelativePath && !(isDefaultLocale && strategy === "prefix_except_default");
if (shouldAddPrefix) {
path = `/${locale}${path}`;
}
if (path) {
path = adjustRoutePathForTrailingSlash(path, trailingSlash, isChildWithRelativePath);
}
if (shouldAddPrefix && isDefaultLocale && strategy === "prefix" && includeUprefixedFallback) {
_routes.push(__spreadValues({}, route));
}
localizedRoute.path = path;
_routes.push(localizedRoute);
return _routes;
}, []);
}
return routes.reduce((localized, route) => [...localized, ...makeLocalizedRoutes(route, _localeCodes || [])], []);
}
function getLocalesRegex(localeCodes) {
return new RegExp(`^/(${localeCodes.join("|")})(?:/|$)`, "i");
}
function createLocaleFromRouteGetter(localeCodes, routesNameSeparator, defaultLocaleRouteNameSuffix) {
const localesPattern = `(${localeCodes.join("|")})`;
const defaultSuffixPattern = `(?:${routesNameSeparator}${defaultLocaleRouteNameSuffix})?`;
const regexpName = new RegExp(`${routesNameSeparator}${localesPattern}${defaultSuffixPattern}$`, "i");
const regexpPath = getLocalesRegex(localeCodes);
const getLocaleFromRoute = (route) => {
if (route.name) {
const name = isString(route.name) ? route.name : route.name.toString();
const matches = name.match(regexpName);
if (matches && matches.length > 1) {
return matches[1];
}
} else if (route.path) {
const matches = route.path.match(regexpPath);
if (matches && matches.length > 1) {
return matches[1];
}
}
return "";
};
return getLocaleFromRoute;
}
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 useI18nRouting(options = {}) {

@@ -366,25 +179,172 @@ const $i18n = useI18n();

}
function extendRouting({
router,
i18n,
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 localizeRoutes(routes, {
defaultLocale = DEFAULT_LOCALE,
strategy = DEFAULT_STRATEGY,
trailingSlash = DEFAULT_TRAILING_SLASH,
routesNameSeparator = DEFAULT_ROUTES_NAME_SEPARATOR,
defaultLocaleRouteNameSuffix = DEFAULT_LOCALE_ROUTE_NAME_SUFFIX,
localeCodes = []
includeUprefixedFallback = false,
locales = []
} = {}) {
if (router == null) {
throw new Error("TODO");
if (strategy === "no_prefix") {
return routes;
}
return extendRouter({
router,
i18n,
const _localeCodes = locales.map((locale) => isString(locale) ? locale : locale.code);
function makeLocalizedRoutes(route, allowedLocaleCodes, isChild = false, isExtraPageTree = false) {
if (route.redirect && (!route.component || !route.file)) {
return [route];
}
const targetLocales = allowedLocaleCodes;
return targetLocales.reduce((_routes, locale) => {
const { name } = route;
let { path } = route;
const localizedRoute = __spreadValues({}, route);
if (name) {
localizedRoute.name = `${name}${routesNameSeparator}${locale}`;
}
if (route.children) {
localizedRoute.children = route.children.reduce((children, child) => [...children, ...makeLocalizedRoutes(child, [locale], true, isExtraPageTree)], []);
}
const isDefaultLocale = locale === defaultLocale;
if (isDefaultLocale && strategy === "prefix_and_default") {
if (!isChild) {
const defaultRoute = __spreadProps(__spreadValues({}, localizedRoute), { path });
if (name) {
defaultRoute.name = `${localizedRoute.name}${routesNameSeparator}${defaultLocaleRouteNameSuffix}`;
}
if (route.children) {
defaultRoute.children = [];
for (const childRoute of route.children) {
defaultRoute.children = defaultRoute.children.concat(makeLocalizedRoutes(childRoute, [locale], true, true));
}
}
_routes.push(defaultRoute);
} else if (isChild && isExtraPageTree && name) {
localizedRoute.name += `${routesNameSeparator}${defaultLocaleRouteNameSuffix}`;
}
}
const isChildWithRelativePath = isChild && !path.startsWith("/");
const shouldAddPrefix = !isChildWithRelativePath && !(isDefaultLocale && strategy === "prefix_except_default");
if (shouldAddPrefix) {
path = `/${locale}${path}`;
}
if (path) {
path = adjustRoutePathForTrailingSlash(path, trailingSlash, isChildWithRelativePath);
}
if (shouldAddPrefix && isDefaultLocale && strategy === "prefix" && includeUprefixedFallback) {
_routes.push(__spreadValues({}, route));
}
localizedRoute.path = path;
_routes.push(localizedRoute);
return _routes;
}, []);
}
return routes.reduce((localized, route) => [...localized, ...makeLocalizedRoutes(route, _localeCodes || [])], []);
}
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) {
return new RegExp(`^/(${localeCodes.join("|")})(?:/|$)`, "i");
}
function createLocaleFromRouteGetter(localeCodes, routesNameSeparator, defaultLocaleRouteNameSuffix) {
const localesPattern = `(${localeCodes.join("|")})`;
const defaultSuffixPattern = `(?:${routesNameSeparator}${defaultLocaleRouteNameSuffix})?`;
const regexpName = new RegExp(`${routesNameSeparator}${localesPattern}${defaultSuffixPattern}$`, "i");
const regexpPath = getLocalesRegex(localeCodes);
const getLocaleFromRoute = (route) => {
if (route.name) {
const name = isString(route.name) ? route.name : route.name.toString();
const matches = name.match(regexpName);
if (matches && matches.length > 1) {
return matches[1];
}
} else if (route.path) {
const matches = route.path.match(regexpPath);
if (matches && matches.length > 1) {
return matches[1];
}
}
return "";
};
return getLocaleFromRoute;
}
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 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 ae=Object.defineProperty,se=Object.defineProperties;var re=Object.getOwnPropertyDescriptors;var V=Object.getOwnPropertySymbols;var k=Object.prototype.hasOwnProperty,H=Object.prototype.propertyIsEnumerable;var Y=(r,l,f)=>l in r?ae(r,l,{enumerable:!0,configurable:!0,writable:!0,value:f}):r[l]=f,S=(r,l)=>{for(var f in l||(l={}))k.call(l,f)&&Y(r,f,l[f]);if(V)for(var f of V(l))H.call(l,f)&&Y(r,f,l[f]);return r},M=(r,l)=>se(r,re(l));var B=(r,l)=>{var f={};for(var F in r)k.call(r,F)&&l.indexOf(F)<0&&(f[F]=r[F]);if(r!=null&&V)for(var F of V(r))l.indexOf(F)<0&&H.call(r,F)&&(f[F]=r[F]);return f};var VueI18nRouting=function(r,l,f,F){"use strict";/*!
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,x=e=>typeof e=="string",D=e=>typeof e=="symbol";function J(e){e=e||[];const a=[];for(const n of e)x(n)?a.push({code:n}):a.push(n);return a}function v(e,a){return l.isRef(e.locale)&&a==="composition"}function j(e){return"global"in e&&"mode"in e}function O(e){return j(e)?v(e.global,e.mode)?e.global.locale.value:e.global.locale:e.locale.value}function G(e,a){j(e)?v(e.global,e.mode)?e.global.locale.value=a:e.global.locale=a:l.isRef(e.locale)&&(e.locale.value=a)}function K(e,a,n){return e.replace(/\/+$/,"")+(a?"/":"")||(n?"":"/")}function Q(e,{localeCodes:a=[]}={}){if(!v(e.global,e.mode))throw new Error("");const n=l.ref(a);e.global.locales=l.computed(()=>n.value),console.log("... extends i18n done")}const Z={PREFIX:"prefix",PREFIX_EXCEPT_DEFAULT:"prefix_except_default",PREFIX_AND_DEFAULT:"prefix_and_default",NO_PREFIX:"no_prefix"},w="",q=Z.PREFIX_EXCEPT_DEFAULT,z=!1,U="___",y="default";function N(e,{defaultLocale:a=w,strategy:n=q,trailingSlash:d=z,routesNameSeparator:R=U,defaultLocaleRouteNameSuffix:m=y,includeUprefixedFallback:_=!1,localeCodes:T=[]}={}){if(n==="no_prefix")return e;const h=T.map(o=>x(o)?o:o.code);function g(o,E,b=!1,p=!1){return o.redirect&&(!o.component||!o.file)?[o]:E.reduce((c,s)=>{const{name:t}=o;let{path:i}=o;const u=S({},o);t&&(u.name=`${t}${R}${s}`),o.children&&(u.children=o.children.reduce((P,X)=>[...P,...g(X,[s],!0,p)],[]));const I=s===a;if(I&&n==="prefix_and_default")if(b)b&&p&&t&&(u.name+=`${R}${m}`);else{const P=M(S({},u),{path:i});if(t&&(P.name=`${u.name}${R}${m}`),o.children){P.children=[];for(const X of o.children)P.children=P.children.concat(g(X,[s],!0,!0))}c.push(P)}const L=b&&!i.startsWith("/"),A=!L&&!(I&&n==="prefix_except_default");return A&&(i=`/${s}${i}`),i&&(i=K(i,d,L)),A&&I&&n==="prefix"&&_&&c.push(S({},o)),u.path=i,c.push(u),c},[])}return e.reduce((o,E)=>[...o,...g(E,h||[])],[])}function ee(e){return new RegExp(`^/(${e.join("|")})(?:/|$)`,"i")}function oe(e,a,n){const d=`(${e.join("|")})`,R=`(?:${a}${n})?`,m=new RegExp(`${a}${d}${R}$`,"i"),_=ee(e);return h=>{if(h.name){const o=(x(h.name)?h.name:h.name.toString()).match(m);if(o&&o.length>1)return o[1]}else if(h.path){const g=h.path.match(_);if(g&&g.length>1)return g[1]}return""}}function te({router:e,i18n:a,defaultLocale:n=w,strategy:d=q,trailingSlash:R=z,routesNameSeparator:m=U,defaultLocaleRouteNameSuffix:_=y,localeCodes:T=[]}={}){const h=J(T),g=oe(h.map(o=>o.code),m,_);if(Q(a,{localeCodes:h}),l.isVue2){const o=e,E=o.constructor,b=o.options.routes||[],p=N(b,{localeCodes:T,defaultLocale:n,strategy:d,trailingSlash:R,routesNameSeparator:m,defaultLocaleRouteNameSuffix:_});console.log("vue2 routes",b,p);const $=new E({mode:"history",base:o.options.base,routes:p});return $.__defaultLocale=n,$.__strategy=d,$.__trailingSlash=R,$.__routesNameSeparator=m,$.__defaultLocaleRouteNameSuffix=_,$.beforeEach((c,s,t)=>{console.log("beforeEach",c,s);const i=O(a),u=g(c)||i||n||"";console.log("currentLocale",i,"finalLocale",u),i!==u&&G(a,u),t()}),$}else{const o=e,E=o.options.routes||[],b=N(E,{localeCodes:T,defaultLocale:n,strategy:d,trailingSlash:R,routesNameSeparator:m,defaultLocaleRouteNameSuffix:_});return console.log("vue3 routes",E,b,o),E.forEach(p=>o.removeRoute(p.name)),b.forEach(p=>o.addRoute(p)),o.__defaultLocale=n,o.__strategy=d,o.__trailingSlash=R,o.__routesNameSeparator=m,o.__defaultLocaleRouteNameSuffix=_,o.beforeEach((p,$,c)=>{console.log("beforeEach",p,$);const s=O(a),t=g(p)||s||n||"";console.log("currentLocale",s,"finalLocale",t),s!==t&&G(a,t),c()}),o}}function ne(e={}){const a=F.useI18n(),n=f.useRouter(),d=f.useRoute(),R=e.defaultLocaleRouteNameSuffix||n.__defaultLocaleRouteNameSuffix,m=e.defaultLocale||n.__defaultLocale,_=e.routesNameSeparator||n.__routesNameSeparator,T=e.strategy||n.__strategy;function h(c){const s=c!=null?c:l.isRef(d)?d.value:d;return s.name?W(s.name).split(_)[0]:void 0}function g(c,s){let t=W(c)+(T==="no_prefix"?"":_+s);return s===m&&T==="prefix_and_default"&&(t+=_+R),t}function o(c,s){const t=s||O(a);let i=c;x(c)&&(c[0]==="/"?i={path:c}:i={name:c});let u=C({},i);if(u.path&&!u.name){const L=n.resolve(u),A=l.isVue2?L.route:L,P=h(A);x(P)&&(u={name:g(P,t),params:A.params,query:A.query,hash:A.hash})}else{u.name=g(u.name,t);const{params:L}=u;L&&L["0"]===void 0&&L.pathMatch&&(L["0"]=L.pathMatch)}const I=n.resolve(u);return(l.isVue2?I.route.name:I.name)?I:n.resolve(c)}function E(c,s){const t=o(c,s);return t==null?"":l.isVue2?t.route.redirectedFrom||t.route.fullPath:t.redirectedFrom||t.fullPath}function b(c,s){const t=o(c,s);return t==null?void 0:l.isVue2?t.route:t}function p(c,s){const t=o(c,s);return t==null?void 0:l.isVue2?t.location:t.href}function $(c){const s=h();if(!s)return"";const A=l.isVue2&&l.isRef(d)?d.value:d,{params:t}=A,i=B(A,["params"]),u={},I=C({},i,{name:s,params:M(S(S({},t),u),{0:t.pathMatch})}),L=E(I,c);return console.log("switchLocalePath",a.locale.value,c,L),L}return{getRouteBaseName:h,localePath:E,localeRoute:b,localeLocation:p,switchLocalePath:$}}function W(e){return x(e)?e:D(e)?e.toString():"(null)"}function ce({router:e,i18n:a,defaultLocale:n=w,trailingSlash:d=z,routesNameSeparator:R=U,defaultLocaleRouteNameSuffix:m=y,localeCodes:_=[]}={}){if(e==null)throw new Error("TODO");return te({router:e,i18n:a,defaultLocale:n,trailingSlash:d,routesNameSeparator:R,defaultLocaleRouteNameSuffix:m,localeCodes:_})}const le="";return r.VERSION=le,r.extendRouting=ce,r.localizeRoutes=N,r.useI18nRouting=ne,Object.defineProperty(r,"__esModule",{value:!0}),r[Symbol.toStringTag]="Module",r}({},VueDemi,VueRouter,VueI18n);
*/const 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-50f6b19",
"version": "0.0.0-6956b1d",
"dependencies": {
"@intlify/shared": "beta",
"@intlify/vue-i18n-bridge": "^0.1.0",
"@intlify/vue-router-bridge": "^0.1.0",
"@intlify/vue-i18n-bridge": "^0.3.4",
"@intlify/vue-router-bridge": "^0.3.4",
"vue-demi": "^0.12.1"

@@ -15,2 +15,3 @@ },

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

@@ -24,4 +25,3 @@ "vite-plugin-dts": "^0.9.6",

"vue-router3": "npm:vue-router@latest",
"vue2": "npm:vue@2",
"typescript": "^4.5.4"
"vue2": "npm:vue@2"
},

@@ -28,0 +28,0 @@ "peerDependencies": {

SocketSocket SOC 2 Logo

Product

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

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc