本文整理汇总了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
}
开发者ID:JREAMLU,项目名称:jkernel_old,代码行数:43,代码来源:inputParams.go
示例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
}
开发者ID:codeshredder,项目名称:infoboard,代码行数:25,代码来源:base.go
示例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))
}
}
开发者ID:thuongdinh,项目名称:beegowebapp,代码行数:13,代码来源:template.go
示例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
}
开发者ID:varding,项目名称:wetalk,代码行数:14,代码来源:template.go
示例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)
}
}
开发者ID:yubo,项目名称:falcon,代码行数:15,代码来源:template.go
示例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
}
开发者ID:codeshredder,项目名称:infoboard,代码行数:30,代码来源:user.go
示例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)
}
开发者ID:jango2015,项目名称:ojsite,代码行数:11,代码来源:base.go
示例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
}
开发者ID:JREAMLU,项目名称:jkernel_old,代码行数:21,代码来源:outputParams.go
示例9: i18nGetString
func i18nGetString(key string) string {
return i18n.Tr(controllers.LANG, key)
}
开发者ID:jango2015,项目名称:ojsite,代码行数:3,代码来源:tplfunc.go
示例10: Help
//帮助
func (this *Main) Help() {
this.seo.Title = i18n.Tr(this.Lang, "help")
this.setTplNames("help")
}
开发者ID:linbaozhong,项目名称:niux,代码行数:5,代码来源:c_main.go
示例11: i18nHTML
// get HTML i18n string
func i18nHTML(lang, format string, args ...interface{}) template.HTML {
return template.HTML(i18n.Tr(lang, format, args...))
}
开发者ID:yubo,项目名称:falcon,代码行数:4,代码来源:template.go
示例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
}
开发者ID:JREAMLU,项目名称:jkernel_old,代码行数:74,代码来源:inputParams.go
示例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("")
})
}
开发者ID:RickyShiJs,项目名称:beego-samples,代码行数:73,代码来源:funcmap.go
示例14: Tr
func (this *BaseController) Tr(format string) string {
return i18n.Tr(Lang, format)
}
开发者ID:JREAMLU,项目名称:jkernel_old,代码行数:3,代码来源:base.go
注:本文中的github.com/beego/i18n.Tr函数示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论