-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex.d.ts
More file actions
55 lines (48 loc) · 1.39 KB
/
index.d.ts
File metadata and controls
55 lines (48 loc) · 1.39 KB
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
import { FastifyPlugin, FastifyRequest } from 'fastify';
import { IntlShape } from '@formatjs/intl';
declare module 'fastify' {
interface FastifyInstance {
[decoratorName: string]: {
createIntl(locale: string, name?: string): Promise<IntlShape<string>>;
getRequestLocale(request: FastifyRequest): string;
};
}
interface FastifyRequest {
locale: string;
intl: IntlShape<string>;
moduleName: string;
t(id: string, values?: Record<string, unknown>): string;
}
namespace FastifyNamespace {
interface LocaleMessage {
[locale: string]: Record<string, string>;
}
interface NamespaceModule {
locale?: LocaleMessage;
[key: string]: unknown;
}
}
}
export interface FastifyIntlOptions {
/** 插件装饰器名称 */
name?: string;
/** 接受的语言列表,'*' 表示接受所有语言 */
acceptLanguage?: string;
/** 默认语言环境 */
defaultLocale?: string;
/** 默认模块名称 */
moduleName?: string;
/** 默认翻译消息对象 */
defaultMessages?: {
[locale: string]: Record<string, string>;
};
/** 动态加载翻译消息的函数 */
requestMessages?: (params: {
locale: string;
name: string;
}) => Promise<Record<string, string>> | Record<string, string>;
/** 缓存大小 */
cacheSize?: number;
}
declare const fastifyIntl: FastifyPlugin<FastifyIntlOptions>;
export default fastifyIntl;