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-f76bb0e to 0.0.0-f84f443

6

dist/vue-i18n-routing.cjs.js

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

"use strict";Object.defineProperty(exports,"__esModule",{value:!0});exports[Symbol.toStringTag]="Module";const n=function(e,u={}){console.log("install vue-i18n-rouging!")},o="0.0.0";exports.VERSION=o;exports.VueI18nRoutingPlugin=n;
"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("vue-i18n");/*!
* shared v9.2.0-beta.25
* (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:_=U,includeUprefixedFallback:i=!1,localeCodes:$=[]}={}){if(o==="no_prefix")return e;const d=$.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}${_}`);else{const b=T(F({},a),{path:u});if(c&&(b.name=`${a.name}${f}${_}`),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,d||[])],[])}function ce(e){return new RegExp(`^/(${e.join("|")})(?:/|$)`,"i")}function le(e,t,o){const r=`(${e.join("|")})`,f=`(?:${t}${o})?`,_=new RegExp(`${t}${r}${f}$`,"i"),i=ce(e);return d=>{if(d.name){const n=(P(d.name)?d.name:d.name.toString()).match(_);if(n&&n.length>1)return n[1]}else if(d.path){const m=d.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:_=z,defaultLocaleRouteNameSuffix:i=U,localeCodes:$=[]}={}){const d=ee($),m=le(d.map(n=>n.code),_,i);if(te(t,{localeCodes:d}),E.isVue2){const n=e,p=n.constructor,L=n.options.routes||[],h=V(L,{localeCodes:$,defaultLocale:o,strategy:r,trailingSlash:f,routesNameSeparator:_,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=_,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:_,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=_,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(){return K.useI18n()}function ae(e={}){const t=re(),o=j.useRouter(),r=j.useRoute(),f=e.defaultLocaleRouteNameSuffix||o.__defaultLocaleRouteNameSuffix,_=e.defaultLocale||o.__defaultLocale,i=e.routesNameSeparator||o.__routesNameSeparator,$=e.strategy||o.__strategy;function d(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===_&&$==="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=d(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=d();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 ue({router:e,i18n:t,defaultLocale:o=w,trailingSlash:r=D,routesNameSeparator:f=z,defaultLocaleRouteNameSuffix:_=U,localeCodes:i=[]}={}){if(e==null)throw new Error("TODO");return se({router:e,i18n:t,defaultLocale:o,trailingSlash:r,routesNameSeparator:f,defaultLocaleRouteNameSuffix:_,localeCodes:i})}const ie="";exports.VERSION=ie;exports.extendRouting=ue;exports.localizeRoutes=V;exports.useI18nRouting=ae;

@@ -0,2 +1,85 @@

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';
/**
* Direction
*/
export declare type Directions = 'ltr' | 'rtl' | 'auto';
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 {
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;
}
/**
* Locale object
*/
export declare interface LocaleObject extends Record<string, any> {
code: Locale;
name?: string;
dir?: Directions;
domain?: string;
file?: string;
isCatchallLocale?: boolean;
iso?: string;
}
export declare function localizeRoutes(routes: VueI18nRoute[], { defaultLocale, strategy, trailingSlash, routesNameSeparator, defaultLocaleRouteNameSuffix, includeUprefixedFallback, localeCodes }?: Pick<VueI18nRoutingOptions, 'defaultLocale' | 'strategy' | 'localeCodes' | 'routesNameSeparator' | 'trailingSlash' | 'defaultLocaleRouteNameSuffix'> & {
includeUprefixedFallback?: boolean;
}): VueI18nRoute[];
/**
* Route config for vue-router v4
*/
export declare interface Route {
name?: string;
path: string;
file?: string;
children?: Route[];
}
declare type _Route = UnionToIntersection<RouteConfig>;
/**
* Route config for lagacy vue-router v3
*/
export declare interface RouteLegacy extends Pick<_Route, Exclude<keyof _Route, 'children' | 'component'>> {
chunkName?: string;
chunkNames?: Record<string, string>;
component?: _Route['component'] | string;
children?: RouteLegacy[];
}
declare const STRATEGIES: {
readonly PREFIX: "prefix";
readonly PREFIX_EXCEPT_DEFAULT: "prefix_except_default";
readonly PREFIX_AND_DEFAULT: "prefix_and_default";
readonly NO_PREFIX: "no_prefix";
};
/**
* Routing strategy
*/
export declare type Strategies = typeof STRATEGIES[keyof typeof STRATEGIES];
declare type UnionToIntersection<T> = (T extends any ? (k: T) => void : never) extends (k: infer U) => void ? U : never;
export declare function useI18nRouting<Legacy extends boolean = false>(options?: I18nRoutingOptions): I18nRoutingReturn;
/**
* Vue I18n Routing Version

@@ -7,10 +90,38 @@ *

*/
export declare const VERSION: string;
export declare const VERSION = "";
/**
* Route config for vue-i18n-routing
*/
export declare type VueI18nRoute = Route & RouteLegacy & {
redirect?: string;
};
/**
* Vue I18n routing options
*/
export declare interface VueI18nRoutingOptions {
routes: [];
/**
* Vue Router instance
*/
router?: VueRouter | Router;
/**
* Vue I18n instance
*/
i18n?: VueI18n | I18n;
defaultLocale?: string;
localeCodes?: string[] | LocaleObject[];
strategy?: Strategies;
trailingSlash?: boolean;
routesNameSeparator?: string;
defaultLocaleRouteNameSuffix?: string;
}
export declare const VueI18nRoutingPlugin: (VueOrApp: any, options?: any) => void;
export { }
import type { ComputedRef } from 'vue'
export { }
declare module 'vue-i18n' {
export interface ComposerCustom {
locales: ComputedRef<string[] | LocaleObject[]>
}
}

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

const VueI18nRoutingPlugin = function(VueOrApp, options = {}) {
console.log("install vue-i18n-rouging!");
var __defProp = Object.defineProperty;
var __defProps = Object.defineProperties;
var __getOwnPropDescs = Object.getOwnPropertyDescriptors;
var __getOwnPropSymbols = Object.getOwnPropertySymbols;
var __hasOwnProp = Object.prototype.hasOwnProperty;
var __propIsEnum = Object.prototype.propertyIsEnumerable;
var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
var __spreadValues = (a, b) => {
for (var prop in b || (b = {}))
if (__hasOwnProp.call(b, prop))
__defNormalProp(a, prop, b[prop]);
if (__getOwnPropSymbols)
for (var prop of __getOwnPropSymbols(b)) {
if (__propIsEnum.call(b, prop))
__defNormalProp(a, prop, b[prop]);
}
return a;
};
const VERSION = "0.0.0";
export { VERSION, VueI18nRoutingPlugin };
var __spreadProps = (a, b) => __defProps(a, __getOwnPropDescs(b));
var __objRest = (source, exclude) => {
var target = {};
for (var prop in source)
if (__hasOwnProp.call(source, prop) && exclude.indexOf(prop) < 0)
target[prop] = source[prop];
if (source != null && __getOwnPropSymbols)
for (var prop of __getOwnPropSymbols(source)) {
if (exclude.indexOf(prop) < 0 && __propIsEnum.call(source, prop))
target[prop] = source[prop];
}
return target;
};
import { ref, computed, isVue2, isRef as isRef$1 } from "vue-demi";
import { useRouter, useRoute } from "@intlify/vue-router-composable";
import { useI18n as useI18n$1 } from "vue-i18n";
/*!
* shared v9.2.0-beta.25
* (c) 2021 kazuya kawaguchi
* Released under the MIT License.
*/
const assign = Object.assign;
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) {
locales = locales || [];
const normalized = [];
for (const locale of locales) {
if (isString(locale)) {
normalized.push({ code: locale });
} else {
normalized.push(locale);
}
}
return normalized;
}
function isComposer(target, mode) {
return isRef(target.locale) && mode === "composition";
}
function isI18nInstance(i18n) {
return "global" in i18n && "mode" in i18n;
}
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;
}
function setLocale(i18n, locale) {
if (isI18nInstance(i18n)) {
if (isComposer(i18n.global, i18n.mode)) {
i18n.global.locale.value = locale;
} else {
i18n.global.locale = locale;
}
} else if (isRef(i18n.locale)) {
i18n.locale.value = locale;
}
}
function adjustRoutePathForTrailingSlash(pagePath, trailingSlash, isChildWithRelativePath) {
return pagePath.replace(/\/+$/, "") + (trailingSlash ? "/" : "") || (isChildWithRelativePath ? "" : "/");
}
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 useI18n() {
return useI18n$1();
}
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,
defaultLocale,
trailingSlash,
routesNameSeparator,
defaultLocaleRouteNameSuffix,
localeCodes
});
}
const VERSION = "";
export { VERSION, extendRouting, localizeRoutes, useI18nRouting };

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

(()=>{var t=function(n){"use strict";const u=function(o,e={}){console.log("install vue-i18n-rouging!")},i="0.0.0";return n.VERSION=i,n.VueI18nRoutingPlugin=u,Object.defineProperty(n,"__esModule",{value:!0}),n[Symbol.toStringTag]="Module",n}({});})();
var ue=Object.defineProperty,ie=Object.defineProperties;var fe=Object.getOwnPropertyDescriptors;var x=Object.getOwnPropertySymbols;var W=Object.prototype.hasOwnProperty,k=Object.prototype.propertyIsEnumerable;var H=(r,s,f)=>s in r?ue(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)=>ie(r,fe(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
* (c) 2021 kazuya kawaguchi
* Released under the MIT License.
*/const C=Object.assign,T=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)T(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:m=N,includeUprefixedFallback:d=!1,localeCodes:I=[]}={}){if(n==="no_prefix")return e;const R=I.map(o=>T(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 S=a===l;if(S&&n==="prefix_and_default")if(F)F&&p&&t&&(u.name+=`${h}${m}`);else{const A=j(v({},u),{path:i});if(t&&(A.name=`${u.name}${h}${m}`),o.children){A.children=[];for(const M of o.children)A.children=A.children.concat(g(M,[a],!0,!0))}c.push(A)}const L=F&&!i.startsWith("/"),P=!L&&!(S&&n==="prefix_except_default");return P&&(i=`/${a}${i}`),i&&(i=Z(i,_,L)),P&&S&&n==="prefix"&&d&&c.push(v({},o)),u.path=i,c.push(u),c},[])}return e.reduce((o,E)=>[...o,...g(E,R||[])],[])}function te(e){return new RegExp(`^/(${e.join("|")})(?:/|$)`,"i")}function ne(e,l,n){const _=`(${e.join("|")})`,h=`(?:${l}${n})?`,m=new RegExp(`${l}${_}${h}$`,"i"),d=te(e);return R=>{if(R.name){const o=(T(R.name)?R.name:R.name.toString()).match(m);if(o&&o.length>1)return o[1]}else if(R.path){const g=R.path.match(d);if(g&&g.length>1)return g[1]}return""}}function ce({router:e,i18n:l,defaultLocale:n=w,strategy:_=B,trailingSlash:h=z,routesNameSeparator:m=U,defaultLocaleRouteNameSuffix:d=N,localeCodes:I=[]}={}){const R=Q(I),g=ne(R.map(o=>o.code),m,d);if(ee(l,{localeCodes:R}),s.isVue2){const o=e,E=o.constructor,F=o.options.routes||[],p=X(F,{localeCodes:I,defaultLocale:n,strategy:_,trailingSlash:h,routesNameSeparator:m,defaultLocaleRouteNameSuffix:d});console.log("vue2 routes",F,p);const b=new E({mode:"history",base:o.options.base,routes:p});return b.__defaultLocale=n,b.__strategy=_,b.__trailingSlash=h,b.__routesNameSeparator=m,b.__defaultLocaleRouteNameSuffix=d,b.beforeEach((c,a,t)=>{console.log("beforeEach",c,a);const i=V(l),u=g(c)||i||n||"";console.log("currentLocale",i,"finalLocale",u),i!==u&&q(l,u),t()}),b}else{const o=e,E=o.options.routes||[],F=X(E,{localeCodes:I,defaultLocale:n,strategy:_,trailingSlash:h,routesNameSeparator:m,defaultLocaleRouteNameSuffix:d});return console.log("vue3 routes",E,F,o),E.forEach(p=>o.removeRoute(p.name)),F.forEach(p=>o.addRoute(p)),o.__defaultLocale=n,o.__strategy=_,o.__trailingSlash=h,o.__routesNameSeparator=m,o.__defaultLocaleRouteNameSuffix=d,o.beforeEach((p,b,c)=>{console.log("beforeEach",p,b);const a=V(l),t=g(p)||a||n||"";console.log("currentLocale",a,"finalLocale",t),a!==t&&q(l,t),c()}),o}}function le(){return $.useI18n()}function ae(e={}){const l=le(),n=f.useRouter(),_=f.useRoute(),h=e.defaultLocaleRouteNameSuffix||n.__defaultLocaleRouteNameSuffix,m=e.defaultLocale||n.__defaultLocale,d=e.routesNameSeparator||n.__routesNameSeparator,I=e.strategy||n.__strategy;function R(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)+(I==="no_prefix"?"":d+a);return a===m&&I==="prefix_and_default"&&(t+=d+h),t}function o(c,a){const t=a||V(l);let i=c;T(c)&&(c[0]==="/"?i={path:c}:i={name:c});let u=C({},i);if(u.path&&!u.name){const L=n.resolve(u),P=s.isVue2?L.route:L,A=R(P);T(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 S=n.resolve(u);return(s.isVue2?S.route.name:S.name)?S:n.resolve(c)}function E(c,a){const t=o(c,a);return t==null?"":s.isVue2?t.route.redirectedFrom||t.route.fullPath:t.redirectedFrom||t.fullPath}function F(c,a){const t=o(c,a);return t==null?void 0:s.isVue2?t.route:t}function p(c,a){const t=o(c,a);return t==null?void 0:s.isVue2?t.location:t.href}function b(c){const a=R();if(!a)return"";const P=s.isVue2&&s.isRef(_)?_.value:_,{params:t}=P,i=Y(P,["params"]),u={},S=C({},i,{name:a,params:j(v(v({},t),u),{0:t.pathMatch})}),L=E(S,c);return console.log("switchLocalePath",l.locale.value,c,L),L}return{localePath:E,localeRoute:F,localeLocation:p,switchLocalePath:b}}function D(e){return T(e)?e:J(e)?e.toString():""}function se({router:e,i18n:l,defaultLocale:n=w,trailingSlash:_=z,routesNameSeparator:h=U,defaultLocaleRouteNameSuffix:m=N,localeCodes:d=[]}={}){if(e==null)throw new Error("TODO");return ce({router:e,i18n:l,defaultLocale:n,trailingSlash:_,routesNameSeparator:h,defaultLocaleRouteNameSuffix:m,localeCodes:d})}const re="";return r.VERSION=re,r.extendRouting=se,r.localizeRoutes=X,r.useI18nRouting=ae,Object.defineProperty(r,"__esModule",{value:!0}),r[Symbol.toStringTag]="Module",r}({},VueDemi,VueRouterComposable,VueI18n);

26

package.json
{
"name": "vue-i18n-routing",
"description": "The i18n routing with using vue-i18n",
"version": "0.0.0-f76bb0e",
"version": "0.0.0-f84f443",
"dependencies": {
"@intlify/shared": "beta",
"@intlify/vue-router-composable": "0.0.0-f84f443",
"vue-demi": "*"
},
"devDependencies": {
"vite": "^2.6.4",
"@microsoft/api-extractor": "^7.18.20",
"api-docs-gen": "^0.4.0",
"rimraf": "^3.0.2",
"vite": "^2.7.4",
"vite-plugin-dts": "^0.9.6",
"vue": "^3.2.23",
"vue-i18n": "npm:vue-i18n@next",
"vue-i18n-bridge": "beta",
"vue-i18n-legacy": "npm:vue-i18n@latest",
"vue-router": "^4.0.12",
"vue2": "npm:vue@2",
"vue-router3": "npm:vue-router@latest",
"rimraf": "^3.0.2",
"@microsoft/api-extractor": "^7.18.20"
"vue2": "npm:vue@2"
},
"peerDependencies": {
"@vue/composition-api": "^1.4.0",
"vue": "^2.6.14 || ^3.2.0",
"vue-router": "^3.5.3 || ^4.0.0"
},
"peerDependenciesMeta": {
"@vue/composition-api": {
"optional": true
}
},
"keywords": [

@@ -71,4 +83,6 @@ "i18n",

"dev": "vite",
"build": "vite build"
"build": "vite build",
"typecheck": "tsc -p . --noEmit",
"build:docs": "api-docs-gen ./temp/vue-i18n-routing.api.json -c ./docsgen.config.js -o ./ -g noprefix"
}
}

@@ -7,4 +7,8 @@ # vue-i18n-routing

## 🤝 API
About details, See the [API References]('./api.md)
## Šī¸ License
[MIT](http://opensource.org/licenses/MIT)
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