react-i18next 11.8.1 → 11.8.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/CHANGELOG.md +18 -0
- package/README.md +5 -5
- package/package.json +9 -7
- package/src/index.d.ts +11 -4
- package/src/ts4.1/index.d.ts +50 -23
package/CHANGELOG.md
CHANGED
|
@@ -1,3 +1,21 @@
|
|
|
1
|
+
### 11.8.5
|
|
2
|
+
|
|
3
|
+
- typescript: fix: Inference for specific keys ts 4.1 [1230](https://github.com/i18next/react-i18next/pull/1230)
|
|
4
|
+
|
|
5
|
+
### 11.8.4
|
|
6
|
+
|
|
7
|
+
- typescript: Add workaround to suppress infinite instantiation warning [1227](https://github.com/i18next/react-i18next/pull/1227)
|
|
8
|
+
- typescript: withTranslation() typing fix for defaultProps [1226](https://github.com/i18next/react-i18next/pull/1226)
|
|
9
|
+
- typescript: Accept const components prop for Trans [1224](https://github.com/i18next/react-i18next/pull/1224)
|
|
10
|
+
|
|
11
|
+
### 11.8.3
|
|
12
|
+
|
|
13
|
+
- Fix: Return type inference for t function (typescript 4.1) [1221](https://github.com/i18next/react-i18next/pull/1221)
|
|
14
|
+
|
|
15
|
+
### 11.8.2
|
|
16
|
+
|
|
17
|
+
- fix: type definitions for typescript 4.1 [1220](https://github.com/i18next/react-i18next/pull/1220)
|
|
18
|
+
|
|
1
19
|
### 11.8.1
|
|
2
20
|
|
|
3
21
|
- fix: typescript definitions for t function without namespaces [1214](https://github.com/i18next/react-i18next/pull/1214)
|
package/README.md
CHANGED
|
@@ -141,14 +141,14 @@ Thanks goes to these wonderful people ([emoji key](https://github.com/kentcdodds
|
|
|
141
141
|
<!-- markdownlint-disable -->
|
|
142
142
|
<table>
|
|
143
143
|
<tr>
|
|
144
|
-
<td align="center"><a href="http://twitter.com/jamuhl"><img src="https://avatars3.githubusercontent.com/u/977772?v=4" width="100px;" alt="
|
|
145
|
-
<td align="center"><a href="http://twitter.com/#!/adrirai"><img src="https://avatars0.githubusercontent.com/u/1086194?v=4" width="100px;" alt="
|
|
146
|
-
<td align="center"><a href="https://
|
|
147
|
-
<td align="center"><a href="
|
|
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
|
+
<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
|
+
<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>
|
|
148
148
|
</tr>
|
|
149
149
|
</table>
|
|
150
150
|
|
|
151
|
-
<!-- markdownlint-
|
|
151
|
+
<!-- markdownlint-restore -->
|
|
152
152
|
<!-- prettier-ignore-end -->
|
|
153
153
|
|
|
154
154
|
<!-- ALL-CONTRIBUTORS-LIST:END -->
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "react-i18next",
|
|
3
|
-
"version": "11.8.
|
|
3
|
+
"version": "11.8.5",
|
|
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;
|
package/src/ts4.1/index.d.ts
CHANGED
|
@@ -5,17 +5,28 @@ import i18next, {
|
|
|
5
5
|
Resource,
|
|
6
6
|
TOptions,
|
|
7
7
|
StringMap,
|
|
8
|
+
TFunctionResult,
|
|
8
9
|
} from 'i18next';
|
|
9
10
|
import * as React from 'react';
|
|
10
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
|
+
|
|
11
22
|
/**
|
|
12
23
|
* This interface can be augmented by users to add types to `react-i18next` default resources.
|
|
13
24
|
*/
|
|
14
25
|
export interface Resources {}
|
|
15
26
|
|
|
16
|
-
type
|
|
27
|
+
type Fallback<F, T = keyof Resources> = [T] extends [never] ? F : T;
|
|
17
28
|
|
|
18
|
-
export type Namespace =
|
|
29
|
+
export type Namespace<F = Fallback<string>> = F | F[];
|
|
19
30
|
|
|
20
31
|
export function setDefaults(options: ReactOptions): void;
|
|
21
32
|
export function getDefaults(): ReactOptions;
|
|
@@ -42,11 +53,13 @@ declare module 'i18next' {
|
|
|
42
53
|
}
|
|
43
54
|
|
|
44
55
|
// Normalize single namespace
|
|
45
|
-
type
|
|
46
|
-
type
|
|
56
|
+
type AppendKeys<K1, K2> = `${K1 & string}.${K2 & string}`;
|
|
57
|
+
type AppendKeys2<K1, K2> = `${K1 & string}.${Exclude<K2, keyof any[]> & string}`;
|
|
47
58
|
type Normalize2<T, K = keyof T> = K extends keyof T
|
|
48
|
-
? T[K] extends
|
|
49
|
-
?
|
|
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]>>
|
|
50
63
|
: never
|
|
51
64
|
: never;
|
|
52
65
|
type Normalize<T> = keyof T | Normalize2<T>;
|
|
@@ -83,31 +96,39 @@ export type TFuncKey<N, T = Resources> = N extends (keyof T)[]
|
|
|
83
96
|
? Normalize<T[N]>
|
|
84
97
|
: string;
|
|
85
98
|
|
|
86
|
-
export type TFuncReturn<N,
|
|
87
|
-
? NormalizeMultiReturn<T,
|
|
99
|
+
export type TFuncReturn<N, TKeys, TDefaultResult, T = Resources> = N extends (keyof T)[]
|
|
100
|
+
? NormalizeMultiReturn<T, TKeys>
|
|
88
101
|
: N extends keyof T
|
|
89
|
-
? NormalizeReturn<T[N],
|
|
90
|
-
:
|
|
102
|
+
? NormalizeReturn<T[N], TKeys>
|
|
103
|
+
: Fallback<TDefaultResult>;
|
|
91
104
|
|
|
92
105
|
export interface TFunction<N extends Namespace = DefaultNamespace> {
|
|
93
|
-
<
|
|
94
|
-
|
|
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[],
|
|
95
112
|
options?: TOptions<TInterpolationMap> | string,
|
|
96
|
-
): TFuncReturn<N,
|
|
97
|
-
<
|
|
98
|
-
|
|
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[],
|
|
99
120
|
defaultValue?: string,
|
|
100
121
|
options?: TOptions<TInterpolationMap> | string,
|
|
101
|
-
): TFuncReturn<N,
|
|
122
|
+
): TFuncReturn<N, TKeys, TDefaultResult>;
|
|
102
123
|
}
|
|
103
124
|
|
|
104
125
|
export interface TransProps<
|
|
105
|
-
K extends TFuncKey<N
|
|
126
|
+
K extends TFuncKey<N> extends infer A ? A : never,
|
|
106
127
|
N extends Namespace = DefaultNamespace,
|
|
107
128
|
E extends Element = HTMLDivElement
|
|
108
129
|
> extends React.HTMLProps<E> {
|
|
109
130
|
children?: React.ReactNode;
|
|
110
|
-
components?: React.ReactNode[] | { [tagName: string]: React.ReactNode };
|
|
131
|
+
components?: readonly React.ReactNode[] | { readonly [tagName: string]: React.ReactNode };
|
|
111
132
|
count?: number;
|
|
112
133
|
defaults?: string;
|
|
113
134
|
i18n?: i18n;
|
|
@@ -119,7 +140,7 @@ export interface TransProps<
|
|
|
119
140
|
t?: TFunction<N>;
|
|
120
141
|
}
|
|
121
142
|
export function Trans<
|
|
122
|
-
K extends TFuncKey<N
|
|
143
|
+
K extends TFuncKey<N> extends infer A ? A : never,
|
|
123
144
|
N extends Namespace = DefaultNamespace,
|
|
124
145
|
E extends Element = HTMLDivElement
|
|
125
146
|
>(props: TransProps<K, N, E>): React.ReactElement;
|
|
@@ -137,7 +158,7 @@ type UseTranslationResponse<N extends Namespace> = [TFunction<N>, i18n, boolean]
|
|
|
137
158
|
ready: boolean;
|
|
138
159
|
};
|
|
139
160
|
|
|
140
|
-
type DefaultNamespace<T = 'translation'> =
|
|
161
|
+
type DefaultNamespace<T = 'translation'> = Fallback<string> extends T ? T : string;
|
|
141
162
|
|
|
142
163
|
export function useTranslation<N extends Namespace = DefaultNamespace>(
|
|
143
164
|
ns?: N,
|
|
@@ -175,9 +196,15 @@ export function withTranslation<N extends Namespace = DefaultNamespace>(
|
|
|
175
196
|
options?: {
|
|
176
197
|
withRef?: boolean;
|
|
177
198
|
},
|
|
178
|
-
): <
|
|
179
|
-
|
|
180
|
-
|
|
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>;
|
|
181
208
|
|
|
182
209
|
export interface I18nextProviderProps {
|
|
183
210
|
i18n: i18n;
|