react-i18next 11.18.5 → 12.0.0

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/CHANGELOG.md CHANGED
@@ -1,3 +1,11 @@
1
+ ### 12.0.0
2
+
3
+ - Update t function types to rely on types coming from i18next [1501](https://github.com/i18next/react-i18next/pull/1501)
4
+
5
+ ### 11.18.6
6
+
7
+ - types: nsMode [1554](https://github.com/i18next/react-i18next/issues/1554)
8
+
1
9
  ### 11.18.5
2
10
 
3
11
  - support unescaping forward slash [1548](https://github.com/i18next/react-i18next/pull/1548)
@@ -1,6 +1,6 @@
1
1
  import React from 'react';
2
- import { Namespace, DefaultNamespace, TFuncKey, Trans } from '.';
3
- import { i18n } from 'i18next';
2
+ import { Trans } from './';
3
+ import { Namespace, DefaultNamespace, TFuncKey, i18n } from 'i18next';
4
4
 
5
5
  export { Trans };
6
6
 
package/index.d.ts CHANGED
@@ -1,11 +1,18 @@
1
- import i18next, { ReactOptions, i18n, ThirdPartyModule, WithT, TFunction, Resource } from 'i18next';
1
+ import i18next, {
2
+ ReactOptions,
3
+ i18n,
4
+ ThirdPartyModule,
5
+ Resource,
6
+ TFuncKey,
7
+ Namespace,
8
+ TypeOptions,
9
+ TFunction,
10
+ KeyPrefix,
11
+ } from 'i18next';
2
12
  import * as React from 'react';
3
13
 
4
- type Omit<T, K> = Pick<T, Exclude<keyof T, K>>;
5
14
  type Subtract<T extends K, K> = Omit<T, keyof K>;
6
15
 
7
- export type Namespace = string | string[];
8
-
9
16
  export function setDefaults(options: ReactOptions): void;
10
17
  export function getDefaults(): ReactOptions;
11
18
  export function setI18n(instance: i18n): void;
@@ -20,7 +27,7 @@ export function getInitialProps(): {
20
27
  };
21
28
 
22
29
  export interface ReportNamespaces {
23
- addUsedNamespaces(namespaces: Namespace[]): void;
30
+ addUsedNamespaces(namespaces: Namespace): void;
24
31
  getUsedNamespaces(): string[];
25
32
  }
26
33
 
@@ -30,43 +37,76 @@ declare module 'i18next' {
30
37
  }
31
38
  }
32
39
 
33
- export interface TransProps<E extends Element = HTMLDivElement>
34
- extends React.HTMLProps<E>,
35
- Partial<WithT> {
36
- children?: React.ReactNode;
40
+ type ObjectOrNever = TypeOptions['allowObjectInHTMLChildren'] extends true
41
+ ? Record<string, unknown>
42
+ : never;
43
+ type ReactI18NextChild = React.ReactNode | ObjectOrNever;
44
+
45
+ declare module 'react' {
46
+ interface HTMLAttributes<T> {
47
+ children?: ReactI18NextChild | Iterable<ReactI18NextChild>;
48
+ }
49
+ }
50
+
51
+ type DefaultNamespace = TypeOptions['defaultNS'];
52
+
53
+ type TransChild = React.ReactNode | Record<string, unknown>;
54
+ export type TransProps<
55
+ K extends TFuncKey<N, TKPrefix> extends infer A ? A : never,
56
+ N extends Namespace = DefaultNamespace,
57
+ TKPrefix = undefined,
58
+ E = React.HTMLProps<HTMLDivElement>
59
+ > = E & {
60
+ children?: TransChild | TransChild[];
37
61
  components?: readonly React.ReactElement[] | { readonly [tagName: string]: React.ReactElement };
38
62
  count?: number;
39
63
  context?: string;
40
64
  defaults?: string;
41
65
  i18n?: i18n;
42
- i18nKey?: string;
43
- ns?: Namespace;
66
+ i18nKey?: K | K[];
67
+ ns?: N;
44
68
  parent?: string | React.ComponentType<any> | null; // used in React.createElement if not null
45
69
  tOptions?: {};
46
70
  values?: {};
47
71
  shouldUnescape?: boolean;
48
- t?: TFunction;
49
- }
50
- export function Trans<E extends Element = HTMLDivElement>(props: TransProps<E>): React.ReactElement;
72
+ t?: TFunction<N, TKPrefix>;
73
+ };
74
+
75
+ export function Trans<
76
+ K extends TFuncKey<N, TKPrefix> extends infer A ? A : never,
77
+ N extends Namespace = DefaultNamespace,
78
+ TKPrefix extends KeyPrefix<N> = undefined,
79
+ E = React.HTMLProps<HTMLDivElement>
80
+ >(props: TransProps<K, N, TKPrefix, E>): React.ReactElement;
51
81
 
52
82
  export function useSSR(initialI18nStore: Resource, initialLanguage: string): void;
53
83
 
54
- export interface UseTranslationOptions {
84
+ export interface UseTranslationOptions<TKPrefix = undefined> {
55
85
  i18n?: i18n;
56
86
  useSuspense?: boolean;
57
- keyPrefix?: string;
87
+ keyPrefix?: TKPrefix;
58
88
  bindI18n?: string | false;
89
+ nsMode?: 'fallback' | 'default';
59
90
  // other of these options might also work: https://github.com/i18next/i18next/blob/master/index.d.ts#L127
60
91
  }
61
- export type UseTranslationResponse = [TFunction, i18n, boolean] & {
62
- t: TFunction;
92
+
93
+ export type UseTranslationResponse<N extends Namespace, TKPrefix = undefined> = [
94
+ TFunction<N, TKPrefix>,
95
+ i18n,
96
+ boolean,
97
+ ] & {
98
+ t: TFunction<N, TKPrefix>;
63
99
  i18n: i18n;
64
100
  ready: boolean;
65
101
  };
66
- export function useTranslation(
67
- ns?: Namespace,
68
- options?: UseTranslationOptions,
69
- ): UseTranslationResponse;
102
+
103
+ export function useTranslation<
104
+ N extends Namespace = DefaultNamespace,
105
+ TKPrefix extends KeyPrefix<N> = undefined
106
+ >(
107
+ ns?: N | Readonly<N>,
108
+ options?: UseTranslationOptions<TKPrefix>,
109
+ ): UseTranslationResponse<N, TKPrefix>;
70
110
 
71
111
  // Need to see usage to improve this
72
112
  export function withSSR(): <Props>(
@@ -83,7 +123,11 @@ export function withSSR(): <Props>(
83
123
  getInitialProps: (ctx: unknown) => Promise<any>;
84
124
  };
85
125
 
86
- export interface WithTranslation extends WithT {
126
+ export interface WithTranslation<
127
+ N extends Namespace = DefaultNamespace,
128
+ TKPrefix extends KeyPrefix<N> = undefined
129
+ > {
130
+ t: TFunction<N, TKPrefix>;
87
131
  i18n: i18n;
88
132
  tReady: boolean;
89
133
  }
@@ -93,20 +137,24 @@ export interface WithTranslationProps {
93
137
  useSuspense?: boolean;
94
138
  }
95
139
 
96
- export function withTranslation(
97
- ns?: Namespace,
140
+ export function withTranslation<
141
+ N extends Namespace = DefaultNamespace,
142
+ TKPrefix extends KeyPrefix<N> = undefined
143
+ >(
144
+ ns?: N,
98
145
  options?: {
99
146
  withRef?: boolean;
147
+ keyPrefix?: TKPrefix;
100
148
  },
101
149
  ): <
102
- C extends React.ComponentType<React.ComponentProps<C> & WithTranslationProps>,
150
+ C extends React.ComponentType<React.ComponentProps<any> & WithTranslationProps>,
103
151
  ResolvedProps = JSX.LibraryManagedAttributes<
104
152
  C,
105
153
  Subtract<React.ComponentProps<C>, WithTranslationProps>
106
154
  >
107
155
  >(
108
156
  component: C,
109
- ) => React.ComponentType<Omit<ResolvedProps, keyof WithTranslation> & WithTranslationProps>;
157
+ ) => React.ComponentType<Omit<ResolvedProps, keyof WithTranslation<N>> & WithTranslationProps>;
110
158
 
111
159
  export interface I18nextProviderProps {
112
160
  children?: React.ReactNode;
@@ -117,18 +165,26 @@ export interface I18nextProviderProps {
117
165
  export const I18nextProvider: React.FunctionComponent<I18nextProviderProps>;
118
166
  export const I18nContext: React.Context<{ i18n: i18n }>;
119
167
 
120
- export interface TranslationProps {
168
+ export interface TranslationProps<
169
+ N extends Namespace = DefaultNamespace,
170
+ TKPrefix extends KeyPrefix<N> = undefined
171
+ > {
121
172
  children: (
122
- t: TFunction,
173
+ t: TFunction<N, TKPrefix>,
123
174
  options: {
124
175
  i18n: i18n;
125
176
  lng: string;
126
177
  },
127
178
  ready: boolean,
128
179
  ) => React.ReactNode;
129
- ns?: Namespace;
180
+ ns?: N;
130
181
  i18n?: i18n;
131
182
  useSuspense?: boolean;
183
+ keyPrefix?: TKPrefix;
184
+ nsMode?: 'fallback' | 'default';
132
185
  }
133
186
 
134
- export function Translation(props: TranslationProps): any;
187
+ export function Translation<
188
+ N extends Namespace = DefaultNamespace,
189
+ TKPrefix extends KeyPrefix<N> = undefined
190
+ >(props: TranslationProps<N, TKPrefix>): any;
package/package.json CHANGED
@@ -1,16 +1,9 @@
1
1
  {
2
2
  "name": "react-i18next",
3
- "version": "11.18.5",
3
+ "version": "12.0.0",
4
4
  "description": "Internationalization for react done right. Using the i18next i18n ecosystem.",
5
5
  "main": "dist/commonjs/index.js",
6
6
  "types": "./index.d.ts",
7
- "typesVersions": {
8
- ">=4.1": {
9
- "*": [
10
- "ts4.1/*"
11
- ]
12
- }
13
- },
14
7
  "jsnext:main": "dist/es/index.js",
15
8
  "module": "dist/es/index.js",
16
9
  "keywords": [
@@ -67,7 +60,7 @@
67
60
  "eslint-plugin-react": "^7.16.0",
68
61
  "eslint-plugin-testing-library": "^3.10.1",
69
62
  "husky": "^3.0.3",
70
- "i18next": "^21.0.0",
63
+ "i18next": "^22.0.1",
71
64
  "jest": "^24.8.0",
72
65
  "jest-cli": "^24.8.4",
73
66
  "lint-staged": "^8.1.3",
@@ -28,6 +28,7 @@ export function withTranslation(ns, options = {}) {
28
28
  I18nextWithTranslation.WrappedComponent = WrappedComponent;
29
29
 
30
30
  const forwardRef = (props, ref) =>
31
+ // eslint-disable-next-line prefer-object-spread
31
32
  createElement(I18nextWithTranslation, Object.assign({}, props, { forwardedRef: ref }));
32
33
 
33
34
  return options.withRef ? forwardRefReact(forwardRef) : I18nextWithTranslation;
package/ts4.1/index.d.ts DELETED
@@ -1,395 +0,0 @@
1
- import i18next, {
2
- ReactOptions,
3
- i18n,
4
- ThirdPartyModule,
5
- Resource,
6
- TOptions,
7
- StringMap,
8
- TFunctionResult,
9
- } from 'i18next';
10
- import * as React from 'react';
11
-
12
- type Subtract<T extends K, K> = Omit<T, keyof K>;
13
-
14
- /**
15
- * Due to a limitation/bug on typescript 4.1 (https://github.com/microsoft/TypeScript/issues/41406), we added
16
- * "extends infer A ? A : never" in a few places to suppress the error "Type instantiation is excessively deep and possibly infinite."
17
- * on cases where users have more than 22 namespaces. Once the issue is fixed, we can remove all instances of the workaround used.
18
- *
19
- * Reference of the bug reported: https://github.com/i18next/react-i18next/issues/1222
20
- */
21
-
22
- /**
23
- * This interface can be augmented by users to add types to `react-i18next` default resources.
24
- *
25
- * @deprecated use the `resources` key of `CustomTypeOptions` instead
26
- */
27
- export interface Resources {}
28
- /**
29
- * This interface can be augmented by users to add types to `react-i18next`. It accepts a `defaultNS`, `resources`, `returnNull` and `returnEmptyString` properties.
30
- *
31
- * Usage:
32
- * ```ts
33
- * // react-i18next.d.ts
34
- * import 'react-i18next';
35
- * declare module 'react-i18next' {
36
- * interface CustomTypeOptions {
37
- * defaultNS: 'custom';
38
- * returnNull: false;
39
- * returnEmptyString: false;
40
- * nsSeparator: ':';
41
- * keySeparator: '.';
42
- * jsonFormat: 'v4';
43
- * allowObjectInHTMLChildren: false;
44
- * resources: {
45
- * custom: {
46
- * foo: 'foo';
47
- * };
48
- * };
49
- * }
50
- * }
51
- * ```
52
- */
53
- export interface CustomTypeOptions {}
54
-
55
- type MergeBy<T, K> = Omit<T, keyof K> & K;
56
-
57
- type TypeOptions = MergeBy<
58
- {
59
- returnNull: true;
60
- returnEmptyString: true;
61
- keySeparator: '.';
62
- nsSeparator: ':';
63
- defaultNS: 'translation';
64
- jsonFormat: 'v4';
65
- resources: Resources;
66
- allowObjectInHTMLChildren: false;
67
- },
68
- CustomTypeOptions
69
- >;
70
-
71
- type DefaultResources = TypeOptions['resources'];
72
- type DefaultNamespace<T = TypeOptions['defaultNS']> = T extends Fallback<string> ? T : string;
73
-
74
- type Fallback<F, T = keyof DefaultResources> = [T] extends [never] ? F : T;
75
-
76
- export type Namespace<F = Fallback<string>> = F | F[];
77
-
78
- export function setDefaults(options: ReactOptions): void;
79
- export function getDefaults(): ReactOptions;
80
- export function setI18n(instance: i18n): void;
81
- export function getI18n(): i18n;
82
- export const initReactI18next: ThirdPartyModule;
83
- export function composeInitialProps(ForComponent: any): (ctx: unknown) => Promise<any>;
84
- export function getInitialProps(): {
85
- initialI18nStore: {
86
- [ns: string]: {};
87
- };
88
- initialLanguage: string;
89
- };
90
-
91
- export interface ReportNamespaces {
92
- addUsedNamespaces(namespaces: Namespace[]): void;
93
- getUsedNamespaces(): string[];
94
- }
95
-
96
- declare module 'i18next' {
97
- interface i18n {
98
- reportNamespaces: ReportNamespaces;
99
- }
100
- }
101
-
102
- type ObjectOrNever = TypeOptions['allowObjectInHTMLChildren'] extends true
103
- ? Record<string, unknown>
104
- : never;
105
-
106
- type ReactI18NextChild = React.ReactNode | ObjectOrNever;
107
-
108
- declare module 'react' {
109
- interface HTMLAttributes<T> {
110
- children?: ReactI18NextChild | Iterable<ReactI18NextChild>;
111
- }
112
- }
113
-
114
- type PluralSuffix = 'zero' | 'one' | 'two' | 'few' | 'many' | 'other';
115
-
116
- type WithOrWithoutPlural<K> = TypeOptions['jsonFormat'] extends 'v4'
117
- ? K extends `${infer B}_${PluralSuffix}`
118
- ? B | K
119
- : K
120
- : K;
121
-
122
- // Normalize single namespace
123
- export type KeysWithSeparator<K1, K2, S extends string = TypeOptions['keySeparator']> = `${K1 &
124
- string}${S}${K2 & string}`;
125
- type KeysWithSeparator2<K1, K2> = KeysWithSeparator<K1, Exclude<K2, keyof any[]>>;
126
- type Normalize2<T, K = keyof T> = K extends keyof T
127
- ? T[K] extends Record<string, any>
128
- ? T[K] extends readonly any[]
129
- ?
130
- | KeysWithSeparator2<K, WithOrWithoutPlural<keyof T[K]>>
131
- | KeysWithSeparator2<K, Normalize2<T[K]>>
132
- :
133
- | KeysWithSeparator<K, WithOrWithoutPlural<keyof T[K]>>
134
- | KeysWithSeparator<K, Normalize2<T[K]>>
135
- : never
136
- : never;
137
- type Normalize<T> = WithOrWithoutPlural<keyof T> | Normalize2<T>;
138
-
139
- // Normalize multiple namespaces
140
- type KeyWithNSSeparator<N, K, S extends string = TypeOptions['nsSeparator']> = `${N &
141
- string}${S}${K & string}`;
142
- type UnionToIntersection<U> = (U extends any ? (k: U) => void : never) extends (k: infer I) => void
143
- ? I
144
- : never;
145
- type LastOf<T> = UnionToIntersection<T extends any ? () => T : never> extends () => infer R
146
- ? R
147
- : never;
148
- type NormalizeMulti<T, U extends keyof T, L = LastOf<U>> = L extends U
149
- ? KeyWithNSSeparator<L, Normalize<T[L]>> | NormalizeMulti<T, Exclude<U, L>>
150
- : never;
151
-
152
- interface CustomTypeParameters {
153
- returnNull?: boolean;
154
- returnEmptyString?: boolean;
155
- }
156
-
157
- type TypeOptionsFallback<TranslationValue, Option, MatchingValue> = Option extends false
158
- ? TranslationValue extends MatchingValue
159
- ? string
160
- : TranslationValue
161
- : TranslationValue;
162
-
163
- /**
164
- * Checks if user has enabled `returnEmptyString` and `returnNull` options to retrieve correct values.
165
- */
166
- export type NormalizeByTypeOptions<
167
- TranslationValue,
168
- Options extends CustomTypeParameters = TypeOptions,
169
- R = TypeOptionsFallback<TranslationValue, Options['returnEmptyString'], ''>
170
- > = TypeOptionsFallback<R, Options['returnNull'], null>;
171
-
172
- type StringIfPlural<T> = TypeOptions['jsonFormat'] extends 'v4'
173
- ? T extends `${string}_${PluralSuffix}`
174
- ? string
175
- : never
176
- : never;
177
-
178
- type NormalizeReturn<
179
- T,
180
- V,
181
- S extends string | false = TypeOptions['keySeparator']
182
- > = V extends keyof T
183
- ? NormalizeByTypeOptions<T[V]>
184
- : S extends false
185
- ? V
186
- : V extends `${infer K}${S}${infer R}`
187
- ? K extends keyof T
188
- ? NormalizeReturn<T[K], R>
189
- : never
190
- : StringIfPlural<keyof T>;
191
-
192
- type NormalizeMultiReturn<T, V> = V extends `${infer N}:${infer R}`
193
- ? N extends keyof T
194
- ? NormalizeReturn<T[N], R>
195
- : never
196
- : never;
197
-
198
- type NormalizeWithKeyPrefix<
199
- T,
200
- K,
201
- S extends string = TypeOptions['keySeparator']
202
- > = K extends `${infer K1}${S}${infer K2}`
203
- ? K1 extends keyof T
204
- ? NormalizeWithKeyPrefix<T[K1], K2>
205
- : never
206
- : K extends keyof T
207
- ? T[K] extends string
208
- ? never
209
- : Normalize<T[K]>
210
- : never;
211
-
212
- type KeyPrefix<N extends Namespace> =
213
- | (N extends keyof DefaultResources ? Normalize<DefaultResources[N]> : string)
214
- | undefined;
215
-
216
- export type TFuncKey<
217
- N extends Namespace = DefaultNamespace,
218
- TKPrefix = undefined,
219
- T = DefaultResources
220
- > = N extends (keyof T)[] | Readonly<(keyof T)[]>
221
- ? NormalizeMulti<T, N[number]>
222
- : N extends keyof T
223
- ? TKPrefix extends undefined
224
- ? Normalize<T[N]>
225
- : NormalizeWithKeyPrefix<T[N], TKPrefix>
226
- : string;
227
-
228
- export type TFuncReturn<
229
- N,
230
- TKeys,
231
- TDefaultResult,
232
- TKPrefix = undefined,
233
- T = DefaultResources
234
- > = N extends (keyof T)[]
235
- ? NormalizeMultiReturn<T, TKeys>
236
- : N extends keyof T
237
- ? TKPrefix extends undefined
238
- ? NormalizeReturn<T[N], TKeys>
239
- : NormalizeReturn<T[N], KeysWithSeparator<TKPrefix, TKeys>>
240
- : Fallback<TDefaultResult>;
241
-
242
- export interface TFunction<N extends Namespace = DefaultNamespace, TKPrefix = undefined> {
243
- <
244
- TKeys extends TFuncKey<N, TKPrefix> | TemplateStringsArray extends infer A ? A : never,
245
- TDefaultResult extends TFunctionResult | React.ReactNode = string,
246
- TInterpolationMap extends object = StringMap
247
- >(
248
- key: TKeys | TKeys[],
249
- options?: TOptions<TInterpolationMap> | string,
250
- ): TFuncReturn<N, TKeys, TDefaultResult, TKPrefix>;
251
- <
252
- TKeys extends TFuncKey<N, TKPrefix> | TemplateStringsArray extends infer A ? A : never,
253
- TDefaultResult extends TFunctionResult | React.ReactNode = string,
254
- TInterpolationMap extends object = StringMap
255
- >(
256
- key: TKeys | TKeys[],
257
- defaultValue?: string,
258
- options?: TOptions<TInterpolationMap> | string,
259
- ): TFuncReturn<N, TKeys, TDefaultResult, TKPrefix>;
260
- }
261
-
262
- type TransChild = React.ReactNode | Record<string, unknown>;
263
- export type TransProps<
264
- K extends TFuncKey<N, TKPrefix> extends infer A ? A : never,
265
- N extends Namespace = DefaultNamespace,
266
- TKPrefix = undefined,
267
- E = React.HTMLProps<HTMLDivElement>
268
- > = E & {
269
- children?: TransChild | TransChild[];
270
- components?: readonly React.ReactElement[] | { readonly [tagName: string]: React.ReactElement };
271
- count?: number;
272
- context?: string;
273
- defaults?: string;
274
- i18n?: i18n;
275
- i18nKey?: K | K[];
276
- ns?: N;
277
- parent?: string | React.ComponentType<any> | null; // used in React.createElement if not null
278
- tOptions?: {};
279
- values?: {};
280
- shouldUnescape?: boolean;
281
- t?: TFunction<N, TKPrefix>;
282
- };
283
-
284
- export function Trans<
285
- K extends TFuncKey<N, TKPrefix> extends infer A ? A : never,
286
- N extends Namespace = DefaultNamespace,
287
- TKPrefix extends KeyPrefix<N> = undefined,
288
- E = React.HTMLProps<HTMLDivElement>
289
- >(props: TransProps<K, N, TKPrefix, E>): React.ReactElement;
290
-
291
- export function useSSR(initialI18nStore: Resource, initialLanguage: string): void;
292
-
293
- export interface UseTranslationOptions<TKPrefix = undefined> {
294
- i18n?: i18n;
295
- useSuspense?: boolean;
296
- keyPrefix?: TKPrefix;
297
- }
298
-
299
- export type UseTranslationResponse<N extends Namespace, TKPrefix = undefined> = [
300
- TFunction<N, TKPrefix>,
301
- i18n,
302
- boolean,
303
- ] & {
304
- t: TFunction<N, TKPrefix>;
305
- i18n: i18n;
306
- ready: boolean;
307
- };
308
-
309
- export function useTranslation<
310
- N extends Namespace = DefaultNamespace,
311
- TKPrefix extends KeyPrefix<N> = undefined
312
- >(
313
- ns?: N | Readonly<N>,
314
- options?: UseTranslationOptions<TKPrefix>,
315
- ): UseTranslationResponse<N, TKPrefix>;
316
-
317
- // Need to see usage to improve this
318
- export function withSSR(): <Props>(
319
- WrappedComponent: React.ComponentType<Props>,
320
- ) => {
321
- ({
322
- initialI18nStore,
323
- initialLanguage,
324
- ...rest
325
- }: {
326
- initialI18nStore: Resource;
327
- initialLanguage: string;
328
- } & Props): React.FunctionComponentElement<Props>;
329
- getInitialProps: (ctx: unknown) => Promise<any>;
330
- };
331
-
332
- export interface WithTranslation<
333
- N extends Namespace = DefaultNamespace,
334
- TKPrefix extends KeyPrefix<N> = undefined
335
- > {
336
- t: TFunction<N, TKPrefix>;
337
- i18n: i18n;
338
- tReady: boolean;
339
- }
340
-
341
- export interface WithTranslationProps {
342
- i18n?: i18n;
343
- useSuspense?: boolean;
344
- }
345
-
346
- export function withTranslation<
347
- N extends Namespace = DefaultNamespace,
348
- TKPrefix extends KeyPrefix<N> = undefined
349
- >(
350
- ns?: N,
351
- options?: {
352
- withRef?: boolean;
353
- keyPrefix?: TKPrefix;
354
- },
355
- ): <
356
- C extends React.ComponentType<React.ComponentProps<any> & WithTranslationProps>,
357
- ResolvedProps = JSX.LibraryManagedAttributes<
358
- C,
359
- Subtract<React.ComponentProps<C>, WithTranslationProps>
360
- >
361
- >(
362
- component: C,
363
- ) => React.ComponentType<Omit<ResolvedProps, keyof WithTranslation<N>> & WithTranslationProps>;
364
-
365
- export interface I18nextProviderProps {
366
- children?: React.ReactNode;
367
- i18n: i18n;
368
- defaultNS?: string;
369
- }
370
-
371
- export const I18nextProvider: React.FunctionComponent<I18nextProviderProps>;
372
- export const I18nContext: React.Context<{ i18n: i18n }>;
373
-
374
- export interface TranslationProps<
375
- N extends Namespace = DefaultNamespace,
376
- TKPrefix extends KeyPrefix<N> = undefined
377
- > {
378
- children: (
379
- t: TFunction<N, TKPrefix>,
380
- options: {
381
- i18n: i18n;
382
- lng: string;
383
- },
384
- ready: boolean,
385
- ) => React.ReactNode;
386
- ns?: N;
387
- i18n?: i18n;
388
- useSuspense?: boolean;
389
- keyPrefix?: TKPrefix;
390
- }
391
-
392
- export function Translation<
393
- N extends Namespace = DefaultNamespace,
394
- TKPrefix extends KeyPrefix<N> = undefined
395
- >(props: TranslationProps<N, TKPrefix>): any;