locale

package
v0.0.0-...-3839eb7 Latest Latest
Warning

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

Go to latest
Published: Mar 5, 2024 License: MIT Imports: 8 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	LocaleUnSupportedErr  = errors.New("locale is unsupported")
	LocaleFileLeastOneErr = errors.New("expected least one language file")
)

Functions

func Get

func Get(key string, args ...any) string

func GetWithLang

func GetWithLang(lang string, key string, args ...any) string

func Setup

func Setup(l *Locale)

Types

type Conf

type Conf struct {
	Locale string `mapstructure:"lang"`
	Dir    string `mapstructure:"dir"`
}

func (Conf) Load

func (c Conf) Load() (Group, error)

Load read lang file from specified lang dir locale name is the language file name without ext eg: zh_CN.toml -> zh_CN

type Group

type Group = map[string]*viper.Viper

type Locale

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

func L

func L() *Locale

func NewLocale

func NewLocale(locale string, mv Group) *Locale

func NewLocaleWithConf

func NewLocaleWithConf(conf *Conf) (*Locale, error)

func (*Locale) Default

func (l *Locale) Default() string

func (*Locale) Get

func (l *Locale) Get(lang string, key string, args ...any) string

func (*Locale) GetDefault

func (l *Locale) GetDefault(key string, args ...any) string

Jump to

Keyboard shortcuts

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