-
-
Notifications
You must be signed in to change notification settings - Fork 1.1k
Expand file tree
/
Copy pathTransWithoutContext.d.ts
More file actions
153 lines (142 loc) · 4.37 KB
/
TransWithoutContext.d.ts
File metadata and controls
153 lines (142 loc) · 4.37 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
import type {
i18n,
ReactOptions,
ApplyTarget,
ConstrainTarget,
GetSource,
InterpolationMap,
ParseKeys,
Namespace,
SelectorFn,
SelectorKey,
TFunctionReturn,
TypeOptions,
TOptions,
TFunction,
} from 'i18next';
import * as React from 'react';
type _DefaultNamespace = TypeOptions['defaultNS'];
type _EnableSelector = TypeOptions['enableSelector'];
type _KeySeparator = TypeOptions['keySeparator'];
type _AppendKeyPrefix<Key, KPrefix> = KPrefix extends string
? `${KPrefix}${_KeySeparator}${Key & string}`
: Key;
type TransChild = React.ReactNode | Record<string, unknown>;
type $NoInfer<T> = [T][T extends T ? 0 : never];
export type TransProps<
Key extends ParseKeys<Ns, TOpt, KPrefix>,
Ns extends Namespace = _DefaultNamespace,
KPrefix = undefined,
TContext extends string | undefined = undefined,
TOpt extends TOptions & { context?: TContext } = { context: TContext },
Ret = TFunctionReturn<Ns, _AppendKeyPrefix<Key, KPrefix>, TOpt>,
E = React.HTMLProps<HTMLDivElement>,
> = E & {
children?: TransChild | readonly TransChild[];
components?: readonly React.ReactElement[] | { readonly [tagName: string]: React.ReactElement };
count?: number;
context?: TContext;
defaults?: string;
i18n?: i18n;
i18nKey?: Key | Key[];
ns?: Ns;
parent?: string | React.ComponentType<any> | null; // used in React.createElement if not null
tOptions?: TOpt;
values?: InterpolationMap<Ret>;
shouldUnescape?: boolean;
t?: TFunction<Ns, KPrefix>;
};
export interface TransLegacy {
<
const Key extends ParseKeys<Ns, TOpt, KPrefix>,
Ns extends Namespace = _DefaultNamespace,
KPrefix = undefined,
TContext extends string | undefined = undefined,
TOpt extends TOptions & { context?: TContext } = { context: TContext },
Ret extends TFunctionReturn<Ns, _AppendKeyPrefix<Key, KPrefix>, TOpt> = TFunctionReturn<
Ns,
_AppendKeyPrefix<Key, KPrefix>,
TOpt
>,
E = React.HTMLProps<HTMLDivElement>,
>(
props: TransProps<Key, Ns, KPrefix, TContext, TOpt, Ret, E>,
): React.ReactElement;
}
export interface TransSelectorProps<
Key,
Ns extends Namespace = _DefaultNamespace,
KPrefix = undefined,
TContext extends string | undefined = undefined,
TOpt extends TOptions & { context?: TContext } = { context: TContext },
> {
children?: TransChild | readonly TransChild[];
components?: readonly React.ReactElement[] | { readonly [tagName: string]: React.ReactElement };
count?: number;
context?: TContext;
defaults?: string | Key;
i18n?: i18n;
i18nKey?: Key | readonly Key[];
ns?: Ns;
parent?: string | React.ComponentType<any> | null; // used in React.createElement if not null
tOptions?: TOpt;
values?: Key extends (...args: any[]) => infer R ? InterpolationMap<R> : {};
shouldUnescape?: boolean;
t?: TFunction<Ns, KPrefix>;
}
export interface TransSelector {
<
Target extends ConstrainTarget<TOpt>,
Key extends
| SelectorFn<GetSource<$NoInfer<Ns>, KPrefix>, ApplyTarget<Target, TOpt>, TOpt>
| SelectorKey,
const Ns extends Namespace = _DefaultNamespace,
KPrefix = undefined,
TContext extends string | undefined = undefined,
TOpt extends TOptions & { context?: TContext } = { context: TContext },
E = React.HTMLProps<HTMLDivElement>,
>(
props: TransSelectorProps<Key, Ns, KPrefix, TContext, TOpt> & E,
): React.ReactElement;
}
export const Trans: _EnableSelector extends true | 'optimize' ? TransSelector : TransLegacy;
export function nodesToString(
children: React.ReactNode,
i18nOptions?: ReactOptions,
i18n?: i18n,
i18nKey?: string,
): string;
export type ErrorCode =
| 'NO_I18NEXT_INSTANCE'
| 'NO_LANGUAGES'
| 'DEPRECATED_OPTION'
| 'TRANS_NULL_VALUE'
| 'TRANS_INVALID_OBJ'
| 'TRANS_INVALID_VAR'
| 'TRANS_INVALID_COMPONENTS'
| 'USE_T_BEFORE_READY';
export type ErrorMeta = {
code: ErrorCode;
i18nKey?: string;
[x: string]: any;
};
/**
* Use to type the logger arguments
* @example
* ```
* import type { ErrorArgs } from 'react-i18next';
*
* const logger = {
* // ....
* warn: function (...args: ErrorArgs) {
* if (args[1]?.code === 'TRANS_INVALID_OBJ') {
* const [msg, { i18nKey, ...rest }] = args;
* return log(i18nKey, msg, rest);
* }
* log(...args);
* }
* }
* i18n.use(logger).use(i18nReactPlugin).init({...});
* ```
*/
export type ErrorArgs = readonly [string, ErrorMeta | undefined, ...any[]];