chat package will not ignore the translate message now, but return the row msg.

This commit is contained in:
Tnze
2019-08-07 15:23:25 +08:00
parent 72ba5b7345
commit 73af09e2ea
8 changed files with 54 additions and 39 deletions

View File

@ -125,15 +125,19 @@ func (m Message) ClearString() string {
msg.WriteString(text)
//handle translate
if m.Translate != "" && translateMap != nil {
if m.Translate != "" {
args := make([]interface{}, len(m.With))
for i, v := range m.With {
var arg Message
_ = arg.UnmarshalJSON(v) //ignore error
args[i] = arg.ClearString()
}
_, _ = fmt.Fprintf(&msg, translateMap[m.Translate], args...)
if translateMap != nil {
_, _ = fmt.Fprintf(&msg, translateMap[m.Translate], args...)
} else {
_, _ = fmt.Fprint(&msg, m.Translate, m.With)
}
}
if m.Extra != nil {
@ -172,8 +176,7 @@ func (m Message) String() string {
msg.WriteString(text)
//handle translate
if m.Translate != "" && translateMap != nil {
if m.Translate != "" {
args := make([]interface{}, len(m.With))
for i, v := range m.With {
var arg Message
@ -181,7 +184,11 @@ func (m Message) String() string {
args[i] = arg
}
_, _ = fmt.Fprintf(&msg, translateMap[m.Translate], args...)
if translateMap != nil {
_, _ = fmt.Fprintf(&msg, translateMap[m.Translate], args...)
} else {
_, _ = fmt.Fprint(&msg, m.Translate, m.With)
}
}
if m.Extra != nil {