Documentation ¶
Index ¶
- func DefaultMessage(messageCode MessageCode, args ...any) string
- func Format(langCode LangCode, varString string) string
- func Load(langCode LangCode, messageMap map[MessageCode]string)
- func Message(langCode LangCode, messageCode MessageCode, args ...any) string
- func ParseLangFromAction(action actions.ActionWrapper) (langCode string)
- func ParseLangFromRequest(req *http.Request) (langCode string)
- type Lang
- type LangCode
- type Manager
- func (this *Manager) AddLang(code string) *Lang
- func (this *Manager) DefaultLang() string
- func (this *Manager) GetLang(code string) (lang *Lang, ok bool)
- func (this *Manager) GetMessage(langCode string, messageCode MessageCode, args ...any) string
- func (this *Manager) HasLang(code string) bool
- func (this *Manager) MatchLang(code string) (matchedCode string)
- func (this *Manager) SetDefaultLang(code string)
- type MessageCode
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func DefaultMessage ¶
func DefaultMessage(messageCode MessageCode, args ...any) string
func Format ¶
Format 格式化变量 Format string that contains message variables, such as ${lang.MESSAGE_CODE}
暂时不支持变量中加参数
func Load ¶
func Load(langCode LangCode, messageMap map[MessageCode]string)
Load 加载消息定义 Load message definitions from map
func Message ¶
func Message(langCode LangCode, messageCode MessageCode, args ...any) string
Message 读取消息 Read message
func ParseLangFromAction ¶
func ParseLangFromAction(action actions.ActionWrapper) (langCode string)
func ParseLangFromRequest ¶
Types ¶
type Lang ¶
type Lang struct {
// contains filtered or unexported fields
}
func (*Lang) Get ¶
func (this *Lang) Get(messageCode MessageCode) string
Get 读取单条消息 get single message with message code
func (*Lang) GetAll ¶
func (this *Lang) GetAll() map[MessageCode]string
GetAll 读取所有消息 get all messages
func (*Lang) Has ¶
func (this *Lang) Has(messageCode MessageCode) bool
func (*Lang) Set ¶
func (this *Lang) Set(messageCode MessageCode, messageText string)
type Manager ¶
type Manager struct {
// contains filtered or unexported fields
}
func DefaultManager ¶
func DefaultManager() *Manager
func NewManager ¶
func NewManager() *Manager
func (*Manager) DefaultLang ¶
func (*Manager) GetMessage ¶
func (this *Manager) GetMessage(langCode string, messageCode MessageCode, args ...any) string
GetMessage message: name: %s, age: %d, salary: %.2f
func (*Manager) SetDefaultLang ¶
type MessageCode ¶
type MessageCode string
func (MessageCode) String ¶
func (this MessageCode) String() string
Click to show internal directories.
Click to hide internal directories.