-
Notifications
You must be signed in to change notification settings - Fork 8
/
locale.go
122 lines (102 loc) · 2.51 KB
/
locale.go
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
package cldr
// @xerox
type Locale struct {
Locale string
Number Number
Calendar Calendar
PluralRule string
}
type Number struct {
Symbols Symbols
Formats NumberFormats
Currencies []Currency
}
type Symbols struct {
Decimal string
Group string
Negative string
Percent string
PerMille string
}
type NumberFormats struct {
Decimal string
Currency string
Percent string
}
type Currency struct {
Currency string
DisplayName string
Symbol string
}
type Calendar struct {
Formats CalendarFormats
FormatNames CalendarFormatNames
}
type CalendarFormats struct {
Date CalendarDateFormat
Time CalendarDateFormat
DateTime CalendarDateFormat
}
type CalendarDateFormat struct{ Full, Long, Medium, Short string }
type CalendarFormatNames struct {
Months CalendarMonthFormatNames
Days CalendarDayFormatNames
Periods CalendarPeriodFormatNames
}
type CalendarMonthFormatNames struct {
Abbreviated CalendarMonthFormatNameValue
Narrow CalendarMonthFormatNameValue
Short CalendarMonthFormatNameValue
Wide CalendarMonthFormatNameValue
}
type CalendarMonthFormatNameValue struct {
Jan, Feb, Mar, Apr, May, Jun, Jul, Aug, Sep, Oct, Nov, Dec string
}
type CalendarDayFormatNames struct {
Abbreviated CalendarDayFormatNameValue
Narrow CalendarDayFormatNameValue
Short CalendarDayFormatNameValue
Wide CalendarDayFormatNameValue
}
type CalendarDayFormatNameValue struct {
Sun, Mon, Tue, Wed, Thu, Fri, Sat string
}
type CalendarPeriodFormatNames struct {
Abbreviated CalendarPeriodFormatNameValue
Narrow CalendarPeriodFormatNameValue
Short CalendarPeriodFormatNameValue
Wide CalendarPeriodFormatNameValue
}
type CalendarPeriodFormatNameValue struct {
AM, PM string
}
var locales = map[string]*Locale{}
// TODO: can override paritally instead of replace it as a whole for existed locales
func RegisterLocale(loc *Locale) {
old, ok := locales[loc.Locale]
if ok {
Copy(loc, old)
} else {
locales[loc.Locale] = loc
}
}
// RegisterLocales registers multiple locales in one go.
func RegisterLocales(locs ...*Locale) {
for _, loc := range locs {
RegisterLocale(loc)
}
}
// GetLocale returns a pointer to an existing locale object and a boolean whether the locale exists.
func GetLocale(locale string) (*Locale, bool) {
l, ok := locales[locale]
return l, ok
}
func (n Number) findCurrency(currency string) (c Currency) {
for _, cur := range n.Currencies {
if cur.Currency == currency {
c = cur
break
}
}
return
}