-
Notifications
You must be signed in to change notification settings - Fork 1
/
i18next-http-middleware.d.ts
174 lines (149 loc) · 4.43 KB
/
i18next-http-middleware.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
/* eslint-disable @typescript-eslint/ban-types */
declare module 'i18next-http-middleware' {
import type * as express from 'express'
import type * as i18next from 'i18next'
type I18next = i18next.i18n
type App = express.Application | express.Router
type I18NextRequest = {
language: string
languages: string[]
i18n: i18next.i18n
t: i18next.TFunction
}
global {
// eslint-disable-next-line
namespace Express {
// eslint-disable-next-line
interface Request extends I18NextRequest {}
}
}
interface ExtendedOptions extends Object {
getPath?: (req: express.Request) => string
getOriginalUrl?: (req: express.Request) => string
getUrl?: (req: express.Request) => string
setUrl?: (req: express.Request, url: string) => void
getParams?: (req: express.Request) => Object
getSession?: (req: express.Request) => Object
getQuery?: (req: express.Request) => Object
getCookies?: (req: express.Request) => Object
getBody?: (req: express.Request) => Object
getHeaders?: (req: express.Request) => Object
getHeader?: (res: express.Response, name: string) => Object
setHeader?: (res: express.Response, name: string, value: string) => void
setContentType?: (res: express.Response, type: string) => void
setStatus?: (res: express.Response, code: number) => void
send?: (res: express.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: express.Request,
res: express.Response,
options: HandleOptions,
i18next: I18next
) => boolean
export function handle(
i18next: I18next,
options?: HandleOptions
): express.Handler
export function plugin(
instance: any,
options: HandleOptions & { i18next?: I18next },
next: express.NextFunction
): express.Handler
export function getResourcesHandler(
i18next: I18next,
options?: GetResourcesHandlerOptions
): express.Handler
export function missingKeyHandler(
i18next: I18next,
options?: MissingKeyHandlerOptions
): express.Handler
export function addRoute(
i18next: I18next,
route: string,
lngs: string[],
app: App,
verb: string,
fc: express.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
}
interface LanguageDetectorAllOptions {
fallbackLng: boolean | string | string[]
}
interface LanguageDetectorInterfaceOptions {
[name: string]: any
}
interface LanguageDetectorInterface {
name: string
lookup: (
req: express.Request,
res: express.Response,
options?: LanguageDetectorInterfaceOptions
) => string | string[]
cacheUserLanguage?: (
req: express.Request,
res: express.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: express.Request,
res: express.Response,
detectionOrder: LanguageDetectorOrder
): void
cacheUserLanguage(
req: express.Request,
res: express.Response,
lng: string,
caches: LanguageDetectorCaches
): void
}
}