tbs

package
v1.0.16 Latest Latest
Warning

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

Go to latest
Published: May 8, 2024 License: MIT Imports: 12 Imported by: 10

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Clear

func Clear()

Clear clear all loaded text resources

func Format

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

Format translate content to target language.

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 default defs[0] bool value

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 default defs[0] float64 value

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 default defs[0] int value

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 default defs[0] int64 value

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) Format

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

Format use fmt.Sprrintf to translate content to the locale language.

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 default defs[0] bool value

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 default defs[0] float64 value

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 default defs[0] int value

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 default defs[0] int64 value

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.

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, format 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