Documentation ¶
Overview ¶
i18n package. some code copy form revel. dependency github.com/robfig/config usage: Load messages from dir: load message first. mmsg.Load("xxx dir") mmsg.SetLocale(locale) mmsg.LocaleMessage(locale, key)
when we donot want to create messages file, we can put messages by code. it's usefull when the application is a single one command in go Language. Provide one executable command is enough, no extra language resources files. Put messages: mmsg.PutMsg(locale, key, value)
Index ¶
- Variables
- func Contains(locale string, key string) bool
- func FprintMessages(locale string, w io.Writer)
- func GetLocale() string
- func GetModelFieldLabel(locale string, model interface{}, field string) string
- func GetTableColumnLabel(locale, table, column string) string
- func GetUserLocale(username string) string
- func LoadDefaultMessages()
- func LoadMatchMessageFile(path string, info os.FileInfo, osError error) error
- func LoadMessageFile(path string, info os.FileInfo, osError error) error
- func LoadMessages(path string)
- func LoadPrefixMessages(path string, prefix string)
- func LocaleMessage(key string, args ...interface{}) string
- func Message(locale, message string, args ...interface{}) string
- func MessageContains(locale string, key string, args ...interface{}) (string, bool)
- func MessageLanguages() []string
- func PutConfig(locale string, c *config.Config)
- func PutKeyMsgs(kms []*KeyMsg)
- func PutMsg(locale, key, value string)
- func PutMsgEnZh(key, en, zh string)
- func PutMsgRes(args ...MsgRes)
- func PutMsgText(locale, text string)
- func PutUserLocale(username, locale string)
- func SaveMessageFile(path string, prefix string)
- func SetDefaultLanguage(v string)
- func UpdateMsg(locale, key, value string)
- func UserMessage(username string, key string, args ...interface{}) string
- type KeyMsg
- type LangMsg
- type ModelLabel
- type MsgRes
Constants ¶
This section is empty.
Variables ¶
var ( // default message directory MessageFilesDirectory = "messages" // DefaultLocale run time locale DefaultLocale = "en-US" )
Functions ¶
func FprintMessages ¶
func GetModelFieldLabel ¶
GetModelFieldLabel returns model locale filed name message. Parameters: locale model can be a slice? no. do as name. field Field name save as column name. table name should be follow some rules.
func GetTableColumnLabel ¶
GetTableColumnLabel returns table column locale label message. if table is "", set table to common key format: common-UserName etc.
func GetUserLocale ¶
func LoadMatchMessageFile ¶
LoadMatchMessageFile
func LoadMessageFile ¶
Load a single message file
func LoadMessages ¶
func LoadMessages(path string)
Recursively read and cache all available messages from all message files on the given path.
func LoadPrefixMessages ¶
LoadPrefixMessages know path and prefix, not all dir files.
func LocaleMessage ¶
func Message ¶
Perform a message look-up for the given locale and message using the given arguments. When either an unknown locale or message is detected, a specially formatted string is returned.
func MessageContains ¶
return value and if contain
func MessageLanguages ¶
func MessageLanguages() []string
Return all currently loaded message languages.
func PutKeyMsgs ¶
func PutKeyMsgs(kms []*KeyMsg)
func PutMsgEnZh ¶
func PutMsgEnZh(key, en, zh string)
func PutMsgText ¶
func PutMsgText(locale, text string)
func PutUserLocale ¶
func PutUserLocale(username, locale string)
func SetDefaultLanguage ¶
func SetDefaultLanguage(v string)
func UserMessage ¶
UserMessage
Types ¶
type KeyMsg ¶
func (*KeyMsg) PutLangMsg ¶
type ModelLabel ¶
func GetModelLabels ¶
func GetModelLabels(locale string, model interface{}) (rows []ModelLabel)
GetModelLabels returns model all labels