This repository has been archived by the owner on May 29, 2018. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
language.go
72 lines (65 loc) · 2.6 KB
/
language.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
package form
import (
"bytes"
)
/*
Implement:
LangaugeInterface
*/
type Langauge map[string]LangaugeTemplateInterface
func (l Langauge) Translate(name string, value interface{}) (msg string) {
if nil != l[name] {
buf := &bytes.Buffer{}
defer buf.Reset()
l[name].Execute(buf, value)
msg = buf.String()
}
return
}
const (
LANG_FIELD_REQUIRED = "field_required"
LANG_MIN_RUNE = "min_rune"
LANG_MAX_RUNE = "max_rune"
LANG_MUST_MATCH = "must_match"
LANG_PATTERN = "pattern"
LANG_IN_LIST = "in_list"
LANG_NOT_INT = "not_int"
LANG_NOT_FLOAT = "not_float"
LANG_NUMBER_MIN = "number_min"
LANG_NUMBER_MAX = "number_max"
LANG_NUMBER_STEP = "number_step"
LANG_TIME_FORMAT = "time_format"
LANG_TIME_MIN = "time_min"
LANG_TIME_MAX = "time_max"
LANG_FILE_MIME = "file_mime"
LANG_FILE_SIZE = "file_size"
LANG_INVALID_EMAIL = "invalid_email"
LANG_INVALID_URL = "invalid_url"
)
func englishLanguage() Langauge {
T := BuildLanguageTemplate
return Langauge{
LANG_FIELD_REQUIRED: T(`'{{.Label}}' is required.`),
LANG_MIN_RUNE: T(`'{{.Label}}' should be more than or equal to '{{.MinRune}}' character{{.MinRune|pluralise "s"}}.`),
LANG_MAX_RUNE: T(`'{{.Label}}' should be less than or equal '{{.MaxRune}}' character{{.MaxRune|pluralise "s"}}.`),
LANG_MUST_MATCH: T(`'{{.Label}}' should match '{{.MustMatchLabel}}.'`),
LANG_PATTERN: T(`'{{.Label}}' should match '{{.Pattern.String}}.'`),
LANG_IN_LIST: T(`Value of '{{.Label}}' is not in the list '{{.InList|list "and"}}'.`),
LANG_NOT_INT: T(`'{{.Label}}' is not a whole number.`),
LANG_NOT_FLOAT: T(`'{{.Label}}' is not a decimal.`),
LANG_NUMBER_MIN: T(`'{{.Label}}' should be more than or equal to '{{.Min}}'.`),
LANG_NUMBER_MAX: T(`'{{.Label}}' should be less than or equal to '{{.Max}}'.`),
LANG_NUMBER_STEP: T(`'{{.Label}}' should be in step of '{{.Step}}'.`),
LANG_TIME_FORMAT: T(`'{{.Label}}' is not a valid time format.`),
LANG_TIME_MIN: T(`'{{.Label}}' should be more than '{{.MinStr}}'.`),
LANG_TIME_MAX: T(`'{{.Label}}' should be less than '{{.MaxStr}}'.`),
LANG_FILE_MIME: T(`'{{.Label}}' should be '{{.Mime|list "and"}}'.`),
LANG_FILE_SIZE: T(`'{{.Label}}' should be less '{{.SizeInByte}}' in bytes.`),
LANG_INVALID_EMAIL: T(`'{{.Label}}' is not a valid email address.`),
LANG_INVALID_URL: T(`'{{.Label}}' is not a valid url.`),
}
}
var englishLanguageMap = englishLanguage()
func AddToEnglishLanguageMap(key string, tmp LangaugeTemplateInterface) {
englishLanguageMap[key] = tmp
}