forked from DefinitelyTyped/DefinitelyTyped
-
Notifications
You must be signed in to change notification settings - Fork 0
/
i18next-express-middleware.d.ts
110 lines (96 loc) · 3.65 KB
/
i18next-express-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
// Type definitions for i18next-express-middleware
// Project: http://i18next.com/
// Definitions by: Cyril Schumacher <https://github.com/cyrilschumacher>
// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped
///<reference path="../express/express.d.ts"/>
///<reference path="../i18next/i18next-2.0.17.d.ts"/>
declare namespace I18next {
interface I18nextOptions extends i18nextExpressMiddleware.I18nextOptions { }
}
declare namespace i18nextExpressMiddleware {
/**
* @summary Interface for Language detector options.
* @interface
*/
interface LanguageDetectorOptions {
caches?: Array<string>|boolean;
cookieDomain?: string;
cookieExpirationDate?: Date;
lookupCookie?: string;
lookupFromPathIndex?: number;
lookupQuerystring?: string;
lookupSession?: string;
order?: Array<string>;
}
/**
* @summary i18next options.
* @interface
*/
interface I18nextOptions {
detection?: LanguageDetectorOptions;
}
}
declare module "i18next-express-middleware" {
import express = require("express");
import i18next = require("i18next");
/**
* @summary Interface for middleware to use i18next in express.js.
* @interface
*/
export interface i18nextExpressMiddleware {
LanguageDetector(): express.Handler;
missingKeyHandler(): express.Handler;
}
/**
* @summary Interface for own detection functionality.
*/
export interface i18nextCustomDetection {
name: string;
lookup: (req: express.Request, res: express.Response, options?: Object) => void;
cacheUserLanguage: (req: express.Request, res: express.Response, lng?: any, options?: Object) => void;
}
/**
* @summary Detects user language from current request.
* @class
*/
export class LanguageDetector {
/**
* @summary Constructor.
* @constructor
* @param {any} services The services.
* @param {Object} options The options.
* @param {Object} allOptions The all options.
*/
constructor(services?: any, options?: Object, allOptions?: Object);
/**
* @summary Adds detector.
* @param {i18nextCustomDetection} detector The detector to add.
*/
addDetector(detector: i18nextCustomDetection): void;
// NOTE: add documentation
cacheUserLanguage(req: express.Request, res: express.Response, detectionOrder: any): void;
/**
* @summary Detects the language.
* @param {Request} req The HTTP request.
* @param {Response} res The HTTP response.
* @param {detectionOrder} detectionOrder The detection order.
*/
detect(req: express.Request, res: express.Response, detectionOrder: any): void;
/**
* @summary Initializes class.
* @param {any} services The services.
* @param {Object} options The options.
* @param {Object} allOptions The all options.
*/
init(services: any, options?: Object, allOptions?: Object): void;
}
export function getResourcesHandler(i18next: I18nextStatic, options: Object): express.Handler;
export function handle(i18next: I18nextStatic, options?: Object): express.Handler;
/**
* @summary Gets handler for missing key.
* @param {I18nextStatic} i18next The i18next.
* @param {Object} options The options.
* @return {express.Handler} The express handler.
*/
export function missingKeyHandler(i18next: I18nextStatic, options: Object): express.Handler;
}