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 +9 -0
- package/dist/express/src/adapters/express/create-intor-handler.js +7 -5
- package/dist/fastify/src/adapters/fastify/create-intor-handler.js +7 -5
- package/dist/fastify/src/adapters/fastify/intor-fastify-plugin.js +1 -1
- package/dist/hono/src/adapters/hono/create-intor-handler.js +14 -1
- package/dist/svelte/export/svelte/index.js +0 -1
- package/dist/svelte/src/client/svelte/translator/use-translator.js +0 -1
- package/dist/types/export/svelte/index.d.ts +1 -1
- package/dist/types/src/adapters/express/create-intor-handler.d.ts +3 -1
- package/dist/types/src/adapters/express/global.d.ts +2 -2
- package/dist/types/src/adapters/fastify/create-intor-handler.d.ts +3 -1
- package/dist/types/src/adapters/fastify/global.d.ts +2 -2
- package/dist/types/src/adapters/fastify/intor-fastify-plugin.d.ts +1 -1
- package/dist/types/src/adapters/hono/create-intor-handler.d.ts +4 -1
- package/dist/types/src/client/svelte/index.d.ts +1 -1
- package/dist/types/src/client/svelte/provider/index.d.ts +0 -1
- package/package.json +5 -1
package/README.md
CHANGED
|
@@ -19,3 +19,12 @@ The i18n library for modern JavaScript
|
|
|
19
19
|
#### [](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 (
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
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 (
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
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';
|
|
@@ -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">
|
|
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 {
|
|
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:
|
|
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">
|
|
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 {
|
|
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:
|
|
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
|
|
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
|
|
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,
|
|
1
|
+
export { createIntorStore, type IntorProviderProps, useIntorContext, } from "./provider";
|
|
2
2
|
export { useTranslator } from "./translator";
|
|
3
3
|
export { getClientLocale } from "../shared/helpers";
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "intor",
|
|
3
|
-
"version": "2.4.
|
|
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"
|