Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

context less version of Trans component #1588

Merged
merged 2 commits into from Dec 6, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
33 changes: 33 additions & 0 deletions TransWithoutContext.d.ts
@@ -0,0 +1,33 @@
import { i18n, TFuncKey, Namespace, TypeOptions, TFunction, KeyPrefix } from 'i18next';
import * as React from 'react';

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 };
count?: number;
context?: string;
defaults?: string;
i18n?: i18n;
i18nKey?: K | K[];
ns?: N;
parent?: string | React.ComponentType<any> | null; // used in React.createElement if not null
tOptions?: {};
values?: {};
shouldUnescape?: boolean;
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;
34 changes: 2 additions & 32 deletions index.d.ts
@@ -1,23 +1,22 @@
import i18next, {
ReactOptions,
i18n,
ThirdPartyModule,
Resource,
TFuncKey,
Namespace,
TypeOptions,
TFunction,
KeyPrefix,
} from 'i18next';
import * as React from 'react';
export { Trans, TransProps } from './TransWithoutContext';
export { initReactI18next } from './initReactI18next';

type Subtract<T extends K, K> = Omit<T, keyof K>;

export function setDefaults(options: ReactOptions): void;
export function getDefaults(): ReactOptions;
export function setI18n(instance: i18n): void;
export function getI18n(): i18n;
export const initReactI18next: ThirdPartyModule;
export function composeInitialProps(ForComponent: any): (ctx: unknown) => Promise<any>;
export function getInitialProps(): {
initialI18nStore: {
Expand Down Expand Up @@ -50,35 +49,6 @@ declare module 'react' {

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 };
count?: number;
context?: string;
defaults?: string;
i18n?: i18n;
i18nKey?: K | K[];
ns?: N;
parent?: string | React.ComponentType<any> | null; // used in React.createElement if not null
tOptions?: {};
values?: {};
shouldUnescape?: boolean;
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<TKPrefix = undefined> {
Expand Down
3 changes: 3 additions & 0 deletions initReactI18next.d.ts
@@ -0,0 +1,3 @@
import { ThirdPartyModule } from 'i18next';

export const initReactI18next: ThirdPartyModule;
18 changes: 18 additions & 0 deletions package.json
Expand Up @@ -17,6 +17,24 @@
"react",
"reactjs"
],
"exports": {
"./package.json": "./package.json",
".": {
"types": "./index.d.ts",
"import": "./dist/es/index.js",
"require": "./dist/commonjs/index.js"
},
"./TransWithoutContext": {
"types": "./TransWithoutContext.d.ts",
"import": "./dist/es/TransWithoutContext.js",
"require": "./dist/commonjs/TransWithoutContext.js"
},
"./initReactI18next": {
"types": "./initReactI18next.d.ts",
"import": "./dist/es/initReactI18next.js",
"require": "./dist/commonjs/initReactI18next.js"
}
},
"homepage": "https://github.com/i18next/react-i18next",
"bugs": "https://github.com/i18next/react-i18next/issues",
"repository": {
Expand Down