-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathmessage.go
47 lines (41 loc) · 1016 Bytes
/
message.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
package respond
import (
"sync"
"github.com/mrjosh/respond.go/translations/en"
"github.com/mrjosh/respond.go/translations/fa"
)
type Messages struct {
Lang string
Success string
Failed string
Errors map[string]map[string]interface{}
Languages map[string]map[string]interface{}
sync.RWMutex
}
func NewMessages() *Messages {
return &Messages{
Lang: "en",
Languages: map[string]map[string]interface{}{
"fa": fa.Messages,
"en": en.Messages,
},
}
}
func (m *Messages) AddLanguageTranslation(lang string, messages map[string]interface{}) {
m.Lock()
m.Languages[lang] = messages
m.Unlock()
}
// Load config of response language
//
// @author Alireza Josheghani <[email protected]>
// @since 15 Mar 2018
// @return *Message
func (m *Messages) load() {
m.RLock()
translation := m.Languages[m.Lang]
m.Errors = translation["errors"].(map[string]map[string]interface{})
m.Success = translation["success"].(string)
m.Failed = translation["failed"].(string)
m.RUnlock()
}