add errors printing when i18n files loading failed for gi18n

This commit is contained in:
John
2019-09-06 15:43:57 +08:00
parent 8f953dabe5
commit 8fd88307f7
3 changed files with 19 additions and 28 deletions

View File

@ -274,24 +274,6 @@ func (j *Json) Append(pattern string, value interface{}) error {
return fmt.Errorf("invalid variable type of %s", pattern)
}
// GetToVar gets the value by specified <pattern>,
// and converts it to specified golang variable <v>.
// The <pointer> should be a pointer type.
// Deprecated.
func (j *Json) GetToVar(pattern string, pointer interface{}) error {
r := j.Get(pattern)
if r != nil {
if t, err := Encode(r); err == nil {
return DecodeTo(t, pointer)
} else {
return err
}
} else {
pointer = nil
}
return nil
}
// GetStruct gets the value by specified <pattern>,
// and converts it to specified object <pointer>.
// The <pointer> should be the pointer to an object.
@ -330,12 +312,6 @@ func (j *Json) GetMapStructsDeep(pattern string, pointer interface{}, mapping ..
return gconv.MapStructsDeep(j.Get(pattern), pointer, mapping...)
}
// GetToStruct is alias of GetStruct.
// Deprecated.
func (j *Json) GetToStruct(pattern string, pointer interface{}, mapping ...map[string]string) error {
return j.GetStruct(pattern, pointer, mapping...)
}
// ToMap converts current Json object to map[string]interface{}.
// It returns nil if fails.
func (j *Json) ToMap() map[string]interface{} {

View File

@ -30,6 +30,17 @@ func New(text string) error {
}
}
// Newf returns an error that formats as the given text.
func Newf(format string, args ...interface{}) error {
if format == "" {
return nil
}
return &Error{
stack: callers(),
text: fmt.Sprintf(format, args...),
}
}
// Wrap wraps error with text.
// It returns nil if given err is nil.
func Wrap(err error, text string) error {

View File

@ -12,6 +12,8 @@ import (
"strings"
"sync"
"github.com/gogf/gf/os/glog"
"github.com/gogf/gf/os/gfsnotify"
"github.com/gogf/gf/text/gregex"
@ -164,11 +166,12 @@ func (m *Manager) init() {
if m.data[lang] == nil {
m.data[lang] = make(map[string]string)
}
j, _ := gjson.LoadContent(file.Content())
if j != nil {
if j, err := gjson.LoadContent(file.Content()); err == nil {
for k, v := range j.ToMap() {
m.data[lang][k] = gconv.String(v)
}
} else {
glog.Errorf("load i18n file '%s' failed: %v", file, err)
}
}
}
@ -190,11 +193,12 @@ func (m *Manager) init() {
if m.data[lang] == nil {
m.data[lang] = make(map[string]string)
}
j, _ := gjson.LoadContent(gfile.GetBytes(file))
if j != nil {
if j, err := gjson.LoadContent(gfile.GetBytes(file)); err == nil {
for k, v := range j.ToMap() {
m.data[lang][k] = gconv.String(v)
}
} else {
glog.Errorf("load i18n file '%s' failed: %v", file, err)
}
}
_, _ = gfsnotify.Add(path, func(event *gfsnotify.Event) {