-
Notifications
You must be signed in to change notification settings - Fork 3
/
pack.go
35 lines (31 loc) · 808 Bytes
/
pack.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
package i18nPackKit
import (
"fmt"
"github.com/richelieu-yang/chimera/v3/src/core/strKit"
"github.com/richelieu-yang/chimera/v3/src/i18n/i18nKit"
)
// Pack
/*
@param langs 可以为空(包括nil)
*/
func Pack(langs []string, code string, data interface{}, msgArgs ...interface{}) interface{} {
return PackFully(langs, code, "", data, msgArgs...)
}
// PackFully
/*
@param langs 可以为空(包括nil)
*/
func PackFully(langs []string, code, msg string, data interface{}, msgArgs ...interface{}) interface{} {
var err error
if strKit.IsEmpty(msg) {
msg, err = i18nKit.GetMessage(innerBundle, code, langs...)
}
if err != nil {
msg = err.Error()
} else {
if strKit.IsNotEmpty(msg) && msgArgs != nil {
msg = fmt.Sprintf(msg, msgArgs...)
}
}
return getMaker()(code, msg, data)
}