intor-translator 1.4.13 → 1.4.15
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 +14 -11
- package/dist/index.d.cts +5 -3
- package/dist/index.d.ts +5 -3
- package/package.json +8 -5
package/README.md
CHANGED
|
@@ -1,27 +1,28 @@
|
|
|
1
1
|
<h1 align="center">Intor Translator</h1>
|
|
2
2
|
|
|
3
|
-
<
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
Easy to use, modular at its core, and fully extensible.
|
|
7
|
-
|
|
8
|
-
</div>
|
|
3
|
+
<p align="center">
|
|
4
|
+
The <a href="https://github.com/yiming-liao/intor">Intor</a> translation engine
|
|
5
|
+
</p>
|
|
9
6
|
|
|
10
7
|
<div align="center">
|
|
11
8
|
|
|
12
9
|
[](https://www.npmjs.com/package/intor-translator)
|
|
13
|
-
[](https://bundlephobia.com/package/intor-translator)
|
|
14
10
|
[](https://coveralls.io/github/yiming-liao/intor-translator?branch=main)
|
|
15
11
|
[](https://www.typescriptlang.org/)
|
|
16
12
|
[](LICENSE)
|
|
17
13
|
|
|
18
14
|
</div>
|
|
19
15
|
|
|
16
|
+
> [!NOTE]
|
|
17
|
+
> intor-translator is the execution core of the Intor ecosystem.
|
|
18
|
+
> It provides deterministic translation resolution and rendering,
|
|
19
|
+
> without coupling to routing, configuration systems, or frameworks.
|
|
20
|
+
|
|
20
21
|
## Features
|
|
21
22
|
|
|
22
|
-
-
|
|
23
|
-
-
|
|
24
|
-
-
|
|
23
|
+
- **Modular Pipeline** – A pluggable, hook-driven flow for any translation logic.
|
|
24
|
+
- **Typed Autocomplete** – Inferred keys and locales with precise, reliable completion.
|
|
25
|
+
- **Framework-Agnostic** – A lightweight engine that runs anywhere in JavaScript.
|
|
25
26
|
|
|
26
27
|
## Installation
|
|
27
28
|
|
|
@@ -94,7 +95,7 @@ Hooks run through the pipeline and can intercept any stage, use them to:
|
|
|
94
95
|
|
|
95
96
|
---
|
|
96
97
|
|
|
97
|
-
|
|
98
|
+
## Rich Message Processing
|
|
98
99
|
|
|
99
100
|
This module provides a semantic message processing flow for **_translated rich-formatted strings_**.
|
|
100
101
|
|
|
@@ -107,3 +108,5 @@ Read the documentation: [Message Processing ↗](https://github.com/yiming-liao/
|
|
|
107
108
|
|
|
108
109
|
**_For more advanced usage, see the full examples._**
|
|
109
110
|
[View examples ↗](https://github.com/yiming-liao/intor-translator/tree/main/examples)
|
|
111
|
+
|
|
112
|
+
**_See full benchmark details:_** [bench ↗](https://github.com/yiming-liao/intor-translator/tree/main/bench)
|
package/dist/index.d.cts
CHANGED
|
@@ -126,6 +126,8 @@ type AtPath<MessageSchema, PK extends string> = PK extends `${infer Head}.${infe
|
|
|
126
126
|
type IfLocaleMessages<T, Then, Else> = T extends LocaleMessages ? Then : Else;
|
|
127
127
|
/** Narrows a type to `MessageObject`, otherwise resolves to never. */
|
|
128
128
|
type IfMessageObject<T> = T extends MessageObject ? T : never;
|
|
129
|
+
/** Detects whether `M` is the generic runtime `LocaleMessages` type. */
|
|
130
|
+
type IsRuntime<M> = [M] extends [LocaleMessages] ? [LocaleMessages] extends [M] ? true : false : false;
|
|
129
131
|
|
|
130
132
|
/**
|
|
131
133
|
* Dot-separated leaf keys derived from a single message object.
|
|
@@ -191,7 +193,7 @@ type Value<M, K extends string> = K extends `${infer Head}.${infer Tail}` ? Head
|
|
|
191
193
|
* LocalizedValue<{ en: { a: { b: { c: string }; z: string } } }, "a.b.c">; // => string
|
|
192
194
|
* ```
|
|
193
195
|
*/
|
|
194
|
-
type LocalizedValue<M, K extends string> =
|
|
196
|
+
type LocalizedValue<M, K extends string> = IsRuntime<M> extends true ? string : M extends LocaleMessages ? Value<M[keyof M], K> : never;
|
|
195
197
|
/**
|
|
196
198
|
* Value resolved under a scoped prefix key.
|
|
197
199
|
*
|
|
@@ -200,7 +202,7 @@ type LocalizedValue<M, K extends string> = IfLocaleMessages<M, Value<M[keyof M],
|
|
|
200
202
|
* ScopedValue<{ en: { a: { b: { c: string }; z: string } } }, "a", "b.c">; // => string
|
|
201
203
|
* ```
|
|
202
204
|
*/
|
|
203
|
-
type ScopedValue<M, PK extends string, K extends string> =
|
|
205
|
+
type ScopedValue<M, PK extends string, K extends string> = IsRuntime<M> extends true ? string : M extends LocaleMessages ? Value<AtPath<M[keyof M], PK>, K> : never;
|
|
204
206
|
|
|
205
207
|
/**
|
|
206
208
|
* Generic replacement object used when no schema is available.
|
|
@@ -567,4 +569,4 @@ interface Renderer<Output> {
|
|
|
567
569
|
*/
|
|
568
570
|
declare function renderRichMessage<Output>(message: MessageValue, renderer: Renderer<Output>): Output[];
|
|
569
571
|
|
|
570
|
-
export { type
|
|
572
|
+
export { type FallbackLocalesMap, type FormatHandler, type HandlerContext, type LoadingHandler, type Locale, type LocaleMessages, type LocalizedKey, type LocalizedPreKey, type LocalizedReplacement, type LocalizedRich, type LocalizedValue, type MessageObject, type MessageValue, type MissingHandler, type Renderer, type Replacement, type Rich, type ScopedKey, type ScopedReplacement, type ScopedRich, type ScopedValue, type Token, type TranslateConfig, type TranslateContext, type TranslateHandlers, type TranslateHook, ScopeTranslator as Translator, type ScopeTranslatorMethods as TranslatorMethods, type ScopeTranslatorOptions as TranslatorOptions, type TranslatorPlugin, parseRichMessage, renderRichMessage, tokenize };
|
package/dist/index.d.ts
CHANGED
|
@@ -126,6 +126,8 @@ type AtPath<MessageSchema, PK extends string> = PK extends `${infer Head}.${infe
|
|
|
126
126
|
type IfLocaleMessages<T, Then, Else> = T extends LocaleMessages ? Then : Else;
|
|
127
127
|
/** Narrows a type to `MessageObject`, otherwise resolves to never. */
|
|
128
128
|
type IfMessageObject<T> = T extends MessageObject ? T : never;
|
|
129
|
+
/** Detects whether `M` is the generic runtime `LocaleMessages` type. */
|
|
130
|
+
type IsRuntime<M> = [M] extends [LocaleMessages] ? [LocaleMessages] extends [M] ? true : false : false;
|
|
129
131
|
|
|
130
132
|
/**
|
|
131
133
|
* Dot-separated leaf keys derived from a single message object.
|
|
@@ -191,7 +193,7 @@ type Value<M, K extends string> = K extends `${infer Head}.${infer Tail}` ? Head
|
|
|
191
193
|
* LocalizedValue<{ en: { a: { b: { c: string }; z: string } } }, "a.b.c">; // => string
|
|
192
194
|
* ```
|
|
193
195
|
*/
|
|
194
|
-
type LocalizedValue<M, K extends string> =
|
|
196
|
+
type LocalizedValue<M, K extends string> = IsRuntime<M> extends true ? string : M extends LocaleMessages ? Value<M[keyof M], K> : never;
|
|
195
197
|
/**
|
|
196
198
|
* Value resolved under a scoped prefix key.
|
|
197
199
|
*
|
|
@@ -200,7 +202,7 @@ type LocalizedValue<M, K extends string> = IfLocaleMessages<M, Value<M[keyof M],
|
|
|
200
202
|
* ScopedValue<{ en: { a: { b: { c: string }; z: string } } }, "a", "b.c">; // => string
|
|
201
203
|
* ```
|
|
202
204
|
*/
|
|
203
|
-
type ScopedValue<M, PK extends string, K extends string> =
|
|
205
|
+
type ScopedValue<M, PK extends string, K extends string> = IsRuntime<M> extends true ? string : M extends LocaleMessages ? Value<AtPath<M[keyof M], PK>, K> : never;
|
|
204
206
|
|
|
205
207
|
/**
|
|
206
208
|
* Generic replacement object used when no schema is available.
|
|
@@ -567,4 +569,4 @@ interface Renderer<Output> {
|
|
|
567
569
|
*/
|
|
568
570
|
declare function renderRichMessage<Output>(message: MessageValue, renderer: Renderer<Output>): Output[];
|
|
569
571
|
|
|
570
|
-
export { type
|
|
572
|
+
export { type FallbackLocalesMap, type FormatHandler, type HandlerContext, type LoadingHandler, type Locale, type LocaleMessages, type LocalizedKey, type LocalizedPreKey, type LocalizedReplacement, type LocalizedRich, type LocalizedValue, type MessageObject, type MessageValue, type MissingHandler, type Renderer, type Replacement, type Rich, type ScopedKey, type ScopedReplacement, type ScopedRich, type ScopedValue, type Token, type TranslateConfig, type TranslateContext, type TranslateHandlers, type TranslateHook, ScopeTranslator as Translator, type ScopeTranslatorMethods as TranslatorMethods, type ScopeTranslatorOptions as TranslatorOptions, type TranslatorPlugin, parseRichMessage, renderRichMessage, tokenize };
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "intor-translator",
|
|
3
|
-
"version": "1.4.
|
|
4
|
-
"description": "
|
|
3
|
+
"version": "1.4.15",
|
|
4
|
+
"description": "The Intor translation engine",
|
|
5
5
|
"author": {
|
|
6
6
|
"name": "Yiming Liao",
|
|
7
7
|
"email": "yimingliao.official@gmail.com",
|
|
@@ -26,7 +26,8 @@
|
|
|
26
26
|
"typescript",
|
|
27
27
|
"type-safe",
|
|
28
28
|
"i18n engine",
|
|
29
|
-
"translator"
|
|
29
|
+
"translator",
|
|
30
|
+
"intor"
|
|
30
31
|
],
|
|
31
32
|
"license": "MIT",
|
|
32
33
|
"type": "module",
|
|
@@ -47,7 +48,7 @@
|
|
|
47
48
|
],
|
|
48
49
|
"sideEffects": false,
|
|
49
50
|
"engines": {
|
|
50
|
-
"node": ">=
|
|
51
|
+
"node": ">=20"
|
|
51
52
|
},
|
|
52
53
|
"scripts": {
|
|
53
54
|
"type": "tsc --noEmit",
|
|
@@ -59,7 +60,8 @@
|
|
|
59
60
|
"build": "tsup",
|
|
60
61
|
"prepublishOnly": "yarn build",
|
|
61
62
|
"examples:html": "vite --config examples/html/basic/vite.config.ts",
|
|
62
|
-
"examples:html:rich-message": "vite --config examples/html/rich-message/vite.config.ts"
|
|
63
|
+
"examples:html:rich-message": "vite --config examples/html/rich-message/vite.config.ts",
|
|
64
|
+
"bench:runtime": "tsx bench/runtime/index.ts"
|
|
63
65
|
},
|
|
64
66
|
"dependencies": {
|
|
65
67
|
"rura": "^1.0.8"
|
|
@@ -80,6 +82,7 @@
|
|
|
80
82
|
"ts-node": "10.9.2",
|
|
81
83
|
"tsd": "0.33.0",
|
|
82
84
|
"tsup": "8.4.0",
|
|
85
|
+
"tsx": "^4.21.0",
|
|
83
86
|
"typescript": "5.8.3",
|
|
84
87
|
"typescript-eslint": "8.46.4",
|
|
85
88
|
"vite": "7.2.6",
|