-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathplural.tmpl
More file actions
52 lines (43 loc) · 1.05 KB
/
plural.tmpl
File metadata and controls
52 lines (43 loc) · 1.05 KB
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
// Generated by https://github.com/gotnospirit/makeplural
// at {{ .Timestamp }}
{{ .Headers }}
package plural
import (
"fmt"
"math"
"strconv"
)
func mod(x, y float64) float64 {
return math.Mod(x, y)
}
func float(v interface{}) float64 {
switch v.(type) {
case int:
return float64(v.(int))
case int64:
return float64(v.(int64))
case float64:
return v.(float64)
case string:
floatval, err := strconv.ParseFloat(v.(string), 64)
if nil != err {
return 0.0
}
return floatval
}
return 0.0
}
var plural_funcs map[string]func(interface{}, bool) string
func init() {
plural_funcs = make(map[string]func(interface{}, bool) string)
{{ range $_, $item := .Items }}
plural_funcs["{{ $item.Culture }}"] = func(value interface{}, ordinal bool) string {
{{ $item.Code }} }
{{ end }}}
func GetFunc(name string) (func(interface{}, bool) string, error) {
fn, ok := plural_funcs[name]
if !ok {
return nil, fmt.Errorf("UnknownCulture: `%s`", name)
}
return fn, nil
}