intor-translator 1.4.13 → 1.4.14
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 -11
- package/dist/index.d.cts +4 -2
- package/dist/index.d.ts +4 -2
- package/package.json +4 -3
package/README.md
CHANGED
|
@@ -1,16 +1,12 @@
|
|
|
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)
|
|
@@ -19,9 +15,9 @@ Easy to use, modular at its core, and fully extensible.
|
|
|
19
15
|
|
|
20
16
|
## Features
|
|
21
17
|
|
|
22
|
-
-
|
|
23
|
-
-
|
|
24
|
-
-
|
|
18
|
+
- **Modular Pipeline** – A pluggable, hook-driven flow for any translation logic.
|
|
19
|
+
- **Typed Autocomplete** – Inferred keys and locales with precise, reliable completion.
|
|
20
|
+
- **Framework-Agnostic** – A lightweight engine that runs anywhere in JavaScript.
|
|
25
21
|
|
|
26
22
|
## Installation
|
|
27
23
|
|
|
@@ -94,7 +90,7 @@ Hooks run through the pipeline and can intercept any stage, use them to:
|
|
|
94
90
|
|
|
95
91
|
---
|
|
96
92
|
|
|
97
|
-
|
|
93
|
+
## Rich Message Processing
|
|
98
94
|
|
|
99
95
|
This module provides a semantic message processing flow for **_translated rich-formatted strings_**.
|
|
100
96
|
|
|
@@ -107,3 +103,5 @@ Read the documentation: [Message Processing ↗](https://github.com/yiming-liao/
|
|
|
107
103
|
|
|
108
104
|
**_For more advanced usage, see the full examples._**
|
|
109
105
|
[View examples ↗](https://github.com/yiming-liao/intor-translator/tree/main/examples)
|
|
106
|
+
|
|
107
|
+
**_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.
|
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.
|
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.14",
|
|
4
|
+
"description": "The Intor translation engine",
|
|
5
5
|
"author": {
|
|
6
6
|
"name": "Yiming Liao",
|
|
7
7
|
"email": "yimingliao.official@gmail.com",
|
|
@@ -59,7 +59,8 @@
|
|
|
59
59
|
"build": "tsup",
|
|
60
60
|
"prepublishOnly": "yarn build",
|
|
61
61
|
"examples:html": "vite --config examples/html/basic/vite.config.ts",
|
|
62
|
-
"examples:html:rich-message": "vite --config examples/html/rich-message/vite.config.ts"
|
|
62
|
+
"examples:html:rich-message": "vite --config examples/html/rich-message/vite.config.ts",
|
|
63
|
+
"bench:runtime": "tsx bench/runtime/index.ts"
|
|
63
64
|
},
|
|
64
65
|
"dependencies": {
|
|
65
66
|
"rura": "^1.0.8"
|