@i18n-micro/vitepress 1.0.1

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.
@@ -0,0 +1 @@
1
+ {"version":3,"file":"i18n-routing-D9iYAKDq.cjs","sources":["../src/router/i18n-routing.ts"],"sourcesContent":["import type { VitePressRouterAdapter } from './adapter'\n\n/**\n * Minimal shapes used by VitePress `themeConfig.i18nRouting`.\n * Kept loose so we do not hard-depend on VitePress internal DefaultTheme types at compile time.\n */\nexport interface VitePressI18nRoutingData {\n site?: {\n value?: {\n locales?: Record<string, { link?: string, lang?: string }>\n }\n }\n localeIndex?: { value?: string }\n}\n\nexport interface VitePressI18nRoutingRoute {\n path: string\n hash?: string\n query?: string\n data?: {\n relativePath?: string\n }\n}\n\nexport type VitePressI18nRoutingFn = (\n data: VitePressI18nRoutingData,\n route: VitePressI18nRoutingRoute,\n targetLocale: string,\n) => string\n\nexport interface I18nRoutingFromAdapterOptions {\n defaultLocale: string\n localeCodes: string[]\n localeKeyToCode?: Record<string, string>\n}\n\nfunction isAdapter(value: VitePressRouterAdapter | I18nRoutingFromAdapterOptions): value is VitePressRouterAdapter {\n return 'switchLocalePath' in value && typeof (value as VitePressRouterAdapter).switchLocalePath === 'function'\n}\n\n/**\n * Bridge so VitePress navbar language menu and `<I18nSwitcher>` share path logic.\n * Pass the result to `themeConfig.i18nRouting`.\n *\n * `targetLocale` is a **VitePress locale key** (`root` / `fr`). URL prefixes use that key;\n * `localeKeyToCode` is only for resolving the i18n code when callers need it elsewhere.\n *\n * Returns a **self-contained** function (no closures) so VitePress can serialize it\n * into site data via `Function#toString()` + `new Function`.\n */\nexport function createI18nRoutingFromAdapter(\n adapterOrOptions: VitePressRouterAdapter | I18nRoutingFromAdapterOptions,\n): VitePressI18nRoutingFn {\n const options: I18nRoutingFromAdapterOptions = isAdapter(adapterOrOptions)\n ? {\n defaultLocale: adapterOrOptions.defaultLocale,\n localeCodes: adapterOrOptions.localeCodes,\n localeKeyToCode: adapterOrOptions.localeKeyToCode ?? {},\n }\n : adapterOrOptions\n\n const defaultLocale = options.defaultLocale\n const localeCodes = options.localeCodes\n const localeKeyToCode = options.localeKeyToCode ?? {}\n\n // Inlined constants — required for VitePress themeConfig function serialization.\n // oxlint-disable-next-line typescript/no-implied-eval -- intentional for VP serializeFunctions\n return new Function(\n 'data',\n 'route',\n 'targetLocale',\n `\n const defaultLocale = ${JSON.stringify(defaultLocale)};\n const localeCodes = ${JSON.stringify(localeCodes)};\n const localeKeyToCode = ${JSON.stringify(localeKeyToCode)};\n const keyFromCode = (code) => {\n for (const key of Object.keys(localeKeyToCode)) {\n if (localeKeyToCode[key] === code) return key;\n }\n return code === defaultLocale ? 'root' : code;\n };\n const prefixes = [];\n for (let i = 0; i < localeCodes.length; i++) {\n const code = localeCodes[i];\n if (code === defaultLocale) continue;\n const key = keyFromCode(code);\n const urlKey = key === 'root' ? code : key;\n prefixes.push(urlKey);\n if (urlKey !== code) prefixes.push(code);\n }\n // VitePress passes locale *keys* (root / fr). URL prefix is the key, not the i18n code.\n const urlPrefix = targetLocale === 'root' ? null : targetLocale;\n let path = (route && route.path) || '/';\n const hash = (route && route.hash) || '';\n const query = (route && route.query) || '';\n const hashIndex = path.indexOf('#');\n const queryIndex = path.indexOf('?');\n let cut = path.length;\n if (hashIndex >= 0) cut = Math.min(cut, hashIndex);\n if (queryIndex >= 0) cut = Math.min(cut, queryIndex);\n const pathname = path.slice(0, cut) || '/';\n const extras = path.slice(cut);\n const hadTrailingSlash = pathname === '/' || pathname.endsWith('/');\n const segments = pathname.split('/').filter(Boolean);\n if (segments[0] && prefixes.indexOf(segments[0]) >= 0) segments.shift();\n if (urlPrefix) segments.unshift(urlPrefix);\n let localized = segments.length === 0 ? '/' : '/' + segments.join('/');\n if (localized !== '/' && hadTrailingSlash) localized += '/';\n const q = extras.indexOf('?') >= 0\n ? ''\n : (query ? (query.charAt(0) === '?' ? query : '?' + query) : '');\n const h = hash\n ? (hash.charAt(0) === '#' ? hash : '#' + hash)\n : '';\n return localized + extras + q + h;\n `,\n ) as VitePressI18nRoutingFn\n}\n"],"names":["isAdapter","value","createI18nRoutingFromAdapter","adapterOrOptions","options","defaultLocale","localeCodes","localeKeyToCode"],"mappings":"aAoCA,SAASA,EAAUC,EAAgG,CACjH,MAAO,qBAAsBA,GAAS,OAAQA,EAAiC,kBAAqB,UACtG,CAYO,SAASC,EACdC,EACwB,CACxB,MAAMC,EAAyCJ,EAAUG,CAAgB,EACrE,CACE,cAAeA,EAAiB,cAChC,YAAaA,EAAiB,YAC9B,gBAAiBA,EAAiB,iBAAmB,CAAA,CAAC,EAExDA,EAEEE,EAAgBD,EAAQ,cACxBE,EAAcF,EAAQ,YACtBG,EAAkBH,EAAQ,iBAAmB,CAAA,EAInD,OAAO,IAAI,SACT,OACA,QACA,eACA;AAAA,8BAC0B,KAAK,UAAUC,CAAa,CAAC;AAAA,4BAC/B,KAAK,UAAUC,CAAW,CAAC;AAAA,gCACvB,KAAK,UAAUC,CAAe,CAAC;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,KAAA,CA2C/D"}
package/dist/index.cjs ADDED
@@ -0,0 +1,2 @@
1
+ "use strict";var V=Object.create;var S=Object.defineProperty;var q=Object.getOwnPropertyDescriptor;var H=Object.getOwnPropertyNames;var E=Object.getPrototypeOf,G=Object.prototype.hasOwnProperty;var N=(e,t,o,r)=>{if(t&&typeof t=="object"||typeof t=="function")for(let s of H(t))!G.call(e,s)&&s!==o&&S(e,s,{get:()=>t[s],enumerable:!(r=q(t,s))||r.enumerable});return e};var x=(e,t,o)=>(o=e!=null?V(E(e)):{},N(t||!e||!e.__esModule?S(o,"default",{value:e,enumerable:!0}):o,e));Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const U=require("@i18n-micro/utils/parse-path"),P=require("@i18n-micro/vue"),K=require("vue"),B=require("./i18n-routing-D9iYAKDq.cjs"),k=require("@i18n-micro/core");function j(e){const t=e.indexOf("#"),o=e.indexOf("?");let r=e.length;return t>=0&&(r=Math.min(r,t)),o>=0&&(r=Math.min(r,o)),{pathname:e.slice(0,r)||"/",extras:e.slice(r)}}function O(e,t,o={}){const r=n=>{for(const[l,i]of Object.entries(o))if(i===n)return l;return n===t?"root":n},s=new Map;for(const n of e){if(n===t)continue;const l=r(n),i=l==="root"?n:l;s.set(i,n),i!==n&&s.set(n,n)}return s}function A(e,t,o,r={}){const{pathname:s}=j(e),n=s.split("/").filter(Boolean)[0];return n===void 0?o:O(t,o,r).get(n)??o}function W(e,t,o,r={}){const{pathname:s}=j(e),n=s.split("/").filter(Boolean),l=n[0];return l!==void 0&&(o!==void 0?O(t,o,r).has(l)&&n.shift():t.includes(l)&&n.shift()),n.length===0?"index":n.join("-").replace(/\.html$/,"")}function z(e){return K.defineComponent({name:"VitePressI18nLink",props:{to:{type:String,required:!0},style:{type:Object,default:void 0}},setup(t,{slots:o}){return()=>K.h("a",{href:t.to,style:t.style,onClick:r=>{r.defaultPrevented||r.button===0&&(r.metaKey||r.altKey||r.ctrlKey||r.shiftKey||(r.preventDefault(),e?e(t.to):typeof window<"u"&&window.location.assign(t.to)))}},o.default?.())}})}function M(e){const{locales:t,defaultLocale:o,localeKeyToCode:r={},getPath:s,go:n}=e,l=t.map(a=>a.code),i={...r},g=O(l,o,i),m=[...g.keys()],p=a=>i[a]?i[a]:a==="root"?o:a,u=a=>{for(const[c,h]of Object.entries(i))if(h===a)return c;return a===o?"root":a},w=a=>{if(a===o)return null;const c=u(a);return c==="root"?a:c},C=a=>{const c=a==="/"||a.endsWith("/"),h=a.split("/").filter(Boolean),b=h[0];return b!==void 0&&g.has(b)&&h.shift(),{segments:h,hadTrailingSlash:c}},v=a=>{const{pathname:c,extras:h}=j(a),{segments:b,hadTrailingSlash:T}=C(c);let L=b.length===0?"/":`/${b.join("/")}`;return L!=="/"&&T&&(L+="/"),`${L}${h}`},f=(a,c)=>{const{pathname:h,extras:b}=j(a),{segments:T,hadTrailingSlash:L}=C(h),R=w(c);R&&T.unshift(R);let I=T.length===0?"/":`/${T.join("/")}`;return I!=="/"&&L&&(I+="/"),`${I}${b}`},d=(a,c)=>f(a,c),y=(a,c)=>{const h=typeof a=="string"?a:a.path||"/";return f(h,c)},F=(a,c=!1)=>{if(n){n(a,{replace:c});return}typeof window<"u"&&(c?window.location.replace(a):window.location.assign(a))};return{localeCodes:l,defaultLocale:o,localeKeyToCode:i,urlPrefixes:m,codeFromLocaleKey:p,localeKeyFromCode:u,getLocaleFromPath:a=>A(a,l,o,i),switchLocalePath:d,localizePath:f,removeLocaleFromPath:v,linkComponent:z(n),getCurrentPath:()=>s?s():typeof window<"u"?window.location.pathname+window.location.search+window.location.hash:"/",push:a=>{F(a.path,!1)},replace:a=>{F(a.path,!0)},resolvePath:y,getRoute:()=>{const a=s?s():typeof window<"u"?window.location.pathname+window.location.search+window.location.hash:"/",c=typeof window<"u"?new URL(a,window.location.origin):new URL(a,"http://localhost");return{fullPath:c.pathname+c.search+c.hash,query:Object.fromEntries(c.searchParams)}}}}function D(e){return e.defaultLocale||e.locale}function _(e,t,o){if(o)for(const[r,s]of Object.entries(o))for(const[n,l]of Object.entries(s))e.global.addRouteTranslations(n,r,U.mergeRouteTranslationsWithRoot(t?.[n],l),!1)}function $(e){const t=D(e),o=e.locales??[],r=e.syncWithVitePress!==!1,s=P.createI18n({locale:e.locale,fallbackLocale:e.fallbackLocale??t,messages:e.messages,plural:e.plural,missingWarn:e.missingWarn,missingHandler:e.missingHandler,locales:o,defaultLocale:t});_(s,e.messages,e.routeMessages);const n=new WeakMap;let l=null;const i=g=>{const{app:m,router:p}=g;let u=n.get(m);if(!u){const f=M({locales:o,defaultLocale:t,localeKeyToCode:e.localeKeyToCode,getPath:()=>{const d=p.route;return`${d.path}${d.query||""}${d.hash||""}`},go:(d,y)=>p.go(d,y)});m.use(s),s.setRoutingStrategy(f),u={adapter:f,boundSyncHandler:null,chainedPrevious:void 0},n.set(m,u)}if(l=u.adapter,!r)return;const{adapter:w}=u,C=(f=p.route.path)=>{const d=w.getLocaleFromPath(f);s.global.getLocale()!==d&&(s.global.locale=d),s.global.setRoute(W(f,w.localeCodes,t,e.localeKeyToCode))};C();const v=p.onAfterRouteChange;v!==u.boundSyncHandler&&(u.chainedPrevious=typeof v=="function"?v:void 0),u.boundSyncHandler=async f=>{typeof u.chainedPrevious=="function"&&await u.chainedPrevious(f);const d=f.startsWith("http")?(()=>{const y=new URL(f);return y.pathname+y.search+y.hash})():f;C(d)},p.onAfterRouteChange=u.boundSyncHandler};return{i18n:s.global,plugin:s,get adapter(){return l},enhanceApp:i}}function J(e,t={}){const o=t.enhanceApp,r=e.enhanceApp,s=new WeakMap;return{...e,async enhanceApp(n){let l=s.get(n.app);if(!l){const[{config:i},g]=await Promise.all([import("virtual:i18n-micro/config"),import("virtual:i18n-micro/messages")]),m=i.localeCodes.length?i.localeCodes:i.locales.map(w=>w.code),p=t.localeKeyToCode??i.localeKeyToCode,u=A(n.router.route.path,m,i.defaultLocale,p);l=$({locale:u,defaultLocale:i.defaultLocale,fallbackLocale:i.fallbackLocale,locales:i.locales,messages:g.messages,routeMessages:g.routeMessages,missingWarn:i.missingWarn,syncWithVitePress:i.syncWithVitePress,localeKeyToCode:p,plural:t.plural,missingHandler:t.missingHandler}),s.set(n.app,l)}l.enhanceApp(n),r&&await r(n),o&&await o(n),l.enhanceApp(n)}}}function Q(e){if(!("default"in e)||!Object.keys(e).every(r=>r==="default"||r==="__esModule"))return!1;const o=e.default;return o!==null&&typeof o=="object"&&!Array.isArray(o)}function X(e){const t={};for(const[o,r]of Object.entries(e)){const n=(o.split("/").pop()||"").replace(/\.json$/,"");n&&(r&&typeof r=="object"&&Q(r)?t[n]=r.default:t[n]=r)}return t}Object.defineProperty(exports,"I18nGroup",{enumerable:!0,get:()=>P.I18nGroup});Object.defineProperty(exports,"I18nLink",{enumerable:!0,get:()=>P.I18nLink});Object.defineProperty(exports,"I18nSwitcher",{enumerable:!0,get:()=>P.I18nSwitcher});Object.defineProperty(exports,"I18nT",{enumerable:!0,get:()=>P.I18nT});Object.defineProperty(exports,"createI18n",{enumerable:!0,get:()=>P.createI18n});Object.defineProperty(exports,"useI18n",{enumerable:!0,get:()=>P.useI18n});exports.createI18nRoutingFromAdapter=B.createI18nRoutingFromAdapter;Object.defineProperty(exports,"FormatService",{enumerable:!0,get:()=>k.FormatService});Object.defineProperty(exports,"defaultPlural",{enumerable:!0,get:()=>k.defaultPlural});Object.defineProperty(exports,"interpolate",{enumerable:!0,get:()=>k.interpolate});exports.createVitePressI18n=$;exports.createVitePressRouterAdapter=M;exports.defineI18nTheme=J;exports.getLocaleFromPath=A;exports.messagesFromGlob=X;exports.routeNameFromPath=W;
2
+ //# sourceMappingURL=index.cjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.cjs","sources":["../src/router/adapter.ts","../src/create.ts","../src/define-theme.ts","../src/messages-from-glob.ts"],"sourcesContent":["import type { Locale } from '@i18n-micro/types'\nimport type { I18nRoutingStrategy } from '@i18n-micro/vue'\nimport { defineComponent, h, type Component, type PropType } from 'vue'\n\nexport interface VitePressRouterLike {\n route: {\n path: string\n hash?: string\n query?: string\n }\n go: (to: string, options?: { initialLoad?: boolean, replace?: boolean }) => void | Promise<void>\n onAfterRouteChange?: (to: string) => unknown\n}\n\nexport type VitePressGo = (href: string, options?: { replace?: boolean }) => void | Promise<void>\n\nexport interface VitePressRouterAdapterOptions {\n locales: Locale[]\n defaultLocale: string\n /**\n * Map VitePress locale keys (`root`, `fr`) to i18n locale codes.\n * Defaults: `root` → `defaultLocale`, other keys → same string as the key.\n * URL prefixes always use VitePress keys; i18n uses codes.\n */\n localeKeyToCode?: Record<string, string>\n getPath?: () => string\n go?: VitePressGo\n}\n\nexport interface VitePressRouterAdapter extends I18nRoutingStrategy {\n getLocaleFromPath: (path: string) => string\n switchLocalePath: (path: string, newLocale: string) => string\n localizePath: (path: string, locale: string) => string\n removeLocaleFromPath: (path: string) => string\n /** Resolve VitePress locale key (`root` / `fr`) to i18n code. */\n codeFromLocaleKey: (localeKey: string) => string\n /** Resolve i18n code to VitePress locale key. */\n localeKeyFromCode: (code: string) => string\n localeCodes: string[]\n defaultLocale: string\n /** Snapshot of mapping used when building the adapter (for `i18nRouting` serialization). */\n localeKeyToCode: Record<string, string>\n /** URL path prefixes (VitePress locale keys except `root`). */\n urlPrefixes: string[]\n}\n\nfunction splitPathAndExtras(path: string): { pathname: string, extras: string } {\n const hashIndex = path.indexOf('#')\n const queryIndex = path.indexOf('?')\n let cut = path.length\n if (hashIndex >= 0) cut = Math.min(cut, hashIndex)\n if (queryIndex >= 0) cut = Math.min(cut, queryIndex)\n return {\n pathname: path.slice(0, cut) || '/',\n extras: path.slice(cut),\n }\n}\n\n/**\n * Build URL prefix → i18n code map.\n * Prefixes are VitePress locale keys (and codes when they differ), never `root`.\n */\nexport function buildUrlPrefixToCode(\n localeCodes: string[],\n defaultLocale: string,\n localeKeyToCode: Record<string, string> = {},\n): Map<string, string> {\n const keyFromCode = (code: string): string => {\n for (const [key, mapped] of Object.entries(localeKeyToCode)) {\n if (mapped === code) return key\n }\n if (code === defaultLocale) return 'root'\n return code\n }\n\n const prefixToCode = new Map<string, string>()\n for (const code of localeCodes) {\n if (code === defaultLocale) continue\n const key = keyFromCode(code)\n const urlKey = key === 'root' ? code : key\n prefixToCode.set(urlKey, code)\n if (urlKey !== code) prefixToCode.set(code, code)\n }\n return prefixToCode\n}\n\n/**\n * Detect i18n locale code from a URL path (prefix_except_default).\n * Path prefixes are VitePress locale keys; return value is the i18n code.\n */\nexport function getLocaleFromPath(\n path: string,\n localeCodes: string[],\n defaultLocale: string,\n localeKeyToCode: Record<string, string> = {},\n): string {\n const { pathname } = splitPathAndExtras(path)\n const first = pathname.split('/').filter(Boolean)[0]\n if (first === undefined) return defaultLocale\n const prefixToCode = buildUrlPrefixToCode(localeCodes, defaultLocale, localeKeyToCode)\n return prefixToCode.get(first) ?? defaultLocale\n}\n\n/**\n * Route name for page-scoped dictionaries (`/guide/demo` → `guide-demo`).\n * Strips VitePress URL prefixes (keys), not only raw i18n codes.\n *\n * When `defaultLocale` is omitted (legacy 2-arg call), any segment that matches a\n * listed locale code is stripped — callers must not rely on `localeCodes[0]` as default.\n */\nexport function routeNameFromPath(\n path: string,\n localeCodes: string[],\n defaultLocale?: string,\n localeKeyToCode: Record<string, string> = {},\n): string {\n const { pathname } = splitPathAndExtras(path)\n const segments = pathname.split('/').filter(Boolean)\n const first = segments[0]\n if (first !== undefined) {\n if (defaultLocale !== undefined) {\n const prefixToCode = buildUrlPrefixToCode(localeCodes, defaultLocale, localeKeyToCode)\n if (prefixToCode.has(first)) segments.shift()\n }\n else if (localeCodes.includes(first)) {\n segments.shift()\n }\n }\n if (segments.length === 0) return 'index'\n return segments.join('-').replace(/\\.html$/, '')\n}\n\nfunction createVitePressLinkComponent(go?: VitePressGo): Component {\n return defineComponent({\n name: 'VitePressI18nLink',\n props: {\n to: { type: String, required: true },\n style: { type: Object as PropType<Record<string, string>>, default: undefined },\n },\n setup(props, { slots }) {\n return () =>\n h(\n 'a',\n {\n href: props.to,\n style: props.style,\n onClick: (e: MouseEvent) => {\n if (e.defaultPrevented) return\n if (e.button !== 0) return\n if (e.metaKey || e.altKey || e.ctrlKey || e.shiftKey) return\n e.preventDefault()\n if (go) {\n void go(props.to)\n }\n else if (typeof window !== 'undefined') {\n window.location.assign(props.to)\n }\n },\n },\n slots.default?.(),\n )\n },\n })\n}\n\n/**\n * VitePress path adapter (prefix_except_default semantics):\n * default locale has no URL prefix; other locales use `/{vitepressKey}/…`.\n * i18n locale values remain `locale.code` (via `localeKeyToCode`).\n */\nexport function createVitePressRouterAdapter(options: VitePressRouterAdapterOptions): VitePressRouterAdapter {\n const { locales, defaultLocale, localeKeyToCode = {}, getPath, go } = options\n const localeCodes = locales.map((loc) => loc.code)\n const localeKeyToCodeSnapshot = { ...localeKeyToCode }\n const prefixToCode = buildUrlPrefixToCode(localeCodes, defaultLocale, localeKeyToCodeSnapshot)\n const urlPrefixes = [...prefixToCode.keys()]\n\n const codeFromLocaleKey = (localeKey: string): string => {\n if (localeKeyToCodeSnapshot[localeKey]) return localeKeyToCodeSnapshot[localeKey]!\n if (localeKey === 'root') return defaultLocale\n return localeKey\n }\n\n const localeKeyFromCode = (code: string): string => {\n for (const [key, mapped] of Object.entries(localeKeyToCodeSnapshot)) {\n if (mapped === code) return key\n }\n if (code === defaultLocale) return 'root'\n return code\n }\n\n const urlPrefixForCode = (code: string): string | null => {\n if (code === defaultLocale) return null\n const key = localeKeyFromCode(code)\n return key === 'root' ? code : key\n }\n\n const stripPrefix = (pathname: string): { segments: string[], hadTrailingSlash: boolean } => {\n const hadTrailingSlash = pathname === '/' || pathname.endsWith('/')\n const segments = pathname.split('/').filter(Boolean)\n const first = segments[0]\n if (first !== undefined && prefixToCode.has(first)) {\n segments.shift()\n }\n return { segments, hadTrailingSlash }\n }\n\n const removeLocaleFromPath = (path: string): string => {\n const { pathname, extras } = splitPathAndExtras(path)\n const { segments, hadTrailingSlash } = stripPrefix(pathname)\n let clean = segments.length === 0 ? '/' : `/${segments.join('/')}`\n if (clean !== '/' && hadTrailingSlash) clean += '/'\n return `${clean}${extras}`\n }\n\n const localizePath = (path: string, locale: string): string => {\n const { pathname, extras } = splitPathAndExtras(path)\n const { segments, hadTrailingSlash } = stripPrefix(pathname)\n const prefix = urlPrefixForCode(locale)\n if (prefix) segments.unshift(prefix)\n let localized = segments.length === 0 ? '/' : `/${segments.join('/')}`\n if (localized !== '/' && hadTrailingSlash) localized += '/'\n return `${localized}${extras}`\n }\n\n const switchLocalePath = (path: string, newLocale: string): string => {\n return localizePath(path, newLocale)\n }\n\n const resolvePath = (to: string | { path?: string }, locale: string): string => {\n const path = typeof to === 'string' ? to : to.path || '/'\n return localizePath(path, locale)\n }\n\n const navigate = (href: string, replace = false) => {\n if (go) {\n void go(href, { replace })\n return\n }\n if (typeof window !== 'undefined') {\n if (replace) {\n window.location.replace(href)\n }\n else {\n window.location.assign(href)\n }\n }\n }\n\n return {\n localeCodes,\n defaultLocale,\n localeKeyToCode: localeKeyToCodeSnapshot,\n urlPrefixes,\n codeFromLocaleKey,\n localeKeyFromCode,\n getLocaleFromPath: (path: string) =>\n getLocaleFromPath(path, localeCodes, defaultLocale, localeKeyToCodeSnapshot),\n switchLocalePath,\n localizePath,\n removeLocaleFromPath,\n linkComponent: createVitePressLinkComponent(go),\n getCurrentPath: () => {\n if (getPath) return getPath()\n if (typeof window !== 'undefined') {\n return window.location.pathname + window.location.search + window.location.hash\n }\n return '/'\n },\n push: (target: { path: string }) => {\n navigate(target.path, false)\n },\n replace: (target: { path: string }) => {\n navigate(target.path, true)\n },\n resolvePath,\n getRoute: () => {\n const path = getPath\n ? getPath()\n : (typeof window !== 'undefined'\n ? window.location.pathname + window.location.search + window.location.hash\n : '/')\n const url = typeof window !== 'undefined'\n ? new URL(path, window.location.origin)\n : new URL(path, 'http://localhost')\n return {\n fullPath: url.pathname + url.search + url.hash,\n query: Object.fromEntries(url.searchParams),\n }\n },\n }\n}\n","import type { Locale, PluralFunc, Translations } from '@i18n-micro/types'\nimport { mergeRouteTranslationsWithRoot } from '@i18n-micro/utils/parse-path'\nimport { createI18n, type I18nPlugin } from '@i18n-micro/vue'\nimport type { App, Ref } from 'vue'\nimport {\n createVitePressRouterAdapter,\n routeNameFromPath,\n type VitePressRouterAdapter,\n type VitePressRouterLike,\n} from './router/adapter'\n\nexport interface VitePressI18nOptions {\n locale: string\n fallbackLocale?: string\n locales?: Locale[]\n defaultLocale?: string\n messages?: Record<string, Translations>\n /**\n * Page-scoped dictionaries keyed by route name (`guide-demo`), then locale.\n * Loaded from `locales/pages/**` when using `withI18nMicro`.\n */\n routeMessages?: Record<string, Record<string, Translations>>\n plural?: PluralFunc\n missingWarn?: boolean\n missingHandler?: (locale: string, key: string, routeName: string) => void\n /**\n * Sync i18n locale from the VitePress URL path on every navigation.\n * @default true\n */\n syncWithVitePress?: boolean\n /**\n * Map VitePress locale keys to i18n codes (`root` → default locale code).\n */\n localeKeyToCode?: Record<string, string>\n}\n\nexport interface VitePressSiteDataLike {\n locales?: Record<string, { lang?: string, link?: string, label?: string }>\n}\n\nexport interface CreateVitePressI18nResult {\n i18n: I18nPlugin['global']\n plugin: I18nPlugin\n adapter: VitePressRouterAdapter | null\n enhanceApp: (ctx: {\n app: App\n router: VitePressRouterLike\n siteData?: Ref<VitePressSiteDataLike> | VitePressSiteDataLike\n }) => void\n}\n\nfunction resolveDefaultLocale(options: VitePressI18nOptions): string {\n return options.defaultLocale || options.locale\n}\n\nfunction applyRouteMessages(\n plugin: I18nPlugin,\n root: Record<string, Translations> | undefined,\n routeMessages: Record<string, Record<string, Translations>> | undefined,\n): void {\n if (!routeMessages) return\n for (const [routeName, byLocale] of Object.entries(routeMessages)) {\n for (const [locale, translations] of Object.entries(byLocale)) {\n plugin.global.addRouteTranslations(\n locale,\n routeName,\n mergeRouteTranslationsWithRoot(root?.[locale], translations),\n false,\n )\n }\n }\n}\n\n/**\n * Create VitePress i18n runtime: Vue plugin + path sync + optional router adapter.\n */\nexport function createVitePressI18n(options: VitePressI18nOptions): CreateVitePressI18nResult {\n const defaultLocale = resolveDefaultLocale(options)\n const locales = options.locales ?? []\n const syncWithVitePress = options.syncWithVitePress !== false\n\n const plugin = createI18n({\n locale: options.locale,\n fallbackLocale: options.fallbackLocale ?? defaultLocale,\n messages: options.messages,\n plural: options.plural,\n missingWarn: options.missingWarn,\n missingHandler: options.missingHandler,\n locales,\n defaultLocale,\n })\n\n applyRouteMessages(plugin, options.messages, options.routeMessages)\n\n // Per Vue app (SSR / multiple VitePress apps sharing one createVitePressI18n result).\n const byApp = new WeakMap<object, {\n adapter: VitePressRouterAdapter\n boundSyncHandler: ((to: string) => unknown) | null\n chainedPrevious: ((to: string) => unknown) | undefined\n }>()\n let lastAdapter: VitePressRouterAdapter | null = null\n\n const enhanceApp = (ctx: {\n app: App\n router: VitePressRouterLike\n siteData?: Ref<VitePressSiteDataLike> | VitePressSiteDataLike\n }) => {\n const { app, router } = ctx\n\n let state = byApp.get(app)\n if (!state) {\n const adapter = createVitePressRouterAdapter({\n locales,\n defaultLocale,\n localeKeyToCode: options.localeKeyToCode,\n getPath: () => {\n const route = router.route\n return `${route.path}${route.query || ''}${route.hash || ''}`\n },\n go: (href, navOptions) => router.go(href, navOptions),\n })\n\n // Install first so `setRoutingStrategy` provides into this app (not a previous one).\n app.use(plugin)\n plugin.setRoutingStrategy(adapter)\n state = { adapter, boundSyncHandler: null, chainedPrevious: undefined }\n byApp.set(app, state)\n }\n // Re-enhance: do not call setRoutingStrategy — vue's setter targets last-installed\n // currentApp and would overwrite another app's router injection.\n lastAdapter = state.adapter\n\n if (!syncWithVitePress) return\n\n const { adapter } = state\n const sync = (path = router.route.path) => {\n const nextLocale = adapter.getLocaleFromPath(path)\n if (plugin.global.getLocale() !== nextLocale) {\n plugin.global.locale = nextLocale\n }\n plugin.global.setRoute(\n routeNameFromPath(path, adapter.localeCodes, defaultLocale, options.localeKeyToCode),\n )\n }\n\n sync()\n\n // Stay outermost: if base/user enhanceApp overwrote the hook, re-wrap on a later call.\n const current = router.onAfterRouteChange\n if (current !== state.boundSyncHandler) {\n state.chainedPrevious = typeof current === 'function' ? current : undefined\n }\n state.boundSyncHandler = async (to: string) => {\n if (typeof state.chainedPrevious === 'function') {\n await state.chainedPrevious(to)\n }\n const path = to.startsWith('http')\n ? (() => {\n const url = new URL(to)\n return url.pathname + url.search + url.hash\n })()\n : to\n sync(path)\n }\n router.onAfterRouteChange = state.boundSyncHandler\n }\n\n return {\n i18n: plugin.global,\n plugin,\n get adapter() {\n return lastAdapter\n },\n enhanceApp,\n }\n}\n","import type { PluralFunc, Translations } from '@i18n-micro/types'\nimport type { Theme } from 'vitepress'\nimport { createVitePressI18n, type CreateVitePressI18nResult } from './create'\nimport { getLocaleFromPath } from './router/adapter'\nimport type { VirtualI18nConfig } from './with-i18n-micro'\n\ntype EnhanceAppContext = Parameters<NonNullable<Theme['enhanceApp']>>[0]\n\nexport interface DefineI18nThemeOptions {\n /**\n * Extra `enhanceApp` run after i18n is installed.\n */\n enhanceApp?: NonNullable<Theme['enhanceApp']>\n /**\n * Overrides not serializable into `virtual:i18n-micro/config`.\n */\n plural?: PluralFunc\n missingHandler?: (locale: string, key: string, routeName: string) => void\n localeKeyToCode?: Record<string, string>\n}\n\ninterface VirtualMessagesModule {\n messages: Record<string, Translations>\n routeMessages?: Record<string, Record<string, Translations>>\n}\n\n/**\n * Zero-boilerplate theme wiring. Requires `withI18nMicro(...)` in `.vitepress/config`\n * so virtual config + messages modules exist.\n *\n * Virtual modules are loaded inside `enhanceApp` (not at package top-level) so\n * `@i18n-micro/vitepress` stays importable from Node when evaluating VitePress config.\n *\n * @example\n * ```ts\n * import DefaultTheme from 'vitepress/theme'\n * import { defineI18nTheme } from '@i18n-micro/vitepress'\n *\n * export default defineI18nTheme(DefaultTheme)\n * ```\n */\nexport function defineI18nTheme<T extends Theme>(base: T, options: DefineI18nThemeOptions = {}): T {\n const userEnhance = options.enhanceApp\n const baseEnhance = base.enhanceApp\n\n // Per app instance (SSR-safe: WeakMap by app).\n const byApp = new WeakMap<object, CreateVitePressI18nResult>()\n\n return {\n ...base,\n async enhanceApp(ctx: EnhanceAppContext) {\n let installed = byApp.get(ctx.app)\n if (!installed) {\n // Cast via `unknown`: root typecheck also sees Astro's ambient `virtual:i18n-micro/config`.\n const [{ config }, messagesMod] = await Promise.all([\n import('virtual:i18n-micro/config') as unknown as Promise<{ config: VirtualI18nConfig }>,\n import('virtual:i18n-micro/messages') as unknown as Promise<VirtualMessagesModule>,\n ])\n\n const localeCodes = config.localeCodes.length\n ? config.localeCodes\n : config.locales.map((l) => l.code)\n const localeKeyToCode = options.localeKeyToCode ?? config.localeKeyToCode\n const initialLocale = getLocaleFromPath(\n ctx.router.route.path,\n localeCodes,\n config.defaultLocale,\n localeKeyToCode,\n )\n\n installed = createVitePressI18n({\n locale: initialLocale,\n defaultLocale: config.defaultLocale,\n fallbackLocale: config.fallbackLocale,\n locales: config.locales,\n messages: messagesMod.messages,\n routeMessages: messagesMod.routeMessages,\n missingWarn: config.missingWarn,\n syncWithVitePress: config.syncWithVitePress,\n localeKeyToCode,\n plural: options.plural,\n missingHandler: options.missingHandler,\n })\n byApp.set(ctx.app, installed)\n }\n\n // Install plugin first so base/user enhanceApp can use $t / components.\n installed.enhanceApp(ctx as unknown as Parameters<typeof installed.enhanceApp>[0])\n if (baseEnhance) await baseEnhance(ctx)\n if (userEnhance) await userEnhance(ctx)\n // Re-run so route sync wraps any onAfterRouteChange set by base/user.\n installed.enhanceApp(ctx as unknown as Parameters<typeof installed.enhanceApp>[0])\n },\n }\n}\n","import type { Translations } from '@i18n-micro/types'\n\n/**\n * Vite `import.meta.glob(..., { eager: true })` modules look like\n * `{ default: { …json } }` or `{ default: { … }, __esModule: true }`.\n * Do not treat a real dictionary that only has a `default` string key as a namespace.\n */\nfunction isModuleNamespace(mod: object): mod is { default: Translations } {\n if (!('default' in mod)) return false\n const keys = Object.keys(mod)\n if (!keys.every((key) => key === 'default' || key === '__esModule')) return false\n const value = (mod as { default: unknown }).default\n return value !== null && typeof value === 'object' && !Array.isArray(value)\n}\n\n/**\n * Tiny helper if you still prefer `import.meta.glob` instead of `defineI18nTheme`.\n * Only unwraps Vite module namespaces — dictionaries with a `default` key stay intact.\n */\nexport function messagesFromGlob(\n modules: Record<string, { default: Translations } | Translations>,\n): Record<string, Translations> {\n const messages: Record<string, Translations> = {}\n for (const [path, mod] of Object.entries(modules)) {\n const file = path.split('/').pop() || ''\n const code = file.replace(/\\.json$/, '')\n if (!code) continue\n if (mod && typeof mod === 'object' && isModuleNamespace(mod)) {\n messages[code] = mod.default\n }\n else {\n messages[code] = mod as Translations\n }\n }\n return messages\n}\n"],"names":["splitPathAndExtras","path","hashIndex","queryIndex","cut","buildUrlPrefixToCode","localeCodes","defaultLocale","localeKeyToCode","keyFromCode","code","key","mapped","prefixToCode","urlKey","getLocaleFromPath","pathname","first","routeNameFromPath","segments","createVitePressLinkComponent","go","defineComponent","props","slots","h","e","createVitePressRouterAdapter","options","locales","getPath","loc","localeKeyToCodeSnapshot","urlPrefixes","codeFromLocaleKey","localeKey","localeKeyFromCode","urlPrefixForCode","stripPrefix","hadTrailingSlash","removeLocaleFromPath","extras","clean","localizePath","locale","prefix","localized","switchLocalePath","newLocale","resolvePath","to","navigate","href","replace","target","url","resolveDefaultLocale","applyRouteMessages","plugin","root","routeMessages","routeName","byLocale","translations","mergeRouteTranslationsWithRoot","createVitePressI18n","syncWithVitePress","createI18n","byApp","lastAdapter","enhanceApp","ctx","app","router","state","adapter","route","navOptions","sync","nextLocale","current","defineI18nTheme","base","userEnhance","baseEnhance","installed","config","messagesMod","l","initialLocale","isModuleNamespace","mod","value","messagesFromGlob","modules","messages"],"mappings":"gsBA8CA,SAASA,EAAmBC,EAAoD,CAC9E,MAAMC,EAAYD,EAAK,QAAQ,GAAG,EAC5BE,EAAaF,EAAK,QAAQ,GAAG,EACnC,IAAIG,EAAMH,EAAK,OACf,OAAIC,GAAa,IAAGE,EAAM,KAAK,IAAIA,EAAKF,CAAS,GAC7CC,GAAc,IAAGC,EAAM,KAAK,IAAIA,EAAKD,CAAU,GAC5C,CACL,SAAUF,EAAK,MAAM,EAAGG,CAAG,GAAK,IAChC,OAAQH,EAAK,MAAMG,CAAG,CAAA,CAE1B,CAMO,SAASC,EACdC,EACAC,EACAC,EAA0C,CAAA,EACrB,CACrB,MAAMC,EAAeC,GAAyB,CAC5C,SAAW,CAACC,EAAKC,CAAM,IAAK,OAAO,QAAQJ,CAAe,EACxD,GAAII,IAAWF,EAAM,OAAOC,EAE9B,OAAID,IAASH,EAAsB,OAC5BG,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BA,EAAQ,cAAA,CACzB,EACDwC,EAAM,IAAIG,EAAI,IAAKc,CAAS,CAC9B,CAGAA,EAAU,WAAWd,CAA4D,EAC7Ea,GAAa,MAAMA,EAAYb,CAAG,EAClCY,GAAa,MAAMA,EAAYZ,CAAG,EAEtCc,EAAU,WAAWd,CAA4D,CACnF,CAAA,CAEJ,CCvFA,SAASmB,EAAkBC,EAA+C,CAGxE,GAFI,EAAE,YAAaA,IAEf,CADS,OAAO,KAAKA,CAAG,EAClB,MAAOhF,GAAQA,IAAQ,WAAaA,IAAQ,YAAY,EAAG,MAAO,GAC5E,MAAMiF,EAASD,EAA6B,QAC5C,OAAOC,IAAU,MAAQ,OAAOA,GAAU,UAAY,CAAC,MAAM,QAAQA,CAAK,CAC5E,CAMO,SAASC,EACdC,EAC8B,CAC9B,MAAMC,EAAyC,CAAA,EAC/C,SAAW,CAAC9F,EAAM0F,CAAG,IAAK,OAAO,QAAQG,CAAO,EAAG,CAEjD,MAAMpF,GADOT,EAAK,MAAM,GAAG,EAAE,OAAS,IACpB,QAAQ,UAAW,EAAE,EAClCS,IACDiF,GAAO,OAAOA,GAAQ,UAAYD,EAAkBC,CAAG,EACzDI,EAASrF,CAAI,EAAIiF,EAAI,QAGrBI,EAASrF,CAAI,EAAIiF,EAErB,CACA,OAAOI,CACT"}
@@ -0,0 +1,315 @@
1
+ /// <reference types="@i18n-micro/vitepress/client" />
2
+ import { App } from 'vue';
3
+ import { CleanTranslation } from '@i18n-micro/types';
4
+ import { createI18n } from '@i18n-micro/vue';
5
+ import { defaultPlural } from '@i18n-micro/core';
6
+ import { FormatService } from '@i18n-micro/core';
7
+ import { Getter } from '@i18n-micro/types';
8
+ import { I18nGroup } from '@i18n-micro/vue';
9
+ import { I18nLink } from '@i18n-micro/vue';
10
+ import { I18nPlugin } from '@i18n-micro/vue';
11
+ import { I18nRoutingStrategy } from '@i18n-micro/vue';
12
+ import { I18nSwitcher } from '@i18n-micro/vue';
13
+ import { I18nT } from '@i18n-micro/vue';
14
+ import { interpolate } from '@i18n-micro/core';
15
+ import { Locale } from '@i18n-micro/types';
16
+ import { LocaleCode } from '@i18n-micro/types';
17
+ import { Params } from '@i18n-micro/types';
18
+ import { Plugin as Plugin_2 } from 'vite';
19
+ import { PluralFunc } from '@i18n-micro/types';
20
+ import { Ref } from 'vue';
21
+ import { Theme } from 'vitepress';
22
+ import { Translations } from '@i18n-micro/types';
23
+ import { useI18n } from '@i18n-micro/vue';
24
+ import { UseI18nOptions } from '@i18n-micro/vue';
25
+ import { VueI18nOptions } from '@i18n-micro/vue';
26
+
27
+ export { CleanTranslation }
28
+
29
+ export { createI18n }
30
+
31
+ /**
32
+ * Bridge so VitePress navbar language menu and `<I18nSwitcher>` share path logic.
33
+ * Pass the result to `themeConfig.i18nRouting`.
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`.
40
+ */
41
+ export declare function createI18nRoutingFromAdapter(adapterOrOptions: VitePressRouterAdapter | I18nRoutingFromAdapterOptions): VitePressI18nRoutingFn;
42
+
43
+ /**
44
+ * Create VitePress i18n runtime: Vue plugin + path sync + optional router adapter.
45
+ */
46
+ export declare function createVitePressI18n(options: VitePressI18nOptions): CreateVitePressI18nResult;
47
+
48
+ export declare interface CreateVitePressI18nResult {
49
+ i18n: I18nPlugin['global'];
50
+ plugin: I18nPlugin;
51
+ adapter: VitePressRouterAdapter | null;
52
+ enhanceApp: (ctx: {
53
+ app: App;
54
+ router: VitePressRouterLike;
55
+ siteData?: Ref<VitePressSiteDataLike> | VitePressSiteDataLike;
56
+ }) => 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;
65
+
66
+ export { defaultPlural }
67
+
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
+ export { FormatService }
99
+
100
+ /**
101
+ * Detect i18n locale code from a URL path (prefix_except_default).
102
+ * Path prefixes are VitePress locale keys; return value is the i18n code.
103
+ */
104
+ export declare function getLocaleFromPath(path: string, localeCodes: string[], defaultLocale: string, localeKeyToCode?: Record<string, string>): string;
105
+
106
+ export { Getter }
107
+
108
+ export { I18nGroup }
109
+
110
+ export { I18nLink }
111
+
112
+ export { I18nPlugin }
113
+
114
+ export declare interface I18nRoutingFromAdapterOptions {
115
+ defaultLocale: string;
116
+ localeCodes: string[];
117
+ localeKeyToCode?: Record<string, string>;
118
+ }
119
+
120
+ export { I18nRoutingStrategy }
121
+
122
+ export { I18nSwitcher }
123
+
124
+ export { I18nT }
125
+
126
+ export { interpolate }
127
+
128
+ export { Locale }
129
+
130
+ export { LocaleCode }
131
+
132
+ /**
133
+ * Tiny helper if you still prefer `import.meta.glob` instead of `defineI18nTheme`.
134
+ * Only unwraps Vite module namespaces — dictionaries with a `default` key stay intact.
135
+ */
136
+ export declare function messagesFromGlob(modules: Record<string, {
137
+ default: Translations;
138
+ } | Translations>): Record<string, Translations>;
139
+
140
+ export { Params }
141
+
142
+ export { PluralFunc }
143
+
144
+ /**
145
+ * Route name for page-scoped dictionaries (`/guide/demo` → `guide-demo`).
146
+ * Strips VitePress URL prefixes (keys), not only raw i18n codes.
147
+ *
148
+ * When `defaultLocale` is omitted (legacy 2-arg call), any segment that matches a
149
+ * listed locale code is stripped — callers must not rely on `localeCodes[0]` as default.
150
+ */
151
+ export declare function routeNameFromPath(path: string, localeCodes: string[], defaultLocale?: string, localeKeyToCode?: Record<string, string>): string;
152
+
153
+ export { Translations }
154
+
155
+ export { useI18n }
156
+
157
+ export { UseI18nOptions }
158
+
159
+ export declare interface VirtualI18nConfig {
160
+ defaultLocale: string;
161
+ fallbackLocale: string;
162
+ locales: Locale[];
163
+ localeCodes: string[];
164
+ missingWarn: boolean;
165
+ syncWithVitePress: boolean;
166
+ translationDir: string;
167
+ disablePageLocales: boolean;
168
+ localeKeyToCode: Record<string, string>;
169
+ }
170
+
171
+ export declare type VitePressGo = (href: string, options?: {
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 {
230
+ getLocaleFromPath: (path: string) => string;
231
+ switchLocalePath: (path: string, newLocale: string) => string;
232
+ localizePath: (path: string, locale: string) => string;
233
+ removeLocaleFromPath: (path: string) => string;
234
+ /** Resolve VitePress locale key (`root` / `fr`) to i18n code. */
235
+ codeFromLocaleKey: (localeKey: string) => string;
236
+ /** Resolve i18n code to VitePress locale key. */
237
+ localeKeyFromCode: (code: string) => string;
238
+ localeCodes: string[];
239
+ defaultLocale: string;
240
+ /** Snapshot of mapping used when building the adapter (for `i18nRouting` serialization). */
241
+ localeKeyToCode: Record<string, string>;
242
+ /** URL path prefixes (VitePress locale keys except `root`). */
243
+ urlPrefixes: string[];
244
+ }
245
+
246
+ export declare interface VitePressRouterAdapterOptions {
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 {
260
+ route: {
261
+ path: string;
262
+ hash?: string;
263
+ query?: string;
264
+ };
265
+ go: (to: string, options?: {
266
+ initialLoad?: boolean;
267
+ replace?: boolean;
268
+ }) => void | Promise<void>;
269
+ onAfterRouteChange?: (to: string) => unknown;
270
+ }
271
+
272
+ export declare interface VitePressSiteDataLike {
273
+ locales?: Record<string, {
274
+ lang?: string;
275
+ link?: string;
276
+ label?: string;
277
+ }>;
278
+ }
279
+
280
+ /**
281
+ * Minimal VitePress / Vite user config shape we merge into.
282
+ * Avoid importing `vitepress` types so the package stays usable as a pure library dep.
283
+ */
284
+ export declare interface VitePressUserConfigLike {
285
+ locales?: Record<string, unknown>;
286
+ vite?: {
287
+ plugins?: Plugin_2[] | Plugin_2[][];
288
+ [key: string]: unknown;
289
+ };
290
+ [key: string]: unknown;
291
+ }
292
+
293
+ export { VueI18nOptions }
294
+
295
+ export declare interface WithI18nMicroOptions extends VitePressI18nOptions {
296
+ /**
297
+ * Directory with locale JSON (`en.json`, `pages/guide/demo/en.json`, …), relative to Vite root
298
+ * (VitePress content / docs root). Used by `virtual:i18n-micro/messages`.
299
+ * @default 'locales'
300
+ */
301
+ translationDir?: string;
302
+ /**
303
+ * When true, treat `pages/**` as root-level dictionaries.
304
+ * @default false
305
+ */
306
+ disablePageLocales?: boolean;
307
+ /**
308
+ * When true, logs a warning if VitePress `locales` keys do not align with
309
+ * configured i18n locale codes.
310
+ * @default true
311
+ */
312
+ warnOnLocaleMismatch?: boolean;
313
+ }
314
+
315
+ export { }