intor-translator 1.2.1 → 1.2.3
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 +6 -0
- package/dist/index.cjs +7 -1
- package/dist/index.d.cts +8 -6
- package/dist/index.d.ts +8 -6
- package/dist/index.js +7 -1
- package/package.json +35 -27
package/README.md
CHANGED
package/dist/index.cjs
CHANGED
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
|
|
3
3
|
var rura = require('rura');
|
|
4
4
|
|
|
5
|
-
// src/
|
|
5
|
+
// src/translators/core-translator/core-translator.ts
|
|
6
6
|
|
|
7
7
|
// src/translators/shared/utils/find-message-in-locales.ts
|
|
8
8
|
var findMessageInLocales = ({
|
|
@@ -275,6 +275,12 @@ var CoreTranslator = class extends BaseTranslator {
|
|
|
275
275
|
}
|
|
276
276
|
this.sortHooks();
|
|
277
277
|
}
|
|
278
|
+
/** Outputs a debug overview of the active pipeline. */
|
|
279
|
+
debugHooks() {
|
|
280
|
+
return rura.rura.createPipeline(this.hooks).debugHooks(
|
|
281
|
+
(hooks) => `\u{1F916} Intor Translator pipeline (${hooks.length} hooks)`
|
|
282
|
+
);
|
|
283
|
+
}
|
|
278
284
|
/** Check if a key exists in the specified locale or current locale. */
|
|
279
285
|
hasKey = (key, targetLocale) => {
|
|
280
286
|
return hasKey({
|
package/dist/index.d.cts
CHANGED
|
@@ -188,7 +188,7 @@ type LeafKeys<M, D extends number = DefaultDepth> = [D] extends [never] ? never
|
|
|
188
188
|
* LocalizedNodeKeys // → string
|
|
189
189
|
* ```
|
|
190
190
|
*/
|
|
191
|
-
type LocalizedNodeKeys<M
|
|
191
|
+
type LocalizedNodeKeys<M = unknown, L extends keyof M | "union" = "union", D extends number = DefaultDepth> = M extends LocaleMessages ? L extends "union" ? NodeKeys<M[keyof M], D> : NodeKeys<M[Extract<L, keyof M>], D> : string;
|
|
192
192
|
/**
|
|
193
193
|
* Extracts all **leaf keys** from the messages
|
|
194
194
|
* of a specified locale (or union of locales).
|
|
@@ -211,7 +211,7 @@ type LocalizedNodeKeys<M extends LocaleMessages | undefined = undefined, L exten
|
|
|
211
211
|
* LocalizedLeafKeys // → string
|
|
212
212
|
* ```
|
|
213
213
|
*/
|
|
214
|
-
type LocalizedLeafKeys<M
|
|
214
|
+
type LocalizedLeafKeys<M = unknown, L extends keyof M | "union" = "union", D extends number = DefaultDepth> = M extends LocaleMessages ? L extends "union" ? LeafKeys<M[keyof M], D> : LeafKeys<M[Extract<L, keyof M>], D> : string;
|
|
215
215
|
|
|
216
216
|
/**
|
|
217
217
|
* Resolves the type at a dot-separated key in a nested object.
|
|
@@ -351,7 +351,7 @@ interface BaseTranslatorOptions<M = unknown> {
|
|
|
351
351
|
*
|
|
352
352
|
* @template M - Shape of the messages object.
|
|
353
353
|
*/
|
|
354
|
-
declare class BaseTranslator<M extends LocaleMessages> {
|
|
354
|
+
declare class BaseTranslator<M extends LocaleMessages | unknown = unknown> {
|
|
355
355
|
/** Current messages for translation */
|
|
356
356
|
protected _messages: Readonly<M>;
|
|
357
357
|
/** Current active locale */
|
|
@@ -400,7 +400,7 @@ interface TranslatorPlugin {
|
|
|
400
400
|
* @template M - Shape of the messages object.
|
|
401
401
|
* @template L - Locale selection strategy ("union" or specific locale keys).
|
|
402
402
|
*/
|
|
403
|
-
declare class CoreTranslator<M extends LocaleMessages, L extends keyof M | "union" = "union"> extends BaseTranslator<M> {
|
|
403
|
+
declare class CoreTranslator<M extends LocaleMessages | unknown = unknown, L extends keyof M | "union" = "union"> extends BaseTranslator<M> {
|
|
404
404
|
/** User-provided options including messages, locale, and config. */
|
|
405
405
|
protected translateConfig: TranslateConfig<M>;
|
|
406
406
|
/** Active pipeline hooks applied during translation. */
|
|
@@ -410,6 +410,8 @@ declare class CoreTranslator<M extends LocaleMessages, L extends keyof M | "unio
|
|
|
410
410
|
private sortHooks;
|
|
411
411
|
/** Register a plugin or a raw pipeline hook. */
|
|
412
412
|
use(plugin: TranslatorPlugin | TranslateHook): void;
|
|
413
|
+
/** Outputs a debug overview of the active pipeline. */
|
|
414
|
+
debugHooks(): void;
|
|
413
415
|
/** Check if a key exists in the specified locale or current locale. */
|
|
414
416
|
hasKey: <K extends LocalizedLeafKeys<M, L>>(key: K, targetLocale?: Locale<M>) => boolean;
|
|
415
417
|
/** Get the translated message for a key, with optional replacements. */
|
|
@@ -417,12 +419,12 @@ declare class CoreTranslator<M extends LocaleMessages, L extends keyof M | "unio
|
|
|
417
419
|
}
|
|
418
420
|
|
|
419
421
|
type ScopeTranslatorOptions<M> = CoreTranslatorOptions<M>;
|
|
420
|
-
type ScopeTranslatorMethods<M extends LocaleMessages |
|
|
422
|
+
type ScopeTranslatorMethods<M extends LocaleMessages | unknown = unknown, L extends keyof M | "union" = "union", K = LocalizedLeafKeys<M, L>> = {
|
|
421
423
|
hasKey: (key?: K, targetLocale?: Locale<M>) => boolean;
|
|
422
424
|
t: <Result = string>(key?: K, replacements?: Replacement) => Result;
|
|
423
425
|
};
|
|
424
426
|
|
|
425
|
-
declare class ScopeTranslator<M extends LocaleMessages, L extends keyof M | "union" = "union"> extends CoreTranslator<M> {
|
|
427
|
+
declare class ScopeTranslator<M extends LocaleMessages | unknown = unknown, L extends keyof M | "union" = "union"> extends CoreTranslator<M> {
|
|
426
428
|
constructor(options: ScopeTranslatorOptions<M>);
|
|
427
429
|
/** Create a scoped translator with a prefix key, providing `t` and `hasKey` for nested keys. */
|
|
428
430
|
scoped<PK extends LocalizedNodeKeys<M, L> | undefined = undefined>(preKey?: PK): PK extends string ? ScopeTranslatorMethods<M, L, ScopedLeafKeys<M, PK, L>> : ScopeTranslatorMethods<M, L>;
|
package/dist/index.d.ts
CHANGED
|
@@ -188,7 +188,7 @@ type LeafKeys<M, D extends number = DefaultDepth> = [D] extends [never] ? never
|
|
|
188
188
|
* LocalizedNodeKeys // → string
|
|
189
189
|
* ```
|
|
190
190
|
*/
|
|
191
|
-
type LocalizedNodeKeys<M
|
|
191
|
+
type LocalizedNodeKeys<M = unknown, L extends keyof M | "union" = "union", D extends number = DefaultDepth> = M extends LocaleMessages ? L extends "union" ? NodeKeys<M[keyof M], D> : NodeKeys<M[Extract<L, keyof M>], D> : string;
|
|
192
192
|
/**
|
|
193
193
|
* Extracts all **leaf keys** from the messages
|
|
194
194
|
* of a specified locale (or union of locales).
|
|
@@ -211,7 +211,7 @@ type LocalizedNodeKeys<M extends LocaleMessages | undefined = undefined, L exten
|
|
|
211
211
|
* LocalizedLeafKeys // → string
|
|
212
212
|
* ```
|
|
213
213
|
*/
|
|
214
|
-
type LocalizedLeafKeys<M
|
|
214
|
+
type LocalizedLeafKeys<M = unknown, L extends keyof M | "union" = "union", D extends number = DefaultDepth> = M extends LocaleMessages ? L extends "union" ? LeafKeys<M[keyof M], D> : LeafKeys<M[Extract<L, keyof M>], D> : string;
|
|
215
215
|
|
|
216
216
|
/**
|
|
217
217
|
* Resolves the type at a dot-separated key in a nested object.
|
|
@@ -351,7 +351,7 @@ interface BaseTranslatorOptions<M = unknown> {
|
|
|
351
351
|
*
|
|
352
352
|
* @template M - Shape of the messages object.
|
|
353
353
|
*/
|
|
354
|
-
declare class BaseTranslator<M extends LocaleMessages> {
|
|
354
|
+
declare class BaseTranslator<M extends LocaleMessages | unknown = unknown> {
|
|
355
355
|
/** Current messages for translation */
|
|
356
356
|
protected _messages: Readonly<M>;
|
|
357
357
|
/** Current active locale */
|
|
@@ -400,7 +400,7 @@ interface TranslatorPlugin {
|
|
|
400
400
|
* @template M - Shape of the messages object.
|
|
401
401
|
* @template L - Locale selection strategy ("union" or specific locale keys).
|
|
402
402
|
*/
|
|
403
|
-
declare class CoreTranslator<M extends LocaleMessages, L extends keyof M | "union" = "union"> extends BaseTranslator<M> {
|
|
403
|
+
declare class CoreTranslator<M extends LocaleMessages | unknown = unknown, L extends keyof M | "union" = "union"> extends BaseTranslator<M> {
|
|
404
404
|
/** User-provided options including messages, locale, and config. */
|
|
405
405
|
protected translateConfig: TranslateConfig<M>;
|
|
406
406
|
/** Active pipeline hooks applied during translation. */
|
|
@@ -410,6 +410,8 @@ declare class CoreTranslator<M extends LocaleMessages, L extends keyof M | "unio
|
|
|
410
410
|
private sortHooks;
|
|
411
411
|
/** Register a plugin or a raw pipeline hook. */
|
|
412
412
|
use(plugin: TranslatorPlugin | TranslateHook): void;
|
|
413
|
+
/** Outputs a debug overview of the active pipeline. */
|
|
414
|
+
debugHooks(): void;
|
|
413
415
|
/** Check if a key exists in the specified locale or current locale. */
|
|
414
416
|
hasKey: <K extends LocalizedLeafKeys<M, L>>(key: K, targetLocale?: Locale<M>) => boolean;
|
|
415
417
|
/** Get the translated message for a key, with optional replacements. */
|
|
@@ -417,12 +419,12 @@ declare class CoreTranslator<M extends LocaleMessages, L extends keyof M | "unio
|
|
|
417
419
|
}
|
|
418
420
|
|
|
419
421
|
type ScopeTranslatorOptions<M> = CoreTranslatorOptions<M>;
|
|
420
|
-
type ScopeTranslatorMethods<M extends LocaleMessages |
|
|
422
|
+
type ScopeTranslatorMethods<M extends LocaleMessages | unknown = unknown, L extends keyof M | "union" = "union", K = LocalizedLeafKeys<M, L>> = {
|
|
421
423
|
hasKey: (key?: K, targetLocale?: Locale<M>) => boolean;
|
|
422
424
|
t: <Result = string>(key?: K, replacements?: Replacement) => Result;
|
|
423
425
|
};
|
|
424
426
|
|
|
425
|
-
declare class ScopeTranslator<M extends LocaleMessages, L extends keyof M | "union" = "union"> extends CoreTranslator<M> {
|
|
427
|
+
declare class ScopeTranslator<M extends LocaleMessages | unknown = unknown, L extends keyof M | "union" = "union"> extends CoreTranslator<M> {
|
|
426
428
|
constructor(options: ScopeTranslatorOptions<M>);
|
|
427
429
|
/** Create a scoped translator with a prefix key, providing `t` and `hasKey` for nested keys. */
|
|
428
430
|
scoped<PK extends LocalizedNodeKeys<M, L> | undefined = undefined>(preKey?: PK): PK extends string ? ScopeTranslatorMethods<M, L, ScopedLeafKeys<M, PK, L>> : ScopeTranslatorMethods<M, L>;
|
package/dist/index.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { rura } from 'rura';
|
|
2
2
|
|
|
3
|
-
// src/
|
|
3
|
+
// src/translators/core-translator/core-translator.ts
|
|
4
4
|
|
|
5
5
|
// src/translators/shared/utils/find-message-in-locales.ts
|
|
6
6
|
var findMessageInLocales = ({
|
|
@@ -273,6 +273,12 @@ var CoreTranslator = class extends BaseTranslator {
|
|
|
273
273
|
}
|
|
274
274
|
this.sortHooks();
|
|
275
275
|
}
|
|
276
|
+
/** Outputs a debug overview of the active pipeline. */
|
|
277
|
+
debugHooks() {
|
|
278
|
+
return rura.createPipeline(this.hooks).debugHooks(
|
|
279
|
+
(hooks) => `\u{1F916} Intor Translator pipeline (${hooks.length} hooks)`
|
|
280
|
+
);
|
|
281
|
+
}
|
|
276
282
|
/** Check if a key exists in the specified locale or current locale. */
|
|
277
283
|
hasKey = (key, targetLocale) => {
|
|
278
284
|
return hasKey({
|
package/package.json
CHANGED
|
@@ -1,9 +1,12 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "intor-translator",
|
|
3
|
-
"version": "1.2.
|
|
3
|
+
"version": "1.2.3",
|
|
4
4
|
"description": "🤖 A modern, type-safe i18n engine.",
|
|
5
|
-
"author":
|
|
6
|
-
|
|
5
|
+
"author": {
|
|
6
|
+
"name": "Yiming Liao",
|
|
7
|
+
"email": "yimingliao.official@gmail.com",
|
|
8
|
+
"url": "https://github.com/yiming-liao"
|
|
9
|
+
},
|
|
7
10
|
"homepage": "https://github.com/yiming-liao/intor-translator#readme",
|
|
8
11
|
"repository": {
|
|
9
12
|
"type": "git",
|
|
@@ -12,6 +15,10 @@
|
|
|
12
15
|
"bugs": {
|
|
13
16
|
"url": "https://github.com/yiming-liao/intor-translator/issues"
|
|
14
17
|
},
|
|
18
|
+
"funding": {
|
|
19
|
+
"type": "github",
|
|
20
|
+
"url": "https://github.com/sponsors/yiming-liao"
|
|
21
|
+
},
|
|
15
22
|
"keywords": [
|
|
16
23
|
"i18n",
|
|
17
24
|
"internationalization",
|
|
@@ -21,6 +28,8 @@
|
|
|
21
28
|
"i18n engine",
|
|
22
29
|
"translator"
|
|
23
30
|
],
|
|
31
|
+
"license": "MIT",
|
|
32
|
+
"type": "module",
|
|
24
33
|
"exports": {
|
|
25
34
|
".": {
|
|
26
35
|
"types": "./dist/index.d.ts",
|
|
@@ -36,7 +45,10 @@
|
|
|
36
45
|
"README.md",
|
|
37
46
|
"LICENSE"
|
|
38
47
|
],
|
|
39
|
-
"
|
|
48
|
+
"sideEffects": false,
|
|
49
|
+
"engines": {
|
|
50
|
+
"node": ">=16.0.0"
|
|
51
|
+
},
|
|
40
52
|
"scripts": {
|
|
41
53
|
"build": "tsup",
|
|
42
54
|
"prepublishOnly": "yarn build",
|
|
@@ -47,32 +59,28 @@
|
|
|
47
59
|
"knip": "knip --config .config/knip.config.ts",
|
|
48
60
|
"examples:html": "vite --config examples/html/vite.config.ts"
|
|
49
61
|
},
|
|
50
|
-
"sideEffects": false,
|
|
51
|
-
"engines": {
|
|
52
|
-
"node": ">=16.0.0"
|
|
53
|
-
},
|
|
54
62
|
"dependencies": {
|
|
55
63
|
"rura": "1.0.7"
|
|
56
64
|
},
|
|
57
65
|
"devDependencies": {
|
|
58
|
-
"@types/node": "
|
|
59
|
-
"@vitest/coverage-v8": "4.0.
|
|
60
|
-
"eslint": "
|
|
61
|
-
"eslint-config-prettier": "
|
|
62
|
-
"eslint-import-resolver-typescript": "
|
|
63
|
-
"eslint-plugin-import": "
|
|
64
|
-
"eslint-plugin-prettier": "
|
|
65
|
-
"eslint-plugin-unicorn": "
|
|
66
|
-
"eslint-plugin-unused-imports": "
|
|
67
|
-
"intl-messageformat": "
|
|
68
|
-
"knip": "
|
|
69
|
-
"prettier": "
|
|
70
|
-
"ts-node": "
|
|
71
|
-
"tsd": "
|
|
72
|
-
"tsup": "
|
|
73
|
-
"typescript": "
|
|
74
|
-
"typescript-eslint": "
|
|
75
|
-
"vite": "
|
|
76
|
-
"vitest": "
|
|
66
|
+
"@types/node": "24.10.1",
|
|
67
|
+
"@vitest/coverage-v8": "4.0.16",
|
|
68
|
+
"eslint": "9.39.1",
|
|
69
|
+
"eslint-config-prettier": "10.1.8",
|
|
70
|
+
"eslint-import-resolver-typescript": "4.4.4",
|
|
71
|
+
"eslint-plugin-import": "2.32.0",
|
|
72
|
+
"eslint-plugin-prettier": "5.5.4",
|
|
73
|
+
"eslint-plugin-unicorn": "62.0.0",
|
|
74
|
+
"eslint-plugin-unused-imports": "4.3.0",
|
|
75
|
+
"intl-messageformat": "10.7.16",
|
|
76
|
+
"knip": "5.69.1",
|
|
77
|
+
"prettier": "3.6.2",
|
|
78
|
+
"ts-node": "10.9.2",
|
|
79
|
+
"tsd": "0.33.0",
|
|
80
|
+
"tsup": "8.4.0",
|
|
81
|
+
"typescript": "5.8.3",
|
|
82
|
+
"typescript-eslint": "8.46.4",
|
|
83
|
+
"vite": "7.2.6",
|
|
84
|
+
"vitest": "4.0.16"
|
|
77
85
|
}
|
|
78
86
|
}
|