translator

package
v0.0.0-...-1c7db09 Latest Latest
Warning

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

Go to latest
Published: Jul 12, 2026 License: MIT Imports: 13 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
)

ProviderSet is providers.

Functions

func CheckLanguageIsValid

func CheckLanguageIsValid(lang string) bool

CheckLanguageIsValid check user input language is valid

func GetLangByCtx

func GetLangByCtx(ctx context.Context) i18n.Language

func NewTranslator

func NewTranslator(c *config.Config) (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 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