-
-
Notifications
You must be signed in to change notification settings - Fork 28
/
index.d.ts
186 lines (158 loc) · 4.29 KB
/
index.d.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
import {
Application,
Handler,
NextFunction,
Request,
RequestHandler,
Response,
Router,
} from "express-serve-static-core";
import * as i18next from "i18next";
/// <reference types="express-serve-static-core" />
type I18next = i18next.i18n;
type App = Application | Router;
type I18NextRequest = {
language: string;
languages: string[];
i18n: i18next.i18n;
t: i18next.TFunction;
};
declare global {
namespace Express {
interface Request extends I18NextRequest {}
}
}
declare module 'fastify' {
interface FastifyRequest extends I18NextRequest {}
}
interface ExtendedOptions extends Object {
getPath?: (req: Request) => string;
getOriginalUrl?: (req: Request) => string;
getUrl?: (req: Request) => string;
setUrl?: (req: Request, url: string) => void;
getParams?: (req: Request) => Object;
getSession?: (req: Request) => Object;
getQuery?: (req: Request) => Object;
getCookies?: (req: Request) => Object;
getBody?: (req: Request) => Object;
getHeaders?: (req: Request) => Object;
getHeader?: (res: Response, name: string) => Object;
setHeader?: (res: Response, name: string, value: string) => void;
setContentType?: (res: Response, type: string) => void;
setStatus?: (res: Response, code: number) => void;
send?: (res: Response, body: any) => void;
}
interface HandleOptions extends ExtendedOptions {
ignoreRoutes?: string[] | IgnoreRoutesFunction;
removeLngFromUrl?: boolean;
}
interface GetResourcesHandlerOptions extends ExtendedOptions {
maxAge?: number;
cache?: boolean;
lngParam?: string;
nsParam?: string;
}
interface MissingKeyHandlerOptions extends ExtendedOptions {
lngParam?: string;
nsParam?: string;
}
type IgnoreRoutesFunction = (
req: Request,
res: Response,
options: HandleOptions,
i18next: I18next
) => boolean;
export function handle(i18next: I18next, options?: HandleOptions): Handler;
export function koaPlugin(i18next: I18next, options?: HandleOptions): (context: unknown, next: Function) => any;
export function plugin(
instance: any,
options: HandleOptions & { i18next?: I18next },
next: NextFunction
): Handler;
export function getResourcesHandler(
i18next: I18next,
options?: GetResourcesHandlerOptions
): Handler;
export function missingKeyHandler(
i18next: I18next,
options?: MissingKeyHandlerOptions
): Handler;
export function addRoute(
i18next: I18next,
route: string,
lngs: string[],
app: App,
verb: string,
fc: RequestHandler
): void;
// LanguageDetector
type LanguageDetectorServices = any;
type LanguageDetectorOrder = string[];
type LanguageDetectorCaches = boolean | string[];
interface LanguageDetectorOptions {
order?: LanguageDetectorOrder;
lookupQuerystring?: string;
lookupCookie?: string;
lookupSession?: string;
lookupFromPathIndex?: number;
caches?: LanguageDetectorCaches;
cookieExpirationDate?: Date;
cookieDomain?: string;
/**
* optional conversion function to use to modify the detected language code
*/
convertDetectedLanguage?: 'Iso15897' | ((lng: string) => string);
}
interface LanguageDetectorAllOptions {
fallbackLng: boolean | string | string[];
}
interface LanguageDetectorInterfaceOptions {
[name: string]: any;
}
interface LanguageDetectorInterface {
name: string;
lookup: (
req: Request,
res: Response,
options?: LanguageDetectorInterfaceOptions
) => string | string[] | undefined;
cacheUserLanguage?: (
req: Request,
res: Response,
lng: string,
options?: Object
) => void;
}
export class LanguageDetector implements i18next.Module {
type: "languageDetector";
constructor(
services: LanguageDetectorServices,
options?: LanguageDetectorOptions,
allOptions?: LanguageDetectorAllOptions
);
constructor(
options?: LanguageDetectorOptions,
allOptions?: LanguageDetectorAllOptions
);
init(
services: LanguageDetectorServices,
options?: LanguageDetectorOptions,
allOptions?: LanguageDetectorAllOptions
): void;
init(
options?: LanguageDetectorOptions,
allOptions?: LanguageDetectorAllOptions
): void;
addDetector(detector: LanguageDetectorInterface): void;
detect(
req: Request,
res: Response,
detectionOrder: LanguageDetectorOrder
): void;
cacheUserLanguage(
req: Request,
res: Response,
lng: string,
caches: LanguageDetectorCaches
): void;
}