intor 2.3.35 → 2.4.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.
Files changed (200) hide show
  1. package/README.md +16 -3
  2. package/dist/core/export/edge/index.js +6 -0
  3. package/dist/core/src/{server → core}/translator/create-translator.js +1 -1
  4. package/dist/core/src/core/utils/normalizers/normalize-locale.js +59 -0
  5. package/dist/core/src/core/utils/normalizers/normalize-query.js +25 -0
  6. package/dist/core/src/edge/helpers/get-translator.js +29 -0
  7. package/dist/core/src/edge/translator/init-translator.js +35 -0
  8. package/dist/core/src/routing/inbound/helpers/resolve-inbound-from-request.js +29 -0
  9. package/dist/core/src/routing/inbound/resolve-inbound.js +45 -0
  10. package/dist/core/src/routing/inbound/resolve-locale/resolve-locale.js +35 -0
  11. package/dist/{next/src/routing/inbound/resolve-pathname/resolve-pathname.js → core/src/routing/inbound/resolve-path/resolve-path.js} +2 -2
  12. package/dist/core/src/routing/locale/get-locale-from-accept-language.js +38 -0
  13. package/dist/core/src/routing/locale/get-locale-from-host.js +32 -0
  14. package/dist/core/src/routing/locale/get-locale-from-pathname.js +47 -0
  15. package/dist/core/src/routing/locale/get-locale-from-query.js +21 -0
  16. package/dist/core/src/server/helpers/get-translator.js +4 -5
  17. package/dist/core/src/server/translator/init-translator.js +1 -1
  18. package/dist/express/src/adapters/express/create-intor-handler.js +9 -9
  19. package/dist/express/src/adapters/express/get-translator.js +7 -1
  20. package/dist/express/src/{server → core}/translator/create-translator.js +1 -1
  21. package/dist/express/src/core/utils/parse-cookie-header.js +22 -0
  22. package/dist/express/src/routing/inbound/resolve-inbound.js +2 -2
  23. package/dist/express/src/routing/inbound/{resolve-pathname/resolve-pathname.js → resolve-path/resolve-path.js} +2 -2
  24. package/dist/express/src/server/helpers/get-translator.js +4 -5
  25. package/dist/express/src/server/translator/init-translator.js +1 -1
  26. package/dist/fastify/export/fastify/index.js +3 -0
  27. package/dist/fastify/src/adapters/fastify/create-intor-handler.js +56 -0
  28. package/dist/fastify/src/adapters/fastify/get-translator.js +28 -0
  29. package/dist/fastify/src/adapters/fastify/intor-fastify-plugin.js +34 -0
  30. package/dist/fastify/src/core/constants/prefix-placeholder.js +4 -0
  31. package/dist/fastify/src/core/error/intor-error.js +9 -0
  32. package/dist/fastify/src/core/logger/get-logger.js +39 -0
  33. package/dist/fastify/src/core/logger/global-logger-pool.js +8 -0
  34. package/dist/fastify/src/core/messages/load-remote-messages/collect-remote-resources.js +25 -0
  35. package/dist/fastify/src/core/messages/load-remote-messages/fetch-remote-resource.js +47 -0
  36. package/dist/fastify/src/core/messages/load-remote-messages/load-remote-messages.js +93 -0
  37. package/dist/fastify/src/core/messages/load-remote-messages/resolve-remote-resources.js +24 -0
  38. package/dist/fastify/src/core/messages/merge-messages.js +33 -0
  39. package/dist/fastify/src/core/messages/utils/is-valid-messages.js +44 -0
  40. package/dist/fastify/src/core/messages/utils/nest-object-from-path.js +21 -0
  41. package/dist/fastify/src/core/render/create-html-renderer.js +44 -0
  42. package/dist/fastify/src/core/render/utils/escape-html.js +10 -0
  43. package/dist/fastify/src/core/render/utils/render-attributes.js +17 -0
  44. package/dist/fastify/src/core/translator/create-t-rich.js +22 -0
  45. package/dist/{svelte-kit/src/server → fastify/src/core}/translator/create-translator.js +1 -1
  46. package/dist/fastify/src/core/utils/deep-merge.js +47 -0
  47. package/dist/fastify/src/core/utils/normalizers/normalize-cache-key.js +45 -0
  48. package/dist/fastify/src/core/utils/normalizers/normalize-locale.js +59 -0
  49. package/dist/fastify/src/core/utils/normalizers/normalize-pathname.js +43 -0
  50. package/dist/fastify/src/core/utils/normalizers/normalize-query.js +25 -0
  51. package/dist/fastify/src/core/utils/parse-cookie-header.js +22 -0
  52. package/dist/fastify/src/core/utils/resolve-loader-options.js +27 -0
  53. package/dist/fastify/src/routing/inbound/resolve-inbound.js +45 -0
  54. package/dist/fastify/src/routing/inbound/resolve-locale/resolve-locale.js +35 -0
  55. package/dist/{svelte-kit/src/routing/inbound/resolve-pathname/resolve-pathname.js → fastify/src/routing/inbound/resolve-path/resolve-path.js} +2 -2
  56. package/dist/fastify/src/routing/inbound/resolve-path/strategies/all.js +28 -0
  57. package/dist/fastify/src/routing/inbound/resolve-path/strategies/except-default.js +29 -0
  58. package/dist/fastify/src/routing/locale/get-locale-from-accept-language.js +38 -0
  59. package/dist/fastify/src/routing/locale/get-locale-from-host.js +32 -0
  60. package/dist/fastify/src/routing/locale/get-locale-from-pathname.js +47 -0
  61. package/dist/fastify/src/routing/locale/get-locale-from-query.js +21 -0
  62. package/dist/fastify/src/routing/pathname/canonicalize-pathname.js +47 -0
  63. package/dist/fastify/src/routing/pathname/localize-pathname.js +36 -0
  64. package/dist/fastify/src/routing/pathname/materialize-pathname.js +42 -0
  65. package/dist/fastify/src/routing/pathname/standardize-pathname.js +34 -0
  66. package/dist/fastify/src/server/helpers/get-translator.js +31 -0
  67. package/dist/fastify/src/server/messages/load-local-messages/cache/messages-pool.js +11 -0
  68. package/dist/fastify/src/server/messages/load-local-messages/load-local-messages.js +108 -0
  69. package/dist/fastify/src/server/messages/load-local-messages/read-locale-messages/collect-file-entries/collect-file-entries.js +91 -0
  70. package/dist/fastify/src/server/messages/load-local-messages/read-locale-messages/parse-file-entries/parse-file-entries.js +103 -0
  71. package/dist/fastify/src/server/messages/load-local-messages/read-locale-messages/parse-file-entries/utils/json-reader.js +12 -0
  72. package/dist/fastify/src/server/messages/load-local-messages/read-locale-messages/read-locale-messages.js +42 -0
  73. package/dist/fastify/src/server/messages/load-messages.js +78 -0
  74. package/dist/fastify/src/server/translator/init-translator.js +36 -0
  75. package/dist/hono/export/hono/index.js +3 -0
  76. package/dist/hono/src/adapters/hono/create-intor-handler.js +53 -0
  77. package/dist/hono/src/adapters/hono/get-translator.js +20 -0
  78. package/dist/hono/src/core/constants/prefix-placeholder.js +4 -0
  79. package/dist/hono/src/core/error/intor-error.js +9 -0
  80. package/dist/hono/src/core/logger/get-logger.js +39 -0
  81. package/dist/hono/src/core/logger/global-logger-pool.js +8 -0
  82. package/dist/hono/src/core/messages/load-remote-messages/collect-remote-resources.js +25 -0
  83. package/dist/hono/src/core/messages/load-remote-messages/fetch-remote-resource.js +47 -0
  84. package/dist/hono/src/core/messages/load-remote-messages/load-remote-messages.js +93 -0
  85. package/dist/hono/src/core/messages/load-remote-messages/resolve-remote-resources.js +24 -0
  86. package/dist/hono/src/core/messages/merge-messages.js +33 -0
  87. package/dist/hono/src/core/messages/utils/is-valid-messages.js +44 -0
  88. package/dist/hono/src/core/messages/utils/nest-object-from-path.js +21 -0
  89. package/dist/hono/src/core/render/create-html-renderer.js +44 -0
  90. package/dist/hono/src/core/render/utils/escape-html.js +10 -0
  91. package/dist/hono/src/core/render/utils/render-attributes.js +17 -0
  92. package/dist/hono/src/core/translator/create-t-rich.js +22 -0
  93. package/dist/{next/src/server → hono/src/core}/translator/create-translator.js +1 -1
  94. package/dist/hono/src/core/utils/deep-merge.js +47 -0
  95. package/dist/hono/src/core/utils/normalizers/normalize-locale.js +59 -0
  96. package/dist/hono/src/core/utils/normalizers/normalize-pathname.js +43 -0
  97. package/dist/hono/src/core/utils/normalizers/normalize-query.js +25 -0
  98. package/dist/hono/src/core/utils/parse-cookie-header.js +22 -0
  99. package/dist/hono/src/edge/helpers/get-translator.js +29 -0
  100. package/dist/hono/src/edge/translator/init-translator.js +35 -0
  101. package/dist/hono/src/routing/inbound/resolve-inbound.js +45 -0
  102. package/dist/hono/src/routing/inbound/resolve-locale/resolve-locale.js +35 -0
  103. package/dist/hono/src/routing/inbound/resolve-path/resolve-path.js +42 -0
  104. package/dist/hono/src/routing/inbound/resolve-path/strategies/all.js +28 -0
  105. package/dist/hono/src/routing/inbound/resolve-path/strategies/except-default.js +29 -0
  106. package/dist/hono/src/routing/inbound/resolve-path/strategies/none.js +8 -0
  107. package/dist/hono/src/routing/locale/get-locale-from-accept-language.js +38 -0
  108. package/dist/hono/src/routing/locale/get-locale-from-host.js +32 -0
  109. package/dist/hono/src/routing/locale/get-locale-from-pathname.js +47 -0
  110. package/dist/hono/src/routing/locale/get-locale-from-query.js +21 -0
  111. package/dist/hono/src/routing/pathname/canonicalize-pathname.js +47 -0
  112. package/dist/hono/src/routing/pathname/localize-pathname.js +36 -0
  113. package/dist/hono/src/routing/pathname/materialize-pathname.js +42 -0
  114. package/dist/hono/src/routing/pathname/standardize-pathname.js +34 -0
  115. package/dist/next/src/adapters/next/server/get-translator.js +7 -1
  116. package/dist/next/src/core/translator/create-translator.js +30 -0
  117. package/dist/next/src/routing/inbound/resolve-inbound.js +2 -2
  118. package/dist/next/src/routing/inbound/resolve-path/resolve-path.js +42 -0
  119. package/dist/next/src/routing/inbound/resolve-path/strategies/none.js +8 -0
  120. package/dist/next/src/server/helpers/get-translator.js +4 -5
  121. package/dist/next/src/server/translator/init-translator.js +1 -1
  122. package/dist/react/src/client/react/translator/use-translator.js +5 -5
  123. package/dist/react/src/client/shared/helpers/get-client-locale.js +1 -7
  124. package/dist/svelte/src/client/shared/helpers/get-client-locale.js +1 -7
  125. package/dist/svelte/src/client/svelte/translator/use-translator.js +6 -6
  126. package/dist/svelte-kit/src/adapters/svelte-kit/server/create-intor-handler.js +1 -3
  127. package/dist/svelte-kit/src/core/translator/create-translator.js +30 -0
  128. package/dist/svelte-kit/src/routing/inbound/resolve-inbound.js +2 -2
  129. package/dist/svelte-kit/src/routing/inbound/resolve-path/resolve-path.js +42 -0
  130. package/dist/svelte-kit/src/routing/inbound/resolve-path/strategies/all.js +28 -0
  131. package/dist/svelte-kit/src/routing/inbound/resolve-path/strategies/except-default.js +29 -0
  132. package/dist/svelte-kit/src/routing/inbound/resolve-path/strategies/none.js +8 -0
  133. package/dist/svelte-kit/src/server/translator/init-translator.js +1 -1
  134. package/dist/types/export/edge/index.d.ts +2 -0
  135. package/dist/types/export/fastify/index.d.ts +1 -0
  136. package/dist/types/export/hono/index.d.ts +1 -0
  137. package/dist/types/src/adapters/express/create-intor-handler.d.ts +4 -4
  138. package/dist/types/src/adapters/express/get-translator.d.ts +5 -6
  139. package/dist/types/src/adapters/express/global.d.ts +6 -6
  140. package/dist/types/src/adapters/fastify/create-intor-handler.d.ts +14 -0
  141. package/dist/types/src/adapters/fastify/get-translator.d.ts +17 -0
  142. package/dist/types/src/adapters/fastify/global.d.ts +17 -0
  143. package/dist/types/src/adapters/fastify/index.d.ts +3 -0
  144. package/dist/types/src/adapters/fastify/intor-fastify-plugin.d.ts +21 -0
  145. package/dist/types/src/adapters/hono/create-intor-handler.d.ts +13 -0
  146. package/dist/types/src/adapters/hono/get-translator.d.ts +17 -0
  147. package/dist/types/src/adapters/hono/global.d.ts +17 -0
  148. package/dist/types/src/adapters/hono/index.d.ts +3 -0
  149. package/dist/types/src/adapters/next/server/get-translator.d.ts +5 -6
  150. package/dist/types/src/adapters/svelte-kit/server/create-intor-handler.d.ts +0 -2
  151. package/dist/types/src/client/react/translator/translator-instance.d.ts +1 -5
  152. package/dist/types/src/client/react/translator/use-translator.d.ts +4 -3
  153. package/dist/types/src/client/shared/helpers/get-client-locale.d.ts +3 -8
  154. package/dist/types/src/client/svelte/translator/translator-instance.d.ts +7 -7
  155. package/dist/types/src/client/svelte/translator/use-translator.d.ts +5 -4
  156. package/dist/types/src/client/vue/translator/translator-instance.d.ts +2 -2
  157. package/dist/types/src/client/vue/translator/use-translator.d.ts +5 -4
  158. package/dist/types/src/core/index.d.ts +2 -2
  159. package/dist/types/src/core/translator/index.d.ts +1 -0
  160. package/dist/types/src/core/types/translator-instance.d.ts +9 -2
  161. package/dist/types/src/core/utils/index.d.ts +1 -0
  162. package/dist/types/src/edge/helpers/get-translator.d.ts +15 -0
  163. package/dist/types/src/edge/helpers/index.d.ts +1 -0
  164. package/dist/types/src/edge/index.d.ts +1 -0
  165. package/dist/types/src/edge/translator/index.d.ts +1 -0
  166. package/dist/types/src/edge/translator/init-translator.d.ts +14 -0
  167. package/dist/types/src/routing/inbound/helpers/index.d.ts +1 -0
  168. package/dist/types/src/routing/inbound/helpers/resolve-inbound-from-request.d.ts +3 -0
  169. package/dist/types/src/routing/inbound/index.d.ts +1 -0
  170. package/dist/types/src/routing/inbound/resolve-path/index.d.ts +1 -0
  171. package/dist/types/src/routing/inbound/{resolve-pathname/resolve-pathname.d.ts → resolve-path/resolve-path.d.ts} +2 -2
  172. package/dist/types/src/routing/inbound/{resolve-pathname → resolve-path}/strategies/all.d.ts +2 -2
  173. package/dist/types/src/routing/inbound/{resolve-pathname → resolve-path}/strategies/except-default.d.ts +2 -2
  174. package/dist/types/src/routing/inbound/resolve-path/strategies/none.d.ts +5 -0
  175. package/dist/types/src/routing/inbound/{resolve-pathname → resolve-path}/types.d.ts +5 -5
  176. package/dist/types/src/routing/index.d.ts +1 -1
  177. package/dist/types/src/server/helpers/get-translator.d.ts +6 -8
  178. package/dist/types/src/server/index.d.ts +0 -2
  179. package/dist/types/src/server/translator/index.d.ts +1 -2
  180. package/dist/types/src/server/translator/init-translator.d.ts +3 -2
  181. package/dist/vue/src/client/shared/helpers/get-client-locale.js +1 -7
  182. package/dist/vue/src/client/vue/translator/use-translator.js +5 -5
  183. package/package.json +18 -1
  184. package/dist/types/src/routing/inbound/resolve-pathname/index.d.ts +0 -1
  185. package/dist/types/src/routing/inbound/resolve-pathname/strategies/none.d.ts +0 -5
  186. package/dist/types/src/server/shared/utils/index.d.ts +0 -1
  187. package/dist/types/src/server/translator/translator-instance.d.ts +0 -10
  188. /package/dist/{express/src/server/shared → core/src/core}/utils/parse-cookie-header.js +0 -0
  189. /package/dist/{express/src/routing/inbound/resolve-pathname → core/src/routing/inbound/resolve-path}/strategies/all.js +0 -0
  190. /package/dist/{express/src/routing/inbound/resolve-pathname → core/src/routing/inbound/resolve-path}/strategies/except-default.js +0 -0
  191. /package/dist/{express/src/routing/inbound/resolve-pathname → core/src/routing/inbound/resolve-path}/strategies/none.js +0 -0
  192. /package/dist/{svelte-kit/src/routing/inbound/resolve-pathname → express/src/routing/inbound/resolve-path}/strategies/all.js +0 -0
  193. /package/dist/{svelte-kit/src/routing/inbound/resolve-pathname → express/src/routing/inbound/resolve-path}/strategies/except-default.js +0 -0
  194. /package/dist/{next/src/routing/inbound/resolve-pathname → express/src/routing/inbound/resolve-path}/strategies/none.js +0 -0
  195. /package/dist/{svelte-kit/src/routing/inbound/resolve-pathname → fastify/src/routing/inbound/resolve-path}/strategies/none.js +0 -0
  196. /package/dist/next/src/routing/inbound/{resolve-pathname → resolve-path}/strategies/all.js +0 -0
  197. /package/dist/next/src/routing/inbound/{resolve-pathname → resolve-path}/strategies/except-default.js +0 -0
  198. /package/dist/types/src/{server → core}/translator/create-translator.d.ts +0 -0
  199. /package/dist/types/src/{server/shared → core}/utils/parse-cookie-header.d.ts +0 -0
  200. /package/dist/types/src/routing/inbound/{resolve-pathname → resolve-path}/strategies/index.d.ts +0 -0
@@ -1,19 +1,19 @@
1
- import type { HtmlTagRenderers, TranslatorInstance } from "../../../core";
2
- import { type Locale, type LocaleMessages, type LocalizedKey, type LocalizedReplacement, type LocalizedRich, type Replacement, type Rich, type ScopedKey } from "intor-translator";
1
+ import type { TranslatorInstance } from "../../../core";
2
+ import { type Locale, type LocaleMessages, type Replacement, type Rich } from "intor-translator";
3
3
  import { type Readable, type Writable } from "svelte/store";
4
4
  export type TranslatorInstanceSvelte<M extends LocaleMessages, ReplacementSchema = Replacement, RichSchema = Rich, PK extends string | undefined = undefined> = {
5
5
  /** `messages`: The message object containing all translations. */
6
- messages: Readable<M>;
6
+ messages: Readable<TranslatorInstance<M, ReplacementSchema, RichSchema, PK>["messages"]>;
7
7
  /** Current locale in use. */
8
- locale: Writable<Locale<M>>;
8
+ locale: Writable<TranslatorInstance<M, ReplacementSchema, RichSchema, PK>["locale"]>;
9
9
  /** Indicates whether translations are currently loading. */
10
10
  isLoading: Readable<boolean>;
11
11
  /** Update the active locale. */
12
12
  setLocale: (locale: Locale<M>) => void;
13
13
  /** Check if a given key exists in the messages. */
14
- hasKey: Readable<TranslatorInstance<M, ReplacementSchema, PK>["hasKey"]>;
14
+ hasKey: Readable<TranslatorInstance<M, ReplacementSchema, RichSchema, PK>["hasKey"]>;
15
15
  /** Translate a given key into its string representation. */
16
- t: Readable<TranslatorInstance<M, ReplacementSchema, PK>["t"]>;
16
+ t: Readable<TranslatorInstance<M, ReplacementSchema, RichSchema, PK>["t"]>;
17
17
  /** Translate a key into an HTML string using semantic rich tags. */
18
- tRich: Readable<(<K extends string = PK extends string ? ScopedKey<M, PK> : LocalizedKey<M>, RI = LocalizedRich<RichSchema, K>, RE = LocalizedReplacement<ReplacementSchema, K>>(key?: K | (string & {}), tagRenderers?: HtmlTagRenderers<RI> | HtmlTagRenderers, replacements?: RE | Replacement) => string)>;
18
+ tRich: Readable<TranslatorInstance<M, ReplacementSchema, RichSchema, PK>["tRich"]>;
19
19
  };
@@ -1,8 +1,9 @@
1
- import type { TranslatorInstanceSvelte } from "./translator-instance";
1
+ import type { TranslatorInstanceSvelte } from "../../../client/svelte/translator/translator-instance";
2
2
  import type { GenConfigKeys, GenMessages, GenReplacements, GenRich } from "../../../core";
3
3
  import type { LocalizedPreKey } from "intor-translator";
4
4
  /**
5
- * Svelte utility for accessing the active Intor translator instance.
5
+ * Svelte utility for accessing the active, scope-aware translator instance.
6
+ *
7
+ * @platform Svelte
6
8
  */
7
- export declare function useTranslator<CK extends GenConfigKeys = "__default__", ReplacementSchema = GenReplacements<CK>, RichSchema = GenRich<CK>>(): TranslatorInstanceSvelte<GenMessages<CK>, ReplacementSchema, RichSchema, undefined>;
8
- export declare function useTranslator<CK extends GenConfigKeys = "__default__", ReplacementSchema = GenReplacements<CK>, RichSchema = GenRich<CK>, PK extends string = LocalizedPreKey<GenMessages<CK>>>(preKey?: PK): TranslatorInstanceSvelte<GenMessages<CK>, ReplacementSchema, RichSchema, PK>;
9
+ export declare function useTranslator<CK extends GenConfigKeys = "__default__", ReplacementSchema = GenReplacements<CK>, RichSchema = GenRich<CK>, PK extends LocalizedPreKey<GenMessages<CK>> | undefined = undefined>(preKey?: PK): TranslatorInstanceSvelte<GenMessages<CK>, ReplacementSchema, RichSchema, PK>;
@@ -2,7 +2,7 @@ import type { VueTagRenderers } from "../../../client/vue/render";
2
2
  import type { TranslatorInstance } from "../../../core";
3
3
  import type { ComputedRef, VNodeChild } from "vue";
4
4
  import { type Locale, type LocaleMessages, type LocalizedKey, type LocalizedReplacement, type LocalizedRich, type Replacement, type Rich, type ScopedKey } from "intor-translator";
5
- export type TranslatorInstanceVue<M extends LocaleMessages, ReplacementSchema = Replacement, RichSchema = Rich, PK extends string | undefined = undefined> = TranslatorInstance<M, ReplacementSchema, PK> & {
5
+ export type TranslatorInstanceVue<M extends LocaleMessages, ReplacementSchema = Replacement, RichSchema = Rich, PK extends string | undefined = undefined> = Omit<TranslatorInstance<M, ReplacementSchema, RichSchema, PK>, "tRich" | "messages" | "locale"> & {
6
6
  /** `messages`: The message object containing all translations. */
7
7
  messages: ComputedRef<M>;
8
8
  /** Current locale in use. */
@@ -11,6 +11,6 @@ export type TranslatorInstanceVue<M extends LocaleMessages, ReplacementSchema =
11
11
  isLoading: ComputedRef<boolean>;
12
12
  /** Update the active locale. */
13
13
  setLocale: (locale: Locale<M>) => void;
14
- /** Translate a key into React nodes using semantic tags */
14
+ /** Translate a key into VNodes using semantic tags */
15
15
  tRich: <K extends string = PK extends string ? ScopedKey<M, PK> : LocalizedKey<M>, RI = LocalizedRich<RichSchema, K>, RE = LocalizedReplacement<ReplacementSchema, K>>(key?: K | (string & {}), tagRenderers?: VueTagRenderers<RI> | VueTagRenderers, replacements?: RE | Replacement) => VNodeChild[];
16
16
  };
@@ -1,8 +1,9 @@
1
- import type { TranslatorInstanceVue } from "./translator-instance";
1
+ import type { TranslatorInstanceVue } from "../../../client/vue/translator/translator-instance";
2
2
  import type { GenConfigKeys, GenMessages, GenReplacements, GenRich } from "../../../core";
3
3
  import type { LocalizedPreKey } from "intor-translator";
4
4
  /**
5
- * Vue composable to access the active translator instance.
5
+ * Vue composable for accessing the active, scope-aware translator instance.
6
+ *
7
+ * @platform Vue
6
8
  */
7
- export declare function useTranslator<CK extends GenConfigKeys = "__default__", ReplacementSchema = GenReplacements<CK>, RichSchema = GenRich<CK>>(): TranslatorInstanceVue<GenMessages<CK>, ReplacementSchema, RichSchema, undefined>;
8
- export declare function useTranslator<CK extends GenConfigKeys = "__default__", ReplacementSchema = GenReplacements<CK>, RichSchema = GenRich<CK>, PK extends string = LocalizedPreKey<GenMessages<CK>>>(preKey?: PK): TranslatorInstanceVue<GenMessages<CK>, ReplacementSchema, RichSchema, PK>;
9
+ export declare function useTranslator<CK extends GenConfigKeys = "__default__", ReplacementSchema = GenReplacements<CK>, RichSchema = GenRich<CK>, PK extends LocalizedPreKey<GenMessages<CK>> | undefined = undefined>(preKey?: PK): TranslatorInstanceVue<GenMessages<CK>, ReplacementSchema, RichSchema, PK>;
@@ -1,8 +1,8 @@
1
1
  export { PREFIX_PLACEHOLDER, INTOR_HEADERS } from "./constants";
2
2
  export { IntorError, IntorErrorCode } from "./error";
3
- export { deepMerge, type PlainObject, type DeepMergeOverrideEvent, resolveLoaderOptions, normalizePathname, normalizeCacheKey, normalizeLocale, normalizeQuery, type NormalizedQuery, } from "./utils";
3
+ export { deepMerge, type PlainObject, type DeepMergeOverrideEvent, resolveLoaderOptions, parseCookieHeader, normalizePathname, normalizeCacheKey, normalizeLocale, normalizeQuery, type NormalizedQuery, } from "./utils";
4
4
  export { getLogger, clearLoggerPool } from "./logger";
5
5
  export { loadRemoteMessages, mergeMessages, isValidMessages, nestObjectFromPath, type MessagesReader, type MessagesReaders, INTOR_PREFIX, INTOR_MESSAGES_KIND_KEY, INTOR_MESSAGES_KIND, getMessagesKind, type IntorMessagesKind, } from "./messages";
6
6
  export { createHtmlRenderer, type TagRenderers, type HtmlTagRenderers, } from "./render";
7
- export { createTRich } from "./translator";
7
+ export { createTranslator, type CreateTranslatorParams, createTRich, } from "./translator";
8
8
  export type { INTOR_GENERATED_KEY, IfGen, GenConfigKeys, GenConfig, GenMessages, GenLocale, GenReplacements, GenRich, TranslatorInstance, RoutingLocaleSource, RoutingLocaleCarrier, LocalePathPrefix, RuntimeFetch, } from "./types";
@@ -1 +1,2 @@
1
+ export { createTranslator, type CreateTranslatorParams, } from "./create-translator";
1
2
  export { createTRich } from "./create-t-rich";
@@ -1,14 +1,21 @@
1
- import { type Locale, type LocaleMessages, type LocalizedKey, type ScopedKey, type LocalizedValue, type ScopedValue, type Replacement, type LocalizedReplacement } from "intor-translator";
1
+ import type { HtmlTagRenderers } from "../render";
2
+ import { type Locale, type LocaleMessages, type LocalizedKey, type ScopedKey, type LocalizedValue, type ScopedValue, type Replacement, type LocalizedReplacement, type LocalizedRich, type Rich } from "intor-translator";
2
3
  type FallbackIfNever<T, Fallback> = [T] extends [never] ? Fallback : T;
3
4
  /**
4
5
  * Core translator instance interface.
5
6
  *
6
7
  * This type represents the minimal, framework-independent translator contract.
7
8
  */
8
- export type TranslatorInstance<M extends LocaleMessages, ReplacementSchema = Replacement, PK extends string | undefined = undefined> = {
9
+ export type TranslatorInstance<M extends LocaleMessages, ReplacementSchema = Replacement, RichSchema = Rich, PK extends string | undefined = undefined> = {
10
+ /** `messages`: The message object containing all translations. */
11
+ messages: M;
12
+ /** Current locale in use. */
13
+ locale: Locale<M>;
9
14
  /** Check if a given key exists in the messages. */
10
15
  hasKey: <K extends string = PK extends string ? ScopedKey<M, PK> : LocalizedKey<M>>(key?: K | (string & {}), targetLocale?: Locale<M>) => boolean;
11
16
  /** Translate a given key into its string representation. */
12
17
  t: <K extends string = PK extends string ? ScopedKey<M, PK> : LocalizedKey<M>, R extends Replacement = LocalizedReplacement<ReplacementSchema, K>>(key?: K | (string & {}), replacements?: R | Replacement) => FallbackIfNever<PK extends string ? ScopedValue<M, PK, K> : LocalizedValue<M, K>, string>;
18
+ /** Translate a key into an HTML string using semantic rich tags. */
19
+ tRich: <K extends string = PK extends string ? ScopedKey<M, PK> : LocalizedKey<M>, RI = LocalizedRich<RichSchema, K>, RE = LocalizedReplacement<ReplacementSchema, K>>(key?: K | (string & {}), tagRenderers?: HtmlTagRenderers<RI> | HtmlTagRenderers, replacements?: RE | Replacement) => string;
13
20
  };
14
21
  export {};
@@ -1,3 +1,4 @@
1
1
  export { deepMerge, type PlainObject, type DeepMergeOverrideEvent, } from "./deep-merge";
2
2
  export { resolveLoaderOptions } from "./resolve-loader-options";
3
+ export { parseCookieHeader } from "./parse-cookie-header";
3
4
  export { normalizeCacheKey, normalizeLocale, normalizePathname, normalizeQuery, type NormalizedQuery, } from "./normalizers";
@@ -0,0 +1,15 @@
1
+ import type { IntorResolvedConfig } from "../../config";
2
+ import type { LocalizedPreKey, TranslateHandlers, TranslateHook, TranslatorPlugin } from "intor-translator";
3
+ import { type GenConfigKeys, type GenLocale, type GenMessages, type GenReplacements, type GenRich, type RuntimeFetch, type TranslatorInstance } from "../../core";
4
+ export interface GetTranslatorParams<CK extends GenConfigKeys = "__default__"> {
5
+ locale: GenLocale<CK> | (string & {});
6
+ fetch?: RuntimeFetch;
7
+ handlers?: TranslateHandlers;
8
+ plugins?: (TranslatorPlugin | TranslateHook)[];
9
+ }
10
+ /**
11
+ * Get a edge-runtime translator for the current execution context.
12
+ */
13
+ export declare function getTranslator<CK extends GenConfigKeys = "__default__", ReplacementSchema = GenReplacements<CK>, RichSchema = GenRich<CK>, PK extends LocalizedPreKey<GenMessages<CK>> | undefined = undefined>(config: IntorResolvedConfig, params: GetTranslatorParams<CK> & {
14
+ preKey?: PK;
15
+ }): Promise<TranslatorInstance<GenMessages<CK>, ReplacementSchema, RichSchema, PK>>;
@@ -0,0 +1 @@
1
+ export { getTranslator, type GetTranslatorParams } from "./get-translator";
@@ -0,0 +1 @@
1
+ export { getTranslator, type GetTranslatorParams } from "./helpers";
@@ -0,0 +1 @@
1
+ export { initTranslator } from "../translator/init-translator";
@@ -0,0 +1,14 @@
1
+ import type { IntorResolvedConfig } from "../../config";
2
+ import type { Locale, Translator } from "intor-translator";
3
+ import { type CreateTranslatorParams, type RuntimeFetch } from "../../core";
4
+ interface InitTranslatorOptions extends Pick<CreateTranslatorParams, "handlers" | "plugins"> {
5
+ fetch: RuntimeFetch;
6
+ }
7
+ /**
8
+ * Initialize a locale-bound Translator snapshot.
9
+ *
10
+ * - Loads translation messages using the configured remote loader, if present.
11
+ * - Creates an immutable Translator instance for edge runtimes
12
+ */
13
+ export declare function initTranslator(config: IntorResolvedConfig, locale: Locale, options: InitTranslatorOptions): Promise<Translator<unknown>>;
14
+ export {};
@@ -0,0 +1 @@
1
+ export { resolveInboundFromRequest } from "./resolve-inbound-from-request";
@@ -0,0 +1,3 @@
1
+ import type { InboundResult } from "../types";
2
+ import type { IntorResolvedConfig } from "../../../config";
3
+ export declare function resolveInboundFromRequest(config: IntorResolvedConfig, request: Request): Promise<InboundResult>;
@@ -1,2 +1,3 @@
1
1
  export { resolveInbound } from "./resolve-inbound";
2
2
  export type { InboundResult, InboundContext } from "./types";
3
+ export { resolveInboundFromRequest } from "./helpers";
@@ -0,0 +1 @@
1
+ export { resolvePath as resolvePathname } from "./resolve-path";
@@ -1,4 +1,4 @@
1
- import type { PathnameContext, ResolvedPathname } from "./types";
1
+ import type { PathContext, ResolvedPath } from "./types";
2
2
  import type { IntorResolvedConfig } from "../../../config";
3
3
  /**
4
4
  * Resolves the canonical pathname based on locale prefix behavior.
@@ -6,4 +6,4 @@ import type { IntorResolvedConfig } from "../../../config";
6
6
  * The resolved pathname represents the final, normalized form
7
7
  * used for routing and navigation.
8
8
  */
9
- export declare const resolvePathname: (config: IntorResolvedConfig, rawPathname: string, context: PathnameContext) => ResolvedPathname;
9
+ export declare const resolvePath: (config: IntorResolvedConfig, rawPathname: string, context: PathContext) => ResolvedPath;
@@ -1,6 +1,6 @@
1
- import type { PathnameContext, PathnameDirective } from "../types";
1
+ import type { PathContext, PathDirective } from "../types";
2
2
  import type { IntorResolvedConfig } from "../../../../config";
3
3
  /**
4
4
  * Resolve pathname decision for routing prefix strategy: "all".
5
5
  */
6
- export declare function all(config: IntorResolvedConfig, context: PathnameContext): PathnameDirective;
6
+ export declare function all(config: IntorResolvedConfig, context: PathContext): PathDirective;
@@ -1,6 +1,6 @@
1
- import type { PathnameContext, PathnameDirective } from "../types";
1
+ import type { PathContext, PathDirective } from "../types";
2
2
  import type { IntorResolvedConfig } from "../../../../config";
3
3
  /**
4
4
  * Resolve pathname decision for routing prefix strategy: "except-default".
5
5
  */
6
- export declare function exceptDefault(config: IntorResolvedConfig, context: PathnameContext): PathnameDirective;
6
+ export declare function exceptDefault(config: IntorResolvedConfig, context: PathContext): PathDirective;
@@ -0,0 +1,5 @@
1
+ import type { PathDirective } from "../types";
2
+ /**
3
+ * Resolve pathname decision for routing prefix strategy: "none".
4
+ */
5
+ export declare function none(): PathDirective;
@@ -1,10 +1,10 @@
1
1
  import type { Locale } from "intor-translator";
2
2
  /**
3
- * Context for pathname processing.
3
+ * Context for path processing.
4
4
  *
5
5
  * - Assumes the locale has already been resolved.
6
6
  */
7
- export interface PathnameContext {
7
+ export interface PathContext {
8
8
  /** Final resolved locale used for pathname decisions */
9
9
  locale: Locale;
10
10
  /** Whether the current URL already contains a locale prefix */
@@ -17,14 +17,14 @@ export interface PathnameContext {
17
17
  /**
18
18
  * Directive describing how the pathname should be handled.
19
19
  */
20
- export interface PathnameDirective {
20
+ export interface PathDirective {
21
21
  /** Indicates whether a redirect is required */
22
22
  type: "pass" | "redirect";
23
23
  }
24
24
  /**
25
- * Final resolved pathname result.
25
+ * Final resolved path result.
26
26
  */
27
- export interface ResolvedPathname {
27
+ export interface ResolvedPath {
28
28
  /** Normalized pathname after applying routing rules */
29
29
  pathname: string;
30
30
  /** Whether a redirect should occur */
@@ -1,4 +1,4 @@
1
- export { resolveInbound, type InboundResult, type InboundContext, } from "./inbound";
1
+ export { resolveInbound, type InboundResult, type InboundContext, resolveInboundFromRequest, } from "./inbound";
2
2
  export { localizePathname, type LocalizedPathname } from "./pathname";
3
3
  export { getLocaleFromAcceptLanguage, getLocaleFromPathname, getLocaleFromHost, getLocaleFromQuery, } from "./locale";
4
4
  export { resolveOutbound, type OutboundResult } from "./outbound";
@@ -1,9 +1,8 @@
1
- import type { TranslatorInstanceServer } from "../translator/translator-instance";
2
1
  import type { IntorResolvedConfig } from "../../config";
3
- import type { Locale, LocalizedPreKey, TranslateHandlers, TranslateHook, TranslatorPlugin } from "intor-translator";
4
- import { type GenConfigKeys, type GenMessages, type GenReplacements, type GenRich, type MessagesReaders, type RuntimeFetch } from "../../core";
5
- export interface GetTranslatorParams {
6
- locale: Locale;
2
+ import type { LocalizedPreKey, TranslateHandlers, TranslateHook, TranslatorPlugin } from "intor-translator";
3
+ import { type GenConfigKeys, type GenLocale, type GenMessages, type GenReplacements, type GenRich, type MessagesReaders, type RuntimeFetch, type TranslatorInstance } from "../../core";
4
+ export interface GetTranslatorParams<CK extends GenConfigKeys = "__default__"> {
5
+ locale: GenLocale<CK> | (string & {});
7
6
  readers?: MessagesReaders;
8
7
  allowCacheWrite?: boolean;
9
8
  fetch?: RuntimeFetch;
@@ -13,7 +12,6 @@ export interface GetTranslatorParams {
13
12
  /**
14
13
  * Get a server-side translator for the current execution context.
15
14
  */
16
- export declare function getTranslator<CK extends GenConfigKeys = "__default__", ReplacementSchema = GenReplacements<CK>, RichSchema = GenRich<CK>>(config: IntorResolvedConfig, params: GetTranslatorParams): Promise<TranslatorInstanceServer<GenMessages<CK>, ReplacementSchema, RichSchema, undefined>>;
17
- export declare function getTranslator<CK extends GenConfigKeys = "__default__", ReplacementSchema = GenReplacements<CK>, RichSchema = GenRich<CK>, PK extends string = LocalizedPreKey<GenMessages<CK>>>(config: IntorResolvedConfig, params: GetTranslatorParams & {
15
+ export declare function getTranslator<CK extends GenConfigKeys = "__default__", ReplacementSchema = GenReplacements<CK>, RichSchema = GenRich<CK>, PK extends LocalizedPreKey<GenMessages<CK>> | undefined = undefined>(config: IntorResolvedConfig, params: GetTranslatorParams<CK> & {
18
16
  preKey?: PK;
19
- }): Promise<TranslatorInstanceServer<GenMessages<CK>, ReplacementSchema, RichSchema, PK>>;
17
+ }): Promise<TranslatorInstance<GenMessages<CK>, ReplacementSchema, RichSchema, PK>>;
@@ -1,5 +1,3 @@
1
1
  export { intor, type IntorValue } from "./intor";
2
2
  export { loadMessages, clearMessagesPool } from "./messages";
3
- export { type TranslatorInstanceServer } from "./translator";
4
3
  export { getTranslator, type GetTranslatorParams } from "./helpers";
5
- export { parseCookieHeader } from "./shared/utils";
@@ -1,2 +1 @@
1
- export { initTranslator, type InitTranslatorOptions, } from "../translator/init-translator";
2
- export type { TranslatorInstanceServer } from "./translator-instance";
1
+ export { initTranslator } from "../translator/init-translator";
@@ -1,8 +1,8 @@
1
1
  import type { IntorResolvedConfig } from "../../config";
2
2
  import type { Locale, Translator } from "intor-translator";
3
+ import { type CreateTranslatorParams } from "../../core";
3
4
  import { type LoadMessagesParams } from "../messages";
4
- import { type CreateTranslatorParams } from "./create-translator";
5
- export interface InitTranslatorOptions extends Pick<LoadMessagesParams, "readers" | "allowCacheWrite" | "fetch">, Pick<CreateTranslatorParams, "handlers" | "plugins"> {
5
+ interface InitTranslatorOptions extends Pick<LoadMessagesParams, "readers" | "allowCacheWrite" | "fetch">, Pick<CreateTranslatorParams, "handlers" | "plugins"> {
6
6
  }
7
7
  /**
8
8
  * Initialize a locale-bound Translator snapshot.
@@ -11,3 +11,4 @@ export interface InitTranslatorOptions extends Pick<LoadMessagesParams, "readers
11
11
  * - Creates an immutable Translator instance for server usage
12
12
  */
13
13
  export declare function initTranslator(config: IntorResolvedConfig, locale: Locale, options: InitTranslatorOptions): Promise<Translator<unknown>>;
14
+ export {};
@@ -7,13 +7,7 @@ import { detectBrowserLocale } from '../utils/locale/detect-browser-locale.js';
7
7
  import { getLocaleFromCookie } from '../utils/locale/get-locale-from-cookie.js';
8
8
 
9
9
  /**
10
- * Resolve the locale in a client-only environment.
11
- *
12
- * This helper is intended for pure CSR setups (e.g. Vite).
13
- *
14
- * For framework-based apps, prefer `useTranslator()`.
15
- *
16
- * - Client-side only
10
+ * Resolve the active locale in a pure client-side environment.
17
11
  */
18
12
  function getClientLocale(config) {
19
13
  const { defaultLocale, supportedLocales, cookie } = config;
@@ -3,7 +3,11 @@ import '../provider/intor-provider.js';
3
3
  import { injectIntor } from '../provider/inject.js';
4
4
  import { createTRich } from './create-t-rich.js';
5
5
 
6
- // Implementation
6
+ /**
7
+ * Vue composable for accessing the active, scope-aware translator instance.
8
+ *
9
+ * @platform Vue
10
+ */
7
11
  function useTranslator(preKey) {
8
12
  const intor = injectIntor();
9
13
  const translator = intor.value.translator;
@@ -16,10 +20,6 @@ function useTranslator(preKey) {
16
20
  hasKey: (...args) => scoped.value.hasKey(...args),
17
21
  t: (...args) => scoped.value.t(...args),
18
22
  tRich: (...args) => createTRich(scoped.value.t)(...args),
19
- // NOTE:
20
- // The runtime implementation is intentionally erased.
21
- // Type safety is guaranteed by public type contracts.
22
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
23
23
  };
24
24
  }
25
25
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "intor",
3
- "version": "2.3.35",
3
+ "version": "2.4.1",
4
4
  "description": "The i18n library for modern JavaScript",
5
5
  "author": "Yiming Liao",
6
6
  "homepage": "https://github.com/yiming-liao/intor#readme",
@@ -42,6 +42,10 @@
42
42
  "require": "./dist/core/export/server/index.js",
43
43
  "default": "./dist/core/export/server/index.js"
44
44
  },
45
+ "./edge": {
46
+ "import": "./dist/core/export/edge/index.js",
47
+ "types": "./dist/types/export/edge/index.d.ts"
48
+ },
45
49
  "./internal": {
46
50
  "types": "./dist/types/export/internal/index.d.ts"
47
51
  },
@@ -78,6 +82,16 @@
78
82
  "types": "./dist/types/export/express/index.d.ts",
79
83
  "require": "./dist/express/export/express/index.js",
80
84
  "default": "./dist/express/export/express/index.js"
85
+ },
86
+ "./fastify": {
87
+ "import": "./dist/fastify/export/fastify/index.js",
88
+ "types": "./dist/types/export/fastify/index.d.ts",
89
+ "require": "./dist/fastify/export/fastify/index.js",
90
+ "default": "./dist/fastify/export/fastify/index.js"
91
+ },
92
+ "./hono": {
93
+ "import": "./dist/hono/export/hono/index.js",
94
+ "types": "./dist/types/export/hono/index.d.ts"
81
95
  }
82
96
  },
83
97
  "main": "./dist/core/export/index.js",
@@ -132,6 +146,9 @@
132
146
  "eslint-plugin-react-hooks": "7.0.1",
133
147
  "eslint-plugin-unicorn": "62.0.0",
134
148
  "eslint-plugin-unused-imports": "4.1.4",
149
+ "fastify": "^5.7.4",
150
+ "fastify-plugin": "^5.1.0",
151
+ "hono": "^4.11.8",
135
152
  "jsdom": "27.3.0",
136
153
  "knip": "5.69.1",
137
154
  "magic-string": "0.30.21",
@@ -1 +0,0 @@
1
- export { resolvePathname } from "./resolve-pathname";
@@ -1,5 +0,0 @@
1
- import type { PathnameDirective } from "../types";
2
- /**
3
- * Resolve pathname decision for routing prefix strategy: "none".
4
- */
5
- export declare function none(): PathnameDirective;
@@ -1 +0,0 @@
1
- export { parseCookieHeader } from "./parse-cookie-header";
@@ -1,10 +0,0 @@
1
- import type { HtmlTagRenderers, TranslatorInstance } from "../../core";
2
- import { type Locale, type LocaleMessages, type LocalizedKey, type LocalizedReplacement, type LocalizedRich, type Replacement, type Rich, type ScopedKey } from "intor-translator";
3
- export type TranslatorInstanceServer<M extends LocaleMessages, ReplacementSchema = Replacement, RichSchema = Rich, PK extends string | undefined = undefined> = TranslatorInstance<M, ReplacementSchema, PK> & {
4
- /** `messages`: The message object containing all translations. */
5
- messages: M;
6
- /** Current locale in use. */
7
- locale: Locale<M>;
8
- /** Translate a key into an HTML string using semantic rich tags. */
9
- tRich: <K extends string = PK extends string ? ScopedKey<M, PK> : LocalizedKey<M>, RI = LocalizedRich<RichSchema, K>, RE = LocalizedReplacement<ReplacementSchema, K>>(key?: K | (string & {}), tagRenderers?: HtmlTagRenderers<RI> | HtmlTagRenderers, replacements?: RE | Replacement) => string;
10
- };