i18next 25.10.3 → 25.10.5
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/esm/package.json +1 -1
- package/index.d.ts +24 -1
- package/jsr.json +1 -1
- package/package.json +1 -1
- package/typescript/t.d.ts +24 -11
package/dist/esm/package.json
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"type":"module","version":"25.10.
|
|
1
|
+
{"type":"module","version":"25.10.5"}
|
package/index.d.ts
CHANGED
|
@@ -11,8 +11,15 @@ import type {
|
|
|
11
11
|
ResourceKey,
|
|
12
12
|
ResourceLanguage,
|
|
13
13
|
TOptions,
|
|
14
|
+
TypeOptions,
|
|
14
15
|
} from './typescript/options.js';
|
|
15
|
-
import type {
|
|
16
|
+
import type {
|
|
17
|
+
KeyPrefix,
|
|
18
|
+
KeyPrefixSelector,
|
|
19
|
+
TFunction,
|
|
20
|
+
KeyFromSelectorFn,
|
|
21
|
+
SelectorKey,
|
|
22
|
+
} from './typescript/t.js';
|
|
16
23
|
|
|
17
24
|
export interface WithT<Ns extends Namespace = DefaultNamespace> {
|
|
18
25
|
// Expose parameterized t in the i18next interface hierarchy
|
|
@@ -200,11 +207,13 @@ export type Callback = (error: any, t: TFunction) => void;
|
|
|
200
207
|
|
|
201
208
|
/**
|
|
202
209
|
* Uses similar args as the t function and returns true if a key exists.
|
|
210
|
+
* Acts as a type guard, narrowing the key to {@link SelectorKey} so it can be passed to `t()`.
|
|
203
211
|
*/
|
|
204
212
|
export interface ExistsFunction<
|
|
205
213
|
TKeys extends string = string,
|
|
206
214
|
TInterpolationMap extends object = $Dictionary,
|
|
207
215
|
> {
|
|
216
|
+
(key: TKeys, options?: TOptions<TInterpolationMap>): key is TKeys & SelectorKey;
|
|
208
217
|
(key: TKeys | TKeys[], options?: TOptions<TInterpolationMap>): boolean;
|
|
209
218
|
}
|
|
210
219
|
|
|
@@ -286,6 +295,18 @@ export interface i18n extends CustomInstanceExtensions {
|
|
|
286
295
|
*
|
|
287
296
|
* Accepts optional keyPrefix that will be automatically applied to returned t function.
|
|
288
297
|
*/
|
|
298
|
+
getFixedT<
|
|
299
|
+
Ns extends Namespace | null,
|
|
300
|
+
const TKPrefixFn extends TypeOptions['enableSelector'] extends true | 'optimize'
|
|
301
|
+
? KeyPrefixSelector<ActualNs>
|
|
302
|
+
: never,
|
|
303
|
+
ActualNs extends Namespace = Ns extends null ? DefaultNamespace : Ns,
|
|
304
|
+
>(
|
|
305
|
+
lng: string | readonly string[] | null,
|
|
306
|
+
ns: Ns,
|
|
307
|
+
keyPrefix: TKPrefixFn,
|
|
308
|
+
): TFunction<ActualNs, TKPrefixFn>;
|
|
309
|
+
|
|
289
310
|
getFixedT<
|
|
290
311
|
Ns extends Namespace | null = DefaultNamespace,
|
|
291
312
|
TKPrefix extends KeyPrefix<ActualNs> = undefined,
|
|
@@ -560,6 +581,8 @@ export type {
|
|
|
560
581
|
TFunctionReturn,
|
|
561
582
|
TFunctionDetailedResult,
|
|
562
583
|
KeyPrefix,
|
|
584
|
+
KeyPrefixSelector,
|
|
585
|
+
NsResource,
|
|
563
586
|
InterpolationMap,
|
|
564
587
|
SelectorKey,
|
|
565
588
|
} from './typescript/t.js';
|
package/jsr.json
CHANGED
package/package.json
CHANGED
package/typescript/t.d.ts
CHANGED
|
@@ -464,6 +464,14 @@ export interface TFunction<
|
|
|
464
464
|
|
|
465
465
|
export type KeyPrefix<Ns extends Namespace> = ResourceKeys<true>[$FirstNamespace<Ns>] | undefined;
|
|
466
466
|
|
|
467
|
+
/** The raw (unfiltered) resource object for a given namespace. */
|
|
468
|
+
export type NsResource<Ns extends Namespace> = Ns extends readonly [keyof Resources, any, ...any]
|
|
469
|
+
? Resources[Ns[0]] & PickNamespaces<Resources, Ns[number]>
|
|
470
|
+
: Resources[$FirstNamespace<Ns>];
|
|
471
|
+
|
|
472
|
+
/** A selector function that can be used as `keyPrefix` to scope `t()` to a sub-tree of the resource. */
|
|
473
|
+
export type KeyPrefixSelector<Ns extends Namespace> = (src: NsResource<Ns>) => object;
|
|
474
|
+
|
|
467
475
|
/// ////////////// ///
|
|
468
476
|
/// ↆ selector ↆ ///
|
|
469
477
|
/// ////////////// ///
|
|
@@ -644,17 +652,22 @@ type PickNamespaces<T, K extends keyof any> = {
|
|
|
644
652
|
[P in K as P extends keyof T ? P : never]: T[P & keyof T];
|
|
645
653
|
};
|
|
646
654
|
|
|
647
|
-
|
|
648
|
-
|
|
649
|
-
|
|
650
|
-
|
|
651
|
-
|
|
652
|
-
|
|
653
|
-
|
|
654
|
-
|
|
655
|
-
:
|
|
656
|
-
|
|
657
|
-
|
|
655
|
+
/** Extracts the sub-tree returned by a selector function used as keyPrefix. */
|
|
656
|
+
type SelectorReturnSource<KPrefix, Fallback> = KPrefix extends (...args: any[]) => infer R
|
|
657
|
+
? R extends object
|
|
658
|
+
? R
|
|
659
|
+
: Fallback
|
|
660
|
+
: Fallback;
|
|
661
|
+
|
|
662
|
+
type GetSource<Ns extends Namespace, KPrefix, Res = NsResource<Ns>> = KPrefix extends (
|
|
663
|
+
...args: any[]
|
|
664
|
+
) => any
|
|
665
|
+
? SelectorReturnSource<KPrefix, Res>
|
|
666
|
+
: KPrefix extends keyof Res
|
|
667
|
+
? Res[KPrefix]
|
|
668
|
+
: undefined extends KPrefix
|
|
669
|
+
? Res
|
|
670
|
+
: ApplyKeyPrefix<[Res], KPrefix>;
|
|
658
671
|
|
|
659
672
|
type Select<T, Context> = $IsResourcesDefined extends false
|
|
660
673
|
? $Turtles
|