本文整理匯總了Golang中github.com/beego/i18n.Tr函數的典型用法代碼示例。如果您正苦於以下問題:Golang Tr函數的具體用法?Golang Tr怎麽用?Golang Tr使用的例子?那麽, 這裏精選的函數代碼示例或許可以為您提供幫助。
在下文中一共展示了Tr函數的14個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Golang代碼示例。
示例1: InputParamsCheck
/**
* @auther jream.lu
* @intro 入參驗證
* @logic
* @todo 返回值
* @meta meta map[string][]string rawMetaHeader
* @data data ...interface{} 切片指針 rawDataBody
* @return 返回 true, metaMap, error
*/
func InputParamsCheck(meta map[string][]string, data ...interface{}) (result Result, err error) {
//MetaHeader check
metaCheckResult, err := MetaHeaderCheck(meta)
if err != nil {
return metaCheckResult, err
}
//DataParams check
valid := validation.Validation{}
for _, val := range data {
is, err := valid.Valid(val)
//日誌
//檢查參數
if err != nil {
// handle error
log.Println(i18n.Tr(global.Lang, "outputParams.SYSTEMILLEGAL"), err)
}
if !is {
for _, err := range valid.Errors {
log.Println(i18n.Tr(global.Lang, "outputParams.DATAPARAMSILLEGAL"), err.Key, ":", err.Message)
result.MetaCheckResult = nil
result.RequestID = metaCheckResult.MetaCheckResult["request-id"]
result.Message = i18n.Tr(global.Lang, "outputParams.DATAPARAMSILLEGAL") + " " + err.Key + ":" + err.Message
return result, errors.New(i18n.Tr(global.Lang, "outputParams.DATAPARAMSILLEGAL"))
}
}
}
return metaCheckResult, nil
}
示例2: ValidForm
func (this *BaseController) ValidForm(form interface{}) bool {
log.Println("ValidForm")
valid := validation.Validation{}
ok, _ := valid.Valid(form)
if !ok {
for _, err := range valid.Errors {
/* set error message */
slice := strings.Split(err.Key, ".")
name := slice[0] + "Error"
message := "valid." + err.Message
this.Data[name] = i18n.Tr(this.Locale.Lang, message)
log.Println(name)
log.Println(message)
log.Println(this.Locale.Lang)
log.Println(i18n.Tr(this.Locale.Lang, message))
return false
}
}
return true
}
示例3: timesince
func timesince(lang string, t time.Time) string {
now := time.Now()
seonds := int(now.Sub(t).Seconds())
if seonds < 60 {
return i18n.Tr(lang, "seconds_ago", seonds)
} else if seonds < 60*60 {
return i18n.Tr(lang, "minutes_ago", seonds/60)
} else if seonds < 60*60*24 {
return i18n.Tr(lang, "hours_ago", seonds/(60*60))
} else {
return i18n.Tr(lang, "days_ago", seonds/(60*60*24))
}
}
示例4: getbulletintype
func getbulletintype(lang string, t int) string {
var typeStr string
switch t {
case setting.BULLETIN_FRIEND_LINK:
typeStr = i18n.Tr(lang, "model.bulletin_friend_link")
case setting.BULLETIN_MOBILE_APP:
typeStr = i18n.Tr(lang, "model.bulletin_mobile_app")
case setting.BULLETIN_NEW_COMER:
typeStr = i18n.Tr(lang, "model.bulletin_new_comer")
case setting.BULLETIN_OPEN_SOURCE:
typeStr = i18n.Tr(lang, "model.bulletin_open_source")
}
return typeStr
}
示例5: timesince
func timesince(lang string, t time.Time) string {
seconds := int(time.Since(t).Seconds())
switch {
case seconds < 60:
return i18n.Tr(lang, "seconds_ago", seconds)
case seconds < 60*60:
return i18n.Tr(lang, "minutes_ago", seconds/60)
case seconds < 60*60*24:
return i18n.Tr(lang, "hours_ago", seconds/(60*60))
case seconds < 60*60*24*100:
return i18n.Tr(lang, "days_ago", seconds/(60*60*24))
default:
return beego.Date(t, setting.DateFormat)
}
}
示例6: Post
func (this *LoginController) Post() {
this.TplNames = "user/login.html"
var user LoginForm
this.ParseForm(&user)
log.Println("Login UserName: ", user.UserName)
log.Println("Login Password: ", user.Password)
log.Println("Login Remember: ", user.Remember)
if this.ValidForm(&user) == false {
return
}
if models.VerifyUser(user.UserName, user.Password) {
log.Println("login Success")
// set login session
this.SetSession("login_user", user.UserName)
this.Redirect("/", 302)
return
} else {
this.Data["Error"] = i18n.Tr(this.Locale.Lang, "auth.sign_connect_error")
}
return
}
示例7: Lang
func (this *BaseController) Lang(key string) string {
lang := this.Ctx.GetCookie("lang")
if len(lang) == 0 {
this.Ctx.SetCookie("lang", "zh-CN", 1<<31-1, "/")
lang = "zh-CN"
}
LANG = lang
return i18n.Tr(lang, key)
}
示例8: OutputSuccess
/**
* @auther jream.lu
* @intro 出參成功
* @logic
* @todo 返回值
* @params params ...interface{} 切片指針
* @return ?
*/
func OutputSuccess(data interface{}, requestID string) Output {
var op Output
op.Meta.RequestId = requestID
op.Meta.UpdatedAt = time.Now().Format("2006-01-02 15:04:05")
op.StatusCode = SUCCESS
op.Message = i18n.Tr(global.Lang, "outputParams.SUCCESS")
op.Data = data
return op
}
示例9: i18nGetString
func i18nGetString(key string) string {
return i18n.Tr(controllers.LANG, key)
}
示例10: Help
//幫助
func (this *Main) Help() {
this.seo.Title = i18n.Tr(this.Lang, "help")
this.setTplNames("help")
}
示例11: i18nHTML
// get HTML i18n string
func i18nHTML(lang, format string, args ...interface{}) template.HTML {
return template.HTML(i18n.Tr(lang, format, args...))
}
示例12: MetaHeaderCheck
/**
* meta參數驗證
* 1.map轉json
* 2.json轉slice
* 3.解析到struct
* 4.將header 放入map 返回
*
* @meta meta map[string][]string header信息 map格式
*/
func MetaHeaderCheck(meta map[string][]string) (result Result, err error) {
rawMetaHeader, _ := ffjson.Marshal(meta)
beego.Trace("入參meta:" + string(rawMetaHeader))
var metaHeader MetaHeader
ffjson.Unmarshal(rawMetaHeader, &metaHeader)
//日誌
fmt.Println("meta json解析:", metaHeader)
for key, val := range meta {
fmt.Println("meta 解析", key, ":", val[0])
}
valid := validation.Validation{}
is, err := valid.Valid(&metaHeader)
//日誌
//Content-Type
if val, ok := meta["Content-Type"]; ok {
if val[0] != beego.AppConfig.String("Content-Type") {
result.MetaCheckResult = nil
result.Message = i18n.Tr(global.Lang, "outputParams.CONTENTTYPEILLEGAL")
if val, ok := meta["request-id"]; ok {
result.RequestID = val[0]
}
return result, errors.New(i18n.Tr(global.Lang, "outputParams.CONTENTTYPEILLEGAL "))
}
}
//檢查參數
if err != nil {
// handle error
log.Println(i18n.Tr(global.Lang, "outputParams.SYSTEMILLEGAL"), err)
}
if !is {
for _, err := range valid.Errors {
log.Println(i18n.Tr(global.Lang, "outputParams.METAPARAMSILLEGAL"), err.Key, ":", err.Message)
result.MetaCheckResult = nil
result.Message = i18n.Tr(global.Lang, "outputParams.METAPARAMSILLEGAL") + " " + err.Key + ":" + err.Message
if val, ok := meta["request-id"]; ok {
result.RequestID = val[0]
}
return result, errors.New(i18n.Tr(global.Lang, "outputParams.METAPARAMSILLEGAL "))
}
}
//把meta參數放入新的struct 返回
var metaMap = make(map[string]string)
for key, val := range meta {
metaMap[key] = val[0]
}
//日誌
if len(metaMap["request-id"]) == 0 {
metaMap["request-id"] = getRequestID()
}
result.MetaCheckResult = metaMap
result.Message = ""
result.RequestID = ""
return result, nil
}
示例13: init
func init() {
beego.AddFuncMap("i18n", i18n.Tr)
beego.AddFuncMap("i18nja", func(format string, args ...interface{}) string {
return i18n.Tr("ja-JP", format, args...)
})
beego.AddFuncMap("datenow", func(format string) string {
return time.Now().Add(time.Duration(9) * time.Hour).Format(format)
})
beego.AddFuncMap("dateformatJst", func(in time.Time) string {
in = in.Add(time.Duration(9) * time.Hour)
return in.Format("2006/01/02 15:04")
})
beego.AddFuncMap("qescape", func(in string) string {
return url.QueryEscape(in)
})
beego.AddFuncMap("nl2br", func(in string) string {
return strings.Replace(in, "\n", "<br>", -1)
})
beego.AddFuncMap("tostr", func(in interface{}) string {
return convert.ToStr(reflect.ValueOf(in).Interface())
})
beego.AddFuncMap("first", func(in interface{}) interface{} {
return reflect.ValueOf(in).Index(0).Interface()
})
beego.AddFuncMap("last", func(in interface{}) interface{} {
s := reflect.ValueOf(in)
return s.Index(s.Len() - 1).Interface()
})
beego.AddFuncMap("truncate", func(in string, length int) string {
return runewidth.Truncate(in, length, "...")
})
beego.AddFuncMap("noname", func(in string) string {
if in == "" {
return "(未入力)"
}
return in
})
beego.AddFuncMap("cleanurl", func(in string) string {
return strings.Trim(strings.Trim(in, " "), " ")
})
beego.AddFuncMap("append", func(data map[interface{}]interface{}, key string, value interface{}) template.JS {
if _, ok := data[key].([]interface{}); !ok {
data[key] = []interface{}{value}
} else {
data[key] = append(data[key].([]interface{}), value)
}
return template.JS("")
})
beego.AddFuncMap("appendmap", func(data map[interface{}]interface{}, key string, name string, value interface{}) template.JS {
v := map[string]interface{}{name: value}
if _, ok := data[key].([]interface{}); !ok {
data[key] = []interface{}{v}
} else {
data[key] = append(data[key].([]interface{}), v)
}
return template.JS("")
})
}
示例14: Tr
func (this *BaseController) Tr(format string) string {
return i18n.Tr(Lang, format)
}