react-i18next 11.8.2 β 11.8.6
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 +18 -0
- package/README.md +1 -0
- package/package.json +9 -7
- package/src/index.d.ts +12 -4
- package/src/ts4.1/index.d.ts +52 -25
package/CHANGELOG.md
CHANGED
|
@@ -1,3 +1,21 @@
|
|
|
1
|
+
### 11.8.6
|
|
2
|
+
|
|
3
|
+
- typescript: Updated TS definitions (adding useSuspense option in TranslationProps) [1247](https://github.com/i18next/react-i18next/pull/1247)
|
|
4
|
+
|
|
5
|
+
### 11.8.5
|
|
6
|
+
|
|
7
|
+
- typescript: fix: Inference for specific keys ts 4.1 [1230](https://github.com/i18next/react-i18next/pull/1230)
|
|
8
|
+
|
|
9
|
+
### 11.8.4
|
|
10
|
+
|
|
11
|
+
- typescript: Add workaround to suppress infinite instantiation warning [1227](https://github.com/i18next/react-i18next/pull/1227)
|
|
12
|
+
- typescript: withTranslation() typing fix for defaultProps [1226](https://github.com/i18next/react-i18next/pull/1226)
|
|
13
|
+
- typescript: Accept const components prop for Trans [1224](https://github.com/i18next/react-i18next/pull/1224)
|
|
14
|
+
|
|
15
|
+
### 11.8.3
|
|
16
|
+
|
|
17
|
+
- Fix: Return type inference for t function (typescript 4.1) [1221](https://github.com/i18next/react-i18next/pull/1221)
|
|
18
|
+
|
|
1
19
|
### 11.8.2
|
|
2
20
|
|
|
3
21
|
- fix: type definitions for typescript 4.1 [1220](https://github.com/i18next/react-i18next/pull/1220)
|
package/README.md
CHANGED
|
@@ -144,6 +144,7 @@ Thanks goes to these wonderful people ([emoji key](https://github.com/kentcdodds
|
|
|
144
144
|
<td align="center"><a href="http://twitter.com/jamuhl"><img src="https://avatars3.githubusercontent.com/u/977772?v=4?s=100" width="100px;" alt=""/><br /><sub><b>Jan MΓΌhlemann</b></sub></a><br /><a href="https://github.com/i18next/react-i18next/commits?author=jamuhl" title="Code">π»</a> <a href="#example-jamuhl" title="Examples">π‘</a> <a href="https://github.com/i18next/react-i18next/commits?author=jamuhl" title="Documentation">π</a> <a href="#question-jamuhl" title="Answering Questions">π¬</a></td>
|
|
145
145
|
<td align="center"><a href="http://twitter.com/#!/adrirai"><img src="https://avatars0.githubusercontent.com/u/1086194?v=4?s=100" width="100px;" alt=""/><br /><sub><b>Adriano Raiano</b></sub></a><br /><a href="https://github.com/i18next/react-i18next/commits?author=adrai" title="Code">π»</a> <a href="#example-adrai" title="Examples">π‘</a> <a href="https://github.com/i18next/react-i18next/commits?author=adrai" title="Documentation">π</a> <a href="#question-adrai" title="Answering Questions">π¬</a></td>
|
|
146
146
|
<td align="center"><a href="https://tigerabrodi.dev/"><img src="https://avatars1.githubusercontent.com/u/49603590?v=4?s=100" width="100px;" alt=""/><br /><sub><b>Tiger Abrodi</b></sub></a><br /><a href="#question-tigerabrodi" title="Answering Questions">π¬</a> <a href="https://github.com/i18next/react-i18next/commits?author=tigerabrodi" title="Code">π»</a> <a href="https://github.com/i18next/react-i18next/pulls?q=is%3Apr+reviewed-by%3Atigerabrodi" title="Reviewed Pull Requests">π</a></td>
|
|
147
|
+
<td align="center"><a href="https://github.com/pedrodurek"><img src="https://avatars1.githubusercontent.com/u/12190482?v=4?s=100" width="100px;" alt=""/><br /><sub><b>Pedro Durek</b></sub></a><br /><a href="https://github.com/i18next/react-i18next/commits?author=pedrodurek" title="Code">π»</a> <a href="#example-pedrodurek" title="Examples">π‘</a></td>
|
|
147
148
|
</tr>
|
|
148
149
|
</table>
|
|
149
150
|
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "react-i18next",
|
|
3
|
-
"version": "11.8.
|
|
3
|
+
"version": "11.8.6",
|
|
4
4
|
"description": "Internationalization for react done right. Using the i18next i18n ecosystem.",
|
|
5
5
|
"main": "dist/commonjs/index.js",
|
|
6
6
|
"types": "src/index.d.ts",
|
|
@@ -45,6 +45,9 @@
|
|
|
45
45
|
"@babel/preset-env": "^7.3.1",
|
|
46
46
|
"@babel/preset-react": "^7.0.0",
|
|
47
47
|
"@babel/register": "^7.0.0",
|
|
48
|
+
"@testing-library/jest-dom": "^5.11.6",
|
|
49
|
+
"@testing-library/react": "^11.2.2",
|
|
50
|
+
"@testing-library/react-hooks": "^3.4.2",
|
|
48
51
|
"@types/react": "^16.8.2",
|
|
49
52
|
"all-contributors-cli": "^6.1.1",
|
|
50
53
|
"babel-core": "^7.0.0-bridge.0",
|
|
@@ -56,15 +59,14 @@
|
|
|
56
59
|
"cp-cli": "^2.0.0",
|
|
57
60
|
"cross-env": "^6.0.3",
|
|
58
61
|
"dtslint": "^0.9.1",
|
|
59
|
-
"enzyme": "^3.8.0",
|
|
60
|
-
"enzyme-adapter-react-16": "^1.9.1",
|
|
61
|
-
"enzyme-adapter-react-helper": "^1.3.2",
|
|
62
62
|
"eslint": "6.8.0",
|
|
63
|
-
"eslint-config-airbnb": "18.0.1",
|
|
63
|
+
"eslint-config-airbnb": "^18.0.1",
|
|
64
64
|
"eslint-config-prettier": "6.4.0",
|
|
65
|
-
"eslint-plugin-import": "2.
|
|
65
|
+
"eslint-plugin-import": "^2.22.1",
|
|
66
|
+
"eslint-plugin-jest-dom": "^3.6.3",
|
|
66
67
|
"eslint-plugin-jsx-a11y": "6.2.3",
|
|
67
68
|
"eslint-plugin-react": "7.16.0",
|
|
69
|
+
"eslint-plugin-testing-library": "^3.10.1",
|
|
68
70
|
"husky": "^3.0.3",
|
|
69
71
|
"i18next": "^19.0.0",
|
|
70
72
|
"jest": "24.8.0",
|
|
@@ -74,6 +76,7 @@
|
|
|
74
76
|
"prettier": "2.2.1",
|
|
75
77
|
"react": "^16.10.2",
|
|
76
78
|
"react-dom": "^16.10.2",
|
|
79
|
+
"react-test-renderer": "^17.0.1",
|
|
77
80
|
"rimraf": "2.6.3",
|
|
78
81
|
"rollup": "1.19.4",
|
|
79
82
|
"rollup-plugin-babel": "^4.3.2",
|
|
@@ -105,7 +108,6 @@
|
|
|
105
108
|
"test": "cross-env BABEL_ENV=development jest --no-cache",
|
|
106
109
|
"test:watch": "cross-env BABEL_ENV=development jest --no-cache --watch",
|
|
107
110
|
"test:coverage": "cross-env BABEL_ENV=development jest --no-cache --coverage",
|
|
108
|
-
"test:coverageOldEnzymeAdapter": "enzyme-adapter-react-install 16 && cross-env BABEL_ENV=development jest --no-cache --coverage",
|
|
109
111
|
"test:lint": "eslint ./src ./test",
|
|
110
112
|
"test:typescript": "tslint --project tsconfig.json",
|
|
111
113
|
"test:typescript:noninterop": "tslint --project tsconfig.nonEsModuleInterop.json",
|
package/src/index.d.ts
CHANGED
|
@@ -2,6 +2,7 @@ import i18next, { ReactOptions, i18n, ThirdPartyModule, WithT, TFunction, Resour
|
|
|
2
2
|
import * as React from 'react';
|
|
3
3
|
|
|
4
4
|
type Omit<T, K> = Pick<T, Exclude<keyof T, K>>;
|
|
5
|
+
type Subtract<T extends K, K> = Omit<T, keyof K>;
|
|
5
6
|
|
|
6
7
|
export type Namespace = string | string[];
|
|
7
8
|
|
|
@@ -33,7 +34,7 @@ export interface TransProps<E extends Element = HTMLDivElement>
|
|
|
33
34
|
extends React.HTMLProps<E>,
|
|
34
35
|
Partial<WithT> {
|
|
35
36
|
children?: React.ReactNode;
|
|
36
|
-
components?: readonly React.ReactNode[] | { [tagName: string]: React.ReactNode };
|
|
37
|
+
components?: readonly React.ReactNode[] | { readonly [tagName: string]: React.ReactNode };
|
|
37
38
|
count?: number;
|
|
38
39
|
defaults?: string;
|
|
39
40
|
i18n?: i18n;
|
|
@@ -92,9 +93,15 @@ export function withTranslation(
|
|
|
92
93
|
options?: {
|
|
93
94
|
withRef?: boolean;
|
|
94
95
|
},
|
|
95
|
-
): <
|
|
96
|
-
|
|
97
|
-
|
|
96
|
+
): <
|
|
97
|
+
C extends React.ComponentType<React.ComponentProps<C> & WithTranslationProps>,
|
|
98
|
+
ResolvedProps = JSX.LibraryManagedAttributes<
|
|
99
|
+
C,
|
|
100
|
+
Subtract<React.ComponentProps<C>, WithTranslationProps>
|
|
101
|
+
>
|
|
102
|
+
>(
|
|
103
|
+
component: C,
|
|
104
|
+
) => React.ComponentType<Omit<ResolvedProps, keyof WithTranslation> & WithTranslationProps>;
|
|
98
105
|
|
|
99
106
|
export interface I18nextProviderProps {
|
|
100
107
|
i18n: i18n;
|
|
@@ -115,6 +122,7 @@ export interface TranslationProps {
|
|
|
115
122
|
) => React.ReactNode;
|
|
116
123
|
ns?: Namespace;
|
|
117
124
|
i18n?: i18n;
|
|
125
|
+
useSuspense?: boolean;
|
|
118
126
|
}
|
|
119
127
|
|
|
120
128
|
export function Translation(props: TranslationProps): any;
|
package/src/ts4.1/index.d.ts
CHANGED
|
@@ -9,14 +9,24 @@ import i18next, {
|
|
|
9
9
|
} from 'i18next';
|
|
10
10
|
import * as React from 'react';
|
|
11
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
|
+
|
|
12
22
|
/**
|
|
13
23
|
* This interface can be augmented by users to add types to `react-i18next` default resources.
|
|
14
24
|
*/
|
|
15
25
|
export interface Resources {}
|
|
16
26
|
|
|
17
|
-
type
|
|
27
|
+
type Fallback<F, T = keyof Resources> = [T] extends [never] ? F : T;
|
|
18
28
|
|
|
19
|
-
export type Namespace =
|
|
29
|
+
export type Namespace<F = Fallback<string>> = F | F[];
|
|
20
30
|
|
|
21
31
|
export function setDefaults(options: ReactOptions): void;
|
|
22
32
|
export function getDefaults(): ReactOptions;
|
|
@@ -43,11 +53,13 @@ declare module 'i18next' {
|
|
|
43
53
|
}
|
|
44
54
|
|
|
45
55
|
// Normalize single namespace
|
|
46
|
-
type
|
|
47
|
-
type
|
|
56
|
+
type AppendKeys<K1, K2> = `${K1 & string}.${K2 & string}`;
|
|
57
|
+
type AppendKeys2<K1, K2> = `${K1 & string}.${Exclude<K2, keyof any[]> & string}`;
|
|
48
58
|
type Normalize2<T, K = keyof T> = K extends keyof T
|
|
49
|
-
? T[K] extends
|
|
50
|
-
?
|
|
59
|
+
? T[K] extends Record<string, any>
|
|
60
|
+
? T[K] extends readonly any[]
|
|
61
|
+
? AppendKeys2<K, keyof T[K]> | AppendKeys2<K, Normalize2<T[K]>>
|
|
62
|
+
: AppendKeys<K, keyof T[K]> | AppendKeys<K, Normalize2<T[K]>>
|
|
51
63
|
: never
|
|
52
64
|
: never;
|
|
53
65
|
type Normalize<T> = keyof T | Normalize2<T>;
|
|
@@ -84,31 +96,39 @@ export type TFuncKey<N, T = Resources> = N extends (keyof T)[]
|
|
|
84
96
|
? Normalize<T[N]>
|
|
85
97
|
: string;
|
|
86
98
|
|
|
87
|
-
export type TFuncReturn<N,
|
|
88
|
-
? NormalizeMultiReturn<T,
|
|
99
|
+
export type TFuncReturn<N, TKeys, TDefaultResult, T = Resources> = N extends (keyof T)[]
|
|
100
|
+
? NormalizeMultiReturn<T, TKeys>
|
|
89
101
|
: N extends keyof T
|
|
90
|
-
? NormalizeReturn<T[N],
|
|
91
|
-
:
|
|
102
|
+
? NormalizeReturn<T[N], TKeys>
|
|
103
|
+
: Fallback<TDefaultResult>;
|
|
92
104
|
|
|
93
105
|
export interface TFunction<N extends Namespace = DefaultNamespace> {
|
|
94
|
-
<
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
key:
|
|
106
|
+
<
|
|
107
|
+
TKeys extends TFuncKey<N> | TemplateStringsArray extends infer A ? A : never,
|
|
108
|
+
TDefaultResult extends TFunctionResult = string,
|
|
109
|
+
TInterpolationMap extends object = StringMap
|
|
110
|
+
>(
|
|
111
|
+
key: TKeys | TKeys[],
|
|
112
|
+
options?: TOptions<TInterpolationMap> | string,
|
|
113
|
+
): TFuncReturn<N, TKeys, TDefaultResult>;
|
|
114
|
+
<
|
|
115
|
+
TKeys extends TFuncKey<N> | TemplateStringsArray extends infer A ? A : never,
|
|
116
|
+
TDefaultResult extends TFunctionResult = string,
|
|
117
|
+
TInterpolationMap extends object = StringMap
|
|
118
|
+
>(
|
|
119
|
+
key: TKeys | TKeys[],
|
|
100
120
|
defaultValue?: string,
|
|
101
|
-
options?: TOptions<
|
|
102
|
-
): TFuncReturn<N,
|
|
121
|
+
options?: TOptions<TInterpolationMap> | string,
|
|
122
|
+
): TFuncReturn<N, TKeys, TDefaultResult>;
|
|
103
123
|
}
|
|
104
124
|
|
|
105
125
|
export interface TransProps<
|
|
106
|
-
K extends TFuncKey<N
|
|
126
|
+
K extends TFuncKey<N> extends infer A ? A : never,
|
|
107
127
|
N extends Namespace = DefaultNamespace,
|
|
108
128
|
E extends Element = HTMLDivElement
|
|
109
129
|
> extends React.HTMLProps<E> {
|
|
110
130
|
children?: React.ReactNode;
|
|
111
|
-
components?: React.ReactNode[] | { [tagName: string]: React.ReactNode };
|
|
131
|
+
components?: readonly React.ReactNode[] | { readonly [tagName: string]: React.ReactNode };
|
|
112
132
|
count?: number;
|
|
113
133
|
defaults?: string;
|
|
114
134
|
i18n?: i18n;
|
|
@@ -120,7 +140,7 @@ export interface TransProps<
|
|
|
120
140
|
t?: TFunction<N>;
|
|
121
141
|
}
|
|
122
142
|
export function Trans<
|
|
123
|
-
K extends TFuncKey<N
|
|
143
|
+
K extends TFuncKey<N> extends infer A ? A : never,
|
|
124
144
|
N extends Namespace = DefaultNamespace,
|
|
125
145
|
E extends Element = HTMLDivElement
|
|
126
146
|
>(props: TransProps<K, N, E>): React.ReactElement;
|
|
@@ -138,7 +158,7 @@ type UseTranslationResponse<N extends Namespace> = [TFunction<N>, i18n, boolean]
|
|
|
138
158
|
ready: boolean;
|
|
139
159
|
};
|
|
140
160
|
|
|
141
|
-
type DefaultNamespace<T = 'translation'> =
|
|
161
|
+
type DefaultNamespace<T = 'translation'> = Fallback<string> extends T ? T : string;
|
|
142
162
|
|
|
143
163
|
export function useTranslation<N extends Namespace = DefaultNamespace>(
|
|
144
164
|
ns?: N,
|
|
@@ -176,9 +196,15 @@ export function withTranslation<N extends Namespace = DefaultNamespace>(
|
|
|
176
196
|
options?: {
|
|
177
197
|
withRef?: boolean;
|
|
178
198
|
},
|
|
179
|
-
): <
|
|
180
|
-
|
|
181
|
-
|
|
199
|
+
): <
|
|
200
|
+
C extends React.ComponentType<React.ComponentProps<C> & WithTranslationProps>,
|
|
201
|
+
ResolvedProps = JSX.LibraryManagedAttributes<
|
|
202
|
+
C,
|
|
203
|
+
Subtract<React.ComponentProps<C>, WithTranslationProps>
|
|
204
|
+
>
|
|
205
|
+
>(
|
|
206
|
+
component: C,
|
|
207
|
+
) => React.ComponentType<Omit<ResolvedProps, keyof WithTranslation<N>> & WithTranslationProps>;
|
|
182
208
|
|
|
183
209
|
export interface I18nextProviderProps {
|
|
184
210
|
i18n: i18n;
|
|
@@ -199,6 +225,7 @@ export interface TranslationProps<N extends Namespace = DefaultNamespace> {
|
|
|
199
225
|
) => React.ReactNode;
|
|
200
226
|
ns?: N;
|
|
201
227
|
i18n?: i18n;
|
|
228
|
+
useSuspense?: boolean;
|
|
202
229
|
}
|
|
203
230
|
|
|
204
231
|
export function Translation<N extends Namespace = DefaultNamespace>(
|