@ubean/i18n 0.6.9 → 0.7.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/dist/browser.d.ts CHANGED
@@ -1,3 +1,3 @@
1
- import { a as localeSegment, c as switchLocalePath, d as HonoLocalePath, f as I18nLocaleMeta, h as LocaleRoutingConfig, i as localeFromSegment, l as toVueRouterLocalePath, m as I18nRoutingStrategy, n as extractLocaleFromPath, o as localeSegments, r as getVueLocaleParam, s as localizePath, t as compileLocalePaths, u as CompiledLocalePath } from "./paths-CnNW2Mah.js";
2
- import { a as parseLocaleCookie, i as detectLocaleFromAcceptLanguage, n as LocaleHeadTags, o as serializeLocaleCookie, r as buildLocaleHead, t as LocaleHeadInput } from "./head-BJtI_y8G.js";
1
+ import { c as localizePath, d as CompiledLocalePath, f as HonoLocalePath, g as LocaleRoutingConfig, h as I18nRoutingStrategy, i as localeFromSegment, l as switchLocalePath, n as extractLocaleFromPath, o as localeSegment, p as I18nLocaleMeta, r as getVueLocaleParam, s as localeSegments, t as compileLocalePaths, u as toVueRouterLocalePath } from "./paths-BDg85ZRp.js";
2
+ import { a as parseLocaleCookie, i as detectLocaleFromAcceptLanguage, n as LocaleHeadTags, o as serializeLocaleCookie, r as buildLocaleHead, t as LocaleHeadInput } from "./head-wpqC86Oe.js";
3
3
  export { type CompiledLocalePath, type HonoLocalePath, type I18nLocaleMeta, type I18nRoutingStrategy, type LocaleHeadInput, type LocaleHeadTags, type LocaleRoutingConfig, buildLocaleHead, compileLocalePaths, detectLocaleFromAcceptLanguage, extractLocaleFromPath, getVueLocaleParam, localeFromSegment, localeSegment, localeSegments, localizePath, parseLocaleCookie, serializeLocaleCookie, switchLocalePath, toVueRouterLocalePath };
package/dist/browser.js CHANGED
@@ -1,3 +1,3 @@
1
- import { a as extractLocaleFromPath, c as localeSegment, d as switchLocalePath, f as toVueRouterLocalePath, i as compileLocalePaths, l as localeSegments, n as parseLocaleCookie, o as getVueLocaleParam, r as serializeLocaleCookie, s as localeFromSegment, t as detectLocaleFromAcceptLanguage, u as localizePath } from "./detect-DgCzeC6u.js";
2
- import { t as buildLocaleHead } from "./head-DWOP7x2f.js";
1
+ import { a as extractLocaleFromPath, d as localizePath, f as switchLocalePath, i as compileLocalePaths, l as localeSegment, n as parseLocaleCookie, o as getVueLocaleParam, p as toVueRouterLocalePath, r as serializeLocaleCookie, s as localeFromSegment, t as detectLocaleFromAcceptLanguage, u as localeSegments } from "./detect-BOSXpF7l.js";
2
+ import { t as buildLocaleHead } from "./head-x9R0hGV-.js";
3
3
  export { buildLocaleHead, compileLocalePaths, detectLocaleFromAcceptLanguage, extractLocaleFromPath, getVueLocaleParam, localeFromSegment, localeSegment, localeSegments, localizePath, parseLocaleCookie, serializeLocaleCookie, switchLocalePath, toVueRouterLocalePath };
@@ -66,6 +66,24 @@ function toVueRouterLocalePath(pagePath, localeParam) {
66
66
  return `/${localeParam}${path}`;
67
67
  }
68
68
  /**
69
+ * Redirect target for a `definePage({ redirect })` route, in the language of
70
+ * the request that reached it.
71
+ *
72
+ * 作者写的是**不带语言前缀**的目标(`/home`),前缀在这里补 —— vue-router 的
73
+ * 字符串重定向是静态路径,不插值参数,所以两侧都不能写成 `/:locale(zh)?/home`。
74
+ *
75
+ * - 客户端: `requestedLocale` 来自 vue-router 已解析的 `to.params.locale`,
76
+ * 于是 `/zh/` → `/zh/home`、`/` → `/home`(默认语言不带前缀)。
77
+ * - 服务端: 传入 `c.get('locale')` 得到的 locale **代码**。
78
+ *
79
+ * 默认语言与 `prefix` 策略下带前缀的语言由 `localizePath` 自己判断前缀与否,
80
+ * 调用方不需要再分情况。`requestedLocale` 为空时原样返回目标。
81
+ */
82
+ function localeRedirectTarget(target, requestedLocale, cfg) {
83
+ if (!requestedLocale || !cfg.locales.length) return target;
84
+ return localizePath(target, requestedLocale, cfg);
85
+ }
86
+ /**
69
87
  * Split a URL path into its locale code and the rest.
70
88
  *
71
89
  * The returned `locale` is the **code**, not the segment — with
@@ -178,4 +196,4 @@ function serializeLocaleCookie(cookieName, locale) {
178
196
  return `${cookieName}=${encodeURIComponent(locale)}; Path=/; SameSite=Lax`;
179
197
  }
180
198
  //#endregion
181
- export { extractLocaleFromPath as a, localeSegment as c, switchLocalePath as d, toVueRouterLocalePath as f, compileLocalePaths as i, localeSegments as l, parseLocaleCookie as n, getVueLocaleParam as o, serializeLocaleCookie as r, localeFromSegment as s, detectLocaleFromAcceptLanguage as t, localizePath as u };
199
+ export { extractLocaleFromPath as a, localeRedirectTarget as c, localizePath as d, switchLocalePath as f, compileLocalePaths as i, localeSegment as l, parseLocaleCookie as n, getVueLocaleParam as o, toVueRouterLocalePath as p, serializeLocaleCookie as r, localeFromSegment as s, detectLocaleFromAcceptLanguage as t, localeSegments as u };
@@ -1,4 +1,4 @@
1
- import { f as I18nLocaleMeta, h as LocaleRoutingConfig } from "./paths-CnNW2Mah.js";
1
+ import { g as LocaleRoutingConfig, p as I18nLocaleMeta } from "./paths-BDg85ZRp.js";
2
2
  //#region src/detect.d.ts
3
3
  declare function detectLocaleFromAcceptLanguage(header: string | undefined, locales: string[], fallback: string): string;
4
4
  declare function parseLocaleCookie(cookieHeader: string | undefined, cookieName: string): string | null;
@@ -1,4 +1,4 @@
1
- import { a as extractLocaleFromPath, u as localizePath } from "./detect-DgCzeC6u.js";
1
+ import { a as extractLocaleFromPath, d as localizePath } from "./detect-BOSXpF7l.js";
2
2
  //#region src/head.ts
3
3
  function abs(baseUrl, path) {
4
4
  if (!baseUrl) return path;
package/dist/index.d.ts CHANGED
@@ -1,5 +1,5 @@
1
- import { a as localeSegment, c as switchLocalePath, d as HonoLocalePath, f as I18nLocaleMeta, h as LocaleRoutingConfig, i as localeFromSegment, l as toVueRouterLocalePath, m as I18nRoutingStrategy, n as extractLocaleFromPath, o as localeSegments, p as I18nMiddlewareOptions, r as getVueLocaleParam, s as localizePath, t as compileLocalePaths, u as CompiledLocalePath } from "./paths-CnNW2Mah.js";
2
- import { a as parseLocaleCookie, i as detectLocaleFromAcceptLanguage, n as LocaleHeadTags, o as serializeLocaleCookie, r as buildLocaleHead, t as LocaleHeadInput } from "./head-BJtI_y8G.js";
1
+ import { a as localeRedirectTarget, c as localizePath, d as CompiledLocalePath, f as HonoLocalePath, g as LocaleRoutingConfig, h as I18nRoutingStrategy, i as localeFromSegment, l as switchLocalePath, m as I18nMiddlewareOptions, n as extractLocaleFromPath, o as localeSegment, p as I18nLocaleMeta, r as getVueLocaleParam, s as localeSegments, t as compileLocalePaths, u as toVueRouterLocalePath } from "./paths-BDg85ZRp.js";
2
+ import { a as parseLocaleCookie, i as detectLocaleFromAcceptLanguage, n as LocaleHeadTags, o as serializeLocaleCookie, r as buildLocaleHead, t as LocaleHeadInput } from "./head-wpqC86Oe.js";
3
3
  import { createI18nMiddleware, getPathWithoutLocale, getRequestLocale as getRequestLocale$1 } from "./routing.js";
4
4
  import { LocaleMessage } from "@intlify/core";
5
5
  //#region src/context.d.ts
@@ -59,4 +59,4 @@ export declare function t(key: string, ...args: unknown[]): string;
59
59
  export declare function d(value: Date | number | string, ...args: unknown[]): string;
60
60
  export declare function n(value: number, ...args: unknown[]): string;
61
61
  //#endregion
62
- export { type CompiledLocalePath, type HonoLocalePath, type I18nCoreContext, type I18nLocaleMeta, type I18nMiddlewareOptions, type I18nRequestScope, type I18nRoutingStrategy, type LocaleHeadInput, type LocaleHeadTags, type LocaleMessages, type LocaleRoutingConfig, buildLocaleHead, compileLocalePaths, createI18nMiddleware, detectLocaleFromAcceptLanguage, extractLocaleFromPath, getRequestLocale as getAlsLocale, getPathWithoutLocale, getRequestLocale$1 as getRequestLocale, getVueLocaleParam, localeFromSegment, localeSegment, localeSegments, localizePath, parseLocaleCookie, serializeLocaleCookie, switchLocalePath, toVueRouterLocalePath };
62
+ export { type CompiledLocalePath, type HonoLocalePath, type I18nCoreContext, type I18nLocaleMeta, type I18nMiddlewareOptions, type I18nRequestScope, type I18nRoutingStrategy, type LocaleHeadInput, type LocaleHeadTags, type LocaleMessages, type LocaleRoutingConfig, buildLocaleHead, compileLocalePaths, createI18nMiddleware, detectLocaleFromAcceptLanguage, extractLocaleFromPath, getRequestLocale as getAlsLocale, getPathWithoutLocale, getRequestLocale$1 as getRequestLocale, getVueLocaleParam, localeFromSegment, localeRedirectTarget, localeSegment, localeSegments, localizePath, parseLocaleCookie, serializeLocaleCookie, switchLocalePath, toVueRouterLocalePath };
package/dist/index.js CHANGED
@@ -1,4 +1,4 @@
1
- import { a as extractLocaleFromPath, c as localeSegment, d as switchLocalePath, f as toVueRouterLocalePath, i as compileLocalePaths, l as localeSegments, n as parseLocaleCookie, o as getVueLocaleParam, r as serializeLocaleCookie, s as localeFromSegment, t as detectLocaleFromAcceptLanguage, u as localizePath } from "./detect-DgCzeC6u.js";
2
- import { C as t, S as setLocaleMeta, _ as n, a as d, b as setFallbackLocale, c as getI18nScope, d as getLocaleMeta, f as getLocaleName, g as mergeLocaleMessages, h as listLocaleCodes, i as createRequestContext, l as getLocaleDir, m as getRequestLocale, n as getPathWithoutLocale, o as ensureLocaleMessages, p as getRegisteredLocalesMeta, r as getRequestLocale$1, s as getFallbackLocale, t as createI18nMiddleware, u as getLocaleMessages, v as registerLocaleLoader, x as setLocaleMessages, y as runWithI18n } from "./routing-CqXNfVlC.js";
3
- import { t as buildLocaleHead } from "./head-DWOP7x2f.js";
4
- export { buildLocaleHead, compileLocalePaths, createI18nMiddleware, createRequestContext, d, detectLocaleFromAcceptLanguage, ensureLocaleMessages, extractLocaleFromPath, getRequestLocale as getAlsLocale, getFallbackLocale, getI18nScope, getLocaleDir, getLocaleMessages, getLocaleMeta, getLocaleName, getPathWithoutLocale, getRegisteredLocalesMeta, getRequestLocale$1 as getRequestLocale, getVueLocaleParam, listLocaleCodes, localeFromSegment, localeSegment, localeSegments, localizePath, mergeLocaleMessages, n, parseLocaleCookie, registerLocaleLoader, runWithI18n, serializeLocaleCookie, setFallbackLocale, setLocaleMessages, setLocaleMeta, switchLocalePath, t, toVueRouterLocalePath };
1
+ import { a as extractLocaleFromPath, c as localeRedirectTarget, d as localizePath, f as switchLocalePath, i as compileLocalePaths, l as localeSegment, n as parseLocaleCookie, o as getVueLocaleParam, p as toVueRouterLocalePath, r as serializeLocaleCookie, s as localeFromSegment, t as detectLocaleFromAcceptLanguage, u as localeSegments } from "./detect-BOSXpF7l.js";
2
+ import { C as t, S as setLocaleMeta, _ as n, a as d, b as setFallbackLocale, c as getI18nScope, d as getLocaleMeta, f as getLocaleName, g as mergeLocaleMessages, h as listLocaleCodes, i as createRequestContext, l as getLocaleDir, m as getRequestLocale, n as getPathWithoutLocale, o as ensureLocaleMessages, p as getRegisteredLocalesMeta, r as getRequestLocale$1, s as getFallbackLocale, t as createI18nMiddleware, u as getLocaleMessages, v as registerLocaleLoader, x as setLocaleMessages, y as runWithI18n } from "./routing-AUeKju4d.js";
3
+ import { t as buildLocaleHead } from "./head-x9R0hGV-.js";
4
+ export { buildLocaleHead, compileLocalePaths, createI18nMiddleware, createRequestContext, d, detectLocaleFromAcceptLanguage, ensureLocaleMessages, extractLocaleFromPath, getRequestLocale as getAlsLocale, getFallbackLocale, getI18nScope, getLocaleDir, getLocaleMessages, getLocaleMeta, getLocaleName, getPathWithoutLocale, getRegisteredLocalesMeta, getRequestLocale$1 as getRequestLocale, getVueLocaleParam, listLocaleCodes, localeFromSegment, localeRedirectTarget, localeSegment, localeSegments, localizePath, mergeLocaleMessages, n, parseLocaleCookie, registerLocaleLoader, runWithI18n, serializeLocaleCookie, setFallbackLocale, setLocaleMessages, setLocaleMeta, switchLocalePath, t, toVueRouterLocalePath };
@@ -76,6 +76,21 @@ declare function localeSegments(cfg: LocaleRoutingConfig): string[];
76
76
  declare function getVueLocaleParam(cfg: LocaleRoutingConfig): string;
77
77
  /** Apply a vue-router locale param to a page path (`/` / `/about` / catch-all). */
78
78
  declare function toVueRouterLocalePath(pagePath: string, localeParam: string): string;
79
+ /**
80
+ * Redirect target for a `definePage({ redirect })` route, in the language of
81
+ * the request that reached it.
82
+ *
83
+ * 作者写的是**不带语言前缀**的目标(`/home`),前缀在这里补 —— vue-router 的
84
+ * 字符串重定向是静态路径,不插值参数,所以两侧都不能写成 `/:locale(zh)?/home`。
85
+ *
86
+ * - 客户端: `requestedLocale` 来自 vue-router 已解析的 `to.params.locale`,
87
+ * 于是 `/zh/` → `/zh/home`、`/` → `/home`(默认语言不带前缀)。
88
+ * - 服务端: 传入 `c.get('locale')` 得到的 locale **代码**。
89
+ *
90
+ * 默认语言与 `prefix` 策略下带前缀的语言由 `localizePath` 自己判断前缀与否,
91
+ * 调用方不需要再分情况。`requestedLocale` 为空时原样返回目标。
92
+ */
93
+ declare function localeRedirectTarget(target: string, requestedLocale: string, cfg: LocaleRoutingConfig): string;
79
94
  /**
80
95
  * Split a URL path into its locale code and the rest.
81
96
  *
@@ -91,4 +106,4 @@ declare function localizePath(path: string, locale: string, cfg: LocaleRoutingCo
91
106
  declare function switchLocalePath(locale: string, currentPath: string, cfg: LocaleRoutingConfig): string;
92
107
  declare function compileLocalePaths(pagePath: string, cfg: LocaleRoutingConfig): CompiledLocalePath;
93
108
  //#endregion
94
- export { localeSegment as a, switchLocalePath as c, HonoLocalePath as d, I18nLocaleMeta as f, LocaleRoutingConfig as h, localeFromSegment as i, toVueRouterLocalePath as l, I18nRoutingStrategy as m, extractLocaleFromPath as n, localeSegments as o, I18nMiddlewareOptions as p, getVueLocaleParam as r, localizePath as s, compileLocalePaths as t, CompiledLocalePath as u };
109
+ export { localeRedirectTarget as a, localizePath as c, CompiledLocalePath as d, HonoLocalePath as f, LocaleRoutingConfig as g, I18nRoutingStrategy as h, localeFromSegment as i, switchLocalePath as l, I18nMiddlewareOptions as m, extractLocaleFromPath as n, localeSegment as o, I18nLocaleMeta as p, getVueLocaleParam as r, localeSegments as s, compileLocalePaths as t, toVueRouterLocalePath as u };
@@ -1,4 +1,4 @@
1
- import { a as extractLocaleFromPath, n as parseLocaleCookie, r as serializeLocaleCookie, t as detectLocaleFromAcceptLanguage, u as localizePath } from "./detect-DgCzeC6u.js";
1
+ import { a as extractLocaleFromPath, d as localizePath, n as parseLocaleCookie, r as serializeLocaleCookie, t as detectLocaleFromAcceptLanguage } from "./detect-BOSXpF7l.js";
2
2
  import { AsyncLocalStorage } from "node:async_hooks";
3
3
  import { createCoreContext, datetime, number, translate } from "@intlify/core";
4
4
  //#region src/context.ts
package/dist/routing.d.ts CHANGED
@@ -1,4 +1,4 @@
1
- import { c as switchLocalePath, m as I18nRoutingStrategy, n as extractLocaleFromPath, p as I18nMiddlewareOptions, s as localizePath, t as compileLocalePaths } from "./paths-CnNW2Mah.js";
1
+ import { c as localizePath, h as I18nRoutingStrategy, l as switchLocalePath, m as I18nMiddlewareOptions, n as extractLocaleFromPath, t as compileLocalePaths } from "./paths-BDg85ZRp.js";
2
2
  import { UbeanEnv } from "@ubean/shared";
3
3
  import { Context, MiddlewareHandler } from "hono";
4
4
  //#region src/routing.d.ts
package/dist/routing.js CHANGED
@@ -1,3 +1,3 @@
1
- import { a as extractLocaleFromPath, d as switchLocalePath, i as compileLocalePaths, u as localizePath } from "./detect-DgCzeC6u.js";
2
- import { n as getPathWithoutLocale, r as getRequestLocale, t as createI18nMiddleware } from "./routing-CqXNfVlC.js";
1
+ import { a as extractLocaleFromPath, d as localizePath, f as switchLocalePath, i as compileLocalePaths } from "./detect-BOSXpF7l.js";
2
+ import { n as getPathWithoutLocale, r as getRequestLocale, t as createI18nMiddleware } from "./routing-AUeKju4d.js";
3
3
  export { compileLocalePaths, createI18nMiddleware, extractLocaleFromPath, getPathWithoutLocale, getRequestLocale, localizePath, switchLocalePath };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@ubean/i18n",
3
- "version": "0.6.9",
3
+ "version": "0.7.0",
4
4
  "description": "i18n for ubean (vue-i18n / @intlify/core, compact locale routing, ALS)",
5
5
  "files": [
6
6
  "dist"
@@ -25,7 +25,7 @@
25
25
  },
26
26
  "dependencies": {
27
27
  "@intlify/core": "11.4.16",
28
- "@ubean/shared": "0.6.9",
28
+ "@ubean/shared": "0.7.0",
29
29
  "hono": "4.13.13"
30
30
  },
31
31
  "devDependencies": {