forked from GoAdminGroup/go-admin
-
Notifications
You must be signed in to change notification settings - Fork 0
/
language.go
57 lines (45 loc) · 939 Bytes
/
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
package language
import (
"github.com/chenhg5/go-admin/modules/config"
"html/template"
"strings"
)
func Get(value string) string {
if config.Get().LANGUAGE == "" {
return value
}
if locale, ok := Lang[config.Get().LANGUAGE][strings.ToLower(value)]; ok {
return locale
} else {
return value
}
}
func GetFromHtml(value template.HTML) template.HTML {
if config.Get().LANGUAGE == "" {
return value
}
if locale, ok := Lang[config.Get().LANGUAGE][strings.ToLower(string(value))]; ok {
return template.HTML(locale)
} else {
return value
}
}
type LangMap map[string]map[string]string
var Lang = LangMap{
"cn": cn,
"en": en,
"jp": jp,
}
func (lang LangMap) Get(value string) string {
if config.Get().LANGUAGE == "" {
return value
}
if locale, ok := lang[config.Get().LANGUAGE][value]; ok {
return locale
} else {
return value
}
}
func Add(key string, lang map[string]string) {
Lang[key] = lang
}