Documentation ¶
Index ¶
- Variables
- func AppName(name string) utils.OptionFunc[useOption]
- func Construct(ctx context.Context, conf Conf, opts ...utils.OptionExtender) func()
- func DefaultLang(opts ...utils.OptionExtender) (lang language.Tag)
- func Lang(lang language.Tag) utils.OptionFunc[localizeOption]
- func Langs(langs []string) utils.OptionFunc[localizeOption]
- func Param(data map[string]any) utils.OptionFunc[localizeOption]
- func Plural(pluralCount any) utils.OptionFunc[localizeOption]
- func Var(vars ...string) utils.OptionFunc[addMessagesOption]
- type Conf
- type Localizable
- type Message
Constants ¶
This section is empty.
Variables ¶
View Source
var (
Bundle *bundle[int]
)
Functions ¶
func AppName ¶
func AppName(name string) utils.OptionFunc[useOption]
func Construct ¶
func Construct(ctx context.Context, conf Conf, opts ...utils.OptionExtender) func()
func DefaultLang ¶
func DefaultLang(opts ...utils.OptionExtender) (lang language.Tag)
func Langs ¶
func Langs(langs []string) utils.OptionFunc[localizeOption]
func Plural ¶
func Plural(pluralCount any) utils.OptionFunc[localizeOption]
func Var ¶
func Var(vars ...string) utils.OptionFunc[addMessagesOption]
Types ¶
type Conf ¶
type Conf struct {
DefaultLang string `yaml:"default_lang" json:"default_lang" toml:"default_lang" default:"zh"`
}
Conf i18n configure
type Localizable ¶
type Localizable[T comparable] interface { AddMessages(code T, trans map[language.Tag]*Message, opts ...utils.OptionExtender) Localizable[T] Localize(code T, opts ...utils.OptionExtender) (message string) }
func NewBundle ¶
func NewBundle[T comparable](lang language.Tag) Localizable[T]
type Message ¶
type Message struct { // ID uniquely identifies the message. ID string // Hash uniquely identifies the content of the message // that this message was translated from. Hash string // Description describes the message to give additional // context to translators that may be relevant for translation. Description string // LeftDelim is the left Go template delimiter. LeftDelim string // RightDelim is the right Go template delimiter.“ RightDelim string // Zero is the content of the message for the CLDR plural form "zero". Zero string // One is the content of the message for the CLDR plural form "one". One string // Two is the content of the message for the CLDR plural form "two". Two string // Few is the content of the message for the CLDR plural form "few". Few string // Many is the content of the message for the CLDR plural form "many". Many string // Other is the content of the message for the CLDR plural form "other". Other string }
Message is a string that can be localized.
Click to show internal directories.
Click to hide internal directories.