mmsg

package module
v0.0.0-...-9a1e14d Latest Latest
Warning

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

Go to latest
Published: Apr 25, 2016 License: Apache-2.0 Imports: 12 Imported by: 2

README

mmsg

Mabetle Go Message

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

Constants

This section is empty.

Variables

View Source
var (

	// default message directory
	MessageFilesDirectory = "messages"

	// DefaultLocale run time locale
	DefaultLocale = "en-US"
)

Functions

func Contains

func Contains(locale string, key string) bool

check if key exists.

func FprintMessages

func FprintMessages(locale string, w io.Writer)

func GetLocale

func GetLocale() string

func GetModelFieldLabel

func GetModelFieldLabel(locale string, model interface{}, field string) string

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

func GetTableColumnLabel(locale, table, column string) string

GetTableColumnLabel returns table column locale label message. if table is "", set table to common key format: common-UserName etc.

func GetUserLocale

func GetUserLocale(username string) string

func LoadDefaultMessages

func LoadDefaultMessages()

LoadDefaultMessages Default work dir messages

func LoadMatchMessageFile

func LoadMatchMessageFile(path string, info os.FileInfo, osError error) error

LoadMatchMessageFile

func LoadMessageFile

func LoadMessageFile(path string, info os.FileInfo, osError error) error

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

func LoadPrefixMessages(path string, prefix string)

LoadPrefixMessages know path and prefix, not all dir files.

func LocaleMessage

func LocaleMessage(key string, args ...interface{}) string

func Message

func Message(locale, message string, args ...interface{}) string

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

func MessageContains(locale string, key string, args ...interface{}) (string, bool)

return value and if contain

func MessageLanguages

func MessageLanguages() []string

Return all currently loaded message languages.

func PutConfig

func PutConfig(locale string, c *config.Config)

func PutKeyMsgs

func PutKeyMsgs(kms []*KeyMsg)

func PutMsg

func PutMsg(locale, key, value string)

PutMsg

func PutMsgEnZh

func PutMsgEnZh(key, en, zh string)

func PutMsgRes

func PutMsgRes(args ...MsgRes)

func PutMsgText

func PutMsgText(locale, text string)

func PutUserLocale

func PutUserLocale(username, locale string)

func SaveMessageFile

func SaveMessageFile(path string, prefix string)

SaveMessageFile

func SetDefaultLanguage

func SetDefaultLanguage(v string)

func UpdateMsg

func UpdateMsg(locale, key, value string)

func UserMessage

func UserMessage(username string, key string, args ...interface{}) string

UserMessage

Types

type KeyMsg

type KeyMsg struct {
	Key      string
	LangMsgs []LangMsg
}

func NewKeyMsg

func NewKeyMsg(key string) *KeyMsg

func (*KeyMsg) En

func (km *KeyMsg) En(msg string) *KeyMsg

func (*KeyMsg) Put

func (km *KeyMsg) Put()

func (*KeyMsg) PutLangMsg

func (km *KeyMsg) PutLangMsg(lang, msg string) *KeyMsg

func (*KeyMsg) Zh

func (km *KeyMsg) Zh(msg string) *KeyMsg

type LangMsg

type LangMsg struct {
	Lang string
	Msg  string
}

type ModelLabel

type ModelLabel struct {
	Field string
	Label string
}

func GetModelLabels

func GetModelLabels(locale string, model interface{}) (rows []ModelLabel)

GetModelLabels returns model all labels

type MsgRes

type MsgRes struct {
	Key  string
	Lang string
	Msg  string
}

Directories

Path Synopsis
demo

Jump to

Keyboard shortcuts

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