react-i18next
Advanced tools
Comparing version 11.12.0 to 11.13.0
@@ -0,1 +1,6 @@ | ||
### 11.13.0 | ||
- feat(types): add type-safe support to keyPrefix option [1390](https://github.com/i18next/react-i18next/pull/1390) | ||
- feat(types): allow key separator augmentation [1367](https://github.com/i18next/react-i18next/pull/1367) | ||
### 11.12.0 | ||
@@ -2,0 +7,0 @@ |
{ | ||
"name": "react-i18next", | ||
"version": "11.12.0", | ||
"version": "11.13.0", | ||
"description": "Internationalization for react done right. Using the i18next i18n ecosystem.", | ||
@@ -70,3 +70,3 @@ "main": "dist/commonjs/index.js", | ||
"husky": "^3.0.3", | ||
"i18next": "^20.6.1", | ||
"i18next": "^21.0.0", | ||
"jest": "^24.8.0", | ||
@@ -73,0 +73,0 @@ "jest-cli": "^24.8.4", |
@@ -57,2 +57,3 @@ import i18next, { | ||
returnEmptyString: true; | ||
keySeparator: '.'; | ||
defaultNS: 'translation'; | ||
@@ -96,4 +97,6 @@ resources: Resources; | ||
// Normalize single namespace | ||
type AppendKeys<K1, K2> = `${K1 & string}.${K2 & string}`; | ||
type AppendKeys2<K1, K2> = `${K1 & string}.${Exclude<K2, keyof any[]> & string}`; | ||
type AppendKeys<K1, K2, S extends string = TypeOptions['keySeparator']> = `${K1 & string}${S}${K2 & | ||
string}`; | ||
type AppendKeys2<K1, K2, S extends string = TypeOptions['keySeparator']> = `${K1 & | ||
string}${S}${Exclude<K2, keyof any[]> & string}`; | ||
type Normalize2<T, K = keyof T> = K extends keyof T | ||
@@ -140,8 +143,14 @@ ? T[K] extends Record<string, any> | ||
type NormalizeReturn<T, V> = V extends `${infer K}.${infer R}` | ||
type NormalizeReturn< | ||
T, | ||
V, | ||
S extends string | false = TypeOptions['keySeparator'] | ||
> = V extends keyof T | ||
? NormalizeByTypeOptions<T[V]> | ||
: S extends false | ||
? V | ||
: V extends `${infer K}${S}${infer R}` | ||
? K extends keyof T | ||
? NormalizeReturn<T[K], R> | ||
: never | ||
: V extends keyof T | ||
? NormalizeByTypeOptions<T[V]> | ||
: never; | ||
@@ -155,8 +164,16 @@ | ||
export type TFuncKey<N extends Namespace = DefaultNamespace, T = DefaultResources> = N extends | ||
| (keyof T)[] | ||
| Readonly<(keyof T)[]> | ||
type KeyPrefix<N extends Namespace> = N extends keyof DefaultResources | ||
? Fallback<string, keyof DefaultResources[N]> | undefined | ||
: string | undefined; | ||
export type TFuncKey< | ||
N extends Namespace = DefaultNamespace, | ||
TKPrefix extends KeyPrefix<N> = undefined, | ||
T = DefaultResources | ||
> = N extends (keyof T)[] | Readonly<(keyof T)[]> | ||
? NormalizeMulti<T, N[number]> | ||
: N extends keyof T | ||
? Normalize<T[N]> | ||
? TKPrefix extends keyof T[N] | ||
? Normalize<T[N][TKPrefix]> | ||
: Normalize<T[N]> | ||
: string; | ||
@@ -170,5 +187,8 @@ | ||
export interface TFunction<N extends Namespace = DefaultNamespace> { | ||
export interface TFunction< | ||
N extends Namespace = DefaultNamespace, | ||
TKPrefix extends KeyPrefix<N> = undefined | ||
> { | ||
< | ||
TKeys extends TFuncKey<N> | TemplateStringsArray extends infer A ? A : never, | ||
TKeys extends TFuncKey<N, TKPrefix> | TemplateStringsArray extends infer A ? A : never, | ||
TDefaultResult extends TFunctionResult = string, | ||
@@ -181,3 +201,3 @@ TInterpolationMap extends object = StringMap | ||
< | ||
TKeys extends TFuncKey<N> | TemplateStringsArray extends infer A ? A : never, | ||
TKeys extends TFuncKey<N, TKPrefix> | TemplateStringsArray extends infer A ? A : never, | ||
TDefaultResult extends TFunctionResult = string, | ||
@@ -217,10 +237,17 @@ TInterpolationMap extends object = StringMap | ||
export interface UseTranslationOptions { | ||
export interface UseTranslationOptions< | ||
N extends Namespace = DefaultNamespace, | ||
TKPrefix extends KeyPrefix<N> = undefined | ||
> { | ||
i18n?: i18n; | ||
useSuspense?: boolean; | ||
keyPrefix?: string; | ||
keyPrefix?: TKPrefix; | ||
} | ||
type UseTranslationResponse<N extends Namespace> = [TFunction<N>, i18n, boolean] & { | ||
t: TFunction<N>; | ||
type UseTranslationResponse<N extends Namespace, TKPrefix extends KeyPrefix<N>> = [ | ||
TFunction<N, TKPrefix>, | ||
i18n, | ||
boolean, | ||
] & { | ||
t: TFunction<N, TKPrefix>; | ||
i18n: i18n; | ||
@@ -230,6 +257,9 @@ ready: boolean; | ||
export function useTranslation<N extends Namespace = DefaultNamespace>( | ||
export function useTranslation< | ||
N extends Namespace = DefaultNamespace, | ||
TKPrefix extends KeyPrefix<N> = undefined | ||
>( | ||
ns?: N | Readonly<N>, | ||
options?: UseTranslationOptions, | ||
): UseTranslationResponse<N>; | ||
options?: UseTranslationOptions<N, TKPrefix>, | ||
): UseTranslationResponse<N, TKPrefix>; | ||
@@ -236,0 +266,0 @@ // Need to see usage to improve this |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
335792
5955