react-i18next
Advanced tools
Comparing version 11.18.6 to 12.0.0
@@ -0,1 +1,5 @@ | ||
### 12.0.0 | ||
- Update t function types to rely on types coming from i18next [1501](https://github.com/i18next/react-i18next/pull/1501) | ||
### 11.18.6 | ||
@@ -2,0 +6,0 @@ |
116
index.d.ts
@@ -1,9 +0,16 @@ | ||
import i18next, { ReactOptions, i18n, ThirdPartyModule, WithT, TFunction, Resource } from 'i18next'; | ||
import i18next, { | ||
ReactOptions, | ||
i18n, | ||
ThirdPartyModule, | ||
Resource, | ||
TFuncKey, | ||
Namespace, | ||
TypeOptions, | ||
TFunction, | ||
KeyPrefix, | ||
} from 'i18next'; | ||
import * as React from 'react'; | ||
type Omit<T, K> = Pick<T, Exclude<keyof T, K>>; | ||
type Subtract<T extends K, K> = Omit<T, keyof K>; | ||
export type Namespace = string | string[]; | ||
export function setDefaults(options: ReactOptions): void; | ||
@@ -23,3 +30,3 @@ export function getDefaults(): ReactOptions; | ||
export interface ReportNamespaces { | ||
addUsedNamespaces(namespaces: Namespace[]): void; | ||
addUsedNamespaces(namespaces: Namespace): void; | ||
getUsedNamespaces(): string[]; | ||
@@ -34,6 +41,23 @@ } | ||
export interface TransProps<E extends Element = HTMLDivElement> | ||
extends React.HTMLProps<E>, | ||
Partial<WithT> { | ||
children?: React.ReactNode; | ||
type ObjectOrNever = TypeOptions['allowObjectInHTMLChildren'] extends true | ||
? Record<string, unknown> | ||
: never; | ||
type ReactI18NextChild = React.ReactNode | ObjectOrNever; | ||
declare module 'react' { | ||
interface HTMLAttributes<T> { | ||
children?: ReactI18NextChild | Iterable<ReactI18NextChild>; | ||
} | ||
} | ||
type DefaultNamespace = TypeOptions['defaultNS']; | ||
type TransChild = React.ReactNode | Record<string, unknown>; | ||
export type TransProps< | ||
K extends TFuncKey<N, TKPrefix> extends infer A ? A : never, | ||
N extends Namespace = DefaultNamespace, | ||
TKPrefix = undefined, | ||
E = React.HTMLProps<HTMLDivElement> | ||
> = E & { | ||
children?: TransChild | TransChild[]; | ||
components?: readonly React.ReactElement[] | { readonly [tagName: string]: React.ReactElement }; | ||
@@ -44,4 +68,4 @@ count?: number; | ||
i18n?: i18n; | ||
i18nKey?: string; | ||
ns?: Namespace; | ||
i18nKey?: K | K[]; | ||
ns?: N; | ||
parent?: string | React.ComponentType<any> | null; // used in React.createElement if not null | ||
@@ -51,12 +75,18 @@ tOptions?: {}; | ||
shouldUnescape?: boolean; | ||
t?: TFunction; | ||
} | ||
export function Trans<E extends Element = HTMLDivElement>(props: TransProps<E>): React.ReactElement; | ||
t?: TFunction<N, TKPrefix>; | ||
}; | ||
export function Trans< | ||
K extends TFuncKey<N, TKPrefix> extends infer A ? A : never, | ||
N extends Namespace = DefaultNamespace, | ||
TKPrefix extends KeyPrefix<N> = undefined, | ||
E = React.HTMLProps<HTMLDivElement> | ||
>(props: TransProps<K, N, TKPrefix, E>): React.ReactElement; | ||
export function useSSR(initialI18nStore: Resource, initialLanguage: string): void; | ||
export interface UseTranslationOptions { | ||
export interface UseTranslationOptions<TKPrefix = undefined> { | ||
i18n?: i18n; | ||
useSuspense?: boolean; | ||
keyPrefix?: string; | ||
keyPrefix?: TKPrefix; | ||
bindI18n?: string | false; | ||
@@ -66,12 +96,21 @@ nsMode?: 'fallback' | 'default'; | ||
} | ||
export type UseTranslationResponse = [TFunction, i18n, boolean] & { | ||
t: TFunction; | ||
export type UseTranslationResponse<N extends Namespace, TKPrefix = undefined> = [ | ||
TFunction<N, TKPrefix>, | ||
i18n, | ||
boolean, | ||
] & { | ||
t: TFunction<N, TKPrefix>; | ||
i18n: i18n; | ||
ready: boolean; | ||
}; | ||
export function useTranslation( | ||
ns?: Namespace, | ||
options?: UseTranslationOptions, | ||
): UseTranslationResponse; | ||
export function useTranslation< | ||
N extends Namespace = DefaultNamespace, | ||
TKPrefix extends KeyPrefix<N> = undefined | ||
>( | ||
ns?: N | Readonly<N>, | ||
options?: UseTranslationOptions<TKPrefix>, | ||
): UseTranslationResponse<N, TKPrefix>; | ||
// Need to see usage to improve this | ||
@@ -92,3 +131,7 @@ export function withSSR(): <Props>( | ||
export interface WithTranslation extends WithT { | ||
export interface WithTranslation< | ||
N extends Namespace = DefaultNamespace, | ||
TKPrefix extends KeyPrefix<N> = undefined | ||
> { | ||
t: TFunction<N, TKPrefix>; | ||
i18n: i18n; | ||
@@ -103,9 +146,13 @@ tReady: boolean; | ||
export function withTranslation( | ||
ns?: Namespace, | ||
export function withTranslation< | ||
N extends Namespace = DefaultNamespace, | ||
TKPrefix extends KeyPrefix<N> = undefined | ||
>( | ||
ns?: N, | ||
options?: { | ||
withRef?: boolean; | ||
keyPrefix?: TKPrefix; | ||
}, | ||
): < | ||
C extends React.ComponentType<React.ComponentProps<C> & WithTranslationProps>, | ||
C extends React.ComponentType<React.ComponentProps<any> & WithTranslationProps>, | ||
ResolvedProps = JSX.LibraryManagedAttributes< | ||
@@ -117,3 +164,3 @@ C, | ||
component: C, | ||
) => React.ComponentType<Omit<ResolvedProps, keyof WithTranslation> & WithTranslationProps>; | ||
) => React.ComponentType<Omit<ResolvedProps, keyof WithTranslation<N>> & WithTranslationProps>; | ||
@@ -129,5 +176,8 @@ export interface I18nextProviderProps { | ||
export interface TranslationProps { | ||
export interface TranslationProps< | ||
N extends Namespace = DefaultNamespace, | ||
TKPrefix extends KeyPrefix<N> = undefined | ||
> { | ||
children: ( | ||
t: TFunction, | ||
t: TFunction<N, TKPrefix>, | ||
options: { | ||
@@ -139,8 +189,12 @@ i18n: i18n; | ||
) => React.ReactNode; | ||
ns?: Namespace; | ||
ns?: N; | ||
i18n?: i18n; | ||
useSuspense?: boolean; | ||
keyPrefix?: TKPrefix; | ||
nsMode?: 'fallback' | 'default'; | ||
} | ||
export function Translation(props: TranslationProps): any; | ||
export function Translation< | ||
N extends Namespace = DefaultNamespace, | ||
TKPrefix extends KeyPrefix<N> = undefined | ||
>(props: TranslationProps<N, TKPrefix>): any; |
{ | ||
"name": "react-i18next", | ||
"version": "11.18.6", | ||
"version": "12.0.0", | ||
"description": "Internationalization for react done right. Using the i18next i18n ecosystem.", | ||
"main": "dist/commonjs/index.js", | ||
"types": "./index.d.ts", | ||
"typesVersions": { | ||
">=4.1": { | ||
"*": [ | ||
"ts4.1/*" | ||
] | ||
} | ||
}, | ||
"jsnext:main": "dist/es/index.js", | ||
@@ -70,3 +63,3 @@ "module": "dist/es/index.js", | ||
"husky": "^3.0.3", | ||
"i18next": "^21.0.0", | ||
"i18next": "^22.0.1", | ||
"jest": "^24.8.0", | ||
@@ -73,0 +66,0 @@ "jest-cli": "^24.8.4", |
@@ -31,2 +31,3 @@ import { createElement, forwardRef as forwardRefReact } from 'react'; | ||
const forwardRef = (props, ref) => | ||
// eslint-disable-next-line prefer-object-spread | ||
createElement(I18nextWithTranslation, Object.assign({}, props, { forwardedRef: ref })); | ||
@@ -33,0 +34,0 @@ |
349463
47
6110
27