translator

package
v1.3.1-RC2 Latest Latest
Warning

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

Go to latest
Published: May 9, 2024 License: Apache-2.0 Imports: 8 Imported by: 0

Documentation

Index

Constants

View Source
const DefaultLangOption = "Default"

DefaultLangOption default language option. If user config the language is default, the language option is admin choose.

Variables

View Source
var GlobalTrans i18n.Translator
View Source
var (
	// LanguageOptions language
	LanguageOptions []*LangOption
)
View Source
var ProviderSet = wire.NewSet(NewTranslator)

ProviderSet is providers.

Functions

func CheckLanguageIsValid

func CheckLanguageIsValid(lang string) bool

CheckLanguageIsValid check user input language is valid

func NewTranslator

func NewTranslator(c *I18n) (tr i18n.Translator, err error)

NewTranslator new a translator

func Tr

func Tr(lang i18n.Language, data string) string

Tr use language to translate data. If this language translation is not available, return default english translation.

func TrWithData

func TrWithData(lang i18n.Language, key string, templateData any) string

TrWithData translate key with template data, it will replace the template data {{ .PlaceHolder }} in the translation.

Types

type I18n

type I18n struct {
	BundleDir string `json:"bundle_dir" mapstructure:"bundle_dir" yaml:"bundle_dir"`
}

I18n i18n config

type LangOption

type LangOption struct {
	Label string `json:"label"`
	Value string `json:"value"`
	// Translation completion percentage
	Progress int `json:"progress"`
}

LangOption language option

Jump to

Keyboard shortcuts

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