-
Notifications
You must be signed in to change notification settings - Fork 1
/
index.d.ts
80 lines (79 loc) · 2.04 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
import * as React from "react";
export type Token = string | Argument | SelectOrdinal | Plural | Select | Func;
export type TokenOrOctothorpe = Token | Octothorpe;
export interface Argument {
type: "argument";
arg: Identifier;
}
export interface SelectOrdinal {
type: "selectordinal";
arg: Identifier;
offset: string;
cases: PluralCase[];
}
export interface Plural {
type: "plural";
arg: Identifier;
offset: string;
cases: PluralCase[];
}
export interface Select {
type: "select";
arg: Identifier;
cases: SelectCase[];
}
export interface Func {
type: "function";
arg: Identifier;
key: Identifier;
}
export interface PluralCase {
key: string; // "zero" | "one" | "two" | "few" | "many" | "other" | "0" | "1" | ...
tokens: TokenOrOctothorpe[];
}
export interface SelectCase {
key: Identifier;
tokens: Token[];
}
export interface Octothorpe {
type: "octothorpe";
}
export type Identifier = string;
export type Value = string | number | object;
export interface Values {
[key: string]: Value;
}
export interface Components {
[key: string]: React.ReactType;
}
export interface LocaleProviderProps {
locale: string;
messageByID: { [key: string]: string | undefined };
children?: React.ReactNode;
defaultComponents?: Components;
}
export interface ContextValue {
locale: string;
language: string;
compile: (id: string) => Token[];
renderToString: (id: string, values?: Values) => string;
}
export interface ConsumerProps {
children: (contextValue: ContextValue) => React.ReactNode;
}
export interface FormattedMessageProps {
id: string;
values?: Values;
components?: Components;
}
export function parse(source: string): Token[];
export function evaluate(
tokens: Token[],
language: string,
values: Values,
components: Components
): Value[];
export const Context: React.Context<ContextValue>;
export class LocaleProvider extends React.Component<LocaleProviderProps> {}
export class Consumer extends React.Component<ConsumerProps> {}
export class FormattedMessage extends React.Component<FormattedMessageProps> {}