当前位置: 首页>>代码示例>>Golang>>正文


Golang i18n.Tr函数代码示例

本文整理汇总了Golang中github.com/Unknwon/i18n.Tr函数的典型用法代码示例。如果您正苦于以下问题:Golang Tr函数的具体用法?Golang Tr怎么用?Golang Tr使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。


在下文中一共展示了Tr函数的12个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。

示例1: Post

func (c *ChgPass) Post() {
	oldPass := c.Req().FormValue("old_pass")
	newPass := c.Req().FormValue("new_pass")
	cfmPass := c.Req().FormValue("cfm_pass")

	defer c.Redirect("/chgpass")

	if newPass != cfmPass {
		c.Flash.Set("cfmError", i18n.Tr(c.CurLang(), "password_not_eq"))
		return
	}

	user := c.Auther.LoginUser()
	if user != nil {
		if models.EncodePassword(oldPass) != user.Password {
			c.Flash.Set("oldError", i18n.Tr(c.CurLang(), "ori_password_not_correct"))
			return
		}
	} else {
		c.Flash.Set("otherError", i18n.Tr(c.CurLang(), "unknown_error"))
		return
	}

	user.Password = newPass
	err := models.UpdateUser(user)
	if err != nil {
		c.Flash.Set("otherError", err.Error())
		return
	}

	c.Flash.Set("changeSuccess", i18n.Tr(c.CurLang(), "password_change_success"))
}
开发者ID:ChunyuLabs,项目名称:dbweb,代码行数:32,代码来源:chgpass.go

示例2: Pager2HTMLSimple

// pager to HTML with navigator elements
func Pager2HTMLSimple(p *Pager, layout, lang string) template.HTML {
	tpl := `<div class="pager clear">`
	if p.Current > 1 {
		tpl += `<a class="prev left" href="` + fmt.Sprintf(layout, p.Current-1) + `">` + i18n.Tr(lang, "pager.prev") + `</a>`
	}
	if p.Current < p.Pages {
		tpl += `<a class="next right" href="` + fmt.Sprintf(layout, p.Current+1) + `">` + i18n.Tr(lang, "pager.next") + `</a>`
	}
	tpl += "</div>"
	return template.HTML(tpl)
}
开发者ID:insionng,项目名称:purine,代码行数:12,代码来源:page.go

示例3: 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:trigrass2,项目名称:wego,代码行数:14,代码来源:template.go

示例4: 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 Date(t, setting.DateFormat)
	}
}
开发者ID:trigrass2,项目名称:wego,代码行数:15,代码来源:template.go

示例5: Post

func (c *Addb) Post() {
	var engine models.Engine
	if err := c.MapForm(&engine); err != nil {
		c.Flash.Set("ErrAdd", i18n.Tr(c.CurLang(), "err_param"))
		c.Redirect("/addb")
		return
	}

	if err := models.AddEngine(&engine); err != nil {
		c.Flash.Set("ErrAdd", i18n.Tr(c.CurLang(), "err_add_failed"))
		c.Redirect("/addb")
		return
	}

	c.Redirect("/")
}
开发者ID:trigrass2,项目名称:dbweb,代码行数:16,代码来源:addb.go

示例6: Post

func (c *Addb) Post() {
	var engine models.Engine
	engine.Name = c.Form("name")
	engine.Driver = c.Form("driver")
	host := c.Form("host")
	port := c.Form("port")
	dbname := c.Form("dbname")
	username := c.Form("username")
	passwd := c.Form("passwd")

	engine.DataSource = fmt.Sprintf("%s:%[email protected](%s:%s)/%s?charset=utf8",
		username, passwd, host, port, dbname)

	/*if err := c.MapForm(&engine); err != nil {
		c.Flash.Set("ErrAdd", i18n.Tr(c.CurLang(), "err_param"))
		c.Redirect("/addb")
		return
	}*/

	if err := models.AddEngine(&engine); err != nil {
		c.Flash.Set("ErrAdd", i18n.Tr(c.CurLang(), "err_add_failed"))
		c.Redirect("/addb")
		return
	}

	c.Redirect("/")
}
开发者ID:ChunyuLabs,项目名称:dbweb,代码行数:27,代码来源:addb.go

示例7: Since

func Since(t time.Time) string {
	//now := time.Now()

	s := since(time.Since(t))

	if s <= 0 {
		return i18n.Tr("ru-RU", "now")
	}

	if ms := int(s.Minutes()); ms <= 45 {
		return fmt.Sprintf("%d %s назад", ms, plural("минута_минуты_минут", ms))
	} else if ms <= 90 {
		return fmt.Sprintf("час назад")
	}

	if hs := int(s.Hours()); hs < 22 {
		return i18n.Tr("ru-RU", "%d %s назад", hs, plural("час_часа_часов", hs))
	} else if hs < 36 {
		return fmt.Sprintf("вчера")
	}

	if ds := int(s.Days()); ds < 6 {
		return fmt.Sprintf("%d %s назад", ds, plural("день_дня_дней", ds))
	} else if ds < 8 {
		return fmt.Sprintf("неделю назад")
	}

	if ws := int(s.Weeks()); ws < 3 {
		return fmt.Sprintf("%d %s назад", ws+1, plural("неделя_недели_недель", ws+1))
	} else if ws < 5 {
		return "месяц назад"
	}
	if ms := int(s.Months()); ms < 11 {
		return fmt.Sprintf("%d %s назад", ms+1, plural("месяц_месяца_месяцев", ms+1))
	} else if ms < 14 {
		return "год назад"
	}

	return fmt.Sprintf("%d %s назад", s.Years(), plural("год_года_лет", s.Years()))
}
开发者ID:zhuharev,项目名称:smoljanin.ru,代码行数:40,代码来源:since.go

示例8: Post

func (c *Login) Post() {
	c.Req().ParseForm()
	name := c.Req().FormValue("user")
	password := c.Req().FormValue("password")

	user, err := models.GetUserByName(name)
	if err != nil {
		c.Flash.Set("user", name)
		c.Flash.Set("AuthError", i18n.Tr(c.CurLang(), "pasword_error"))
		c.Redirect("/login")
		return
	}

	if user.Password != models.EncodePassword(password) {
		c.Flash.Set("user", name)
		c.Flash.Set("AuthError", i18n.Tr(c.CurLang(), "pasword_error"))
		c.Redirect("/login")
	} else {
		c.SetLogin(user.Id)
		c.Redirect("/")
	}
}
开发者ID:ChunyuLabs,项目名称:dbweb,代码行数:22,代码来源:login.go

示例9: timeSince

func timeSince(then time.Time, lang string) string {
	now := time.Now()

	lbl := i18n.Tr(lang, "tool.ago")
	diff := now.Unix() - then.Unix()
	if then.After(now) {
		lbl = i18n.Tr(lang, "tool.from_now")
		diff = then.Unix() - now.Unix()
	}

	switch {
	case diff <= 0:
		return i18n.Tr(lang, "tool.now")
	case diff <= 2:
		return i18n.Tr(lang, "tool.1s", lbl)
	case diff < 1*Minute:
		return i18n.Tr(lang, "tool.seconds", diff, lbl)

	case diff < 2*Minute:
		return i18n.Tr(lang, "tool.1m", lbl)
	case diff < 1*Hour:
		return i18n.Tr(lang, "tool.minutes", diff/Minute, lbl)

	case diff < 2*Hour:
		return i18n.Tr(lang, "tool.1h", lbl)
	case diff < 1*Day:
		return i18n.Tr(lang, "tool.hours", diff/Hour, lbl)

	case diff < 2*Day:
		return i18n.Tr(lang, "tool.1d", lbl)
	case diff < 1*Week:
		return i18n.Tr(lang, "tool.days", diff/Day, lbl)

	case diff < 2*Week:
		return i18n.Tr(lang, "tool.1w", lbl)
	case diff < 1*Month:
		return i18n.Tr(lang, "tool.weeks", diff/Week, lbl)

	case diff < 2*Month:
		return i18n.Tr(lang, "tool.1mon", lbl)
	case diff < 1*Year:
		return i18n.Tr(lang, "tool.months", diff/Month, lbl)

	case diff < 2*Year:
		return i18n.Tr(lang, "tool.1y", lbl)
	default:
		return i18n.Tr(lang, "tool.years", diff/Year, lbl)
	}
}
开发者ID:gigforks,项目名称:gogs,代码行数:49,代码来源:tool.go

示例10: i18nHTML

// get HTML i18n string
func i18nHTML(lang, format string, args ...interface{}) template.HTML {
	return template.HTML(i18n.Tr(lang, format, args...))
}
开发者ID:trigrass2,项目名称:wego,代码行数:4,代码来源:template.go

示例11: Tr

func (i *i18nHandle) Tr(format string, args ...interface{}) string {
	return i18n.Tr(i.Lang, format, args...)
}
开发者ID:insionng,项目名称:purine,代码行数:3,代码来源:i18n.go

示例12: LangTr

// current translate method
func (bl *BaseLanguager) LangTr(format string, args ...interface{}) string {
	return i18n.Tr(bl.Lang, format, args...)
}
开发者ID:insionng,项目名称:purine,代码行数:4,代码来源:i18n.go


注:本文中的github.com/Unknwon/i18n.Tr函数示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。