i18n

package
v1.4.3 Latest Latest
Warning

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

Go to latest
Published: May 16, 2024 License: Apache-2.0 Imports: 15 Imported by: 1

Documentation

Index

Constants

View Source
const (
	Success            = "common.success"
	Failed             = "common.failed"
	UpdateSuccess      = "common.updateSuccess"
	UpdateFailed       = "common.updateFailed"
	CreateSuccess      = "common.createSuccess"
	CreateFailed       = "common.createFailed"
	DeleteSuccess      = "common.deleteSuccess"
	DeleteFailed       = "common.deleteFailed"
	TargetNotFound     = "common.targetNotExist"
	DatabaseError      = "common.databaseError"
	RedisError         = "common.redisError"
	AlreadyInit        = "init.alreadyInit"
	InitRunning        = "init.initializeIsRunning"
	ConstraintError    = "common.constraintError"
	ValidationError    = "common.validationError"
	NotSingularError   = "common.notSingularError"
	PermissionDeny     = "common.permissionDeny"
	ServiceUnavailable = "common.serviceUnavailable"
	ServiceBusy        = "common.serviceBusy"
	CacheError         = "common.cacheError"

	ApiRequestFailed = "sys.api.apiRequestFailed"
)

Variables

View Source
var LocaleFS embed.FS

Functions

This section is empty.

Types

type Conf added in v1.0.7

type Conf struct {
	Dir string `json:",env=I18N_DIR"`
	// BundleFilePaths store the paths of i18n bundles.
	BundleFilePaths []string `json:",optional,env=BUNDLE_FILE_PATHS"`
	// SupportLanguages store the languages you want to support, the language order must the same as the files' order
	// in BundleFilePaths.
	SupportLanguages []string `json:",optional,env=SUPPORT_LANGUAGES"`
}

Conf is the configuration structure for i18n

type Translator

type Translator struct {
	// contains filtered or unexported fields
}

Translator is a struct storing translating data.

func NewTranslator

func NewTranslator(file embed.FS) *Translator

NewTranslator returns a translator by FS.

func NewTranslatorFromFile added in v1.0.7

func NewTranslatorFromFile(conf Conf) *Translator

NewTranslatorFromFile returns a translator by FS.

func (*Translator) AddBundleFromEmbeddedFS added in v1.4.2

func (l *Translator) AddBundleFromEmbeddedFS(file embed.FS, path string) error

AddBundleFromEmbeddedFS adds new bundle into translator from embedded file system

func (*Translator) AddBundleFromFile added in v1.4.2

func (l *Translator) AddBundleFromFile(path string) error

AddBundleFromFile adds new bundle into translator from file path.

func (*Translator) AddLanguageSupport added in v1.4.2

func (l *Translator) AddLanguageSupport(lang language.Tag)

AddLanguageSupport adds supports for new language

func (*Translator) AddLanguagesByConf added in v1.4.2

func (l *Translator) AddLanguagesByConf(conf Conf, fs embed.FS)

AddLanguagesByConf adds multiple languages from file system by i18n Conf. If Conf.Dir is empty, it will load paths in embedded FS. If Conf.Dir is not empty, it will load paths joined with Dir path.

func (*Translator) MatchLocalizer

func (l *Translator) MatchLocalizer(lang string) *i18n.Localizer

MatchLocalizer used to matcher the localizer in map

func (*Translator) NewBundle

func (l *Translator) NewBundle(file embed.FS)

NewBundle returns a bundle from FS.

func (*Translator) NewBundleFromFile added in v1.0.7

func (l *Translator) NewBundleFromFile(conf Conf)

NewBundleFromFile returns a bundle from a directory which contains i18n files.

func (*Translator) NewTranslator

func (l *Translator) NewTranslator()

NewTranslator sets localize for translator.

func (*Translator) Trans

func (l *Translator) Trans(ctx context.Context, msgId string) string

Trans used to translate any i18n string.

func (*Translator) TransError

func (l *Translator) TransError(ctx context.Context, err error) error

TransError translates the error message

Jump to

Keyboard shortcuts

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