Add shared internal UI toolkit for both readers
This commit is contained in:
1 parent
672caca854
commit
e49ba198d7
34 files changed
+3471
No files matched your search
@@ -0,0 +1,27 @@
|
||||
// Copyright (c) 2026 Storm Dragon
|
||||
// SPDX-License-Identifier: GPL-3.0-or-later
|
||||
|
||||
package message
|
||||
|
||||
import (
|
||||
"strconv"
|
||||
"strings"
|
||||
)
|
||||
|
||||
// Messages belongs to one session. Translate must be safe for the host's
|
||||
// calling context; a nil function selects the built-in English messages.
|
||||
type Messages struct{ Translate func(string) string }
|
||||
|
||||
func (m Messages) T(message string) string {
|
||||
if m.Translate != nil {
|
||||
return m.Translate(message)
|
||||
}
|
||||
return message
|
||||
}
|
||||
func (m Messages) Format(message string, fields ...string) string {
|
||||
replacements := []string{"{{", "{", "}}", "}"}
|
||||
for index, value := range fields {
|
||||
replacements = append(replacements, "{"+strconv.Itoa(index)+"}", value)
|
||||
}
|
||||
return strings.NewReplacer(replacements...).Replace(m.T(message))
|
||||
}
|
||||
Reference in new issue
Block a user