@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.mjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.mjs","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":";;;;;;AA8CA,SAASA,EAAmBC,GAAoD;AAC9E,QAAMC,IAAYD,EAAK,QAAQ,GAAG,GAC5BE,IAAaF,EAAK,QAAQ,GAAG;AACnC,MAAIG,IAAMH,EAAK;AACf,SAAIC,KAAa,MAAGE,IAAM,KAAK,IAAIA,GAAKF,CAAS,IAC7CC,KAAc,MAAGC,IAAM,KAAK,IAAIA,GAAKD,CAAU,IAC5C;AAAA,IACL,UAAUF,EAAK,MAAM,GAAGG,CAAG,KAAK;AAAA,IAChC,QAAQH,EAAK,MAAMG,CAAG;AAAA,EAAA;AAE1B;AAMO,SAASC,EACdC,GACAC,GACAC,IAA0C,CAAA,GACrB;AACrB,QAAMC,IAAc,CAACC,MAAyB;AAC5C,eAAW,CAACC,GAAKC,CAAM,KAAK,OAAO,QAAQJ,CAAe;AACxD,UAAII,MAAWF,EAAM,QAAOC;AAE9B,WAAID,MAASH,IAAsB,SAC5BG;AAAA,EACT,GAEMG,wBAAmB,IAAA;AACzB,aAAWH,KAAQJ,GAAa;AAC9B,QAAII,MAASH,EAAe;AAC5B,UAAMI,IAAMF,EAAYC,CAAI,GACtBI,IAASH,MAAQ,SAASD,IAAOC;AACvC,IAAAE,EAAa,IAAIC,GAAQJ,CAAI,GACzBI,MAAWJ,KAAMG,EAAa,IAAIH,GAAMA,CAAI;AAAA,EAClD;AACA,SAAOG;AACT;AAMO,SAASE,EACdd,GACAK,GACAC,GACAC,IAA0C,CAAA,GAClC;AACR,QAAM,EAAE,UAAA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IiF,EAAI,UAGrBI,EAASrF,CAAI,IAAIiF;AAAA,EAErB;AACA,SAAOI;AACT;"}
|
|
1
|
+
{"version":3,"file":"index.mjs","sources":["../src/runtime/messages-from-glob.ts"],"sourcesContent":["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(modules: Record<string, { default: Translations } | Translations>): 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 } else {\n messages[code] = mod as Translations\n }\n }\n return messages\n}\n"],"names":["isModuleNamespace","mod","key","value","messagesFromGlob","modules","messages","path","code"],"mappings":";;;;AAOA,SAASA,EAAkBC,GAA+C;AAGxE,MAFI,EAAE,aAAaA,MAEf,CADS,OAAO,KAAKA,CAAG,EAClB,MAAM,CAACC,MAAQA,MAAQ,aAAaA,MAAQ,YAAY,EAAG,QAAO;AAC5E,QAAMC,IAASF,EAA6B;AAC5C,SAAOE,MAAU,QAAQ,OAAOA,KAAU,YAAY,CAAC,MAAM,QAAQA,CAAK;AAC5E;AAMO,SAASC,EAAiBC,GAAiG;AAChI,QAAMC,IAAyC,CAAA;AAC/C,aAAW,CAACC,GAAMN,CAAG,KAAK,OAAO,QAAQI,CAAO,GAAG;AAEjD,UAAMG,KADOD,EAAK,MAAM,GAAG,EAAE,SAAS,IACpB,QAAQ,WAAW,EAAE;AACvC,IAAKC,MACDP,KAAO,OAAOA,KAAQ,YAAYD,EAAkBC,CAAG,IACzDK,EAASE,CAAI,IAAIP,EAAI,UAErBK,EAASE,CAAI,IAAIP;AAAA,EAErB;AACA,SAAOK;AACT;"}
|
package/dist/node.cjs
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const
|
|
1
|
+
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const o=require("@i18n-micro/node"),c=require("./adapter-BJ-0ltIc.cjs"),s=require("./vitepress-locales-Cz4AutfI.cjs");function n(e){const l=e.defaultLocale||e.locale,r=(e.locales?.length?e.locales:[e.locale]).map(t=>typeof t=="string"?{code:t}:t),a=c.createVitePressRouterAdapter({locales:r,defaultLocale:l,localeKeyToCode:e.localeKeyToCode,base:e.base});return o.createI18n(e).extend({localizePath:a.localizePath,switchLocalePath:a.switchLocalePath,getLocaleFromPath:a.getLocaleFromPath,removeLocaleFromPath:a.removeLocaleFromPath,routeNameFromPath:a.routeNameFromPath})}Object.defineProperty(exports,"loadRootTranslations",{enumerable:!0,get:()=>o.loadRootTranslations});Object.defineProperty(exports,"loadTranslations",{enumerable:!0,get:()=>o.loadTranslations});exports.buildVitePressLocales=s.buildVitePressLocales;exports.createI18n=n;
|
|
2
2
|
//# sourceMappingURL=node.cjs.map
|
package/dist/node.cjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"node.cjs","sources":[],"sourcesContent":[],"names":[],"mappings":""}
|
|
1
|
+
{"version":3,"file":"node.cjs","sources":["../src/runtime/node-create.ts"],"sourcesContent":["import type { Locale } from '@i18n-micro/types'\nimport { createI18n as createNodeI18n, type I18n, type I18nOptions } from '@i18n-micro/node'\nimport { createVitePressRouterAdapter, type PathMethods } from '../router/adapter'\n\nexport type { I18nOptions, LoadedTranslations } from '@i18n-micro/node'\nexport { loadTranslations, loadRootTranslations } from '@i18n-micro/node'\nexport type { PathMethods }\n\nexport interface CreateI18nOptions extends I18nOptions {\n /** Locales for path helpers (`localizePath`, …). Defaults to `[{ code: locale }]`. */\n locales?: Locale[] | string[]\n defaultLocale?: string\n localeKeyToCode?: Record<string, string>\n base?: string\n}\n\nexport type NodeI18n = I18n & PathMethods\n\n/**\n * Node `createI18n` (`@i18n-micro/node`) + VitePress path methods from the router adapter.\n */\nexport function createI18n(options: CreateI18nOptions): NodeI18n {\n const defaultLocale = options.defaultLocale || options.locale\n const locales = (options.locales?.length ? options.locales : [options.locale]).map((item) => (typeof item === 'string' ? { code: item } : item))\n const adapter = createVitePressRouterAdapter({\n locales,\n defaultLocale,\n localeKeyToCode: options.localeKeyToCode,\n base: options.base,\n })\n\n return createNodeI18n(options).extend({\n localizePath: adapter.localizePath,\n switchLocalePath: adapter.switchLocalePath,\n getLocaleFromPath: adapter.getLocaleFromPath,\n removeLocaleFromPath: adapter.removeLocaleFromPath,\n routeNameFromPath: adapter.routeNameFromPath,\n })\n}\n"],"names":["createI18n","options","defaultLocale","locales","item","adapter","createVitePressRouterAdapter","createNodeI18n"],"mappings":"sMAqBO,SAASA,EAAWC,EAAsC,CAC/D,MAAMC,EAAgBD,EAAQ,eAAiBA,EAAQ,OACjDE,GAAWF,EAAQ,SAAS,OAASA,EAAQ,QAAU,CAACA,EAAQ,MAAM,GAAG,IAAKG,GAAU,OAAOA,GAAS,SAAW,CAAE,KAAMA,CAAA,EAASA,CAAK,EACzIC,EAAUC,EAAAA,6BAA6B,CAC3C,QAAAH,EACA,cAAAD,EACA,gBAAiBD,EAAQ,gBACzB,KAAMA,EAAQ,IAAA,CACf,EAED,OAAOM,EAAAA,WAAeN,CAAO,EAAE,OAAO,CACpC,aAAcI,EAAQ,aACtB,iBAAkBA,EAAQ,iBAC1B,kBAAmBA,EAAQ,kBAC3B,qBAAsBA,EAAQ,qBAC9B,kBAAmBA,EAAQ,iBAAA,CAC5B,CACH"}
|
package/dist/node.d.cts
CHANGED
|
@@ -1,140 +1,80 @@
|
|
|
1
|
+
import { I18n } from '@i18n-micro/node';
|
|
2
|
+
import { I18nOptions } from '@i18n-micro/node';
|
|
3
|
+
import { I18nRoutingStrategy } from '@i18n-micro/vue';
|
|
4
|
+
import { LoadedTranslations } from '@i18n-micro/node';
|
|
5
|
+
import { loadRootTranslations } from '@i18n-micro/node';
|
|
6
|
+
import { loadTranslations } from '@i18n-micro/node';
|
|
1
7
|
import { Locale } from '@i18n-micro/types';
|
|
2
|
-
import { Plugin as Plugin_2 } from 'vite';
|
|
3
|
-
import { PluralFunc } from '@i18n-micro/types';
|
|
4
|
-
import { TranslationFileBuckets } from '@i18n-micro/utils/parse-path';
|
|
5
|
-
import { Translations } from '@i18n-micro/types';
|
|
6
8
|
|
|
7
9
|
/**
|
|
8
|
-
*
|
|
10
|
+
* Build VitePress `config.locales` from i18n-micro `Locale[]`.
|
|
11
|
+
* Default locale becomes `root` (no URL prefix); others get `/{key}/`.
|
|
9
12
|
*/
|
|
10
|
-
export declare function
|
|
11
|
-
addTranslations: (locale: string, translations: Translations, merge?: boolean) => void;
|
|
12
|
-
addRouteTranslations: (locale: string, routeName: string, translations: Translations, merge?: boolean) => void;
|
|
13
|
-
}, loaded: LoadedTranslations): void;
|
|
13
|
+
export declare function buildVitePressLocales(locales: Locale[], defaultLocale: string, options?: BuildVitePressLocalesOptions): Record<string, VitePressLocaleEntry>;
|
|
14
14
|
|
|
15
|
-
|
|
16
|
-
* List JSON translation files under `translationDir` (absolute + relative paths).
|
|
17
|
-
*/
|
|
18
|
-
export declare function listTranslationFiles(options: LoadMessagesOptions): TranslationFileRef[];
|
|
19
|
-
|
|
20
|
-
export declare type LoadedTranslations = TranslationFileBuckets<Translations>;
|
|
21
|
-
|
|
22
|
-
/**
|
|
23
|
-
* Load root-level locale JSON only (`en.json`, `fr.json`, …).
|
|
24
|
-
* Prefer `loadTranslationBuckets` when page locales are needed.
|
|
25
|
-
*
|
|
26
|
-
* Node.js-only (`node:fs`). For bundler-friendly loading prefer
|
|
27
|
-
* `withI18nMicro` virtual modules or `messagesFromGlob` in the theme.
|
|
28
|
-
*/
|
|
29
|
-
export declare function loadMessages(options: LoadMessagesOptions): Record<string, Translations>;
|
|
30
|
-
|
|
31
|
-
export declare interface LoadMessagesOptions {
|
|
32
|
-
/** Directory with locale JSON (`en.json`, `pages/guide/demo/en.json`, …). */
|
|
33
|
-
translationDir: string;
|
|
34
|
-
rootDir?: string;
|
|
15
|
+
export declare interface BuildVitePressLocalesOptions {
|
|
35
16
|
/**
|
|
36
|
-
*
|
|
37
|
-
*
|
|
17
|
+
* Map VitePress locale keys → i18n codes (`root` → default).
|
|
18
|
+
* When a non-default code maps to a short VP key (`fr` → `fr-FR`), the URL
|
|
19
|
+
* prefix / config key uses the VP key.
|
|
38
20
|
*/
|
|
39
|
-
|
|
21
|
+
localeKeyToCode?: Record<string, string>;
|
|
40
22
|
}
|
|
41
23
|
|
|
42
24
|
/**
|
|
43
|
-
*
|
|
44
|
-
* Node.js-only (`node:fs`).
|
|
25
|
+
* Node `createI18n` (`@i18n-micro/node`) + VitePress path methods from the router adapter.
|
|
45
26
|
*/
|
|
46
|
-
export declare function
|
|
47
|
-
|
|
48
|
-
export declare interface TranslationFileRef {
|
|
49
|
-
/** Path relative to `translationDir` using `/` separators. */
|
|
50
|
-
relativePath: string;
|
|
51
|
-
absolutePath: string;
|
|
52
|
-
}
|
|
27
|
+
export declare function createI18n(options: CreateI18nOptions): NodeI18n;
|
|
53
28
|
|
|
54
|
-
export declare interface
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
locales: Locale[];
|
|
58
|
-
localeCodes: string[];
|
|
59
|
-
missingWarn: boolean;
|
|
60
|
-
syncWithVitePress: boolean;
|
|
61
|
-
translationDir: string;
|
|
62
|
-
disablePageLocales: boolean;
|
|
63
|
-
localeKeyToCode: Record<string, string>;
|
|
64
|
-
}
|
|
65
|
-
|
|
66
|
-
declare interface VitePressI18nOptions {
|
|
67
|
-
locale: string;
|
|
68
|
-
fallbackLocale?: string;
|
|
69
|
-
locales?: Locale[];
|
|
29
|
+
export declare interface CreateI18nOptions extends I18nOptions {
|
|
30
|
+
/** Locales for path helpers (`localizePath`, …). Defaults to `[{ code: locale }]`. */
|
|
31
|
+
locales?: Locale[] | string[];
|
|
70
32
|
defaultLocale?: string;
|
|
71
|
-
messages?: Record<string, Translations>;
|
|
72
|
-
/**
|
|
73
|
-
* Page-scoped dictionaries keyed by route name (`guide-demo`), then locale.
|
|
74
|
-
* Loaded from `locales/pages/**` when using `withI18nMicro`.
|
|
75
|
-
*/
|
|
76
|
-
routeMessages?: Record<string, Record<string, Translations>>;
|
|
77
|
-
plural?: PluralFunc;
|
|
78
|
-
missingWarn?: boolean;
|
|
79
|
-
missingHandler?: (locale: string, key: string, routeName: string) => void;
|
|
80
|
-
/**
|
|
81
|
-
* Sync i18n locale from the VitePress URL path on every navigation.
|
|
82
|
-
* @default true
|
|
83
|
-
*/
|
|
84
|
-
syncWithVitePress?: boolean;
|
|
85
|
-
/**
|
|
86
|
-
* Map VitePress locale keys to i18n codes (`root` → default locale code).
|
|
87
|
-
*/
|
|
88
33
|
localeKeyToCode?: Record<string, string>;
|
|
34
|
+
base?: string;
|
|
89
35
|
}
|
|
90
36
|
|
|
91
|
-
|
|
92
|
-
* Minimal VitePress / Vite user config shape we merge into.
|
|
93
|
-
* Avoid importing `vitepress` types so the package stays usable as a pure library dep.
|
|
94
|
-
*/
|
|
95
|
-
export declare interface VitePressUserConfigLike {
|
|
96
|
-
locales?: Record<string, unknown>;
|
|
97
|
-
vite?: {
|
|
98
|
-
plugins?: Plugin_2[] | Plugin_2[][];
|
|
99
|
-
[key: string]: unknown;
|
|
100
|
-
};
|
|
101
|
-
[key: string]: unknown;
|
|
102
|
-
}
|
|
37
|
+
export { I18nOptions }
|
|
103
38
|
|
|
104
|
-
export
|
|
39
|
+
export { LoadedTranslations }
|
|
40
|
+
|
|
41
|
+
export { loadRootTranslations }
|
|
42
|
+
|
|
43
|
+
export { loadTranslations }
|
|
44
|
+
|
|
45
|
+
export declare type NodeI18n = I18n & PathMethods;
|
|
46
|
+
|
|
47
|
+
/** Path helpers exposed on `createI18n` instances (slice of the router adapter). */
|
|
48
|
+
declare type PathMethods = Pick<VitePressRouterAdapter, 'localizePath' | 'switchLocalePath' | 'getLocaleFromPath' | 'removeLocaleFromPath' | 'routeNameFromPath'>;
|
|
105
49
|
|
|
106
50
|
/**
|
|
107
|
-
*
|
|
108
|
-
* `withI18n` is already used by the unrelated `vitepress-i18n` package.
|
|
109
|
-
*
|
|
110
|
-
* Registers virtual modules:
|
|
111
|
-
* - `virtual:i18n-micro/config`
|
|
112
|
-
* - `virtual:i18n-micro/messages` (from `translationDir`, default `locales/`)
|
|
113
|
-
*
|
|
114
|
-
* Pair with `defineI18nTheme(DefaultTheme)` — no manual `import.meta.glob` in the theme.
|
|
115
|
-
*
|
|
116
|
-
* Import from `@i18n-micro/vitepress/config` (Node / config files only).
|
|
51
|
+
* Minimal VitePress `locales` entry used by the default theme language menu.
|
|
117
52
|
*/
|
|
118
|
-
export declare
|
|
53
|
+
export declare interface VitePressLocaleEntry {
|
|
54
|
+
label: string;
|
|
55
|
+
lang: string;
|
|
56
|
+
link?: string;
|
|
57
|
+
}
|
|
119
58
|
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
/**
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
59
|
+
declare interface VitePressRouterAdapter extends I18nRoutingStrategy {
|
|
60
|
+
getLocaleFromPath: (path: string) => string;
|
|
61
|
+
switchLocalePath: (path: string, newLocale: string) => string;
|
|
62
|
+
localizePath: (path: string, locale: string) => string;
|
|
63
|
+
removeLocaleFromPath: (path: string) => string;
|
|
64
|
+
/** Page dictionary route name (`/fr/guide/demo` → `guide-demo`). */
|
|
65
|
+
routeNameFromPath: (path: string) => string;
|
|
66
|
+
/** Resolve VitePress locale key (`root` / `fr`) to i18n code. */
|
|
67
|
+
codeFromLocaleKey: (localeKey: string) => string;
|
|
68
|
+
/** Resolve i18n code to VitePress locale key. */
|
|
69
|
+
localeKeyFromCode: (code: string) => string;
|
|
70
|
+
localeCodes: string[];
|
|
71
|
+
defaultLocale: string;
|
|
72
|
+
/** Snapshot of mapping used when building the adapter (for `i18nRouting` serialization). */
|
|
73
|
+
localeKeyToCode: Record<string, string>;
|
|
74
|
+
/** URL path prefixes (VitePress locale keys except `root`). */
|
|
75
|
+
urlPrefixes: string[];
|
|
76
|
+
/** VitePress `site.base` used when constructing this adapter (may be undefined). */
|
|
77
|
+
base?: string;
|
|
138
78
|
}
|
|
139
79
|
|
|
140
80
|
export { }
|
package/dist/node.d.ts
CHANGED
|
@@ -1,140 +1,80 @@
|
|
|
1
|
+
import { I18n } from '@i18n-micro/node';
|
|
2
|
+
import { I18nOptions } from '@i18n-micro/node';
|
|
3
|
+
import { I18nRoutingStrategy } from '@i18n-micro/vue';
|
|
4
|
+
import { LoadedTranslations } from '@i18n-micro/node';
|
|
5
|
+
import { loadRootTranslations } from '@i18n-micro/node';
|
|
6
|
+
import { loadTranslations } from '@i18n-micro/node';
|
|
1
7
|
import { Locale } from '@i18n-micro/types';
|
|
2
|
-
import { Plugin as Plugin_2 } from 'vite';
|
|
3
|
-
import { PluralFunc } from '@i18n-micro/types';
|
|
4
|
-
import { TranslationFileBuckets } from '@i18n-micro/utils/parse-path';
|
|
5
|
-
import { Translations } from '@i18n-micro/types';
|
|
6
8
|
|
|
7
9
|
/**
|
|
8
|
-
*
|
|
10
|
+
* Build VitePress `config.locales` from i18n-micro `Locale[]`.
|
|
11
|
+
* Default locale becomes `root` (no URL prefix); others get `/{key}/`.
|
|
9
12
|
*/
|
|
10
|
-
export declare function
|
|
11
|
-
addTranslations: (locale: string, translations: Translations, merge?: boolean) => void;
|
|
12
|
-
addRouteTranslations: (locale: string, routeName: string, translations: Translations, merge?: boolean) => void;
|
|
13
|
-
}, loaded: LoadedTranslations): void;
|
|
13
|
+
export declare function buildVitePressLocales(locales: Locale[], defaultLocale: string, options?: BuildVitePressLocalesOptions): Record<string, VitePressLocaleEntry>;
|
|
14
14
|
|
|
15
|
-
|
|
16
|
-
* List JSON translation files under `translationDir` (absolute + relative paths).
|
|
17
|
-
*/
|
|
18
|
-
export declare function listTranslationFiles(options: LoadMessagesOptions): TranslationFileRef[];
|
|
19
|
-
|
|
20
|
-
export declare type LoadedTranslations = TranslationFileBuckets<Translations>;
|
|
21
|
-
|
|
22
|
-
/**
|
|
23
|
-
* Load root-level locale JSON only (`en.json`, `fr.json`, …).
|
|
24
|
-
* Prefer `loadTranslationBuckets` when page locales are needed.
|
|
25
|
-
*
|
|
26
|
-
* Node.js-only (`node:fs`). For bundler-friendly loading prefer
|
|
27
|
-
* `withI18nMicro` virtual modules or `messagesFromGlob` in the theme.
|
|
28
|
-
*/
|
|
29
|
-
export declare function loadMessages(options: LoadMessagesOptions): Record<string, Translations>;
|
|
30
|
-
|
|
31
|
-
export declare interface LoadMessagesOptions {
|
|
32
|
-
/** Directory with locale JSON (`en.json`, `pages/guide/demo/en.json`, …). */
|
|
33
|
-
translationDir: string;
|
|
34
|
-
rootDir?: string;
|
|
15
|
+
export declare interface BuildVitePressLocalesOptions {
|
|
35
16
|
/**
|
|
36
|
-
*
|
|
37
|
-
*
|
|
17
|
+
* Map VitePress locale keys → i18n codes (`root` → default).
|
|
18
|
+
* When a non-default code maps to a short VP key (`fr` → `fr-FR`), the URL
|
|
19
|
+
* prefix / config key uses the VP key.
|
|
38
20
|
*/
|
|
39
|
-
|
|
21
|
+
localeKeyToCode?: Record<string, string>;
|
|
40
22
|
}
|
|
41
23
|
|
|
42
24
|
/**
|
|
43
|
-
*
|
|
44
|
-
* Node.js-only (`node:fs`).
|
|
25
|
+
* Node `createI18n` (`@i18n-micro/node`) + VitePress path methods from the router adapter.
|
|
45
26
|
*/
|
|
46
|
-
export declare function
|
|
47
|
-
|
|
48
|
-
export declare interface TranslationFileRef {
|
|
49
|
-
/** Path relative to `translationDir` using `/` separators. */
|
|
50
|
-
relativePath: string;
|
|
51
|
-
absolutePath: string;
|
|
52
|
-
}
|
|
27
|
+
export declare function createI18n(options: CreateI18nOptions): NodeI18n;
|
|
53
28
|
|
|
54
|
-
export declare interface
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
locales: Locale[];
|
|
58
|
-
localeCodes: string[];
|
|
59
|
-
missingWarn: boolean;
|
|
60
|
-
syncWithVitePress: boolean;
|
|
61
|
-
translationDir: string;
|
|
62
|
-
disablePageLocales: boolean;
|
|
63
|
-
localeKeyToCode: Record<string, string>;
|
|
64
|
-
}
|
|
65
|
-
|
|
66
|
-
declare interface VitePressI18nOptions {
|
|
67
|
-
locale: string;
|
|
68
|
-
fallbackLocale?: string;
|
|
69
|
-
locales?: Locale[];
|
|
29
|
+
export declare interface CreateI18nOptions extends I18nOptions {
|
|
30
|
+
/** Locales for path helpers (`localizePath`, …). Defaults to `[{ code: locale }]`. */
|
|
31
|
+
locales?: Locale[] | string[];
|
|
70
32
|
defaultLocale?: string;
|
|
71
|
-
messages?: Record<string, Translations>;
|
|
72
|
-
/**
|
|
73
|
-
* Page-scoped dictionaries keyed by route name (`guide-demo`), then locale.
|
|
74
|
-
* Loaded from `locales/pages/**` when using `withI18nMicro`.
|
|
75
|
-
*/
|
|
76
|
-
routeMessages?: Record<string, Record<string, Translations>>;
|
|
77
|
-
plural?: PluralFunc;
|
|
78
|
-
missingWarn?: boolean;
|
|
79
|
-
missingHandler?: (locale: string, key: string, routeName: string) => void;
|
|
80
|
-
/**
|
|
81
|
-
* Sync i18n locale from the VitePress URL path on every navigation.
|
|
82
|
-
* @default true
|
|
83
|
-
*/
|
|
84
|
-
syncWithVitePress?: boolean;
|
|
85
|
-
/**
|
|
86
|
-
* Map VitePress locale keys to i18n codes (`root` → default locale code).
|
|
87
|
-
*/
|
|
88
33
|
localeKeyToCode?: Record<string, string>;
|
|
34
|
+
base?: string;
|
|
89
35
|
}
|
|
90
36
|
|
|
91
|
-
|
|
92
|
-
* Minimal VitePress / Vite user config shape we merge into.
|
|
93
|
-
* Avoid importing `vitepress` types so the package stays usable as a pure library dep.
|
|
94
|
-
*/
|
|
95
|
-
export declare interface VitePressUserConfigLike {
|
|
96
|
-
locales?: Record<string, unknown>;
|
|
97
|
-
vite?: {
|
|
98
|
-
plugins?: Plugin_2[] | Plugin_2[][];
|
|
99
|
-
[key: string]: unknown;
|
|
100
|
-
};
|
|
101
|
-
[key: string]: unknown;
|
|
102
|
-
}
|
|
37
|
+
export { I18nOptions }
|
|
103
38
|
|
|
104
|
-
export
|
|
39
|
+
export { LoadedTranslations }
|
|
40
|
+
|
|
41
|
+
export { loadRootTranslations }
|
|
42
|
+
|
|
43
|
+
export { loadTranslations }
|
|
44
|
+
|
|
45
|
+
export declare type NodeI18n = I18n & PathMethods;
|
|
46
|
+
|
|
47
|
+
/** Path helpers exposed on `createI18n` instances (slice of the router adapter). */
|
|
48
|
+
declare type PathMethods = Pick<VitePressRouterAdapter, 'localizePath' | 'switchLocalePath' | 'getLocaleFromPath' | 'removeLocaleFromPath' | 'routeNameFromPath'>;
|
|
105
49
|
|
|
106
50
|
/**
|
|
107
|
-
*
|
|
108
|
-
* `withI18n` is already used by the unrelated `vitepress-i18n` package.
|
|
109
|
-
*
|
|
110
|
-
* Registers virtual modules:
|
|
111
|
-
* - `virtual:i18n-micro/config`
|
|
112
|
-
* - `virtual:i18n-micro/messages` (from `translationDir`, default `locales/`)
|
|
113
|
-
*
|
|
114
|
-
* Pair with `defineI18nTheme(DefaultTheme)` — no manual `import.meta.glob` in the theme.
|
|
115
|
-
*
|
|
116
|
-
* Import from `@i18n-micro/vitepress/config` (Node / config files only).
|
|
51
|
+
* Minimal VitePress `locales` entry used by the default theme language menu.
|
|
117
52
|
*/
|
|
118
|
-
export declare
|
|
53
|
+
export declare interface VitePressLocaleEntry {
|
|
54
|
+
label: string;
|
|
55
|
+
lang: string;
|
|
56
|
+
link?: string;
|
|
57
|
+
}
|
|
119
58
|
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
/**
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
59
|
+
declare interface VitePressRouterAdapter extends I18nRoutingStrategy {
|
|
60
|
+
getLocaleFromPath: (path: string) => string;
|
|
61
|
+
switchLocalePath: (path: string, newLocale: string) => string;
|
|
62
|
+
localizePath: (path: string, locale: string) => string;
|
|
63
|
+
removeLocaleFromPath: (path: string) => string;
|
|
64
|
+
/** Page dictionary route name (`/fr/guide/demo` → `guide-demo`). */
|
|
65
|
+
routeNameFromPath: (path: string) => string;
|
|
66
|
+
/** Resolve VitePress locale key (`root` / `fr`) to i18n code. */
|
|
67
|
+
codeFromLocaleKey: (localeKey: string) => string;
|
|
68
|
+
/** Resolve i18n code to VitePress locale key. */
|
|
69
|
+
localeKeyFromCode: (code: string) => string;
|
|
70
|
+
localeCodes: string[];
|
|
71
|
+
defaultLocale: string;
|
|
72
|
+
/** Snapshot of mapping used when building the adapter (for `i18nRouting` serialization). */
|
|
73
|
+
localeKeyToCode: Record<string, string>;
|
|
74
|
+
/** URL path prefixes (VitePress locale keys except `root`). */
|
|
75
|
+
urlPrefixes: string[];
|
|
76
|
+
/** VitePress `site.base` used when constructing this adapter (may be undefined). */
|
|
77
|
+
base?: string;
|
|
138
78
|
}
|
|
139
79
|
|
|
140
80
|
export { }
|
package/dist/node.mjs
CHANGED
|
@@ -1,10 +1,26 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { createI18n as r } from "@i18n-micro/node";
|
|
2
|
+
import { loadRootTranslations as n, loadTranslations as L } from "@i18n-micro/node";
|
|
3
|
+
import { c } from "./adapter-BnsyIKhp.js";
|
|
4
|
+
import { b as u } from "./vitepress-locales-6msv22Sn.js";
|
|
5
|
+
function h(e) {
|
|
6
|
+
const l = e.defaultLocale || e.locale, t = (e.locales?.length ? e.locales : [e.locale]).map((o) => typeof o == "string" ? { code: o } : o), a = c({
|
|
7
|
+
locales: t,
|
|
8
|
+
defaultLocale: l,
|
|
9
|
+
localeKeyToCode: e.localeKeyToCode,
|
|
10
|
+
base: e.base
|
|
11
|
+
});
|
|
12
|
+
return r(e).extend({
|
|
13
|
+
localizePath: a.localizePath,
|
|
14
|
+
switchLocalePath: a.switchLocalePath,
|
|
15
|
+
getLocaleFromPath: a.getLocaleFromPath,
|
|
16
|
+
removeLocaleFromPath: a.removeLocaleFromPath,
|
|
17
|
+
routeNameFromPath: a.routeNameFromPath
|
|
18
|
+
});
|
|
19
|
+
}
|
|
2
20
|
export {
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
t as warnLocaleMismatch,
|
|
8
|
-
e as withI18nMicro
|
|
21
|
+
u as buildVitePressLocales,
|
|
22
|
+
h as createI18n,
|
|
23
|
+
n as loadRootTranslations,
|
|
24
|
+
L as loadTranslations
|
|
9
25
|
};
|
|
10
26
|
//# sourceMappingURL=node.mjs.map
|
package/dist/node.mjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"node.mjs","sources":[],"sourcesContent":[],"names":[],"mappings":";"}
|
|
1
|
+
{"version":3,"file":"node.mjs","sources":["../src/runtime/node-create.ts"],"sourcesContent":["import type { Locale } from '@i18n-micro/types'\nimport { createI18n as createNodeI18n, type I18n, type I18nOptions } from '@i18n-micro/node'\nimport { createVitePressRouterAdapter, type PathMethods } from '../router/adapter'\n\nexport type { I18nOptions, LoadedTranslations } from '@i18n-micro/node'\nexport { loadTranslations, loadRootTranslations } from '@i18n-micro/node'\nexport type { PathMethods }\n\nexport interface CreateI18nOptions extends I18nOptions {\n /** Locales for path helpers (`localizePath`, …). Defaults to `[{ code: locale }]`. */\n locales?: Locale[] | string[]\n defaultLocale?: string\n localeKeyToCode?: Record<string, string>\n base?: string\n}\n\nexport type NodeI18n = I18n & PathMethods\n\n/**\n * Node `createI18n` (`@i18n-micro/node`) + VitePress path methods from the router adapter.\n */\nexport function createI18n(options: CreateI18nOptions): NodeI18n {\n const defaultLocale = options.defaultLocale || options.locale\n const locales = (options.locales?.length ? options.locales : [options.locale]).map((item) => (typeof item === 'string' ? { code: item } : item))\n const adapter = createVitePressRouterAdapter({\n locales,\n defaultLocale,\n localeKeyToCode: options.localeKeyToCode,\n base: options.base,\n })\n\n return createNodeI18n(options).extend({\n localizePath: adapter.localizePath,\n switchLocalePath: adapter.switchLocalePath,\n getLocaleFromPath: adapter.getLocaleFromPath,\n removeLocaleFromPath: adapter.removeLocaleFromPath,\n routeNameFromPath: adapter.routeNameFromPath,\n })\n}\n"],"names":["createI18n","options","defaultLocale","locales","item","adapter","createVitePressRouterAdapter","createNodeI18n"],"mappings":";;;;AAqBO,SAASA,EAAWC,GAAsC;AAC/D,QAAMC,IAAgBD,EAAQ,iBAAiBA,EAAQ,QACjDE,KAAWF,EAAQ,SAAS,SAASA,EAAQ,UAAU,CAACA,EAAQ,MAAM,GAAG,IAAI,CAACG,MAAU,OAAOA,KAAS,WAAW,EAAE,MAAMA,EAAA,IAASA,CAAK,GACzIC,IAAUC,EAA6B;AAAA,IAC3C,SAAAH;AAAA,IACA,eAAAD;AAAA,IACA,iBAAiBD,EAAQ;AAAA,IACzB,MAAMA,EAAQ;AAAA,EAAA,CACf;AAED,SAAOM,EAAeN,CAAO,EAAE,OAAO;AAAA,IACpC,cAAcI,EAAQ;AAAA,IACtB,kBAAkBA,EAAQ;AAAA,IAC1B,mBAAmBA,EAAQ;AAAA,IAC3B,sBAAsBA,EAAQ;AAAA,IAC9B,mBAAmBA,EAAQ;AAAA,EAAA,CAC5B;AACH;"}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { Locale } from '@i18n-micro/types';
|
|
2
|
-
/** Typecheck stub — real module is provided by `
|
|
2
|
+
/** Typecheck stub — real module is provided by `withI18n` Vite plugin. */
|
|
3
3
|
export declare const config: {
|
|
4
4
|
defaultLocale: string;
|
|
5
5
|
fallbackLocale: string;
|
|
@@ -10,4 +10,5 @@ export declare const config: {
|
|
|
10
10
|
translationDir: string;
|
|
11
11
|
disablePageLocales: boolean;
|
|
12
12
|
localeKeyToCode: Record<string, string>;
|
|
13
|
+
base?: string;
|
|
13
14
|
};
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
import { PluralFunc, Translations } from '@i18n-micro/types';
|
|
2
|
+
import { Theme } from 'vitepress';
|
|
3
|
+
import { VirtualI18nConfig } from '../plugin/with-i18n';
|
|
4
|
+
export interface DefineI18nThemeOptions {
|
|
5
|
+
/**
|
|
6
|
+
* Extra `enhanceApp` run after i18n is installed.
|
|
7
|
+
*/
|
|
8
|
+
enhanceApp?: NonNullable<Theme['enhanceApp']>;
|
|
9
|
+
/**
|
|
10
|
+
* Overrides not serializable into `virtual:i18n-micro/config`.
|
|
11
|
+
*/
|
|
12
|
+
plural?: PluralFunc;
|
|
13
|
+
missingHandler?: (locale: string, key: string, routeName: string) => void;
|
|
14
|
+
localeKeyToCode?: Record<string, string>;
|
|
15
|
+
/**
|
|
16
|
+
* Optional overrides (tests / advanced). Defaults come from `virtual:i18n-micro/*`
|
|
17
|
+
* registered by `withI18n`.
|
|
18
|
+
*/
|
|
19
|
+
config?: VirtualI18nConfig;
|
|
20
|
+
messages?: Record<string, Translations>;
|
|
21
|
+
routeMessages?: Record<string, Record<string, Translations>>;
|
|
22
|
+
}
|
|
23
|
+
/**
|
|
24
|
+
* Zero-boilerplate theme wiring. Requires `withI18n(...)` in `.vitepress/config`
|
|
25
|
+
* so virtual config + messages modules exist.
|
|
26
|
+
*
|
|
27
|
+
* Uses **static** `virtual:i18n-micro/*` imports so VitePress SSG can rewrite them.
|
|
28
|
+
* Import this helper from `@i18n-micro/vitepress/theme` (not the root entry) so Node
|
|
29
|
+
* config evaluation never loads virtual modules.
|
|
30
|
+
*
|
|
31
|
+
* @example
|
|
32
|
+
* ```ts
|
|
33
|
+
* import DefaultTheme from 'vitepress/theme'
|
|
34
|
+
* import { defineI18nTheme } from '@i18n-micro/vitepress/theme'
|
|
35
|
+
*
|
|
36
|
+
* export default defineI18nTheme(DefaultTheme)
|
|
37
|
+
* ```
|
|
38
|
+
*/
|
|
39
|
+
export declare function defineI18nTheme<T extends Theme>(base: T, options?: DefineI18nThemeOptions): T;
|
package/dist/theme.cjs
ADDED
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const h=require("virtual:i18n-micro/config"),i=require("virtual:i18n-micro/messages"),m=require("./create-BgMbe0w1.cjs"),y=require("./adapter-BJ-0ltIc.cjs");function b(l,a={}){const c=a.enhanceApp,o=l.enhanceApp,t=new WeakMap;return{...l,async enhanceApp(s){let n=t.get(s.app);if(!n){const e=a.config??h.config,g=a.messages??i.messages,u=a.routeMessages??i.routeMessages,d=e.localeCodes.length?e.localeCodes:e.locales.map(f=>f.code),r=a.localeKeyToCode??e.localeKeyToCode,p=y.getLocaleFromPath(s.router.route.path,d,e.defaultLocale,r,e.base);n=m.createI18n({locale:p,defaultLocale:e.defaultLocale,fallbackLocale:e.fallbackLocale,locales:e.locales,messages:g,routeMessages:u,missingWarn:e.missingWarn??void 0,syncWithVitePress:e.syncWithVitePress,localeKeyToCode:r,base:e.base,plural:a.plural,missingHandler:a.missingHandler}),t.set(s.app,n)}n.enhanceApp(s),o&&await o(s),c&&await c(s),n.enhanceApp(s)}}}exports.defineI18nTheme=b;
|
|
2
|
+
//# sourceMappingURL=theme.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"theme.cjs","sources":["../src/runtime/define-theme.ts"],"sourcesContent":["import type { PluralFunc, Translations } from '@i18n-micro/types'\nimport type { Theme } from 'vitepress'\nimport { config as virtualConfig } from 'virtual:i18n-micro/config'\nimport { messages as virtualMessages, routeMessages as virtualRouteMessages } from 'virtual:i18n-micro/messages'\nimport { createI18n, type CreateI18nResult } from './create'\nimport { getLocaleFromPath } from '../router/adapter'\nimport type { VirtualI18nConfig } from '../plugin/with-i18n'\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 * Optional overrides (tests / advanced). Defaults come from `virtual:i18n-micro/*`\n * registered by `withI18n`.\n */\n config?: VirtualI18nConfig\n messages?: Record<string, Translations>\n routeMessages?: Record<string, Record<string, Translations>>\n}\n\n/**\n * Zero-boilerplate theme wiring. Requires `withI18n(...)` in `.vitepress/config`\n * so virtual config + messages modules exist.\n *\n * Uses **static** `virtual:i18n-micro/*` imports so VitePress SSG can rewrite them.\n * Import this helper from `@i18n-micro/vitepress/theme` (not the root entry) so Node\n * config evaluation never loads virtual modules.\n *\n * @example\n * ```ts\n * import DefaultTheme from 'vitepress/theme'\n * import { defineI18nTheme } from '@i18n-micro/vitepress/theme'\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, CreateI18nResult>()\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 = (options.config ?? virtualConfig) as unknown as VirtualI18nConfig\n const messages = options.messages ?? (virtualMessages as Record<string, Translations>)\n const routeMessages = options.routeMessages ?? (virtualRouteMessages as Record<string, Record<string, Translations>>)\n\n const localeCodes = config.localeCodes.length ? config.localeCodes : config.locales.map((l) => l.code)\n const localeKeyToCode = options.localeKeyToCode ?? config.localeKeyToCode\n const initialLocale = getLocaleFromPath(ctx.router.route.path, localeCodes, config.defaultLocale, localeKeyToCode, config.base)\n\n installed = createI18n({\n locale: initialLocale,\n defaultLocale: config.defaultLocale,\n fallbackLocale: config.fallbackLocale,\n locales: config.locales,\n messages,\n routeMessages,\n missingWarn: config.missingWarn ?? undefined,\n syncWithVitePress: config.syncWithVitePress,\n localeKeyToCode,\n base: config.base,\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"],"names":["defineI18nTheme","base","options","userEnhance","baseEnhance","byApp","ctx","installed","config","virtualConfig","messages","virtualMessages","routeMessages","virtualRouteMessages","localeCodes","l","localeKeyToCode","initialLocale","getLocaleFromPath","createI18n"],"mappings":"6OA8CO,SAASA,EAAiCC,EAASC,EAAkC,GAAO,CACjG,MAAMC,EAAcD,EAAQ,WACtBE,EAAcH,EAAK,WAGnBI,MAAY,QAElB,MAAO,CACL,GAAGJ,EACH,MAAM,WAAWK,EAAwB,CACvC,IAAIC,EAAYF,EAAM,IAAIC,EAAI,GAAG,EACjC,GAAI,CAACC,EAAW,CAEd,MAAMC,EAAUN,EAAQ,QAAUO,EAAAA,OAC5BC,EAAWR,EAAQ,UAAaS,EAAAA,SAChCC,EAAgBV,EAAQ,eAAkBW,EAAAA,cAE1CC,EAAcN,EAAO,YAAY,OAASA,EAAO,YAAcA,EAAO,QAAQ,IAAKO,GAAMA,EAAE,IAAI,EAC/FC,EAAkBd,EAAQ,iBAAmBM,EAAO,gBACpDS,EAAgBC,EAAAA,kBAAkBZ,EAAI,OAAO,MAAM,KAAMQ,EAAaN,EAAO,cAAeQ,EAAiBR,EAAO,IAAI,EAE9HD,EAAYY,EAAAA,WAAW,CACrB,OAAQF,EACR,cAAeT,EAAO,cACtB,eAAgBA,EAAO,eACvB,QAASA,EAAO,QAAA,SAChBE,EACA,cAAAE,EACA,YAAaJ,EAAO,aAAe,OACnC,kBAAmBA,EAAO,kBAC1B,gBAAAQ,EACA,KAAMR,EAAO,KACb,OAAQN,EAAQ,OAChB,eAAgBA,EAAQ,cAAA,CACzB,EACDG,EAAM,IAAIC,EAAI,IAAKC,CAAS,CAC9B,CAGAA,EAAU,WAAWD,CAA4D,EAC7EF,GAAa,MAAMA,EAAYE,CAAG,EAClCH,GAAa,MAAMA,EAAYG,CAAG,EAEtCC,EAAU,WAAWD,CAA4D,CACnF,CAAA,CAEJ"}
|