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


Golang i18n.IsExist函数代码示例

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


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

示例1: setLangVer

// setLangVer sets site language version.
func (this *baseController) setLangVer() bool {
	isNeedRedir := false
	hasCookie := false

	// 1. Check URL arguments.
	lang := this.Input().Get("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. Get language information from 'Accept-Language'.
	if len(lang) == 0 {
		al := this.Ctx.Request.Header.Get("Accept-Language")
		if len(al) > 4 {
			al = al[:5] // Only compare first 5 letters.
			if i18n.IsExist(al) {
				lang = al
			}
		}
	}

	// 4. Default language is (Chinese) English.
	if len(lang) == 0 {
		lang = "zh-CN" //"en-US"
		isNeedRedir = false
	}

	curLang := langType{
		Lang: lang,
	}

	// Save language information in cookies.
	if !hasCookie {
		this.Ctx.SetCookie("lang", curLang.Lang, 1<<31-1, "/")
	}

	restLangs := make([]*langType, 0, len(langTypes)-1)
	for _, v := range langTypes {
		restLangs = append(restLangs, v)
	}

	// Set language properties.
	this.Lang = lang
	this.Data["Lang"] = curLang.Lang
	this.Data["CurLang"] = curLang.Name
	this.Data["RestLangs"] = restLangs
	return isNeedRedir
}
开发者ID:yh453926638,项目名称:website,代码行数:61,代码来源:controller.go

示例2: 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

示例3: setLang

// 设置语言
func (this *BaseController) setLang() bool {
	isNeedRedir := false
	hasCookie := false

	langs := common.Langs

	lang := this.Input().Get("lang")

	if len(lang) == 0 {
		lang = this.Ctx.GetCookie("lang")
		hasCookie = true
	} else {
		isNeedRedir = true
	}

	if !i18n.IsExist(lang) {
		lang = ""
		isNeedRedir = false
		hasCookie = false
	}

	if len(lang) == 0 {
		al := this.Ctx.Request.Header.Get("Accept-Language")

		if len(al) > 4 {
			al := al[:5]

			if i18n.IsExist(al) {
				lang = al
			}
		}
	}

	if len(lang) == 0 {
		lang = "en-US"
		isNeedRedir = false
	}

	if !hasCookie {
		this.Ctx.SetCookie("lang", lang, 60*60*24*365, "/", nil, nil, false)
	}

	this.Data["Lang"] = lang
	this.Data["Langs"] = langs
	this.Data["CurrentLang"] = lang
	this.Lang = lang

	if lang == "zh-CN" {
		this.Data["CN"] = true
	}

	return isNeedRedir
}
开发者ID:wangroot,项目名称:SCDht,代码行数:54,代码来源:base.go

示例4: Prepare

func (this *BaseController) Prepare() {
	//Accept-Language
	acceptLanguage := this.Ctx.Request.Header.Get("Accept-Language")
	if len(acceptLanguage) > 4 {
		acceptLanguage = acceptLanguage[:5] // Only compare first 5 letters.
		if i18n.IsExist(acceptLanguage) {
			Lang = acceptLanguage
		}
	}

	if len(Lang) == 0 {
		Lang = "en-US"
	}

	// Initialized language type list.
	langs := strings.Split(beego.AppConfig.String("lang::types"), "|")
	names := strings.Split(beego.AppConfig.String("lang::names"), "|")
	langTypes := make([]*langType, 0, len(langs))
	for i, v := range langs {
		langTypes = append(langTypes, &langType{
			Lang: v,
			Name: names[i],
		})
	}

	for _, lang := range langs {
		beego.Trace("Loading language: " + lang)
		if err := i18n.SetMessage(lang, "lang/"+"locale_"+lang+".ini"); err != nil {
			beego.Error("Fail to set message file: " + err.Error())
			return
		}
	}
}
开发者ID:JREAMLU,项目名称:jkernel_old,代码行数:33,代码来源:base.go

示例5: setLangVer

/**
 * 设定当前语言
 */
func (this *BaseController) setLangVer() bool {

	hasCookie := false

	// 参数传入语言类型
	lang := this.Input().Get("lang")

	// 丛cokkie获取语言类型
	if len(lang) == 0 {
		lang = this.Ctx.GetCookie("lang")
		hasCookie = true
	}

	// 如果语言不在设定内,重置语言类型
	if !i18n.IsExist(lang) {
		lang = ""
		hasCookie = false
	}

	// 从 'Accept-Language' 响应头部获取已设定的语言类型
	if len(lang) == 0 {
		al := this.Ctx.Request.Header.Get("Accept-Language")
		if len(al) > 4 {
			al = al[:5] // Only compare first 5 letters.
			if i18n.IsExist(al) {
				lang = al
			}
		}
	}

	// 无法获取语言类型,取配置文件默认
	if len(lang) == 0 {
		lang = beego.AppConfig.String("lang")
	}

	// 设置cookie
	if !hasCookie {
		this.Ctx.SetCookie("lang", lang, 1<<31-1, "/")
	}

	this.Data["Lang"] = lang
	return true
}
开发者ID:lvzhongyi,项目名称:canku,代码行数:46,代码来源:base.go

示例6: DocsStatic

func DocsStatic(ctx *context.Context) {
	uri := ctx.Input.Params[":all"]
	if len(uri) > 0 {
		lang := ctx.GetCookie("lang")
		if !i18n.IsExist(lang) {
			lang = "en-US"
		}
		http.ServeFile(ctx.ResponseWriter, ctx.Request, "docs/"+lang+"/"+"images/"+uri)
	}
}
开发者ID:hiproz,项目名称:beeweb,代码行数:10,代码来源:docs.go

示例7: 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

示例8: settingLocales

/**
 * 设置语言包
 */
func (this *BaseController) settingLocales() {
	// load locales with locale_LANG.ini files
	this.langTypes = []langType{
		langType{Lang: "en-US", Name: "English"},
		langType{Lang: "zh-CN", Name: "中文"},
	}

	for _, langT := range this.langTypes {
		lang := langT.Lang

		if i18n.IsExist(lang) {
			continue
		}
		if err := i18n.SetMessage(lang, "conf/i18n/"+lang+".ini"); err != nil {
			beego.Error("Fail to set message file: " + err.Error())
			return
		}
	}
}
开发者ID:lvzhongyi,项目名称:canku,代码行数:22,代码来源:base.go

示例9: Prepare

func (this *BaseController) Prepare() {
	lang := this.Input().Get("lang")
	if len(lang) == 0 {
		lang = this.Ctx.GetCookie("lang")
	}
	if len(lang) == 0 {
		al := this.Ctx.Request.Header.Get("Accept-Language")
		if len(al) > 4 {
			al = al[:5]
			if i18n.IsExist(al) {
				lang = al
			}
		}
	}
	if len(lang) == 0 {
		lang = "zh-CN"
		fmt.Println("zh-CN")
	}
	this.Data["Lang"] = lang
}
开发者ID:alex8023,项目名称:citycloud.cf-deploy-ui,代码行数:20,代码来源:base.go

示例10: DocsStatic

func DocsStatic(ctx *context.Context) {
	if uri := ctx.Input.Param(":all"); len(uri) > 0 {
		lang := ctx.GetCookie("lang")
		if !i18n.IsExist(lang) {
			lang = "en-US"
		}

		f, err := os.Open("docs/" + lang + "/" + "images/" + uri)
		if err != nil {
			ctx.WriteString(err.Error())
			return
		}
		defer f.Close()

		_, err = io.Copy(ctx.ResponseWriter, f)
		if err != nil {
			ctx.WriteString(err.Error())
			return
		}
	}
}
开发者ID:flying99999,项目名称:beeweb,代码行数:21,代码来源:docs.go

示例11: Prepare

// Prepare implemented Prepare() method for baseController.
// It's used for language option check and setting.
func (this *baseController) Prepare() {
	// Reset language option.
	this.Lang = "" // This field is from i18n.Locale.

	// 1. Get language information from 'Accept-Language'.
	al := this.Ctx.Request.Header.Get("Accept-Language")
	if len(al) > 4 {
		al = al[:5] // Only compare first 5 letters.
		if i18n.IsExist(al) {
			this.Lang = al
		}
	}

	// 2. Default language is English.
	if len(this.Lang) == 0 {
		this.Lang = "en-US"
	}

	// Set template level language option.
	this.Data["Lang"] = this.Lang
}
开发者ID:RaymondWilkinson,项目名称:samples,代码行数:23,代码来源:app.go

示例12: Prepare

// Prepare implemented Prepare() method for baseController.
// It's used for language option check and setting.
func (this *baseController) Prepare() {
	// Reset language option.
	this.Lang = "" // This field is from i18n.Locale.

	// 1. Get language information from 'Accept-Language'.
	al := this.Ctx.Request.Header.Get("Accept-Language")
	if len(al) > 4 {
		al = al[:5] // Only compare first 5 letters.
		allAl := strings.Split(al, ",")
		fmt.Println("browser lang: ", allAl)
		for _, v := range allAl {
			//Compared the first one!
			if v == "en" {
				v = "en-US"
			} else if v == "zh" {
				v = "zh-CN"
			}
			//Choose the first one.
			if i18n.IsExist(v) {
				this.Lang = v
				fmt.Println("browser : ", this.Lang)
				break
			}
		}

	}

	// 2. Default language is Chinese.
	if len(this.Lang) == 0 {
		this.Lang = "zh-CN"
	}

	// Set template level language option.
	this.Data["Lang"] = this.Lang
	fmt.Println("Choose the first lang: ", this.Data["Lang"])
}
开发者ID:elitecodegroovy,项目名称:GolangBestPractice,代码行数:38,代码来源:app.go

示例13: setLangVer

// setLangVer sets site language version.
func (this *baseRouter) setLangVer() bool {

	// Initialized language type list.
	langs := strings.Split(beego.AppConfig.String("lang::types"), "|")
	names := strings.Split(beego.AppConfig.String("lang::names"), "|")
	langTypes := make([]*langType, 0, len(langs))
	for i, v := range langs {
		langTypes = append(langTypes, &langType{
			Lang: v,
			Name: names[i],
		})
	}

	isNeedRedir := false
	hasCookie := false

	// 1. Check URL arguments.
	lang := this.Input().Get("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. Get language information from 'Accept-Language'.
	if len(lang) == 0 {
		al := this.Ctx.Request.Header.Get("Accept-Language")
		if len(al) > 4 {
			al = al[:5] // Only compare first 5 letters.
			if i18n.IsExist(al) {
				lang = al
			}
		}
	}

	// 4. Default language is English.
	if len(lang) == 0 {
		lang = "en-US"
		isNeedRedir = false
	}

	curLang := langType{
		Lang: lang,
	}

	// Save language information in cookies.
	if !hasCookie {
		this.Ctx.SetCookie("lang", curLang.Lang, 1<<31-1, "/")
	}

	restLangs := make([]*langType, 0, len(langTypes)-1)
	for _, v := range langTypes {
		if lang != v.Lang {
			restLangs = append(restLangs, v)
		} else {
			curLang.Name = v.Name
		}
	}

	// Set language properties.
	this.Lang = lang
	this.Data["Lang"] = curLang.Lang
	this.Data["CurLang"] = curLang.Name
	this.Data["RestLangs"] = restLangs

	return isNeedRedir
}
开发者ID:shenyp09,项目名称:juna,代码行数:78,代码来源:base.go

示例14: Prepare

// Prepare extracts the language information from request and populate data for rendering templates.
func (b *BaseController) Prepare() {

	var lang string

	langCookie, err := b.Ctx.Request.Cookie("language")
	if err != nil {
		log.Errorf("Error occurred in Request.Cookie: %v", err)
	}
	if langCookie != nil {
		lang = langCookie.Value
	}
	if len(lang) == 0 {
		sessionLang := b.GetSession("lang")
		if sessionLang != nil {
			b.SetSession("Lang", lang)
			lang = sessionLang.(string)
		} else {
			al := b.Ctx.Request.Header.Get("Accept-Language")
			if len(al) > 4 {
				al = al[:5] // Only compare first 5 letters.
				if i18n.IsExist(al) {
					lang = al
				}
			}
		}
	}

	if _, exist := supportLanguages[lang]; !exist { //Check if support the request language.
		lang = defaultLang //Set default language if not supported.
	}

	b.Ctx.SetCookie("language", lang, 0, "/")
	b.SetSession("Lang", lang)

	curLang := langType{
		Lang: lang,
	}

	restLangs := make([]*langType, 0, len(langTypes)-1)
	for _, v := range langTypes {
		if lang != v.Lang {
			restLangs = append(restLangs, v)
		} else {
			curLang.Name = v.Name
		}
	}

	// Set language properties.
	b.Lang = lang
	b.Data["Lang"] = curLang.Lang
	b.Data["CurLang"] = curLang.Name
	b.Data["RestLangs"] = restLangs

	authMode := strings.ToLower(os.Getenv("AUTH_MODE"))
	if authMode == "" {
		authMode = "db_auth"
	}
	b.AuthMode = authMode
	b.Data["AuthMode"] = b.AuthMode

	useCompressedJS := os.Getenv("USE_COMPRESSED_JS")
	if useCompressedJS == "on" {
		b.UseCompressedJS = true
	}

	if _, err := os.Stat(filepath.Join("static", "resources", "js", "harbor.app.min.js")); os.IsNotExist(err) {
		b.UseCompressedJS = false
	}

	selfRegistration := strings.ToLower(os.Getenv("SELF_REGISTRATION"))
	if selfRegistration == "on" {
		b.SelfRegistration = true
	}
	b.Data["SelfRegistration"] = b.SelfRegistration
}
开发者ID:vmware,项目名称:harbor,代码行数:76,代码来源:base.go


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