Documentation
¶
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type PluralOption ¶
type PluralOption func(*pluralMessage)
PluralOption defines a function type for modifying a pluralMessage.
func PluralFew ¶
func PluralFew(msg string) PluralOption
PluralFew sets the message for a few counts (e.g., 3-10).
func PluralMany ¶
func PluralMany(msg string) PluralOption
PluralMany sets the message for many counts (e.g., >10).
func PluralZero ¶
func PluralZero(msg string) PluralOption
PluralZero sets the message for count = 0.
type Translator ¶
type Translator interface {
// AddLocale adds a new locale with the given key and formatter.
AddLocale(key string, formatter *language.Tag)
// LoadBytes loads translation JSON content from byte slices for the specified locale.
LoadBytes(locale string, content ...[]byte)
// LoadFiles loads translation content from JSON files for the specified locale.
LoadFiles(locale string, files ...string) error
// AddMessage adds a new message with the given key and message string.
AddMessage(locale, key, message string, options ...PluralOption)
// Translate translates a message identified by the key using the provided values.
Translate(locale, key string, values map[string]any) string
// Plural translates a plural message identified by the key based on the count and provided values.
Plural(locale, key string, count int, values map[string]any) string
}
Translator defines an interface for handling translations and localization.
func NewTranslator ¶
func NewTranslator(locale string, formatter language.Tag) Translator
NewTranslator creates a new translator with the default locale and formatter.