@i18n-micro/vitepress 1.0.1 → 1.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +73 -39
- package/client.d.ts +1 -0
- package/dist/adapter-BJ-0ltIc.cjs +2 -0
- package/dist/adapter-BJ-0ltIc.cjs.map +1 -0
- package/dist/adapter-BnsyIKhp.js +128 -0
- package/dist/adapter-BnsyIKhp.js.map +1 -0
- package/dist/config.cjs +64 -1
- package/dist/config.cjs.map +1 -1
- package/dist/config.d.cts +113 -111
- package/dist/config.d.ts +113 -111
- package/dist/config.mjs +393 -9
- package/dist/config.mjs.map +1 -1
- package/dist/create-BgMbe0w1.cjs +2 -0
- package/dist/create-BgMbe0w1.cjs.map +1 -0
- package/dist/create-Dev8Q66O.js +80 -0
- package/dist/create-Dev8Q66O.js.map +1 -0
- package/dist/index.cjs +1 -1
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +87 -141
- package/dist/index.d.ts +87 -141
- package/dist/index.mjs +28 -249
- package/dist/index.mjs.map +1 -1
- package/dist/node.cjs +1 -1
- package/dist/node.cjs.map +1 -1
- package/dist/node.d.cts +56 -116
- package/dist/node.d.ts +56 -116
- package/dist/node.mjs +23 -7
- package/dist/node.mjs.map +1 -1
- package/dist/{virtual-stubs → plugin/virtual-stubs}/config.d.cts +2 -1
- package/dist/runtime/define-theme.d.cts +39 -0
- package/dist/theme.cjs +2 -0
- package/dist/theme.cjs.map +1 -0
- package/dist/theme.d.cts +58 -0
- package/dist/theme.d.ts +58 -0
- package/dist/theme.mjs +35 -0
- package/dist/theme.mjs.map +1 -0
- package/dist/vitepress-locales-6msv22Sn.js +27 -0
- package/dist/vitepress-locales-6msv22Sn.js.map +1 -0
- package/dist/vitepress-locales-Cz4AutfI.cjs +2 -0
- package/dist/vitepress-locales-Cz4AutfI.cjs.map +1 -0
- package/package.json +18 -6
- package/dist/i18n-routing-CcppCuuS.js +0 -64
- package/dist/i18n-routing-CcppCuuS.js.map +0 -1
- package/dist/i18n-routing-D9iYAKDq.cjs +0 -46
- package/dist/i18n-routing-D9iYAKDq.cjs.map +0 -1
- package/dist/with-i18n-micro-01q-vPO9.cjs +0 -15
- package/dist/with-i18n-micro-01q-vPO9.cjs.map +0 -1
- package/dist/with-i18n-micro-DIAoqY71.js +0 -216
- package/dist/with-i18n-micro-DIAoqY71.js.map +0 -1
package/dist/index.d.ts
CHANGED
|
@@ -1,7 +1,6 @@
|
|
|
1
1
|
/// <reference types="@i18n-micro/vitepress/client" />
|
|
2
2
|
import { App } from 'vue';
|
|
3
3
|
import { CleanTranslation } from '@i18n-micro/types';
|
|
4
|
-
import { createI18n } from '@i18n-micro/vue';
|
|
5
4
|
import { defaultPlural } from '@i18n-micro/core';
|
|
6
5
|
import { FormatService } from '@i18n-micro/core';
|
|
7
6
|
import { Getter } from '@i18n-micro/types';
|
|
@@ -18,7 +17,6 @@ import { Params } from '@i18n-micro/types';
|
|
|
18
17
|
import { Plugin as Plugin_2 } from 'vite';
|
|
19
18
|
import { PluralFunc } from '@i18n-micro/types';
|
|
20
19
|
import { Ref } from 'vue';
|
|
21
|
-
import { Theme } from 'vitepress';
|
|
22
20
|
import { Translations } from '@i18n-micro/types';
|
|
23
21
|
import { useI18n } from '@i18n-micro/vue';
|
|
24
22
|
import { UseI18nOptions } from '@i18n-micro/vue';
|
|
@@ -26,82 +24,62 @@ import { VueI18nOptions } from '@i18n-micro/vue';
|
|
|
26
24
|
|
|
27
25
|
export { CleanTranslation }
|
|
28
26
|
|
|
29
|
-
export { createI18n }
|
|
30
|
-
|
|
31
27
|
/**
|
|
32
|
-
*
|
|
33
|
-
*
|
|
34
|
-
*
|
|
35
|
-
* `targetLocale` is a **VitePress locale key** (`root` / `fr`). URL prefixes use that key;
|
|
36
|
-
* `localeKeyToCode` is only for resolving the i18n code when callers need it elsewhere.
|
|
37
|
-
*
|
|
38
|
-
* Returns a **self-contained** function (no closures) so VitePress can serialize it
|
|
39
|
-
* into site data via `Function#toString()` + `new Function`.
|
|
28
|
+
* Universal VitePress i18n: Vue plugin + path helpers + `enhanceApp` sync.
|
|
29
|
+
* Path methods are the router adapter’s own functions (no wrapper layer).
|
|
40
30
|
*/
|
|
41
|
-
export declare function
|
|
31
|
+
export declare function createI18n(options: CreateI18nOptions): CreateI18nResult;
|
|
42
32
|
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
33
|
+
export declare interface CreateI18nOptions {
|
|
34
|
+
locale: string;
|
|
35
|
+
fallbackLocale?: string;
|
|
36
|
+
locales?: Locale[];
|
|
37
|
+
defaultLocale?: string;
|
|
38
|
+
messages?: Record<string, Translations>;
|
|
39
|
+
/**
|
|
40
|
+
* Page-scoped dictionaries keyed by route name (`guide-demo`), then locale.
|
|
41
|
+
* Loaded from `locales/pages/**` when using `withI18n`.
|
|
42
|
+
*/
|
|
43
|
+
routeMessages?: Record<string, Record<string, Translations>>;
|
|
44
|
+
plural?: PluralFunc;
|
|
45
|
+
missingWarn?: boolean;
|
|
46
|
+
missingHandler?: (locale: string, key: string, routeName: string) => void;
|
|
47
|
+
/**
|
|
48
|
+
* Sync i18n locale from the VitePress URL path on every navigation.
|
|
49
|
+
* @default true
|
|
50
|
+
*/
|
|
51
|
+
syncWithVitePress?: boolean;
|
|
52
|
+
/**
|
|
53
|
+
* Map VitePress locale keys to i18n codes (`root` → default locale code).
|
|
54
|
+
*/
|
|
55
|
+
localeKeyToCode?: Record<string, string>;
|
|
56
|
+
/**
|
|
57
|
+
* VitePress `site.base`. Needed so SSG paths (`withBase`) and lang switcher
|
|
58
|
+
* do not treat the base segment as content / double-prefix links.
|
|
59
|
+
*/
|
|
60
|
+
base?: string;
|
|
61
|
+
}
|
|
47
62
|
|
|
48
|
-
export declare
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
adapter: VitePressRouterAdapter | null;
|
|
63
|
+
export declare type CreateI18nResult = I18nPlugin & PathMethods & {
|
|
64
|
+
/** Same as `.global` (VueI18n + path methods). */
|
|
65
|
+
i18n: I18nPlugin['global'] & PathMethods;
|
|
52
66
|
enhanceApp: (ctx: {
|
|
53
67
|
app: App;
|
|
54
68
|
router: VitePressRouterLike;
|
|
55
69
|
siteData?: Ref<VitePressSiteDataLike> | VitePressSiteDataLike;
|
|
56
70
|
}) => void;
|
|
57
|
-
}
|
|
58
|
-
|
|
59
|
-
/**
|
|
60
|
-
* VitePress path adapter (prefix_except_default semantics):
|
|
61
|
-
* default locale has no URL prefix; other locales use `/{vitepressKey}/…`.
|
|
62
|
-
* i18n locale values remain `locale.code` (via `localeKeyToCode`).
|
|
63
|
-
*/
|
|
64
|
-
export declare function createVitePressRouterAdapter(options: VitePressRouterAdapterOptions): VitePressRouterAdapter;
|
|
71
|
+
};
|
|
65
72
|
|
|
66
73
|
export { defaultPlural }
|
|
67
74
|
|
|
68
|
-
/**
|
|
69
|
-
* Zero-boilerplate theme wiring. Requires `withI18nMicro(...)` in `.vitepress/config`
|
|
70
|
-
* so virtual config + messages modules exist.
|
|
71
|
-
*
|
|
72
|
-
* Virtual modules are loaded inside `enhanceApp` (not at package top-level) so
|
|
73
|
-
* `@i18n-micro/vitepress` stays importable from Node when evaluating VitePress config.
|
|
74
|
-
*
|
|
75
|
-
* @example
|
|
76
|
-
* ```ts
|
|
77
|
-
* import DefaultTheme from 'vitepress/theme'
|
|
78
|
-
* import { defineI18nTheme } from '@i18n-micro/vitepress'
|
|
79
|
-
*
|
|
80
|
-
* export default defineI18nTheme(DefaultTheme)
|
|
81
|
-
* ```
|
|
82
|
-
*/
|
|
83
|
-
export declare function defineI18nTheme<T extends Theme>(base: T, options?: DefineI18nThemeOptions): T;
|
|
84
|
-
|
|
85
|
-
export declare interface DefineI18nThemeOptions {
|
|
86
|
-
/**
|
|
87
|
-
* Extra `enhanceApp` run after i18n is installed.
|
|
88
|
-
*/
|
|
89
|
-
enhanceApp?: NonNullable<Theme['enhanceApp']>;
|
|
90
|
-
/**
|
|
91
|
-
* Overrides not serializable into `virtual:i18n-micro/config`.
|
|
92
|
-
*/
|
|
93
|
-
plural?: PluralFunc;
|
|
94
|
-
missingHandler?: (locale: string, key: string, routeName: string) => void;
|
|
95
|
-
localeKeyToCode?: Record<string, string>;
|
|
96
|
-
}
|
|
97
|
-
|
|
98
75
|
export { FormatService }
|
|
99
76
|
|
|
100
77
|
/**
|
|
101
78
|
* Detect i18n locale code from a URL path (prefix_except_default).
|
|
102
79
|
* Path prefixes are VitePress locale keys; return value is the i18n code.
|
|
80
|
+
* Pass `base` when the path may include VitePress `site.base` (SSG).
|
|
103
81
|
*/
|
|
104
|
-
export declare function getLocaleFromPath(path: string, localeCodes: string[], defaultLocale: string, localeKeyToCode?: Record<string, string
|
|
82
|
+
export declare function getLocaleFromPath(path: string, localeCodes: string[], defaultLocale: string, localeKeyToCode?: Record<string, string>, base?: string): string;
|
|
105
83
|
|
|
106
84
|
export { Getter }
|
|
107
85
|
|
|
@@ -111,12 +89,6 @@ export { I18nLink }
|
|
|
111
89
|
|
|
112
90
|
export { I18nPlugin }
|
|
113
91
|
|
|
114
|
-
export declare interface I18nRoutingFromAdapterOptions {
|
|
115
|
-
defaultLocale: string;
|
|
116
|
-
localeCodes: string[];
|
|
117
|
-
localeKeyToCode?: Record<string, string>;
|
|
118
|
-
}
|
|
119
|
-
|
|
120
92
|
export { I18nRoutingStrategy }
|
|
121
93
|
|
|
122
94
|
export { I18nSwitcher }
|
|
@@ -139,6 +111,9 @@ export declare function messagesFromGlob(modules: Record<string, {
|
|
|
139
111
|
|
|
140
112
|
export { Params }
|
|
141
113
|
|
|
114
|
+
/** Path helpers exposed on `createI18n` instances (slice of the router adapter). */
|
|
115
|
+
export declare type PathMethods = Pick<VitePressRouterAdapter, 'localizePath' | 'switchLocalePath' | 'getLocaleFromPath' | 'removeLocaleFromPath' | 'routeNameFromPath'>;
|
|
116
|
+
|
|
142
117
|
export { PluralFunc }
|
|
143
118
|
|
|
144
119
|
/**
|
|
@@ -148,7 +123,13 @@ export { PluralFunc }
|
|
|
148
123
|
* When `defaultLocale` is omitted (legacy 2-arg call), any segment that matches a
|
|
149
124
|
* listed locale code is stripped — callers must not rely on `localeCodes[0]` as default.
|
|
150
125
|
*/
|
|
151
|
-
export declare function routeNameFromPath(path: string, localeCodes: string[], defaultLocale?: string, localeKeyToCode?: Record<string, string
|
|
126
|
+
export declare function routeNameFromPath(path: string, localeCodes: string[], defaultLocale?: string, localeKeyToCode?: Record<string, string>, base?: string): string;
|
|
127
|
+
|
|
128
|
+
/**
|
|
129
|
+
* Strip VitePress `site.base` from a path. Leaves query/hash intact.
|
|
130
|
+
* No-op when `base` is missing or `/`.
|
|
131
|
+
*/
|
|
132
|
+
export declare function stripSiteBase(path: string, base?: string): string;
|
|
152
133
|
|
|
153
134
|
export { Translations }
|
|
154
135
|
|
|
@@ -166,71 +147,17 @@ export declare interface VirtualI18nConfig {
|
|
|
166
147
|
translationDir: string;
|
|
167
148
|
disablePageLocales: boolean;
|
|
168
149
|
localeKeyToCode: Record<string, string>;
|
|
150
|
+
/** VitePress `site.base` (normalized, trailing slash preserved from config). */
|
|
151
|
+
base?: string;
|
|
169
152
|
}
|
|
170
153
|
|
|
171
|
-
|
|
172
|
-
replace?: boolean;
|
|
173
|
-
}) => void | Promise<void>;
|
|
174
|
-
|
|
175
|
-
export declare interface VitePressI18nOptions {
|
|
176
|
-
locale: string;
|
|
177
|
-
fallbackLocale?: string;
|
|
178
|
-
locales?: Locale[];
|
|
179
|
-
defaultLocale?: string;
|
|
180
|
-
messages?: Record<string, Translations>;
|
|
181
|
-
/**
|
|
182
|
-
* Page-scoped dictionaries keyed by route name (`guide-demo`), then locale.
|
|
183
|
-
* Loaded from `locales/pages/**` when using `withI18nMicro`.
|
|
184
|
-
*/
|
|
185
|
-
routeMessages?: Record<string, Record<string, Translations>>;
|
|
186
|
-
plural?: PluralFunc;
|
|
187
|
-
missingWarn?: boolean;
|
|
188
|
-
missingHandler?: (locale: string, key: string, routeName: string) => void;
|
|
189
|
-
/**
|
|
190
|
-
* Sync i18n locale from the VitePress URL path on every navigation.
|
|
191
|
-
* @default true
|
|
192
|
-
*/
|
|
193
|
-
syncWithVitePress?: boolean;
|
|
194
|
-
/**
|
|
195
|
-
* Map VitePress locale keys to i18n codes (`root` → default locale code).
|
|
196
|
-
*/
|
|
197
|
-
localeKeyToCode?: Record<string, string>;
|
|
198
|
-
}
|
|
199
|
-
|
|
200
|
-
/**
|
|
201
|
-
* Minimal shapes used by VitePress `themeConfig.i18nRouting`.
|
|
202
|
-
* Kept loose so we do not hard-depend on VitePress internal DefaultTheme types at compile time.
|
|
203
|
-
*/
|
|
204
|
-
export declare interface VitePressI18nRoutingData {
|
|
205
|
-
site?: {
|
|
206
|
-
value?: {
|
|
207
|
-
locales?: Record<string, {
|
|
208
|
-
link?: string;
|
|
209
|
-
lang?: string;
|
|
210
|
-
}>;
|
|
211
|
-
};
|
|
212
|
-
};
|
|
213
|
-
localeIndex?: {
|
|
214
|
-
value?: string;
|
|
215
|
-
};
|
|
216
|
-
}
|
|
217
|
-
|
|
218
|
-
export declare type VitePressI18nRoutingFn = (data: VitePressI18nRoutingData, route: VitePressI18nRoutingRoute, targetLocale: string) => string;
|
|
219
|
-
|
|
220
|
-
export declare interface VitePressI18nRoutingRoute {
|
|
221
|
-
path: string;
|
|
222
|
-
hash?: string;
|
|
223
|
-
query?: string;
|
|
224
|
-
data?: {
|
|
225
|
-
relativePath?: string;
|
|
226
|
-
};
|
|
227
|
-
}
|
|
228
|
-
|
|
229
|
-
export declare interface VitePressRouterAdapter extends I18nRoutingStrategy {
|
|
154
|
+
declare interface VitePressRouterAdapter extends I18nRoutingStrategy {
|
|
230
155
|
getLocaleFromPath: (path: string) => string;
|
|
231
156
|
switchLocalePath: (path: string, newLocale: string) => string;
|
|
232
157
|
localizePath: (path: string, locale: string) => string;
|
|
233
158
|
removeLocaleFromPath: (path: string) => string;
|
|
159
|
+
/** Page dictionary route name (`/fr/guide/demo` → `guide-demo`). */
|
|
160
|
+
routeNameFromPath: (path: string) => string;
|
|
234
161
|
/** Resolve VitePress locale key (`root` / `fr`) to i18n code. */
|
|
235
162
|
codeFromLocaleKey: (localeKey: string) => string;
|
|
236
163
|
/** Resolve i18n code to VitePress locale key. */
|
|
@@ -241,22 +168,11 @@ export declare interface VitePressRouterAdapter extends I18nRoutingStrategy {
|
|
|
241
168
|
localeKeyToCode: Record<string, string>;
|
|
242
169
|
/** URL path prefixes (VitePress locale keys except `root`). */
|
|
243
170
|
urlPrefixes: string[];
|
|
171
|
+
/** VitePress `site.base` used when constructing this adapter (may be undefined). */
|
|
172
|
+
base?: string;
|
|
244
173
|
}
|
|
245
174
|
|
|
246
|
-
|
|
247
|
-
locales: Locale[];
|
|
248
|
-
defaultLocale: string;
|
|
249
|
-
/**
|
|
250
|
-
* Map VitePress locale keys (`root`, `fr`) to i18n locale codes.
|
|
251
|
-
* Defaults: `root` → `defaultLocale`, other keys → same string as the key.
|
|
252
|
-
* URL prefixes always use VitePress keys; i18n uses codes.
|
|
253
|
-
*/
|
|
254
|
-
localeKeyToCode?: Record<string, string>;
|
|
255
|
-
getPath?: () => string;
|
|
256
|
-
go?: VitePressGo;
|
|
257
|
-
}
|
|
258
|
-
|
|
259
|
-
export declare interface VitePressRouterLike {
|
|
175
|
+
declare interface VitePressRouterLike {
|
|
260
176
|
route: {
|
|
261
177
|
path: string;
|
|
262
178
|
hash?: string;
|
|
@@ -282,9 +198,17 @@ export declare interface VitePressSiteDataLike {
|
|
|
282
198
|
* Avoid importing `vitepress` types so the package stays usable as a pure library dep.
|
|
283
199
|
*/
|
|
284
200
|
export declare interface VitePressUserConfigLike {
|
|
201
|
+
base?: string;
|
|
285
202
|
locales?: Record<string, unknown>;
|
|
203
|
+
themeConfig?: Record<string, unknown> | null;
|
|
204
|
+
transformHead?: (...args: any[]) => any;
|
|
205
|
+
transformPageData?: (...args: any[]) => any;
|
|
286
206
|
vite?: {
|
|
287
207
|
plugins?: Plugin_2[] | Plugin_2[][];
|
|
208
|
+
ssr?: {
|
|
209
|
+
noExternal?: string | true | Array<string | RegExp>;
|
|
210
|
+
[key: string]: unknown;
|
|
211
|
+
};
|
|
288
212
|
[key: string]: unknown;
|
|
289
213
|
};
|
|
290
214
|
[key: string]: unknown;
|
|
@@ -292,7 +216,7 @@ export declare interface VitePressUserConfigLike {
|
|
|
292
216
|
|
|
293
217
|
export { VueI18nOptions }
|
|
294
218
|
|
|
295
|
-
export declare interface
|
|
219
|
+
export declare interface WithI18nOptions extends CreateI18nOptions {
|
|
296
220
|
/**
|
|
297
221
|
* Directory with locale JSON (`en.json`, `pages/guide/demo/en.json`, …), relative to Vite root
|
|
298
222
|
* (VitePress content / docs root). Used by `virtual:i18n-micro/messages`.
|
|
@@ -310,6 +234,28 @@ export declare interface WithI18nMicroOptions extends VitePressI18nOptions {
|
|
|
310
234
|
* @default true
|
|
311
235
|
*/
|
|
312
236
|
warnOnLocaleMismatch?: boolean;
|
|
237
|
+
/**
|
|
238
|
+
* Inject `themeConfig.i18nRouting` from adapter options + `config.base`.
|
|
239
|
+
* Set `false` to skip. Skipped automatically when `themeConfig.i18nRouting` is already set.
|
|
240
|
+
* @default true
|
|
241
|
+
*/
|
|
242
|
+
i18nRouting?: boolean;
|
|
243
|
+
/**
|
|
244
|
+
* Emit i18n SEO tags via `transformHead` (canonical, hreflang, og:locale…) —
|
|
245
|
+
* Nuxt `meta` / plugin `02.meta` analogue.
|
|
246
|
+
* Absolute link tags require `metaBaseUrl`.
|
|
247
|
+
* @default true when `metaBaseUrl` is set, otherwise false
|
|
248
|
+
*/
|
|
249
|
+
meta?: boolean;
|
|
250
|
+
/**
|
|
251
|
+
* Public origin without trailing slash (`https://example.com`).
|
|
252
|
+
* Same role as Nuxt `metaBaseUrl`.
|
|
253
|
+
*/
|
|
254
|
+
metaBaseUrl?: string;
|
|
255
|
+
/** Also emit bare-language hreflang from `iso` (Nuxt `hreflangBaseLanguage`). @default false */
|
|
256
|
+
hreflangBaseLanguage?: boolean;
|
|
257
|
+
/** Query keys kept on canonical / alternate URLs. @default [] */
|
|
258
|
+
canonicalQueryWhitelist?: string[];
|
|
313
259
|
}
|
|
314
260
|
|
|
315
261
|
export { }
|
package/dist/index.mjs
CHANGED
|
@@ -1,254 +1,33 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
3
|
-
import { I18nGroup as
|
|
4
|
-
import {
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
function x(e, r, a = {}) {
|
|
16
|
-
const o = (t) => {
|
|
17
|
-
for (const [l, i] of Object.entries(a))
|
|
18
|
-
if (i === t) return l;
|
|
19
|
-
return t === r ? "root" : t;
|
|
20
|
-
}, s = /* @__PURE__ */ new Map();
|
|
21
|
-
for (const t of e) {
|
|
22
|
-
if (t === r) continue;
|
|
23
|
-
const l = o(t), i = l === "root" ? t : l;
|
|
24
|
-
s.set(i, t), i !== t && s.set(t, t);
|
|
25
|
-
}
|
|
26
|
-
return s;
|
|
27
|
-
}
|
|
28
|
-
function R(e, r, a, o = {}) {
|
|
29
|
-
const { pathname: s } = v(e), t = s.split("/").filter(Boolean)[0];
|
|
30
|
-
return t === void 0 ? a : x(r, a, o).get(t) ?? a;
|
|
31
|
-
}
|
|
32
|
-
function S(e, r, a, o = {}) {
|
|
33
|
-
const { pathname: s } = v(e), t = s.split("/").filter(Boolean), l = t[0];
|
|
34
|
-
return l !== void 0 && (a !== void 0 ? x(r, a, o).has(l) && t.shift() : r.includes(l) && t.shift()), t.length === 0 ? "index" : t.join("-").replace(/\.html$/, "");
|
|
35
|
-
}
|
|
36
|
-
function M(e) {
|
|
37
|
-
return W({
|
|
38
|
-
name: "VitePressI18nLink",
|
|
39
|
-
props: {
|
|
40
|
-
to: { type: String, required: !0 },
|
|
41
|
-
style: { type: Object, default: void 0 }
|
|
42
|
-
},
|
|
43
|
-
setup(r, { slots: a }) {
|
|
44
|
-
return () => F(
|
|
45
|
-
"a",
|
|
46
|
-
{
|
|
47
|
-
href: r.to,
|
|
48
|
-
style: r.style,
|
|
49
|
-
onClick: (o) => {
|
|
50
|
-
o.defaultPrevented || o.button === 0 && (o.metaKey || o.altKey || o.ctrlKey || o.shiftKey || (o.preventDefault(), e ? e(r.to) : typeof window < "u" && window.location.assign(r.to)));
|
|
51
|
-
}
|
|
52
|
-
},
|
|
53
|
-
a.default?.()
|
|
54
|
-
);
|
|
55
|
-
}
|
|
56
|
-
});
|
|
57
|
-
}
|
|
58
|
-
function $(e) {
|
|
59
|
-
const { locales: r, defaultLocale: a, localeKeyToCode: o = {}, getPath: s, go: t } = e, l = r.map((n) => n.code), i = { ...o }, m = x(l, a, i), g = [...m.keys()], p = (n) => i[n] ? i[n] : n === "root" ? a : n, f = (n) => {
|
|
60
|
-
for (const [c, h] of Object.entries(i))
|
|
61
|
-
if (h === n) return c;
|
|
62
|
-
return n === a ? "root" : n;
|
|
63
|
-
}, P = (n) => {
|
|
64
|
-
if (n === a) return null;
|
|
65
|
-
const c = f(n);
|
|
66
|
-
return c === "root" ? n : c;
|
|
67
|
-
}, C = (n) => {
|
|
68
|
-
const c = n === "/" || n.endsWith("/"), h = n.split("/").filter(Boolean), w = h[0];
|
|
69
|
-
return w !== void 0 && m.has(w) && h.shift(), { segments: h, hadTrailingSlash: c };
|
|
70
|
-
}, b = (n) => {
|
|
71
|
-
const { pathname: c, extras: h } = v(n), { segments: w, hadTrailingSlash: L } = C(c);
|
|
72
|
-
let T = w.length === 0 ? "/" : `/${w.join("/")}`;
|
|
73
|
-
return T !== "/" && L && (T += "/"), `${T}${h}`;
|
|
74
|
-
}, u = (n, c) => {
|
|
75
|
-
const { pathname: h, extras: w } = v(n), { segments: L, hadTrailingSlash: T } = C(h), j = P(c);
|
|
76
|
-
j && L.unshift(j);
|
|
77
|
-
let k = L.length === 0 ? "/" : `/${L.join("/")}`;
|
|
78
|
-
return k !== "/" && T && (k += "/"), `${k}${w}`;
|
|
79
|
-
}, d = (n, c) => u(n, c), y = (n, c) => {
|
|
80
|
-
const h = typeof n == "string" ? n : n.path || "/";
|
|
81
|
-
return u(h, c);
|
|
82
|
-
}, A = (n, c = !1) => {
|
|
83
|
-
if (t) {
|
|
84
|
-
t(n, { replace: c });
|
|
85
|
-
return;
|
|
86
|
-
}
|
|
87
|
-
typeof window < "u" && (c ? window.location.replace(n) : window.location.assign(n));
|
|
88
|
-
};
|
|
89
|
-
return {
|
|
90
|
-
localeCodes: l,
|
|
91
|
-
defaultLocale: a,
|
|
92
|
-
localeKeyToCode: i,
|
|
93
|
-
urlPrefixes: g,
|
|
94
|
-
codeFromLocaleKey: p,
|
|
95
|
-
localeKeyFromCode: f,
|
|
96
|
-
getLocaleFromPath: (n) => R(n, l, a, i),
|
|
97
|
-
switchLocalePath: d,
|
|
98
|
-
localizePath: u,
|
|
99
|
-
removeLocaleFromPath: b,
|
|
100
|
-
linkComponent: M(t),
|
|
101
|
-
getCurrentPath: () => s ? s() : typeof window < "u" ? window.location.pathname + window.location.search + window.location.hash : "/",
|
|
102
|
-
push: (n) => {
|
|
103
|
-
A(n.path, !1);
|
|
104
|
-
},
|
|
105
|
-
replace: (n) => {
|
|
106
|
-
A(n.path, !0);
|
|
107
|
-
},
|
|
108
|
-
resolvePath: y,
|
|
109
|
-
getRoute: () => {
|
|
110
|
-
const n = s ? s() : typeof window < "u" ? window.location.pathname + window.location.search + window.location.hash : "/", c = typeof window < "u" ? new URL(n, window.location.origin) : new URL(n, "http://localhost");
|
|
111
|
-
return {
|
|
112
|
-
fullPath: c.pathname + c.search + c.hash,
|
|
113
|
-
query: Object.fromEntries(c.searchParams)
|
|
114
|
-
};
|
|
115
|
-
}
|
|
116
|
-
};
|
|
117
|
-
}
|
|
118
|
-
function O(e) {
|
|
119
|
-
return e.defaultLocale || e.locale;
|
|
120
|
-
}
|
|
121
|
-
function H(e, r, a) {
|
|
122
|
-
if (a)
|
|
123
|
-
for (const [o, s] of Object.entries(a))
|
|
124
|
-
for (const [t, l] of Object.entries(s))
|
|
125
|
-
e.global.addRouteTranslations(
|
|
126
|
-
t,
|
|
127
|
-
o,
|
|
128
|
-
I(r?.[t], l),
|
|
129
|
-
!1
|
|
130
|
-
);
|
|
131
|
-
}
|
|
132
|
-
function V(e) {
|
|
133
|
-
const r = O(e), a = e.locales ?? [], o = e.syncWithVitePress !== !1, s = K({
|
|
134
|
-
locale: e.locale,
|
|
135
|
-
fallbackLocale: e.fallbackLocale ?? r,
|
|
136
|
-
messages: e.messages,
|
|
137
|
-
plural: e.plural,
|
|
138
|
-
missingWarn: e.missingWarn,
|
|
139
|
-
missingHandler: e.missingHandler,
|
|
140
|
-
locales: a,
|
|
141
|
-
defaultLocale: r
|
|
142
|
-
});
|
|
143
|
-
H(s, e.messages, e.routeMessages);
|
|
144
|
-
const t = /* @__PURE__ */ new WeakMap();
|
|
145
|
-
let l = null;
|
|
146
|
-
const i = (m) => {
|
|
147
|
-
const { app: g, router: p } = m;
|
|
148
|
-
let f = t.get(g);
|
|
149
|
-
if (!f) {
|
|
150
|
-
const u = $({
|
|
151
|
-
locales: a,
|
|
152
|
-
defaultLocale: r,
|
|
153
|
-
localeKeyToCode: e.localeKeyToCode,
|
|
154
|
-
getPath: () => {
|
|
155
|
-
const d = p.route;
|
|
156
|
-
return `${d.path}${d.query || ""}${d.hash || ""}`;
|
|
157
|
-
},
|
|
158
|
-
go: (d, y) => p.go(d, y)
|
|
159
|
-
});
|
|
160
|
-
g.use(s), s.setRoutingStrategy(u), f = { adapter: u, boundSyncHandler: null, chainedPrevious: void 0 }, t.set(g, f);
|
|
161
|
-
}
|
|
162
|
-
if (l = f.adapter, !o) return;
|
|
163
|
-
const { adapter: P } = f, C = (u = p.route.path) => {
|
|
164
|
-
const d = P.getLocaleFromPath(u);
|
|
165
|
-
s.global.getLocale() !== d && (s.global.locale = d), s.global.setRoute(
|
|
166
|
-
S(u, P.localeCodes, r, e.localeKeyToCode)
|
|
167
|
-
);
|
|
168
|
-
};
|
|
169
|
-
C();
|
|
170
|
-
const b = p.onAfterRouteChange;
|
|
171
|
-
b !== f.boundSyncHandler && (f.chainedPrevious = typeof b == "function" ? b : void 0), f.boundSyncHandler = async (u) => {
|
|
172
|
-
typeof f.chainedPrevious == "function" && await f.chainedPrevious(u);
|
|
173
|
-
const d = u.startsWith("http") ? (() => {
|
|
174
|
-
const y = new URL(u);
|
|
175
|
-
return y.pathname + y.search + y.hash;
|
|
176
|
-
})() : u;
|
|
177
|
-
C(d);
|
|
178
|
-
}, p.onAfterRouteChange = f.boundSyncHandler;
|
|
179
|
-
};
|
|
180
|
-
return {
|
|
181
|
-
i18n: s.global,
|
|
182
|
-
plugin: s,
|
|
183
|
-
get adapter() {
|
|
184
|
-
return l;
|
|
185
|
-
},
|
|
186
|
-
enhanceApp: i
|
|
187
|
-
};
|
|
188
|
-
}
|
|
189
|
-
function N(e, r = {}) {
|
|
190
|
-
const a = r.enhanceApp, o = e.enhanceApp, s = /* @__PURE__ */ new WeakMap();
|
|
191
|
-
return {
|
|
192
|
-
...e,
|
|
193
|
-
async enhanceApp(t) {
|
|
194
|
-
let l = s.get(t.app);
|
|
195
|
-
if (!l) {
|
|
196
|
-
const [{ config: i }, m] = await Promise.all([
|
|
197
|
-
import("virtual:i18n-micro/config"),
|
|
198
|
-
import("virtual:i18n-micro/messages")
|
|
199
|
-
]), g = i.localeCodes.length ? i.localeCodes : i.locales.map((P) => P.code), p = r.localeKeyToCode ?? i.localeKeyToCode, f = R(
|
|
200
|
-
t.router.route.path,
|
|
201
|
-
g,
|
|
202
|
-
i.defaultLocale,
|
|
203
|
-
p
|
|
204
|
-
);
|
|
205
|
-
l = V({
|
|
206
|
-
locale: f,
|
|
207
|
-
defaultLocale: i.defaultLocale,
|
|
208
|
-
fallbackLocale: i.fallbackLocale,
|
|
209
|
-
locales: i.locales,
|
|
210
|
-
messages: m.messages,
|
|
211
|
-
routeMessages: m.routeMessages,
|
|
212
|
-
missingWarn: i.missingWarn,
|
|
213
|
-
syncWithVitePress: i.syncWithVitePress,
|
|
214
|
-
localeKeyToCode: p,
|
|
215
|
-
plural: r.plural,
|
|
216
|
-
missingHandler: r.missingHandler
|
|
217
|
-
}), s.set(t.app, l);
|
|
218
|
-
}
|
|
219
|
-
l.enhanceApp(t), o && await o(t), a && await a(t), l.enhanceApp(t);
|
|
220
|
-
}
|
|
221
|
-
};
|
|
222
|
-
}
|
|
223
|
-
function q(e) {
|
|
224
|
-
if (!("default" in e) || !Object.keys(e).every((o) => o === "default" || o === "__esModule")) return !1;
|
|
225
|
-
const a = e.default;
|
|
226
|
-
return a !== null && typeof a == "object" && !Array.isArray(a);
|
|
227
|
-
}
|
|
228
|
-
function z(e) {
|
|
229
|
-
const r = {};
|
|
230
|
-
for (const [a, o] of Object.entries(e)) {
|
|
231
|
-
const t = (a.split("/").pop() || "").replace(/\.json$/, "");
|
|
232
|
-
t && (o && typeof o == "object" && q(o) ? r[t] = o.default : r[t] = o);
|
|
1
|
+
import { c as i } from "./create-Dev8Q66O.js";
|
|
2
|
+
import { g as p, r as m, s as d } from "./adapter-BnsyIKhp.js";
|
|
3
|
+
import { I18nGroup as I, I18nLink as b, I18nSwitcher as j, I18nT as x, useI18n as g } from "@i18n-micro/vue";
|
|
4
|
+
import { FormatService as F, defaultPlural as k, interpolate as v } from "@i18n-micro/core";
|
|
5
|
+
function a(t) {
|
|
6
|
+
if (!("default" in t) || !Object.keys(t).every((e) => e === "default" || e === "__esModule")) return !1;
|
|
7
|
+
const r = t.default;
|
|
8
|
+
return r !== null && typeof r == "object" && !Array.isArray(r);
|
|
9
|
+
}
|
|
10
|
+
function f(t) {
|
|
11
|
+
const o = {};
|
|
12
|
+
for (const [r, e] of Object.entries(t)) {
|
|
13
|
+
const s = (r.split("/").pop() || "").replace(/\.json$/, "");
|
|
14
|
+
s && (e && typeof e == "object" && a(e) ? o[s] = e.default : o[s] = e);
|
|
233
15
|
}
|
|
234
|
-
return
|
|
16
|
+
return o;
|
|
235
17
|
}
|
|
236
18
|
export {
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
z as messagesFromGlob,
|
|
251
|
-
S as routeNameFromPath,
|
|
252
|
-
Z as useI18n
|
|
19
|
+
F as FormatService,
|
|
20
|
+
I as I18nGroup,
|
|
21
|
+
b as I18nLink,
|
|
22
|
+
j as I18nSwitcher,
|
|
23
|
+
x as I18nT,
|
|
24
|
+
i as createI18n,
|
|
25
|
+
k as defaultPlural,
|
|
26
|
+
p as getLocaleFromPath,
|
|
27
|
+
v as interpolate,
|
|
28
|
+
f as messagesFromGlob,
|
|
29
|
+
m as routeNameFromPath,
|
|
30
|
+
d as stripSiteBase,
|
|
31
|
+
g as useI18n
|
|
253
32
|
};
|
|
254
33
|
//# sourceMappingURL=index.mjs.map
|