i18n

package
v1.1.8 Latest Latest
Warning

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

Go to latest
Published: Dec 3, 2023 License: Apache-2.0 Imports: 13 Imported by: 0

Documentation

Index

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 Lang

func Lang(lang language.Tag) utils.OptionFunc[localizeOption]

func Langs

func Langs(langs []string) utils.OptionFunc[localizeOption]

func Param

func Param(data map[string]any) 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.

Jump to

Keyboard shortcuts

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