intor 2.4.0 → 2.4.2

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 CHANGED
@@ -19,3 +19,12 @@ The i18n library for modern JavaScript
19
19
  #### [![Documentation ↗](https://img.shields.io/badge/%20Documentation%20%F0%9F%93%9A%20-3e668c?style=for-the-badge)](https://intor-doc.pages.dev/en-US/frameworks)
20
20
 
21
21
  </div>
22
+
23
+ > Intor began as an internal i18n tool.
24
+ >
25
+ > After multiple private iterations, it evolved into a minimal,
26
+ > framework-agnostic translation system.
27
+ >
28
+ > **v3 marks its first intentional public release.**
29
+ >
30
+ > _Currently available as v2.x. v3 is in active development._
@@ -43,11 +43,13 @@ function createIntorHandler(config, options) {
43
43
  readers: options?.readers,
44
44
  allowCacheWrite: true,
45
45
  });
46
- // DX shortcuts (optional)
47
- req.locale = locale;
48
- req.hasKey = hasKey;
49
- req.t = t;
50
- req.tRich = tRich;
46
+ // DX shortcuts (enabled by default)
47
+ if (options?.shortcuts !== false) {
48
+ req.locale = locale;
49
+ req.hasKey = hasKey;
50
+ req.t = t;
51
+ req.tRich = tRich;
52
+ }
51
53
  return next();
52
54
  };
53
55
  }
@@ -43,11 +43,13 @@ function createIntorHandler(config, options) {
43
43
  readers: options?.readers,
44
44
  allowCacheWrite: true,
45
45
  });
46
- // DX shortcuts (optional)
47
- request.locale = locale;
48
- request.hasKey = hasKey;
49
- request.t = t;
50
- request.tRich = tRich;
46
+ // DX shortcuts (enabled by default)
47
+ if (options?.shortcuts !== false) {
48
+ request.locale = locale;
49
+ request.hasKey = hasKey;
50
+ request.t = t;
51
+ request.tRich = tRich;
52
+ }
51
53
  };
52
54
  }
53
55
 
@@ -18,7 +18,7 @@ function intorFastifyPlugin(fastify, options) {
18
18
  // --------------------------------------------------
19
19
  // Bind inbound handler
20
20
  // --------------------------------------------------
21
- fastify.addHook("onRequest", createIntorHandler(config, { handlers, plugins, readers }));
21
+ fastify.addHook("onRequest", createIntorHandler(config, { handlers, plugins, readers, shortcuts }));
22
22
  }
23
23
  /** Fastify plugin metadata (without fastify-plugin) */
24
24
  intorFastifyPlugin[Symbol.for("fastify.display-name")] =
@@ -4,6 +4,7 @@ import { normalizeQuery } from '../../core/utils/normalizers/normalize-query.js'
4
4
  import 'logry';
5
5
  import 'p-limit';
6
6
  import 'intor-translator';
7
+ import { getTranslator } from '../../edge/helpers/get-translator.js';
7
8
  import { resolveInbound } from '../../routing/inbound/resolve-inbound.js';
8
9
  import { getLocaleFromAcceptLanguage } from '../../routing/locale/get-locale-from-accept-language.js';
9
10
 
@@ -14,7 +15,7 @@ import { getLocaleFromAcceptLanguage } from '../../routing/locale/get-locale-fro
14
15
  *
15
16
  * @platform Hono
16
17
  */
17
- function createIntorHandler(config) {
18
+ function createIntorHandler(config, options) {
18
19
  return async function intorHandler(c, next) {
19
20
  // Locale from Accept-Language header
20
21
  const acceptLanguage = c.req.header("accept-language");
@@ -33,6 +34,18 @@ function createIntorHandler(config) {
33
34
  // Bind inbound routing context
34
35
  // --------------------------------------------------
35
36
  c.set("intor", { locale, localeSource, pathname });
37
+ const { hasKey, t, tRich } = await getTranslator(config, {
38
+ locale,
39
+ handlers: options?.handlers,
40
+ plugins: options?.plugins,
41
+ });
42
+ // DX shortcuts (enabled by default)
43
+ if (options?.shortcuts !== false) {
44
+ c.set("locale", locale);
45
+ c.set("hasKey", hasKey);
46
+ c.set("t", t);
47
+ c.set("tRich", tRich);
48
+ }
36
49
  await next();
37
50
  };
38
51
  }
@@ -1,5 +1,4 @@
1
1
  export { createIntorStore } from '../../src/client/svelte/provider/create-intor-store.js';
2
- export { default as IntorProvider } from '../../src/client/svelte/provider/intor-provider.svelte';
3
2
  export { useIntorContext } from '../../src/client/svelte/provider/use-intor-context.js';
4
3
  export { useTranslator } from '../../src/client/svelte/translator/use-translator.js';
5
4
  export { getClientLocale } from '../../src/client/shared/helpers/get-client-locale.js';
@@ -5,7 +5,6 @@ import 'p-limit';
5
5
  import 'intor-translator';
6
6
  import { createTRich } from '../../../core/translator/create-t-rich.js';
7
7
  import 'svelte';
8
- import '../provider/intor-provider.svelte';
9
8
  import { useIntorContext } from '../provider/use-intor-context.js';
10
9
 
11
10
  /**
@@ -1,3 +1,3 @@
1
1
  export { createIntorStore, // @internal
2
- IntorProvider, type IntorProviderProps, useIntorContext, // @internal
2
+ type IntorProviderProps, useIntorContext, // @internal
3
3
  useTranslator, getClientLocale, } from "../../src/client/svelte";
@@ -9,4 +9,6 @@ import { type GetTranslatorParams } from "../../server";
9
9
  *
10
10
  * @platform Express
11
11
  */
12
- export declare function createIntorHandler(config: IntorResolvedConfig, options?: Omit<GetTranslatorParams, "locale" | "fetch" | "allowCacheWrite">): (req: Request, _res: Response, next: NextFunction) => Promise<void>;
12
+ export declare function createIntorHandler(config: IntorResolvedConfig, options?: Omit<GetTranslatorParams, "locale" | "fetch" | "allowCacheWrite"> & {
13
+ shortcuts?: boolean;
14
+ }): (req: Request, _res: Response, next: NextFunction) => Promise<void>;
@@ -1,6 +1,6 @@
1
1
  import type { TranslatorInstance } from "../../core";
2
2
  import type { InboundContext } from "../../routing";
3
- import type { Locale, LocaleMessages } from "intor-translator";
3
+ import type { LocaleMessages } from "intor-translator";
4
4
  /**
5
5
  * Global type augmentations for Express request
6
6
  */
@@ -8,7 +8,7 @@ declare global {
8
8
  namespace Express {
9
9
  interface Request {
10
10
  intor: InboundContext;
11
- locale: Locale;
11
+ locale: TranslatorInstance<LocaleMessages>["locale"];
12
12
  hasKey: TranslatorInstance<LocaleMessages>["hasKey"];
13
13
  t: TranslatorInstance<LocaleMessages>["t"];
14
14
  tRich: TranslatorInstance<LocaleMessages>["tRich"];
@@ -9,4 +9,6 @@ import { type GetTranslatorParams } from "../../server";
9
9
  *
10
10
  * @platform Fastify
11
11
  */
12
- export declare function createIntorHandler(config: IntorResolvedConfig, options?: Omit<GetTranslatorParams, "locale" | "fetch" | "allowCacheWrite">): (request: FastifyRequest) => Promise<void>;
12
+ export declare function createIntorHandler(config: IntorResolvedConfig, options?: Omit<GetTranslatorParams, "locale" | "fetch" | "allowCacheWrite"> & {
13
+ shortcuts?: boolean;
14
+ }): (request: FastifyRequest) => Promise<void>;
@@ -1,14 +1,14 @@
1
1
  import "fastify";
2
2
  import type { TranslatorInstance } from "../../core";
3
3
  import type { InboundContext } from "../../routing";
4
- import type { Locale, LocaleMessages } from "intor-translator";
4
+ import type { LocaleMessages } from "intor-translator";
5
5
  /**
6
6
  * Global type augmentations for Fastify request
7
7
  */
8
8
  declare module "fastify" {
9
9
  interface FastifyRequest {
10
10
  intor: InboundContext;
11
- locale: Locale;
11
+ locale: TranslatorInstance<LocaleMessages>["locale"];
12
12
  hasKey: TranslatorInstance<LocaleMessages>["hasKey"];
13
13
  t: TranslatorInstance<LocaleMessages>["t"];
14
14
  tRich: TranslatorInstance<LocaleMessages>["tRich"];
@@ -1,7 +1,7 @@
1
1
  import type { IntorResolvedConfig } from "../../config";
2
2
  import type { GetTranslatorParams } from "../../server";
3
3
  import type { FastifyInstance } from "fastify";
4
- interface IntorFastifyPluginOptions extends Omit<GetTranslatorParams, "locale"> {
4
+ interface IntorFastifyPluginOptions extends Pick<GetTranslatorParams, "handlers" | "plugins" | "readers"> {
5
5
  config: IntorResolvedConfig;
6
6
  /**
7
7
  * Bind DX shortcuts to request:
@@ -1,5 +1,6 @@
1
1
  import type { IntorResolvedConfig } from "../../config";
2
2
  import type { Context, Next } from "hono";
3
+ import { type GetTranslatorParams } from "../../edge";
3
4
  /**
4
5
  * Resolves locale-aware routing for the current execution context.
5
6
  *
@@ -7,4 +8,6 @@ import type { Context, Next } from "hono";
7
8
  *
8
9
  * @platform Hono
9
10
  */
10
- export declare function createIntorHandler(config: IntorResolvedConfig): (c: Context, next: Next) => Promise<void>;
11
+ export declare function createIntorHandler(config: IntorResolvedConfig, options?: Omit<GetTranslatorParams, "locale" | "fetch"> & {
12
+ shortcuts?: boolean;
13
+ }): (c: Context, next: Next) => Promise<void>;
@@ -1,3 +1,3 @@
1
- export { createIntorStore, IntorProvider, type IntorProviderProps, useIntorContext, } from "./provider";
1
+ export { createIntorStore, type IntorProviderProps, useIntorContext, } from "./provider";
2
2
  export { useTranslator } from "./translator";
3
3
  export { getClientLocale } from "../shared/helpers";
@@ -1,4 +1,3 @@
1
1
  export { createIntorStore } from "./create-intor-store";
2
- export { default as IntorProvider } from "./intor-provider.svelte";
3
2
  export type { IntorValue, IntorProviderProps } from "./types";
4
3
  export { useIntorContext } from "./use-intor-context";
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "intor",
3
- "version": "2.4.0",
3
+ "version": "2.4.2",
4
4
  "description": "The i18n library for modern JavaScript",
5
5
  "author": "Yiming Liao",
6
6
  "homepage": "https://github.com/yiming-liao/intor#readme",
@@ -61,6 +61,10 @@
61
61
  "import": "./dist/svelte/export/svelte/index.js",
62
62
  "types": "./dist/types/export/svelte/index.d.ts"
63
63
  },
64
+ "./svelte/provider": {
65
+ "import": "./dist/svelte/src/client/svelte/provider",
66
+ "types": "./dist/types/export/svelte/index.d.ts"
67
+ },
64
68
  "./next": {
65
69
  "import": "./dist/next/export/next/index.js",
66
70
  "types": "./dist/types/export/next/index.d.ts"