langs

package
v1.3.9 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: May 17, 2024 License: BSD-3-Clause Imports: 6 Imported by: 1

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func DefaultMessage

func DefaultMessage(messageCode MessageCode, args ...any) string

func Format

func Format(langCode LangCode, varString string) string

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

func ParseLangFromRequest(req *http.Request) (langCode string)

Types

type Lang

type Lang struct {
	// contains filtered or unexported fields
}

func NewLang

func NewLang(code string) *Lang

func (*Lang) Compile

func (this *Lang) Compile() error

Compile variable to literal strings

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 LangCode

type LangCode = string

type Manager

type Manager struct {
	// contains filtered or unexported fields
}

func DefaultManager

func DefaultManager() *Manager

func NewManager

func NewManager() *Manager

func (*Manager) AddLang

func (this *Manager) AddLang(code string) *Lang

func (*Manager) DefaultLang

func (this *Manager) DefaultLang() string

func (*Manager) GetLang

func (this *Manager) GetLang(code string) (lang *Lang, ok bool)

func (*Manager) GetMessage

func (this *Manager) GetMessage(langCode string, messageCode MessageCode, args ...any) string

GetMessage message: name: %s, age: %d, salary: %.2f

func (*Manager) HasLang

func (this *Manager) HasLang(code string) bool

func (*Manager) MatchLang

func (this *Manager) MatchLang(code string) (matchedCode string)

func (*Manager) SetDefaultLang

func (this *Manager) SetDefaultLang(code string)

type MessageCode

type MessageCode string

func (MessageCode) For

func (this MessageCode) For(langCode LangCode, args ...any) string

func (MessageCode) String

func (this MessageCode) String() string

Directories

Path Synopsis

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL