vue-i18n-routing
Advanced tools
Comparing version
@@ -98,2 +98,4 @@ import type { Composer } from '@intlify/vue-i18n-bridge'; | ||
export declare const DEFAULT_DYNAMIC_PARAMS_KEY = ""; | ||
export declare const DEFAULT_LOCALE = ""; | ||
@@ -230,3 +232,3 @@ | ||
*/ | ||
export declare type I18nRoutingGlobalOptions<Context = unknown> = Pick<I18nRoutingOptions<Context>, 'defaultLocale' | 'defaultDirection' | 'defaultLocaleRouteNameSuffix' | 'trailingSlash' | 'routesNameSeparator' | 'strategy' | 'prefixable' | 'switchLocalePathIntercepter'> & { | ||
export declare type I18nRoutingGlobalOptions<Context = unknown> = Pick<I18nRoutingOptions<Context>, 'defaultLocale' | 'defaultDirection' | 'defaultLocaleRouteNameSuffix' | 'trailingSlash' | 'routesNameSeparator' | 'strategy' | 'prefixable' | 'switchLocalePathIntercepter' | 'dynamicRouteParamsKey'> & { | ||
localeCodes?: string[]; | ||
@@ -351,2 +353,8 @@ }; | ||
localizeRoutesPrefixable?: LocalizeRoutesPrefixable; | ||
/** | ||
* The key which to access vue router meta object, when dynamic route params need localize. | ||
* | ||
* @defaultValue '' | ||
*/ | ||
dynamicRouteParamsKey?: string | symbol; | ||
} & RouterOptions; | ||
@@ -561,2 +569,3 @@ | ||
switchLocalePathIntercepter?: SwitchLocalePathIntercepter; | ||
dynamicRouteParamsKey?: string | symbol; | ||
} | ||
@@ -563,0 +572,0 @@ |
@@ -18,2 +18,3 @@ var VueI18nRouting = function(exports, vueDemi, VueRouter3, vueI18nBridge) { | ||
const DEFAULT_BASE_URL = ""; | ||
const DEFAULT_DYNAMIC_PARAMS_KEY = ""; | ||
/*! | ||
@@ -475,2 +476,3 @@ * shared v9.3.0-beta.6 | ||
localizeRoutesPrefixable, | ||
dynamicRouteParamsKey, | ||
routeOptionsResolver: optionsResolver | ||
@@ -502,3 +504,4 @@ } = asDefaultVueI18nRouterOptions(options); | ||
prefixable: prefixable2, | ||
switchLocalePathIntercepter | ||
switchLocalePathIntercepter, | ||
dynamicRouteParamsKey | ||
}); | ||
@@ -558,3 +561,3 @@ extendI18n(i18n, { locales: normalizedLocaleCodes, baseUrl, localeCodes, context: router }); | ||
function asDefaultVueI18nRouterOptions(options) { | ||
var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j, _k, _l, _m; | ||
var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j, _k, _l, _m, _n; | ||
options.version = (_a = options.version) != null ? _a : 4; | ||
@@ -573,2 +576,3 @@ options.defaultLocale = (_b = options.defaultLocale) != null ? _b : DEFAULT_LOCALE; | ||
options.localizeRoutesPrefixable = (_m = options.localizeRoutesPrefixable) != null ? _m : DefaultLocalizeRoutesPrefixable; | ||
options.dynamicRouteParamsKey = (_n = options.dynamicRouteParamsKey) != null ? _n : DEFAULT_DYNAMIC_PARAMS_KEY; | ||
return options; | ||
@@ -585,3 +589,4 @@ } | ||
prefixable: prefixable2 = DefaultPrefixable, | ||
switchLocalePathIntercepter = DefaultSwitchLocalePathIntercepter | ||
switchLocalePathIntercepter = DefaultSwitchLocalePathIntercepter, | ||
dynamicRouteParamsKey = DEFAULT_DYNAMIC_PARAMS_KEY | ||
} = {}) { | ||
@@ -598,3 +603,4 @@ const options = getGlobalOptions(router); | ||
prefixable: proxy.prefixable || options.prefixable || prefixable2, | ||
switchLocalePathIntercepter: proxy.switchLocalePathIntercepter || options.switchLocalePathIntercepter || switchLocalePathIntercepter | ||
switchLocalePathIntercepter: proxy.switchLocalePathIntercepter || options.switchLocalePathIntercepter || switchLocalePathIntercepter, | ||
dynamicRouteParamsKey: proxy.dynamicRouteParamsKey || options.dynamicRouteParamsKey || dynamicRouteParamsKey | ||
}; | ||
@@ -706,2 +712,14 @@ } | ||
const DefaultSwitchLocalePathIntercepter = (path) => path; | ||
function getLocalizableMetaFromDynamicParams(route, key) { | ||
const metaDefault = {}; | ||
if (key === DEFAULT_DYNAMIC_PARAMS_KEY) { | ||
return metaDefault; | ||
} | ||
const meta = vueDemi.isVue3 ? route.meta : vueDemi.isRef(route) ? route.value.meta || metaDefault : route.meta || metaDefault; | ||
if (vueDemi.isRef(meta)) { | ||
return meta.value[key] || metaDefault; | ||
} else { | ||
return meta[key] || metaDefault; | ||
} | ||
} | ||
function switchLocalePath(locale) { | ||
@@ -713,4 +731,5 @@ const route = this.route; | ||
} | ||
const { params, ...routeCopy } = !vueDemi.isVue3 && vueDemi.isRef(route) ? route.value : route; | ||
const langSwitchParams = {}; | ||
const { switchLocalePathIntercepter, dynamicRouteParamsKey } = getI18nRoutingOptions(this.router, this); | ||
const { params, ...routeCopy } = vueDemi.isVue3 ? route : vueDemi.isRef(route) ? route.value : route; | ||
const langSwitchParams = getLocalizableMetaFromDynamicParams(route, dynamicRouteParamsKey)[locale] || {}; | ||
const _baseRoute = { | ||
@@ -728,3 +747,2 @@ name, | ||
let path = localePath.call(this, baseRoute, locale); | ||
const { switchLocalePathIntercepter } = getI18nRoutingOptions(this.router, this); | ||
path = switchLocalePathIntercepter(path, locale); | ||
@@ -1057,5 +1075,6 @@ return path; | ||
} | ||
const VERSION = "0.6.0"; | ||
const VERSION = "0.7.0"; | ||
exports.DEFAULT_BASE_URL = DEFAULT_BASE_URL; | ||
exports.DEFAULT_DETECTION_DIRECTION = DEFAULT_DETECTION_DIRECTION; | ||
exports.DEFAULT_DYNAMIC_PARAMS_KEY = DEFAULT_DYNAMIC_PARAMS_KEY; | ||
exports.DEFAULT_LOCALE = DEFAULT_LOCALE; | ||
@@ -1062,0 +1081,0 @@ exports.DEFAULT_LOCALE_ROUTE_NAME_SUFFIX = DEFAULT_LOCALE_ROUTE_NAME_SUFFIX; |
@@ -21,2 +21,3 @@ "use strict"; | ||
const DEFAULT_BASE_URL = ""; | ||
const DEFAULT_DYNAMIC_PARAMS_KEY = ""; | ||
/*! | ||
@@ -478,2 +479,3 @@ * shared v9.3.0-beta.6 | ||
localizeRoutesPrefixable, | ||
dynamicRouteParamsKey, | ||
routeOptionsResolver: optionsResolver | ||
@@ -505,3 +507,4 @@ } = asDefaultVueI18nRouterOptions(options); | ||
prefixable: prefixable2, | ||
switchLocalePathIntercepter | ||
switchLocalePathIntercepter, | ||
dynamicRouteParamsKey | ||
}); | ||
@@ -561,3 +564,3 @@ extendI18n(i18n, { locales: normalizedLocaleCodes, baseUrl, localeCodes, context: router }); | ||
function asDefaultVueI18nRouterOptions(options) { | ||
var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j, _k, _l, _m; | ||
var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j, _k, _l, _m, _n; | ||
options.version = (_a = options.version) != null ? _a : 4; | ||
@@ -576,2 +579,3 @@ options.defaultLocale = (_b = options.defaultLocale) != null ? _b : DEFAULT_LOCALE; | ||
options.localizeRoutesPrefixable = (_m = options.localizeRoutesPrefixable) != null ? _m : DefaultLocalizeRoutesPrefixable; | ||
options.dynamicRouteParamsKey = (_n = options.dynamicRouteParamsKey) != null ? _n : DEFAULT_DYNAMIC_PARAMS_KEY; | ||
return options; | ||
@@ -588,3 +592,4 @@ } | ||
prefixable: prefixable2 = DefaultPrefixable, | ||
switchLocalePathIntercepter = DefaultSwitchLocalePathIntercepter | ||
switchLocalePathIntercepter = DefaultSwitchLocalePathIntercepter, | ||
dynamicRouteParamsKey = DEFAULT_DYNAMIC_PARAMS_KEY | ||
} = {}) { | ||
@@ -601,3 +606,4 @@ const options = getGlobalOptions(router); | ||
prefixable: proxy.prefixable || options.prefixable || prefixable2, | ||
switchLocalePathIntercepter: proxy.switchLocalePathIntercepter || options.switchLocalePathIntercepter || switchLocalePathIntercepter | ||
switchLocalePathIntercepter: proxy.switchLocalePathIntercepter || options.switchLocalePathIntercepter || switchLocalePathIntercepter, | ||
dynamicRouteParamsKey: proxy.dynamicRouteParamsKey || options.dynamicRouteParamsKey || dynamicRouteParamsKey | ||
}; | ||
@@ -709,2 +715,14 @@ } | ||
const DefaultSwitchLocalePathIntercepter = (path) => path; | ||
function getLocalizableMetaFromDynamicParams(route, key) { | ||
const metaDefault = {}; | ||
if (key === DEFAULT_DYNAMIC_PARAMS_KEY) { | ||
return metaDefault; | ||
} | ||
const meta = vueDemi.isVue3 ? route.meta : vueDemi.isRef(route) ? route.value.meta || metaDefault : route.meta || metaDefault; | ||
if (vueDemi.isRef(meta)) { | ||
return meta.value[key] || metaDefault; | ||
} else { | ||
return meta[key] || metaDefault; | ||
} | ||
} | ||
function switchLocalePath(locale) { | ||
@@ -716,4 +734,5 @@ const route = this.route; | ||
} | ||
const { params, ...routeCopy } = !vueDemi.isVue3 && vueDemi.isRef(route) ? route.value : route; | ||
const langSwitchParams = {}; | ||
const { switchLocalePathIntercepter, dynamicRouteParamsKey } = getI18nRoutingOptions(this.router, this); | ||
const { params, ...routeCopy } = vueDemi.isVue3 ? route : vueDemi.isRef(route) ? route.value : route; | ||
const langSwitchParams = getLocalizableMetaFromDynamicParams(route, dynamicRouteParamsKey)[locale] || {}; | ||
const _baseRoute = { | ||
@@ -731,3 +750,2 @@ name, | ||
let path = localePath.call(this, baseRoute, locale); | ||
const { switchLocalePathIntercepter } = getI18nRoutingOptions(this.router, this); | ||
path = switchLocalePathIntercepter(path, locale); | ||
@@ -1060,5 +1078,6 @@ return path; | ||
} | ||
const VERSION = "0.6.0"; | ||
const VERSION = "0.7.0"; | ||
exports.DEFAULT_BASE_URL = DEFAULT_BASE_URL; | ||
exports.DEFAULT_DETECTION_DIRECTION = DEFAULT_DETECTION_DIRECTION; | ||
exports.DEFAULT_DYNAMIC_PARAMS_KEY = DEFAULT_DYNAMIC_PARAMS_KEY; | ||
exports.DEFAULT_LOCALE = DEFAULT_LOCALE; | ||
@@ -1065,0 +1084,0 @@ exports.DEFAULT_LOCALE_ROUTE_NAME_SUFFIX = DEFAULT_LOCALE_ROUTE_NAME_SUFFIX; |
{ | ||
"name": "vue-i18n-routing", | ||
"description": "The i18n routing with using vue-i18n", | ||
"version": "0.6.0", | ||
"scripts": { | ||
"dev": "vite", | ||
"build": "vite build", | ||
"typecheck": "tsc -p . --noEmit", | ||
"switch:2": "vue-demi-switch 2 vue2 && vue-router-switch 3 vue-router3 && vue-i18n-switch 8 vue-i18n-legacy", | ||
"switch:3": "vue-demi-switch 3 && vue-router-switch 4 && vue-i18n-switch 9", | ||
"test": "vitest run", | ||
"test:watch": "vitest", | ||
"test:cover": "vitest --coverage", | ||
"build:docs": "api-docs-gen ./temp/vue-i18n-routing.api.json -c ./docsgen.config.js -o ./ -g noprefix" | ||
}, | ||
"version": "0.7.0-8d07c4a", | ||
"dependencies": { | ||
@@ -117,3 +106,14 @@ "@intlify/shared": "next", | ||
}, | ||
"sideEffects": false | ||
} | ||
"sideEffects": false, | ||
"scripts": { | ||
"dev": "vite", | ||
"build": "vite build", | ||
"typecheck": "tsc -p . --noEmit", | ||
"switch:2": "vue-demi-switch 2 vue2 && vue-router-switch 3 vue-router3 && vue-i18n-switch 8 vue-i18n-legacy", | ||
"switch:3": "vue-demi-switch 3 && vue-router-switch 4 && vue-i18n-switch 9", | ||
"test": "vitest run", | ||
"test:watch": "vitest", | ||
"test:cover": "vitest --coverage", | ||
"build:docs": "api-docs-gen ./temp/vue-i18n-routing.api.json -c ./docsgen.config.js -o ./ -g noprefix" | ||
} | ||
} |
Sorry, the diff of this file is not supported yet
151772
2.15%4099
1.64%