react-i18next 11.12.0 → 11.13.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 +2 -2
- package/ts4.1/index.d.ts +49 -19
package/CHANGELOG.md
CHANGED
|
@@ -1,3 +1,8 @@
|
|
|
1
|
+
### 11.13.0
|
|
2
|
+
|
|
3
|
+
- feat(types): add type-safe support to keyPrefix option [1390](https://github.com/i18next/react-i18next/pull/1390)
|
|
4
|
+
- feat(types): allow key separator augmentation [1367](https://github.com/i18next/react-i18next/pull/1367)
|
|
5
|
+
|
|
1
6
|
### 11.12.0
|
|
2
7
|
|
|
3
8
|
- feature: add key prefix support to useTranslation hook [1371](https://github.com/i18next/react-i18next/pull/1371)
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "react-i18next",
|
|
3
|
-
"version": "11.
|
|
3
|
+
"version": "11.13.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",
|
|
@@ -67,7 +67,7 @@
|
|
|
67
67
|
"eslint-plugin-react": "^7.16.0",
|
|
68
68
|
"eslint-plugin-testing-library": "^3.10.1",
|
|
69
69
|
"husky": "^3.0.3",
|
|
70
|
-
"i18next": "^
|
|
70
|
+
"i18next": "^21.0.0",
|
|
71
71
|
"jest": "^24.8.0",
|
|
72
72
|
"jest-cli": "^24.8.4",
|
|
73
73
|
"lint-staged": "^8.1.3",
|
package/ts4.1/index.d.ts
CHANGED
|
@@ -54,6 +54,7 @@ type TypeOptions = MergeBy<
|
|
|
54
54
|
{
|
|
55
55
|
returnNull: true;
|
|
56
56
|
returnEmptyString: true;
|
|
57
|
+
keySeparator: '.';
|
|
57
58
|
defaultNS: 'translation';
|
|
58
59
|
resources: Resources;
|
|
59
60
|
},
|
|
@@ -92,8 +93,10 @@ declare module 'i18next' {
|
|
|
92
93
|
}
|
|
93
94
|
|
|
94
95
|
// Normalize single namespace
|
|
95
|
-
type AppendKeys<K1, K2> = `${K1 & string}
|
|
96
|
-
|
|
96
|
+
type AppendKeys<K1, K2, S extends string = TypeOptions['keySeparator']> = `${K1 & string}${S}${K2 &
|
|
97
|
+
string}`;
|
|
98
|
+
type AppendKeys2<K1, K2, S extends string = TypeOptions['keySeparator']> = `${K1 &
|
|
99
|
+
string}${S}${Exclude<K2, keyof any[]> & string}`;
|
|
97
100
|
type Normalize2<T, K = keyof T> = K extends keyof T
|
|
98
101
|
? T[K] extends Record<string, any>
|
|
99
102
|
? T[K] extends readonly any[]
|
|
@@ -135,12 +138,18 @@ export type NormalizeByTypeOptions<
|
|
|
135
138
|
R = TypeOptionsFallback<TranslationValue, Options['returnEmptyString'], ''>
|
|
136
139
|
> = TypeOptionsFallback<R, Options['returnNull'], null>;
|
|
137
140
|
|
|
138
|
-
type NormalizeReturn<
|
|
141
|
+
type NormalizeReturn<
|
|
142
|
+
T,
|
|
143
|
+
V,
|
|
144
|
+
S extends string | false = TypeOptions['keySeparator']
|
|
145
|
+
> = V extends keyof T
|
|
146
|
+
? NormalizeByTypeOptions<T[V]>
|
|
147
|
+
: S extends false
|
|
148
|
+
? V
|
|
149
|
+
: V extends `${infer K}${S}${infer R}`
|
|
139
150
|
? K extends keyof T
|
|
140
151
|
? NormalizeReturn<T[K], R>
|
|
141
152
|
: never
|
|
142
|
-
: V extends keyof T
|
|
143
|
-
? NormalizeByTypeOptions<T[V]>
|
|
144
153
|
: never;
|
|
145
154
|
|
|
146
155
|
type NormalizeMultiReturn<T, V> = V extends `${infer N}:${infer R}`
|
|
@@ -149,12 +158,20 @@ type NormalizeMultiReturn<T, V> = V extends `${infer N}:${infer R}`
|
|
|
149
158
|
: never
|
|
150
159
|
: never;
|
|
151
160
|
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
|
161
|
+
type KeyPrefix<N extends Namespace> = N extends keyof DefaultResources
|
|
162
|
+
? Fallback<string, keyof DefaultResources[N]> | undefined
|
|
163
|
+
: string | undefined;
|
|
164
|
+
|
|
165
|
+
export type TFuncKey<
|
|
166
|
+
N extends Namespace = DefaultNamespace,
|
|
167
|
+
TKPrefix extends KeyPrefix<N> = undefined,
|
|
168
|
+
T = DefaultResources
|
|
169
|
+
> = N extends (keyof T)[] | Readonly<(keyof T)[]>
|
|
155
170
|
? NormalizeMulti<T, N[number]>
|
|
156
171
|
: N extends keyof T
|
|
157
|
-
?
|
|
172
|
+
? TKPrefix extends keyof T[N]
|
|
173
|
+
? Normalize<T[N][TKPrefix]>
|
|
174
|
+
: Normalize<T[N]>
|
|
158
175
|
: string;
|
|
159
176
|
|
|
160
177
|
export type TFuncReturn<N, TKeys, TDefaultResult, T = DefaultResources> = N extends (keyof T)[]
|
|
@@ -163,9 +180,12 @@ export type TFuncReturn<N, TKeys, TDefaultResult, T = DefaultResources> = N exte
|
|
|
163
180
|
? NormalizeReturn<T[N], TKeys>
|
|
164
181
|
: Fallback<TDefaultResult>;
|
|
165
182
|
|
|
166
|
-
export interface TFunction<
|
|
183
|
+
export interface TFunction<
|
|
184
|
+
N extends Namespace = DefaultNamespace,
|
|
185
|
+
TKPrefix extends KeyPrefix<N> = undefined
|
|
186
|
+
> {
|
|
167
187
|
<
|
|
168
|
-
TKeys extends TFuncKey<N> | TemplateStringsArray extends infer A ? A : never,
|
|
188
|
+
TKeys extends TFuncKey<N, TKPrefix> | TemplateStringsArray extends infer A ? A : never,
|
|
169
189
|
TDefaultResult extends TFunctionResult = string,
|
|
170
190
|
TInterpolationMap extends object = StringMap
|
|
171
191
|
>(
|
|
@@ -173,7 +193,7 @@ export interface TFunction<N extends Namespace = DefaultNamespace> {
|
|
|
173
193
|
options?: TOptions<TInterpolationMap> | string,
|
|
174
194
|
): TFuncReturn<N, TKeys, TDefaultResult>;
|
|
175
195
|
<
|
|
176
|
-
TKeys extends TFuncKey<N> | TemplateStringsArray extends infer A ? A : never,
|
|
196
|
+
TKeys extends TFuncKey<N, TKPrefix> | TemplateStringsArray extends infer A ? A : never,
|
|
177
197
|
TDefaultResult extends TFunctionResult = string,
|
|
178
198
|
TInterpolationMap extends object = StringMap
|
|
179
199
|
>(
|
|
@@ -208,22 +228,32 @@ export function Trans<
|
|
|
208
228
|
|
|
209
229
|
export function useSSR(initialI18nStore: Resource, initialLanguage: string): void;
|
|
210
230
|
|
|
211
|
-
export interface UseTranslationOptions
|
|
231
|
+
export interface UseTranslationOptions<
|
|
232
|
+
N extends Namespace = DefaultNamespace,
|
|
233
|
+
TKPrefix extends KeyPrefix<N> = undefined
|
|
234
|
+
> {
|
|
212
235
|
i18n?: i18n;
|
|
213
236
|
useSuspense?: boolean;
|
|
214
|
-
keyPrefix?:
|
|
237
|
+
keyPrefix?: TKPrefix;
|
|
215
238
|
}
|
|
216
239
|
|
|
217
|
-
type UseTranslationResponse<N extends Namespace
|
|
218
|
-
|
|
240
|
+
type UseTranslationResponse<N extends Namespace, TKPrefix extends KeyPrefix<N>> = [
|
|
241
|
+
TFunction<N, TKPrefix>,
|
|
242
|
+
i18n,
|
|
243
|
+
boolean,
|
|
244
|
+
] & {
|
|
245
|
+
t: TFunction<N, TKPrefix>;
|
|
219
246
|
i18n: i18n;
|
|
220
247
|
ready: boolean;
|
|
221
248
|
};
|
|
222
249
|
|
|
223
|
-
export function useTranslation<
|
|
250
|
+
export function useTranslation<
|
|
251
|
+
N extends Namespace = DefaultNamespace,
|
|
252
|
+
TKPrefix extends KeyPrefix<N> = undefined
|
|
253
|
+
>(
|
|
224
254
|
ns?: N | Readonly<N>,
|
|
225
|
-
options?: UseTranslationOptions,
|
|
226
|
-
): UseTranslationResponse<N>;
|
|
255
|
+
options?: UseTranslationOptions<N, TKPrefix>,
|
|
256
|
+
): UseTranslationResponse<N, TKPrefix>;
|
|
227
257
|
|
|
228
258
|
// Need to see usage to improve this
|
|
229
259
|
export function withSSR(): <Props>(
|