forked from DefinitelyTyped/DefinitelyTyped
-
Notifications
You must be signed in to change notification settings - Fork 0
/
i18n-node.d.ts
349 lines (310 loc) · 11.9 KB
/
i18n-node.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
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
// Type definitions for i18n-node 0.5.0
// Project: https://github.com/mashpie/i18n-node
// Definitions by: Maxime LUCE <https://github.com/SomaticIT>
// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped
/// <reference path="../express/express.d.ts" />
declare namespace i18n {
export interface ConfigurationOptions {
/** Setup some locales - other locales default to en silently */
locales?: string[];
/** Alter a site wide default locale */
defaultLocale?: string;
/**
* Sets a custom cookie name to parse locale settings from
* @default null
*/
cookie?: string;
/**
* Where to store json files, relative to modules directory
* @default "./locales"
*/
directory?: string;
/**
* whether to write new locale information to disk
* @default true
*/
updateFiles?: boolean;
/**
* What to use as the indentation unit
* @default "\t"
*/
indent?: string;
/**
* Setting extension of json files (you might want to set this to '.js' according to webtranslateit)
* @default ".json"
*/
extension?: string;
/**
* Enable object notation
* @default false
*/
objectNotation?: boolean;
/**
* json files prefix
*/
prefix?: string;
/**
* object or [obj1, obj2] to bind the i18n api and current locale to - defaults to null
*/
register?: any;
}
export interface TranslateOptions {
phrase: string;
locale?: string;
}
export interface PluralOptions {
singular: string;
plural: string;
count?: number;
locale?: string;
}
export interface Replacements {
[key: string]: string;
}
export interface LocaleCatalog {
[key: string]: string;
}
export interface GlobalCatalog {
[key: string]: LocaleCatalog;
}
/**
* Configure current i18n instance
* @param {ConfigurationOptions} options - configuration options for i18n
*/
function configure(options: ConfigurationOptions): void;
/**
* Initialize i18n middleware for express
* @param {Express.Request} request - Current express request
* @param {Express.Response} response - Current express response
* @param {Function} next - Callback to continue process
*/
function init(request: Express.Request, response: Express.Response, next?: Function): void;
//#region __()
/**
* Translate the given phrase using locale configuration
* @param {string} phrase - The phrase to translate
* @returns {string} The translated phrase
*/
function __(phrase: string, ...replace: string[]): string;
/**
* Translate the given phrase using locale configuration
* @param {string} phrase - The phrase to translate
* @param {Object} replacements - An object containing replacements
* @returns {string} The translated phrase
*/
function __(phrase: string, replacements: Replacements): string;
/**
* Translate the given phrase using locale configuration
* @param {TranslateOptions} options - Options for translation
* @returns {string} The translated phrase
*/
function __(options: TranslateOptions): string;
/**
* Translate the given phrase using locale configuration
* @param {TranslateOptions} options - Options for translation
* @returns {string} The translated phrase
*/
function __(options: TranslateOptions, ...replace: string[]): string;
/**
* Translate the given phrase using locale configuration
* @param {TranslateOptions} options - Options for translation
* @param {Object} replacements - An object containing replacements
* @returns {string} The translated phrase
*/
function __(options: TranslateOptions, replacements: Replacements): string;
//#endregion
//#region __n()
/**
* Translate with plural condition the given phrase and count using locale configuration
* @param {PluralOptions} options - Options for plural translate
* @returns {string} The translated phrase
*/
function __n(options: PluralOptions): string;
/**
* Translate with plural condition the given phrase and count using locale configuration
* @param {PluralOptions} options - Options for plural translate
* @param {number} count - The number which allow to select from plural to singular
* @returns {string} The translated phrase
*/
function __n(options: PluralOptions, count: number): string;
/**
* Translate with plural condition the given phrase and count using locale configuration
* @param {string} singular - The singular pharse to translate if count is <= 1
* @param {string} plural - The plural pharse to translate if count is > 1
* @param {number} count - The number which allow to select from plural to singular
* @returns {string} The translated phrase
*/
function __n(singular: string, plural: string, count: number): string;
/**
* Translate with plural condition the given phrase and count using locale configuration
* @param {string} singular - The singular pharse to translate if count is <= 1
* @param {string} plural - The plural pharse to translate if count is > 1
* @param {number} count - The number which allow to select from plural to singular
* @returns {string} The translated phrase
*/
function __n(singular: string, plural: string, count: string): string;
//#endregion
//#region Locale
/**
* Change the current active locale
* @param {string} locale - The locale to set as default
*/
function setLocale(locale: string): void;
/**
* Change the current active locale for specified request
* @param {Express.Request} request - The request to change locale on
* @param {string} locale - The locale to set as default
*/
function setLocale(request: Express.Request, locale: string): void;
/**
* Get the current active locale
* @returns {string} The current locale in request
*/
function getLocale(): string;
/**
* Get the current active locale for specified request
* @param {Express.Request} request - The request to get locale for
* @returns {string} The current locale in request
*/
function getLocale(request: Express.Request): string;
//#endregion
//#region Catalog
/**
* Get the current global catalog
* @returns {GlobalCatalog} The current global catalog
*/
function getCatalog(): GlobalCatalog;
/**
* Get the catalog for the given locale
* @param {string} locale - The locale to get catalog for
* @returns {LocaleCatalog} The specified locale catalog
*/
function getCatalog(locale: string): LocaleCatalog;
/**
* Get the current active locale catalog for specified request
* @param {Express.Request} request - The request to get locale catalog for
* @returns {LocaleCatalog} The current locale catalog for the specified request
*/
function getCatalog(request: Express.Request): LocaleCatalog;
/**
* Get the current locale catalog for specified request and specified locale
* @param {Express.Request} request - The request to get locale catalog for
* @param {string} locale - The locale to get catalog for
* @returns {LocaleCatalog} The specified locale catalog
*/
function getCatalog(request: Express.Request, locale: string): LocaleCatalog;
//#endregion
/**
* Override the current request locale by using the query param (?locale=en)
* @param {Express.Request} [request] - The request to override locale for
*/
function overrideLocaleFromQuery(request?: Express.Request): void;
/**
* Get current i18n-node version
* @member {string}
*/
var version: string;
}
interface i18nAPI {
locale: string;
//#region __()
/**
* Translate the given phrase using locale configuration
* @param {string} phrase - The phrase to translate
* @returns {string} The translated phrase
*/
__(phrase: string, ...replace: string[]): string;
/**
* Translate the given phrase using locale configuration
* @param {string} phrase - The phrase to translate
* @param {Object} replacements - An object containing replacements
* @returns {string} The translated phrase
*/
__(phrase: string, replacements: i18n.Replacements): string;
/**
* Translate the given phrase using locale configuration
* @param {TranslateOptions} options - Options for translation
* @returns {string} The translated phrase
*/
__(options: i18n.TranslateOptions): string;
/**
* Translate the given phrase using locale configuration
* @param {TranslateOptions} options - Options for translation
* @returns {string} The translated phrase
*/
__(options: i18n.TranslateOptions, ...replace: string[]): string;
/**
* Translate the given phrase using locale configuration
* @param {TranslateOptions} options - Options for translation
* @param {Object} replacements - An object containing replacements
* @returns {string} The translated phrase
*/
__(options: i18n.TranslateOptions, replacements: i18n.Replacements): string;
//#endregion
//#region __n()
/**
* Translate with plural condition the given phrase and count using locale configuration
* @param {PluralOptions} options - Options for plural translate
* @returns {string} The translated phrase
*/
__n(options: i18n.PluralOptions): string;
/**
* Translate with plural condition the given phrase and count using locale configuration
* @param {PluralOptions} options - Options for plural translate
* @param {number} count - The number which allow to select from plural to singular
* @returns {string} The translated phrase
*/
__n(options: i18n.PluralOptions, count: number): string;
/**
* Translate with plural condition the given phrase and count using locale configuration
* @param {string} singular - The singular pharse to translate if count is <= 1
* @param {string} plural - The plural pharse to translate if count is > 1
* @param {number} count - The number which allow to select from plural to singular
* @returns {string} The translated phrase
*/
__n(singular: string, plural: string, count: number): string;
/**
* Translate with plural condition the given phrase and count using locale configuration
* @param {string} singular - The singular pharse to translate if count is <= 1
* @param {string} plural - The plural pharse to translate if count is > 1
* @param {number} count - The number which allow to select from plural to singular
* @returns {string} The translated phrase
*/
__n(singular: string, plural: string, count: string): string;
//#endregion
/**
* Get the current active locale
* @returns {string} The current locale in request
*/
getLocale(): string;
/**
* Change the current active locale
* @param {string} locale - The locale to set as default
*/
setLocale(locale: string): void;
/**
* Get the current global catalog
* @returns {GlobalCatalog} The current global catalog
*/
getCatalog(): i18n.GlobalCatalog;
/**
* Get the catalog for the given locale
* @param {string} locale - The locale to get catalog for
* @returns {LocaleCatalog} The specified locale catalog
*/
getCatalog(locale: string): i18n.LocaleCatalog;
}
declare module "i18n" {
export = i18n;
}
declare namespace Express {
export interface Request extends i18nAPI {
languages: string[];
regions: string[];
language: string;
region: string;
}
export interface Response extends i18nAPI {
locals: i18nAPI
}
}