Documentation ¶
Index ¶
- Constants
- func DefTr(key string, args ...interface{}) string
- func Dt(key string, args ...interface{}) string
- func T(lang string, key string, args ...interface{}) string
- func Tr(lang string, key string, args ...interface{}) string
- type I18n
- func (l *I18n) Add(lang string, name string)
- func (l *I18n) DefTr(key string, args ...interface{}) string
- func (l *I18n) DelLang(lang string) bool
- func (l *I18n) Dt(key string, args ...interface{}) string
- func (l *I18n) Export(lang string) string
- func (l *I18n) HasKey(lang, key string) (ok bool)
- func (l *I18n) HasLang(lang string) bool
- func (l *I18n) Init() *I18n
- func (l *I18n) Lang(lang string) *ini.Ini
- func (l *I18n) Languages() map[string]string
- func (l *I18n) LoadFile(lang string, file string) (err error)
- func (l *I18n) LoadString(lang string, data string) (err error)
- func (l *I18n) NewLang(lang string, name string)
- func (l *I18n) T(lang, key string, args ...interface{}) string
- func (l *I18n) Tr(lang, key string, args ...interface{}) string
Constants ¶
View Source
const ( // FileMode language name is file name. "en" -> "lang/en.ini" FileMode uint8 = 0 // DirMode language name is dir name, will load all file in the dir. "en" -> "lang/en/*.ini" DirMode uint8 = 1 // SprintfMode render message arguments by fmt.Sprintf SprintfMode uint8 = 0 // ReplaceMode render message arguments by string replace ReplaceMode uint8 = 1 )
Variables ¶
This section is empty.
Functions ¶
Types ¶
type I18n ¶
type I18n struct { // mode for the load language files. // 0 single language file // 1 multi language directory LoadMode uint8 // TODO translate mode. // 0 sprintf // 1 replace TransMode uint8 // default language name. eg. "en" DefaultLang string // spare(fallback) language name. eg. "en" FallbackLang string // contains filtered or unexported fields }
I18n language manager
func NewWithInit ¶
NewWithInit a i18n instance and call init
func (*I18n) LoadFile ¶
LoadFile append data to a exist language Usage:
i18n.LoadFile("zh-CN", "path/to/zh-CN.ini")
func (*I18n) LoadString ¶
LoadString load language data form a string Usage:
i18n.Set("zh-CN", "name = blog")
Click to show internal directories.
Click to hide internal directories.