vue-i18n-routing
Advanced tools
Comparing version 0.5.0 to 0.6.0-4930265
@@ -98,2 +98,4 @@ import type { Composer } from '@intlify/vue-i18n-bridge'; | ||
export declare const DEFAULT_DYNAMIC_PARAMS_KEY = ""; | ||
export declare const DEFAULT_LOCALE = ""; | ||
@@ -130,3 +132,3 @@ | ||
export declare function extendI18n<TI18n extends I18n>(i18n: TI18n, { locales, localeCodes, baseUrl, hooks, context }?: VueI18nExtendOptions): EffectScope; | ||
export declare function extendI18n<Context = unknown, TI18n extends I18n = I18n>(i18n: TI18n, { locales, localeCodes, baseUrl, hooks, context }?: VueI18nExtendOptions<Context>): EffectScope; | ||
@@ -231,3 +233,3 @@ export declare interface ExtendProperyDescripters { | ||
*/ | ||
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[]; | ||
@@ -352,2 +354,8 @@ }; | ||
localizeRoutesPrefixable?: LocalizeRoutesPrefixable; | ||
/** | ||
* The key which to access vue router meta object, when dynamic route params need localize. | ||
* | ||
* @defaultValue '' | ||
*/ | ||
dynamicRouteParamsKey?: string | symbol; | ||
} & RouterOptions; | ||
@@ -562,2 +570,3 @@ | ||
switchLocalePathIntercepter?: SwitchLocalePathIntercepter; | ||
dynamicRouteParamsKey?: string | symbol; | ||
} | ||
@@ -688,6 +697,6 @@ | ||
export declare type VueI18nExtendOptions = Pick<I18nRoutingOptions, 'baseUrl'> & { | ||
export declare type VueI18nExtendOptions<Context = unknown> = Pick<I18nRoutingOptions<Context>, 'baseUrl'> & { | ||
locales?: string[] | LocaleObject[]; | ||
localeCodes?: string[]; | ||
context?: unknown; | ||
context?: Context; | ||
hooks?: ExtendHooks; | ||
@@ -694,0 +703,0 @@ }; |
@@ -18,2 +18,3 @@ var VueI18nRouting = function(exports, vueDemi, VueRouter3, vueI18nBridge) { | ||
const DEFAULT_BASE_URL = ""; | ||
const DEFAULT_DYNAMIC_PARAMS_KEY = ""; | ||
/*! | ||
@@ -325,3 +326,9 @@ * shared v9.3.0-beta.6 | ||
} | ||
function extendI18n(i18n, { locales = [], localeCodes = [], baseUrl = DEFAULT_BASE_URL, hooks = {}, context = {} } = {}) { | ||
function extendI18n(i18n, { | ||
locales = [], | ||
localeCodes = [], | ||
baseUrl = DEFAULT_BASE_URL, | ||
hooks = {}, | ||
context = {} | ||
} = {}) { | ||
const scope = vueDemi.effectScope(); | ||
@@ -470,2 +477,3 @@ const orgInstall = i18n.install; | ||
localizeRoutesPrefixable, | ||
dynamicRouteParamsKey, | ||
routeOptionsResolver: optionsResolver | ||
@@ -476,3 +484,2 @@ } = asDefaultVueI18nRouterOptions(options); | ||
const getLocaleFromRoute = createLocaleFromRouteGetter(localeCodes, routesNameSeparator, defaultLocaleRouteNameSuffix); | ||
extendI18n(i18n, { locales: normalizedLocaleCodes, baseUrl, localeCodes }); | ||
const localizedRoutes = localizeRoutes(routes, { | ||
@@ -499,4 +506,6 @@ locales, | ||
prefixable: prefixable2, | ||
switchLocalePathIntercepter | ||
switchLocalePathIntercepter, | ||
dynamicRouteParamsKey | ||
}); | ||
extendI18n(i18n, { locales: normalizedLocaleCodes, baseUrl, localeCodes, context: router }); | ||
router.beforeEach((to, from, next) => { | ||
@@ -554,3 +563,3 @@ const currentLocale = getLocale(i18n); | ||
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; | ||
@@ -569,2 +578,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; | ||
@@ -581,3 +591,4 @@ } | ||
prefixable: prefixable2 = DefaultPrefixable, | ||
switchLocalePathIntercepter = DefaultSwitchLocalePathIntercepter | ||
switchLocalePathIntercepter = DefaultSwitchLocalePathIntercepter, | ||
dynamicRouteParamsKey = DEFAULT_DYNAMIC_PARAMS_KEY | ||
} = {}) { | ||
@@ -594,3 +605,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 | ||
}; | ||
@@ -702,2 +714,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) { | ||
@@ -709,4 +733,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 = { | ||
@@ -724,3 +749,2 @@ name, | ||
let path = localePath.call(this, baseRoute, locale); | ||
const { switchLocalePathIntercepter } = getI18nRoutingOptions(this.router, this); | ||
path = switchLocalePathIntercepter(path, locale); | ||
@@ -1053,5 +1077,6 @@ return path; | ||
} | ||
const VERSION = "0.5.0"; | ||
const VERSION = "0.6.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; | ||
@@ -1058,0 +1083,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 = ""; | ||
/*! | ||
@@ -328,3 +329,9 @@ * shared v9.3.0-beta.6 | ||
} | ||
function extendI18n(i18n, { locales = [], localeCodes = [], baseUrl = DEFAULT_BASE_URL, hooks = {}, context = {} } = {}) { | ||
function extendI18n(i18n, { | ||
locales = [], | ||
localeCodes = [], | ||
baseUrl = DEFAULT_BASE_URL, | ||
hooks = {}, | ||
context = {} | ||
} = {}) { | ||
const scope = vueDemi.effectScope(); | ||
@@ -473,2 +480,3 @@ const orgInstall = i18n.install; | ||
localizeRoutesPrefixable, | ||
dynamicRouteParamsKey, | ||
routeOptionsResolver: optionsResolver | ||
@@ -479,3 +487,2 @@ } = asDefaultVueI18nRouterOptions(options); | ||
const getLocaleFromRoute = createLocaleFromRouteGetter(localeCodes, routesNameSeparator, defaultLocaleRouteNameSuffix); | ||
extendI18n(i18n, { locales: normalizedLocaleCodes, baseUrl, localeCodes }); | ||
const localizedRoutes = localizeRoutes(routes, { | ||
@@ -502,4 +509,6 @@ locales, | ||
prefixable: prefixable2, | ||
switchLocalePathIntercepter | ||
switchLocalePathIntercepter, | ||
dynamicRouteParamsKey | ||
}); | ||
extendI18n(i18n, { locales: normalizedLocaleCodes, baseUrl, localeCodes, context: router }); | ||
router.beforeEach((to, from, next) => { | ||
@@ -557,3 +566,3 @@ const currentLocale = getLocale(i18n); | ||
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; | ||
@@ -572,2 +581,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; | ||
@@ -584,3 +594,4 @@ } | ||
prefixable: prefixable2 = DefaultPrefixable, | ||
switchLocalePathIntercepter = DefaultSwitchLocalePathIntercepter | ||
switchLocalePathIntercepter = DefaultSwitchLocalePathIntercepter, | ||
dynamicRouteParamsKey = DEFAULT_DYNAMIC_PARAMS_KEY | ||
} = {}) { | ||
@@ -597,3 +608,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 | ||
}; | ||
@@ -705,2 +717,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) { | ||
@@ -712,4 +736,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 = { | ||
@@ -727,3 +752,2 @@ name, | ||
let path = localePath.call(this, baseRoute, locale); | ||
const { switchLocalePathIntercepter } = getI18nRoutingOptions(this.router, this); | ||
path = switchLocalePathIntercepter(path, locale); | ||
@@ -1056,5 +1080,6 @@ return path; | ||
} | ||
const VERSION = "0.5.0"; | ||
const VERSION = "0.6.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; | ||
@@ -1061,0 +1086,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.5.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.6.0-4930265", | ||
"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
4099