react-i18next 11.13.0 → 11.14.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 +5 -0
- package/package.json +1 -1
- package/ts4.1/index.d.ts +20 -12
package/CHANGELOG.md
CHANGED
|
@@ -1,3 +1,8 @@
|
|
|
1
|
+
### 11.14.0
|
|
2
|
+
|
|
3
|
+
- Remove generics from Trans component to suppress warning issue [1400](https://github.com/i18next/react-i18next/pull/1400)
|
|
4
|
+
- Add type support to plurals [1399](https://github.com/i18next/react-i18next/pull/1399)
|
|
5
|
+
|
|
1
6
|
### 11.13.0
|
|
2
7
|
|
|
3
8
|
- feat(types): add type-safe support to keyPrefix option [1390](https://github.com/i18next/react-i18next/pull/1390)
|
package/package.json
CHANGED
package/ts4.1/index.d.ts
CHANGED
|
@@ -35,8 +35,10 @@ export interface Resources {}
|
|
|
35
35
|
* declare module 'react-i18next' {
|
|
36
36
|
* interface CustomTypeOptions {
|
|
37
37
|
* defaultNS: 'custom';
|
|
38
|
-
* returnNull: false
|
|
39
|
-
* returnEmptyString: false
|
|
38
|
+
* returnNull: false;
|
|
39
|
+
* returnEmptyString: false;
|
|
40
|
+
* keySeparator: '.';
|
|
41
|
+
* jsonFormat: 'v4';
|
|
40
42
|
* resources: {
|
|
41
43
|
* custom: {
|
|
42
44
|
* foo: 'foo';
|
|
@@ -56,6 +58,7 @@ type TypeOptions = MergeBy<
|
|
|
56
58
|
returnEmptyString: true;
|
|
57
59
|
keySeparator: '.';
|
|
58
60
|
defaultNS: 'translation';
|
|
61
|
+
jsonFormat: 'v4';
|
|
59
62
|
resources: Resources;
|
|
60
63
|
},
|
|
61
64
|
CustomTypeOptions
|
|
@@ -92,6 +95,12 @@ declare module 'i18next' {
|
|
|
92
95
|
}
|
|
93
96
|
}
|
|
94
97
|
|
|
98
|
+
type WithOrWithoutPlural<K> = TypeOptions['jsonFormat'] extends 'v4'
|
|
99
|
+
? K extends `${infer B}_${'zero' | 'one' | 'two' | 'few' | 'many' | 'other'}`
|
|
100
|
+
? B | K
|
|
101
|
+
: K
|
|
102
|
+
: K;
|
|
103
|
+
|
|
95
104
|
// Normalize single namespace
|
|
96
105
|
type AppendKeys<K1, K2, S extends string = TypeOptions['keySeparator']> = `${K1 & string}${S}${K2 &
|
|
97
106
|
string}`;
|
|
@@ -100,11 +109,11 @@ type AppendKeys2<K1, K2, S extends string = TypeOptions['keySeparator']> = `${K1
|
|
|
100
109
|
type Normalize2<T, K = keyof T> = K extends keyof T
|
|
101
110
|
? T[K] extends Record<string, any>
|
|
102
111
|
? T[K] extends readonly any[]
|
|
103
|
-
? AppendKeys2<K, keyof T[K]
|
|
104
|
-
: AppendKeys<K, keyof T[K]
|
|
112
|
+
? AppendKeys2<K, WithOrWithoutPlural<keyof T[K]>> | AppendKeys2<K, Normalize2<T[K]>>
|
|
113
|
+
: AppendKeys<K, WithOrWithoutPlural<keyof T[K]>> | AppendKeys<K, Normalize2<T[K]>>
|
|
105
114
|
: never
|
|
106
115
|
: never;
|
|
107
|
-
type Normalize<T> = keyof T | Normalize2<T>;
|
|
116
|
+
type Normalize<T> = WithOrWithoutPlural<keyof T> | Normalize2<T>;
|
|
108
117
|
|
|
109
118
|
// Normalize multiple namespaces
|
|
110
119
|
type UnionToIntersection<U> = (U extends any ? (k: U) => void : never) extends (k: infer I) => void
|
|
@@ -203,8 +212,8 @@ export interface TFunction<
|
|
|
203
212
|
): TFuncReturn<N, TKeys, TDefaultResult>;
|
|
204
213
|
}
|
|
205
214
|
|
|
215
|
+
type I18nKeyType<N extends Namespace> = TFuncKey<N> extends infer A ? A : never;
|
|
206
216
|
export interface TransProps<
|
|
207
|
-
K extends TFuncKey<N> extends infer A ? A : never,
|
|
208
217
|
N extends Namespace = DefaultNamespace,
|
|
209
218
|
E extends Element = HTMLDivElement
|
|
210
219
|
> extends React.HTMLProps<E> {
|
|
@@ -213,18 +222,17 @@ export interface TransProps<
|
|
|
213
222
|
count?: number;
|
|
214
223
|
defaults?: string;
|
|
215
224
|
i18n?: i18n;
|
|
216
|
-
i18nKey?:
|
|
225
|
+
i18nKey?: I18nKeyType<N> | I18nKeyType<N>[];
|
|
217
226
|
ns?: N;
|
|
218
227
|
parent?: string | React.ComponentType<any> | null; // used in React.createElement if not null
|
|
219
228
|
tOptions?: {};
|
|
220
229
|
values?: {};
|
|
221
230
|
t?: TFunction<N>;
|
|
222
231
|
}
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
N
|
|
226
|
-
|
|
227
|
-
>(props: TransProps<K, N, E>): React.ReactElement;
|
|
232
|
+
|
|
233
|
+
export function Trans<N extends Namespace = DefaultNamespace, E extends Element = HTMLDivElement>(
|
|
234
|
+
props: TransProps<N, E>,
|
|
235
|
+
): React.ReactElement;
|
|
228
236
|
|
|
229
237
|
export function useSSR(initialI18nStore: Resource, initialLanguage: string): void;
|
|
230
238
|
|