本文整理汇总了Golang中github.com/beego/i18n.GetLangByIndex函数的典型用法代码示例。如果您正苦于以下问题:Golang GetLangByIndex函数的具体用法?Golang GetLangByIndex怎么用?Golang GetLangByIndex使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了GetLangByIndex函数的11个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Golang代码示例。
示例1: Valid
func (form *UserAdminForm) Valid(v *validation.Validation) {
qs := models.Users()
if models.CheckIsExist(qs, "UserName", form.UserName, form.Id) {
v.SetError("UserName", "auth.username_already_taken")
}
if models.CheckIsExist(qs, "Email", form.Email, form.Id) {
v.SetError("Email", "auth.email_already_taken")
}
if len(i18n.GetLangByIndex(form.Lang)) == 0 {
v.SetError("Lang", "Can not be empty")
}
if len(form.LangAdds) > 0 {
adds := make(models.SliceStringField, 0, len(form.LangAdds))
for _, l := range form.LangAdds {
if d, err := utils.StrTo(l).Int(); err == nil {
if form.Lang == d {
continue
}
if len(i18n.GetLangByIndex(form.Lang)) == 0 {
v.SetError("Lang", "Can not be empty")
return
}
adds = append(adds, l)
}
}
form.LangAdds = adds
}
}
开发者ID:JessonChan,项目名称:wetalk,代码行数:32,代码来源:form.go
示例2: Valid
func (form *PostAdminForm) Valid(v *validation.Validation) {
user := models.User{Id: form.User}
if user.Read() != nil {
v.SetError("User", "admin.not_found_by_id")
}
user.Id = form.LastReply
if user.Read() != nil {
v.SetError("LastReply", "admin.not_found_by_id")
}
user.Id = form.LastAuthor
if user.Read() != nil {
v.SetError("LastReply", "admin.not_found_by_id")
}
topic := models.Topic{Id: form.Topic}
if topic.Read() != nil {
v.SetError("Topic", "admin.not_found_by_id")
}
if len(i18n.GetLangByIndex(form.Lang)) == 0 {
v.SetError("Lang", "Not Found")
}
}
开发者ID:varding,项目名称:wetalk,代码行数:25,代码来源:form.go
示例3: setLang
// setLang sets site language version.
func (this *baseRouter) setLang() bool {
isNeedRedir := false
hasCookie := false
// get all lang names from i18n
langs := utils.Langs
// 1. Check URL arguments.
lang := this.GetString("lang")
// 2. Get language information from cookies.
if len(lang) == 0 {
lang = this.Ctx.GetCookie("lang")
hasCookie = true
} else {
isNeedRedir = true
}
// Check again in case someone modify by purpose.
if !i18n.IsExist(lang) {
lang = ""
isNeedRedir = false
hasCookie = false
}
// 3. check if isLogin then use user setting
if len(lang) == 0 && this.isLogin {
lang = i18n.GetLangByIndex(this.user.Lang)
}
// 4. Get language information from 'Accept-Language'.
if len(lang) == 0 {
al := this.Ctx.Input.Header("Accept-Language")
if len(al) > 4 {
al = al[:5] // Only compare first 5 letters.
if i18n.IsExist(al) {
lang = al
}
}
}
// 4. DefaucurLang language is English.
if len(lang) == 0 {
lang = "en-US"
isNeedRedir = false
}
// Save language information in cookies.
if !hasCookie {
this.setLangCookie(lang)
}
// Set language properties.
this.Data["Lang"] = lang
this.Data["Langs"] = langs
this.Lang = lang
return isNeedRedir
}
开发者ID:thuongdinh,项目名称:beegowebapp,代码行数:61,代码来源:router.go
示例4: Valid
func (form *PostForm) Valid(v *validation.Validation) {
valid := false
for _, topic := range form.Topics {
if topic.Id == form.Topic {
valid = true
}
}
if !valid {
v.SetError("Topic", "error")
}
valid = false
for _, cat := range form.Categories {
if cat.Id == form.Category {
valid = true
}
}
if !valid {
v.SetError("Category", "error")
}
if len(i18n.GetLangByIndex(form.Lang)) == 0 {
v.SetError("Lang", "error")
}
}
开发者ID:oyoy8629,项目名称:XWetalk,代码行数:27,代码来源:form.go
示例5: Valid
func (model *UserAdminModel) Valid(v *validation.Validation) {
qs := userServ.UserService{}.Queryable()
if services.CheckIsExist(qs, "user_name", model.Username, model.Id) {
v.SetError("Username", "auth.username_already_taken")
}
if services.CheckIsExist(qs, "email", model.Email, model.Id) {
v.SetError("Email", "auth.email_already_taken")
}
if len(i18n.GetLangByIndex(model.Lang)) == 0 {
v.SetError("Lang", "Can not be empty")
}
//if len(model.LangAdds) > 0 {
// adds := make(models.SliceStringField, 0, len(model.LangAdds))
// for _, l := range model.LangAdds {
// if d, err := utils.StrTo(l).Int(); err == nil {
// if model.Lang == d {
// continue
// }
// if len(i18n.GetLangByIndex(model.Lang)) == 0 {
// v.SetError("Lang", "Can not be empty")
// return
// }
// adds = append(adds, l)
// }
// }
// model.LangAdds = adds
//}
}
开发者ID:thanzen,项目名称:identity,代码行数:31,代码来源:viewmodel.go
示例6: LoginUser
func (this *BaseRouter) LoginUser(user *models.User, remember bool) string {
loginRedirect := strings.TrimSpace(this.Ctx.GetCookie("login_to"))
if utils.IsMatchHost(loginRedirect) == false {
loginRedirect = "/"
} else {
this.Ctx.SetCookie("login_to", "", -1, "/")
}
// login user
auth.LoginUser(user, this.Ctx, remember)
this.setLangCookie(i18n.GetLangByIndex(user.Lang))
return loginRedirect
}
开发者ID:varding,项目名称:wetalk,代码行数:15,代码来源:base.go
示例7: Valid
func (form *UserAdminForm) Valid(v *validation.Validation) {
qs := models.Users()
if models.CheckIsExist(qs, "UserName", form.UserName, form.Id) {
v.SetError("UserName", "auth.username_already_taken")
}
if models.CheckIsExist(qs, "Email", form.Email, form.Id) {
v.SetError("Email", "auth.email_already_taken")
}
if len(i18n.GetLangByIndex(form.Lang)) == 0 {
v.SetError("Lang", "Can not be empty")
}
}
开发者ID:netxfly,项目名称:wetalk,代码行数:15,代码来源:form.go
示例8: setLang
func (this *BaseController) setLang() {
// get all lang names from i18n
langs := models.Langs
// Get language information from cookies.
lang := this.Ctx.GetCookie("lang")
// Check again in case someone modify by purpose.
if !i18n.IsExist(lang) {
lang = ""
}
// check if isLogin then use user setting
if len(lang) == 0 && this.IsLogin {
lang = i18n.GetLangByIndex(this.User.Lang)
}
// Get language information from 'Accept-Language'.
if len(lang) == 0 {
al := this.Ctx.Input.Header("Accept-Language")
if len(al) > 4 {
al = al[:5] // Only compare first 5 letters.
if i18n.IsExist(al) {
lang = al
}
}
}
// Default language is English.
if len(lang) == 0 {
lang = "en-US"
}
// Save language information in cookies.
// this.Ctx.SetCookie("lang", lang, 60*60*24*365, "/", nil, nil, false)
// Set language properties.
this.Locale.Lang = lang
this.Data["Lang"] = lang
this.Data["Langs"] = langs
}
开发者ID:codeshredder,项目名称:infoboard,代码行数:42,代码来源:base.go
示例9: Login
// Login implemented user login.
func (this *LoginRouter) Login() {
this.Data["IsLoginPage"] = true
this.TplNames = "auth/login.html"
// no need login
if this.CheckLoginRedirect(false) {
return
}
var user models.User
var key string
ajaxErrMsg := "auth.login_error_ajax"
form := models.LoginForm{}
// valid form and put errors to template context
if this.ValidFormSets(&form) == false {
if this.IsAjax() {
goto ajaxError
}
return
}
key = "auth.login." + form.UserName + this.Ctx.Input.IP()
if times, ok := utils.TimesReachedTest(key, utils.LoginMaxRetries); ok {
if this.IsAjax() {
ajaxErrMsg = "auth.login_error_times_reached"
goto ajaxError
}
this.Data["ErrorReached"] = true
} else if models.VerifyUser(&user, form.UserName, form.Password) {
loginRedirect := strings.TrimSpace(this.Ctx.GetCookie("login_to"))
if utils.IsMatchHost(loginRedirect) == false {
loginRedirect = "/"
} else {
this.Ctx.SetCookie("login_to", "", -1, "/")
}
// login user
models.LoginUser(&user, &this.Controller, form.Remember)
this.setLangCookie(i18n.GetLangByIndex(user.Lang))
if this.IsAjax() {
this.Data["json"] = map[string]interface{}{
"success": true,
"message": this.Tr("auth.login_success_ajax"),
"redirect": loginRedirect,
}
this.ServeJson()
return
}
this.Redirect(loginRedirect, 302)
return
} else {
utils.TimesReachedSet(key, times, utils.LoginFailedBlocks)
if this.IsAjax() {
goto ajaxError
}
}
this.Data["Error"] = true
return
ajaxError:
this.Data["json"] = map[string]interface{}{
"success": false,
"message": this.Tr(ajaxErrMsg),
"once": this.Data["once_token"],
}
this.ServeJson()
}
开发者ID:supermouseno1,项目名称:wetalk,代码行数:73,代码来源:auth.go
示例10: GetLang
func (m *Post) GetLang() string {
return i18n.GetLangByIndex(m.Lang)
}
开发者ID:EPICPaaS,项目名称:wetalk,代码行数:3,代码来源:post.go
示例11: Login
// Login implemented POST user login.
func (this *LoginRouter) Login() {
this.Data["IsLoginPage"] = true
this.TplNames = "auth/login.html"
// no need login
if this.CheckLoginRedirect(false) {
return
}
var user models.User
form := models.LoginForm{Locale: this.Locale}
// valid form and put errors to template context
if this.ValidFormSets(&form) == false {
if this.IsAjax() {
goto ajaxError
}
return
}
if models.VerifyUser(&user, form.Email, form.Password) {
loginRedirect := strings.TrimSpace(this.Ctx.GetCookie("login_to"))
if utils.IsMatchHost(loginRedirect) == false {
loginRedirect = "/home"
} else {
this.Ctx.SetCookie("login_to", "", -1, "/")
}
// login user
models.LoginUser(&user, &this.Controller, form.Remember)
this.setLangCookie(i18n.GetLangByIndex(user.Lang))
if this.IsAjax() {
this.Data["json"] = map[string]interface{}{
"success": true,
"message": this.Tr("auth.login_success_ajax"),
"redirect": loginRedirect,
}
this.ServeJson()
return
}
this.Redirect(loginRedirect, 302)
return
} else {
if this.IsAjax() {
goto ajaxError
}
}
this.Data["Error"] = true
return
ajaxError:
this.Data["json"] = map[string]interface{}{
"success": false,
"message": this.Tr("auth.login_error_ajax"),
"once": this.Data["once_token"],
}
this.ServeJson()
}
开发者ID:thuongdinh,项目名称:beegowebapp,代码行数:62,代码来源:auth.go
注:本文中的github.com/beego/i18n.GetLangByIndex函数示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论