forked from martinandert/counterpart
-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js.flow
71 lines (63 loc) · 1.82 KB
/
index.js.flow
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
// @flow
export type Options = {
locale?: string,
fallbackLocale?: string,
separator?: string,
fallback?: string,
scope?: string | string[],
interpolate?: boolean,
format?: 'default' | string,
type?: 'datetime' | string,
// @TODO: check if other types than number are really allowed.
count?: number | string | null,
...
};
export type NotFoundHandler = (evt: {
...CustomEvent,
detail: { locale: string, key: string, fallback: string, scope: string },
...
}) => void;
export type LocaleChangeHandler = (evt: {
...CustomEvent,
detail: {
locale: string,
previous: string,
},
...
}) => void;
export type ErrorHandler = (evt: {
...CustomEvent,
detail: {
error: Error,
entry: string,
values: Options,
},
...
}) => void;
declare function translate(key: string | string[], options?: Options): string;
declare class Counterpart {
constructor(): this;
translate: typeof translate;
localize(date: Date, options: { ... }): string;
setSeparator(value: string): string;
setMissingEntryGenerator(callback: (value: string) => void): void;
getLocale(): string;
setLocale(value: string): string;
setFallbackLocale(value: string | string[]): void;
registerTranslations(locale: string, data: { ... }): void;
registerInterpolations(data: { ... }): void;
setKeyTransformer(
callback: (value: string, options: { ... }) => string,
): string;
onLocaleChange(callback: LocaleChangeHandler): void;
offLocaleChange(callback: LocaleChangeHandler): void;
onTranslationNotFound(callback: NotFoundHandler): void;
offTranslationNotFound(callback: NotFoundHandler): void;
onError(callback: ErrorHandler): void;
offError(callback: ErrorHandler): void;
}
declare module.exports: {
Instance: Class<Counterpart>,
Translator: Class<Counterpart>,
} & Counterpart &
typeof translate;