README ¶
internationalization
Output the corresponding results according to different languages go-i18n
Usage
package main
import (
"fmt"
tran "github.com/segmentfault/pacman/contrib/i18n"
"github.com/segmentfault/pacman/i18n"
)
func main() {
translator, err := tran.NewTranslator("/BundleDir")
if err != nil {
panic(err)
}
fmt.Println(translator.Tr(i18n.LanguageChinese, "base.success"))
fmt.Println(translator.Tr(i18n.LanguageEnglish, "base.success"))
}
Documentation ¶
Index ¶
Constants ¶
This section is empty.
Variables ¶
View Source
var ( GlobalTrans = &Translator{ localizes: make(map[i18n.Language]*goI18n.Localizer), jsonData: make(map[i18n.Language]any), } Bundle = goI18n.NewBundle(language.English) )
GlobalTrans global translation
Functions ¶
func AddTranslator ¶
AddTranslator add translator to global translations translation is content language is language file name like en_US.yaml
func NewTranslator ¶
func NewTranslator(bundleDir string) (i18n.Translator, error)
NewTranslator new translator from Bundle/resource directory TODO: singleton and multi-thread safe initialization
Types ¶
type Translator ¶
type Translator struct {
// contains filtered or unexported fields
}
Translator save the language type with localizer mapping
func (*Translator) Dump ¶
func (tr *Translator) Dump(la i18n.Language) ([]byte, error)
Dump the translator into json format
func (*Translator) Tr ¶
func (tr *Translator) Tr(la i18n.Language, key string) string
Tr to Translate from specified language and string TODO: improve multi-threading performance
func (*Translator) TrWithData ¶
TrWithData to Translate from specified language and string
Click to show internal directories.
Click to hide internal directories.