-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathindex.d.ts
120 lines (93 loc) · 3.44 KB
/
index.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
declare namespace localizify {
type Translation = Record<string, string>;
type Callback<T = unknown> = (...args: Array<T>) => void;
type Event = string;
type Store = {
locale: string;
localesList: string[];
separator: string;
scope: string | null;
translations: Record<string, Translation>;
interpolations: Translation;
normalizedKeys: Record<string, Translation>;
};
interface Instance {
new (): Localizify;
}
interface EventEmitter {
getListeners(event: string): Callback[];
on(event: Event, listener: Callback): Callback;
off(event: Event, listener: Callback): this;
emit(event: Event, ...args: Array<unknown>): this;
hasListeners(event: Event): boolean;
}
interface Localizify extends EventEmitter {
getStore(): Store;
/**
* Get selected locale.
*/
getLocale(): string;
/**
* Change or set locale.
* If locales list includes passed locale and it's not set now,
* set locale or emit event `CHANGE_LOCALE`.
* Return `this` for chaining.
*/
setLocale(locale: string): this;
/**
* Check that locale is registered
*/
isLocale(locale: string): boolean;
/**
* Handler will be executed when locale was changed.
*/
onLocaleChange(callback: Callback): Callback;
/**
* Handler will be executed when translation is not found.
*/
onTranslationNotFound(callback: Callback): void;
/**
* Handler will be executed when template data is not passed.
*/
onReplacedDataNotFound(callback: Callback): void;
setDefaultScope(scope: string): this;
clearDefaultScope(): this;
/**
* Register default interpolations.
* Interpolations you give as options to the translate method
* take precedence over registered interpolations.
*/
registerInterpolations(translation: Translation): this;
/**
* Register new locale.
* If scope is provided, translations will be third argument,
* otherwise - second.
*/
add(locale: string, scope: string, translations: Translation): this;
add(locale: string, translations: Translation): this;
/**
* Define user's language by browser or by request header language.
* `language` params should be passed from server headers
* (`request.headers['accept-language']`).
* In client-size this param is optional (usually not using at all).
*/
detectLocale(_language?: string): boolean | string;
/**
* Translate by key!
* If translation not found, return passed string with replacing data
* to string and emit `TRANSLATION_NOT_FOUND` event.
*/
translate(key: string, data?: Record<string, string>): string;
}
}
declare const localizify: localizify.Localizify;
declare function t(key: string, data?: Record<string, string>): string;
/**
By default returns instance of Localizify, so it's a singelton.
Translations that has been added in one module can be used in another.
But you can also create another Localizify instance.
*/
declare const Instance: localizify.Instance;
export { t, Instance };
export default localizify;
export as namespace Localizify;