-
Notifications
You must be signed in to change notification settings - Fork 2
/
types.ts
128 lines (117 loc) · 1.99 KB
/
types.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
/**
* Plural locale descriptor.
*/
export interface I18nPluralLocale {
one?: string;
few?: string;
many?: string;
other?: string;
}
/**
* Locale descriptor.
*/
export type I18nLocale = string | I18nPluralLocale;
/**
* Language locales.
*/
export interface I18nLangLocales {
[key: string]: I18nLocale | I18nLangLocales;
}
/**
* All locales.
*/
export interface I18nLocales {
[key: string]: I18nLangLocales;
}
/**
* Language fallbacks map.
*/
export type I18nFallbacks = Record<string, string>;
/**
* Unknown phrase listener.
*/
export type I18nUnknownPhraseListener = (
locale: string,
phrase: string,
value: I18nLocale
) => void;
/**
* Custom locale post processor.
*/
export type I18nProcessor = (
text: string,
namedValues: any,
values: any[],
count?: number
) => string;
/**
* I18n instance config.
*/
export interface I18nConfig {
/**
* Default locale to use.
*/
defaultLocale?: string;
/**
* Store of translations.
*/
locales?: I18nLocales;
/**
* Fallbacks map for locales.
*/
fallbacks?: I18nFallbacks;
/**
* Translate phrases or get phrases by keys.
*/
objectNotation?: boolean;
/**
* Cookie name to store locale.
*/
cookieName?: string;
/**
* Query parameter to get locale.
*/
queryParameter?: string;
/**
* Unknown phrases listener.
*/
unknownPhraseListener?: I18nUnknownPhraseListener;
/**
* List of post processors.
*/
processors?: I18nProcessor[];
}
/**
* I18n fork instance config.
*/
export type I18nForkConfig = Pick<
I18nConfig,
Exclude<
keyof I18nConfig,
'objectNotation' | 'cookieName' | 'queryParameter'
>
>;
/**
* I18n fork instance linked fields.
*/
export interface I18nForkLinkedFields {
defaultLocale: boolean;
locales: boolean;
unknownPhraseListener: boolean;
}
/**
* Translate params.
*/
export interface I18nParams {
phrase: string;
locale?: string;
}
/**
* Plural translate params.
*/
export interface I18nPluralParams {
singular: string;
plural?: string;
count?: number | string;
locale?: string;
}