tbs

package
v1.1.0 Latest Latest
Warning

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

Go to latest
Published: Aug 17, 2025 License: MIT Imports: 12 Imported by: 21

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Clear

func Clear()

Clear clear all loaded text resources

func Error added in v1.0.27

func Error(locale, key string, defs ...string) error

Error create a error with the locale text by key.

func Errorf added in v1.0.27

func Errorf(locale, key string, args ...any) error

Errorf create a error with the locale text by key and args.

func Format

func Format(locale, format string, args ...any) string

Format use fmt.Sprintf to format the locale text by key and args.

func GetBool added in v1.0.10

func GetBool(locale, key string, defs ...bool) bool

GetBool get a bool value of the key from the text bundle. if not found or convert error, returns the first non-false value from defs.

func GetBundle

func GetBundle(locale string) *ini.Ini

GetBundle get target locale ini bundle

func GetFloat added in v1.0.10

func GetFloat(locale, key string, defs ...float64) float64

GetFloat get a float64 value of the key from the text bundle. if not found or convert error, returns the first non-zero value from defs.

func GetInt added in v1.0.10

func GetInt(locale, key string, defs ...int) int

GetInt get a int value of the key from the text bundle. if not found or convert error, returns the first non-zero value from defs.

func GetInt64 added in v1.0.10

func GetInt64(locale, key string, defs ...int64) int64

GetInt64 get a int64 value of the key from the text bundle. if not found or convert error, returns the first non-zero value from defs.

func GetText added in v1.0.10

func GetText(locale, key string, defs ...string) string

GetText get the locale text by key.

func Load

func Load(root string) error

Load glob and parse text files under root path

func LoadFS

func LoadFS(fsys fs.FS, root string) error

LoadFS glob and parse template files from FS

func Replace added in v1.0.10

func Replace(locale, format string, args ...any) string

Replace use strings.Replacer to translate content to the locale language.

func SetDefault

func SetDefault(tbs *TextBundles)

SetDefault set the default TextBundles instance used by the package-level functions.

Types

type TextBundles

type TextBundles struct {
	Extensions []string  // file extensions
	Timestamp  time.Time // modified timestamp
	// contains filtered or unexported fields
}

TextBundles a localized text resource bundle container

func Default

func Default() *TextBundles

Default returns the default TextBundles instance used by the package-level functions.

func NewTextBundles

func NewTextBundles(extensions ...string) *TextBundles

NewTextBundles returns a new TextBundles instance

func (*TextBundles) Clear

func (tbs *TextBundles) Clear()

Clear clear all loaded text resources

func (*TextBundles) Error added in v1.0.27

func (tbs *TextBundles) Error(locale, key string, defs ...string) error

Error create a error with the locale text by key.

func (*TextBundles) Errorf added in v1.0.27

func (tbs *TextBundles) Errorf(locale, key string, args ...any) error

Errorf create a error with the locale text by key and args.

func (*TextBundles) Format

func (tbs *TextBundles) Format(locale, key string, args ...any) string

Format use fmt.Sprintf to format the locale text by key and args.

func (*TextBundles) GetBool added in v1.0.10

func (tbs *TextBundles) GetBool(locale, key string, defs ...bool) bool

GetBool get a bool value of the key from the text bundle. if not found or convert error, returns the first non-false value from defs.

func (*TextBundles) GetBundle

func (tbs *TextBundles) GetBundle(locale string) *ini.Ini

GetBundle get target locale ini bundle

func (*TextBundles) GetFloat added in v1.0.10

func (tbs *TextBundles) GetFloat(locale, key string, defs ...float64) float64

GetFloat get a float64 value of the key from the text bundle. if not found or convert error, returns the first non-zero value from defs.

func (*TextBundles) GetInt added in v1.0.10

func (tbs *TextBundles) GetInt(locale, key string, defs ...int) int

GetInt get a int value of the key from the text bundle. if not found or convert error, returns the first non-zero value from defs.

func (*TextBundles) GetInt64 added in v1.0.10

func (tbs *TextBundles) GetInt64(locale, key string, defs ...int64) int64

GetInt64 get a int64 value of the key from the text bundle. if not found or convert error, returns the first non-zero value from defs.

func (*TextBundles) GetText added in v1.0.10

func (tbs *TextBundles) GetText(locale, key string, defs ...string) string

GetText get the locale text by key. if not found, returns the first non-empty value from defs.

func (*TextBundles) Load

func (tbs *TextBundles) Load(root string) error

Load glob and parse text files under root path

func (*TextBundles) LoadFS

func (tbs *TextBundles) LoadFS(fsys fs.FS, root string) error

LoadFS glob and parse template files from FS

func (*TextBundles) Replace added in v1.0.10

func (tbs *TextBundles) Replace(locale, key string, args ...any) string

Replace use strings.Replacer to translate content to the locale language.

Jump to

Keyboard shortcuts

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