1 | import type { $Subtract, $Tuple } from './helpers.js';
|
2 | import type {
|
3 | ReactOptions,
|
4 | i18n,
|
5 | Resource,
|
6 | FlatNamespace,
|
7 | Namespace,
|
8 | TypeOptions,
|
9 | TFunction,
|
10 | KeyPrefix,
|
11 | } from 'i18next';
|
12 | import * as React from 'react';
|
13 | import { Trans, TransProps, ErrorCode, ErrorArgs } from './TransWithoutContext.js';
|
14 | export { initReactI18next } from './initReactI18next.js';
|
15 |
|
16 | export const TransWithoutContext: typeof Trans;
|
17 | export { Trans, TransProps, ErrorArgs, ErrorCode };
|
18 |
|
19 | export function setDefaults(options: ReactOptions): void;
|
20 | export function getDefaults(): ReactOptions;
|
21 | export function setI18n(instance: i18n): void;
|
22 | export function getI18n(): i18n;
|
23 | export function composeInitialProps(ForComponent: any): (ctx: unknown) => Promise<any>;
|
24 | export function getInitialProps(): {
|
25 | initialI18nStore: {
|
26 | [ns: string]: {};
|
27 | };
|
28 | initialLanguage: string;
|
29 | };
|
30 |
|
31 | export interface ReportNamespaces {
|
32 | addUsedNamespaces(namespaces: Namespace): void;
|
33 | getUsedNamespaces(): string[];
|
34 | }
|
35 |
|
36 | declare module 'i18next' {
|
37 |
|
38 |
|
39 |
|
40 | interface CustomInstanceExtensions {
|
41 | reportNamespaces?: ReportNamespaces;
|
42 | }
|
43 | }
|
44 |
|
45 | type ObjectOrNever = TypeOptions['allowObjectInHTMLChildren'] extends true
|
46 | ? Record<string, unknown>
|
47 | : never;
|
48 |
|
49 | type ReactI18NextChildren = React.ReactNode | ObjectOrNever;
|
50 |
|
51 | declare module 'react' {
|
52 | namespace JSX {
|
53 | interface IntrinsicAttributes {
|
54 | i18nIsDynamicList?: boolean;
|
55 | }
|
56 | }
|
57 |
|
58 | interface HTMLAttributes<T> {
|
59 |
|
60 |
|
61 |
|
62 | children?: ReactI18NextChildren | Iterable<ReactI18NextChildren>;
|
63 | }
|
64 | }
|
65 |
|
66 | type _DefaultNamespace = TypeOptions['defaultNS'];
|
67 |
|
68 | export function useSSR(initialI18nStore: Resource, initialLanguage: string): void;
|
69 |
|
70 | export interface UseTranslationOptions<KPrefix> {
|
71 | i18n?: i18n;
|
72 | useSuspense?: boolean;
|
73 | keyPrefix?: KPrefix;
|
74 | bindI18n?: string | false;
|
75 | nsMode?: 'fallback' | 'default';
|
76 | lng?: string;
|
77 |
|
78 | }
|
79 |
|
80 | export type UseTranslationResponse<Ns extends Namespace, KPrefix> = [
|
81 | t: TFunction<Ns, KPrefix>,
|
82 | i18n: i18n,
|
83 | ready: boolean,
|
84 | ] & {
|
85 | t: TFunction<Ns, KPrefix>;
|
86 | i18n: i18n;
|
87 | ready: boolean;
|
88 | };
|
89 |
|
90 |
|
91 |
|
92 |
|
93 | export type FallbackNs<Ns> = Ns extends undefined
|
94 | ? _DefaultNamespace
|
95 | : Ns extends Namespace
|
96 | ? Ns
|
97 | : _DefaultNamespace;
|
98 |
|
99 | export function useTranslation<
|
100 | Ns extends FlatNamespace | $Tuple<FlatNamespace> | undefined = undefined,
|
101 | KPrefix extends KeyPrefix<FallbackNs<Ns>> = undefined,
|
102 | >(
|
103 | ns?: Ns,
|
104 | options?: UseTranslationOptions<KPrefix>,
|
105 | ): UseTranslationResponse<FallbackNs<Ns>, KPrefix>;
|
106 |
|
107 |
|
108 | export function withSSR(): <Props>(WrappedComponent: React.ComponentType<Props>) => {
|
109 | ({
|
110 | initialI18nStore,
|
111 | initialLanguage,
|
112 | ...rest
|
113 | }: {
|
114 | initialI18nStore: Resource;
|
115 | initialLanguage: string;
|
116 | } & Props): React.FunctionComponentElement<Props>;
|
117 | getInitialProps: (ctx: unknown) => Promise<any>;
|
118 | };
|
119 |
|
120 | export interface WithTranslation<
|
121 | Ns extends FlatNamespace | $Tuple<FlatNamespace> | undefined = undefined,
|
122 | KPrefix extends KeyPrefix<FallbackNs<Ns>> = undefined,
|
123 | > {
|
124 | t: TFunction<FallbackNs<Ns>, KPrefix>;
|
125 | i18n: i18n;
|
126 | tReady: boolean;
|
127 | }
|
128 |
|
129 | export interface WithTranslationProps {
|
130 | i18n?: i18n;
|
131 | useSuspense?: boolean;
|
132 | }
|
133 |
|
134 | export function withTranslation<
|
135 | Ns extends FlatNamespace | $Tuple<FlatNamespace> | undefined = undefined,
|
136 | KPrefix extends KeyPrefix<FallbackNs<Ns>> = undefined,
|
137 | >(
|
138 | ns?: Ns,
|
139 | options?: {
|
140 | withRef?: boolean;
|
141 | keyPrefix?: KPrefix;
|
142 | },
|
143 | ): <
|
144 | C extends React.ComponentType<React.ComponentProps<any> & WithTranslationProps>,
|
145 | ResolvedProps = React.JSX.LibraryManagedAttributes<
|
146 | C,
|
147 | $Subtract<React.ComponentProps<C>, WithTranslationProps>
|
148 | >,
|
149 | >(
|
150 | component: C,
|
151 | ) => React.ComponentType<Omit<ResolvedProps, keyof WithTranslation<Ns>> & WithTranslationProps>;
|
152 |
|
153 | export interface I18nextProviderProps {
|
154 | children?: React.ReactNode;
|
155 | i18n: i18n;
|
156 | defaultNS?: string | string[];
|
157 | }
|
158 |
|
159 | export const I18nextProvider: React.FunctionComponent<I18nextProviderProps>;
|
160 | export const I18nContext: React.Context<{ i18n: i18n }>;
|
161 |
|
162 | export interface TranslationProps<
|
163 | Ns extends FlatNamespace | $Tuple<FlatNamespace> | undefined = undefined,
|
164 | KPrefix extends KeyPrefix<FallbackNs<Ns>> = undefined,
|
165 | > {
|
166 | children: (
|
167 | t: TFunction<FallbackNs<Ns>, KPrefix>,
|
168 | options: {
|
169 | i18n: i18n;
|
170 | lng: string;
|
171 | },
|
172 | ready: boolean,
|
173 | ) => React.ReactNode;
|
174 | ns?: Ns;
|
175 | i18n?: i18n;
|
176 | useSuspense?: boolean;
|
177 | keyPrefix?: KPrefix;
|
178 | nsMode?: 'fallback' | 'default';
|
179 | }
|
180 |
|
181 | export function Translation<
|
182 | Ns extends FlatNamespace | $Tuple<FlatNamespace> | undefined = undefined,
|
183 | KPrefix extends KeyPrefix<FallbackNs<Ns>> = undefined,
|
184 | >(props: TranslationProps<Ns, KPrefix>): any;
|