@firsthandjs/i18n 0.7.0 → 0.7.1
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/dist/index.d.ts +8 -8
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +1 -1
- package/package.json +2 -2
package/dist/index.d.ts
CHANGED
|
@@ -26,7 +26,7 @@ import { type Dispose, type ReadonlyCell } from '@firsthandjs/core';
|
|
|
26
26
|
/** A translation function, whatever shape the library gave it. */
|
|
27
27
|
type Translate = (...args: never[]) => unknown;
|
|
28
28
|
/** What a localisation library has to offer to be made reactive. */
|
|
29
|
-
export
|
|
29
|
+
export type Source<T extends Translate> = {
|
|
30
30
|
/** The library's own `t`, untouched — its types are the ones you keep. */
|
|
31
31
|
translate: T;
|
|
32
32
|
/** The language in effect right now, read when something asks. */
|
|
@@ -41,16 +41,16 @@ export interface Source<T extends Translate> {
|
|
|
41
41
|
* never recover.
|
|
42
42
|
*/
|
|
43
43
|
subscribe: (changed: () => void) => Dispose;
|
|
44
|
-
}
|
|
44
|
+
};
|
|
45
45
|
/** A reactive translation function, and the language it is reading. */
|
|
46
|
-
export
|
|
46
|
+
export type Translator<T extends Translate> = {
|
|
47
47
|
/** The same function, with the same types, that now re-runs when it should. */
|
|
48
48
|
t: T;
|
|
49
49
|
/** The current language, as a cell: read it in a part and it stays current. */
|
|
50
50
|
language: ReadonlyCell<string>;
|
|
51
51
|
/** Stops listening. Registered with the enclosing scope, if there is one. */
|
|
52
52
|
dispose: Dispose;
|
|
53
|
-
}
|
|
53
|
+
};
|
|
54
54
|
/**
|
|
55
55
|
* Wraps any translation function so that reading it subscribes.
|
|
56
56
|
*
|
|
@@ -72,7 +72,7 @@ export declare function translator<T extends Translate>(source: Source<T>): Tran
|
|
|
72
72
|
* on i18next, no opinion about its version, and works with anything that looks
|
|
73
73
|
* like it — `createInstance()`, a mock in a test, or a fork.
|
|
74
74
|
*/
|
|
75
|
-
export
|
|
75
|
+
export type I18nextLike<T extends Translate> = {
|
|
76
76
|
t: T;
|
|
77
77
|
language: string;
|
|
78
78
|
on(event: string, handler: () => void): void;
|
|
@@ -86,12 +86,12 @@ export interface I18nextLike<T extends Translate> {
|
|
|
86
86
|
* against the real library rather than against something shaped like it.
|
|
87
87
|
*/
|
|
88
88
|
store?: Emitter;
|
|
89
|
-
}
|
|
89
|
+
};
|
|
90
90
|
/** The part of an event emitter this package uses. */
|
|
91
|
-
export
|
|
91
|
+
export type Emitter = {
|
|
92
92
|
on(event: string, handler: () => void): void;
|
|
93
93
|
off(event: string, handler: () => void): void;
|
|
94
|
-
}
|
|
94
|
+
};
|
|
95
95
|
/** Connects an i18next instance. See {@link translator} for what it does. */
|
|
96
96
|
export declare function fromI18next<T extends Translate>(instance: I18nextLike<T>): Translator<T>;
|
|
97
97
|
export {};
|
package/dist/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;GAuBG;AACH,OAAO,EAKL,KAAK,OAAO,EACZ,KAAK,YAAY,EAClB,MAAM,mBAAmB,CAAC;AAE3B,kEAAkE;AAClE,KAAK,SAAS,GAAG,CAAC,GAAG,IAAI,EAAE,KAAK,EAAE,KAAK,OAAO,CAAC;AAE/C,oEAAoE;AACpE,MAAM,
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;GAuBG;AACH,OAAO,EAKL,KAAK,OAAO,EACZ,KAAK,YAAY,EAClB,MAAM,mBAAmB,CAAC;AAE3B,kEAAkE;AAClE,KAAK,SAAS,GAAG,CAAC,GAAG,IAAI,EAAE,KAAK,EAAE,KAAK,OAAO,CAAC;AAE/C,oEAAoE;AACpE,MAAM,MAAM,MAAM,CAAC,CAAC,SAAS,SAAS,IAAI;IACxC,0EAA0E;I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Q,EAAE,WAAW,CAAC,CAAC,CAAC,GAAG,UAAU,CAAC,CAAC,CAAC,CA4BxF"}
|
package/dist/index.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
import{batch as
|
|
1
|
+
import{batch as g,getOwner as T,onCleanup as u,signal as s}from"@firsthandjs/core";function v(e){let n=s(0),o=s(e.language()),t=e.subscribe(()=>{g(()=>{o.value=e.language(),n.value++})}),i=((...d)=>(n.value,e.translate(...d))),r=()=>{t()};return T()!==null&&u(r),{t:i,language:o,dispose:r}}var a=["languageChanged","loaded"],l=["added","removed"];function p(e){return v({translate:((...n)=>e.t(...n)),language:()=>e.language,subscribe:n=>{let o=e.store;for(let t of a)e.on(t,n);if(o!==void 0)for(let t of l)o.on(t,n);return()=>{for(let t of a)e.off(t,n);if(o!==void 0)for(let t of l)o.off(t,n)}}})}export{p as fromI18next,v as translator};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@firsthandjs/i18n",
|
|
3
|
-
"version": "0.7.
|
|
3
|
+
"version": "0.7.1",
|
|
4
4
|
"description": "Makes i18next (or any translation function) reactive in Firsthand.",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"type": "module",
|
|
@@ -19,7 +19,7 @@
|
|
|
19
19
|
"LICENSE"
|
|
20
20
|
],
|
|
21
21
|
"dependencies": {
|
|
22
|
-
"@firsthandjs/core": "0.7.
|
|
22
|
+
"@firsthandjs/core": "0.7.1"
|
|
23
23
|
},
|
|
24
24
|
"engines": {
|
|
25
25
|
"node": ">=20.11.0"
|