本文整理汇总了Golang中github.com/beego/i18n.SetMessage函数的典型用法代码示例。如果您正苦于以下问题:Golang SetMessage函数的具体用法?Golang SetMessage怎么用?Golang SetMessage使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了SetMessage函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。
示例1: main
func main() {
orm.Debug = true
orm.RunSyncdb("default", false, true)
beego.Router("/", &controllers.MainController{})
beego.Router("/login", &controllers.LoginController{})
beego.Router("/category", &controllers.CategoryController{})
beego.Router("/reply", &controllers.ReplyController{})
beego.AutoRouter(&controllers.ReplyController{})
beego.Router("/topic", &controllers.TopicController{})
beego.AutoRouter(&controllers.TopicController{})
os.Mkdir("attachment", os.ModePerm)
beego.SetStaticPath("/attachment", "attachment")
err := i18n.SetMessage("en-US", "conf/locale_en-US.ini")
if err != nil {
beego.Error(err)
}
err = i18n.SetMessage("zh-CN", "conf/locale_zh-CN.ini")
if err != nil {
beego.Error(err)
}
err = i18n.SetMessage("zh-HK", "conf/locale_zh-HK.ini")
if err != nil {
beego.Error(err)
}
beego.AddFuncMap("i18n", i18n.Tr)
beego.Run()
}
示例2: main
func main() {
i18n.SetMessage("en-US", "conf/locale_en-US.ini")
i18n.SetMessage("zh-CN", "conf/locale_zh-CN.ini")
beego.AddFuncMap("i18n", i18n.Tr)
beego.Run()
}
示例3: init
func init() {
//conf/app.conf -> os.Getenv("config_path")
configPath := os.Getenv("CONFIG_PATH")
if len(configPath) != 0 {
log.Infof("Config path: %s", configPath)
beego.LoadAppConfig("ini", configPath)
}
beego.AddFuncMap("i18n", i18n.Tr)
langs := strings.Split(beego.AppConfig.String("lang::types"), "|")
names := strings.Split(beego.AppConfig.String("lang::names"), "|")
supportLanguages = make(map[string]langType)
langTypes = make([]*langType, 0, len(langs))
for i, lang := range langs {
t := langType{
Lang: lang,
Name: names[i],
}
langTypes = append(langTypes, &t)
supportLanguages[lang] = t
if err := i18n.SetMessage(lang, "static/i18n/"+"locale_"+lang+".ini"); err != nil {
log.Errorf("Fail to set message file: %s", err.Error())
}
}
}
示例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
}
}
}
示例5: New
func New(localeDir string, f FindLangFunc) (p *I18nPlug, err error) {
/*
/etc/xrest/locale/zh-CN.ini
/etc/xrest/locale/en-US.ini
*/
var locales []*i18n.Locale
if err = filepath.Walk(localeDir, func(path string, info os.FileInfo, e error) error {
if e != nil {
return e
}
ext := filepath.Ext(path)
if info.IsDir() || ext != ".ini" {
return nil
}
lang := strings.ToLower(strings.TrimRight(info.Name(), ext))
if smErr := i18n.SetMessage(lang, path); smErr != nil {
return smErr
}
locales = append(locales, &i18n.Locale{Lang: lang})
return nil
}); err != nil {
return nil, err
}
return &I18nPlug{
findLang: f,
locales: locales,
}, nil
}
示例6: SetLang
// 设置语言
func SetLang() {
// 设定语言类型
langs := "en-US|zh-CN|ja-JP|zh-TW|ko-KR"
// 对语言进行循环
for _, lang := range strings.Split(langs, "|") {
// 去除首尾空格
lang = strings.TrimSpace(lang)
// 设置文件路径
files := []string{"conf/locale_" + lang + ".ini"}
if fh, err := os.Open(files[0]); err == nil {
// 打开正确则关闭
fh.Close()
} else {
// 打开失败则报错
files = nil
beego.Error(err.Error())
}
if err := i18n.SetMessage(lang, "conf/locale_"+lang+".ini", files...); err != nil {
// 载入语言文件失败则报错并退出
beego.Error("Fail to set message file: " + err.Error())
os.Exit(2)
}
}
// 列出所有语言文件
Langs = i18n.ListLangs()
}
示例7: InitLang
// 初始化多国语言模块
func InitLang() {
languages := beego.AppConfig.String("langs")
langs := strings.Split(languages, "|")
for _, lang := range langs {
beego.Trace("Loading language: " + lang)
if err := i18n.SetMessage(lang, "conf/locale/"+"locale_"+lang+".ini"); err != nil {
beego.Error("Fail to set message file: " + err.Error())
return
}
}
}
示例8: init
func init() {
// Initialize language type list.
langTypes = strings.Split(beego.AppConfig.String("lang_types"), "|")
// Load locale files according to language types.
for _, lang := range langTypes {
beego.Trace("Loading language: " + lang)
if err := i18n.SetMessage(lang, "conf/"+"locale_"+lang+".ini"); err != nil {
beego.Error("Fail to set message file:", err)
return
}
}
}
示例9: init
func init() {
beego.Router("/", &controllers.MainController{})
beego.Router("/topic", &controllers.TopicController{})
beego.AutoRouter(&controllers.TopicController{})
beego.Router("/about", &controllers.AboutController{})
langs := strings.Split(beego.AppConfig.String("types"), "|")
for _, lang := range langs {
if err := i18n.SetMessage(lang, "conf/"+"locale_"+lang+".ini"); err != nil {
beego.Error(err.Error())
}
}
beego.AddFuncMap("i18n", i18n.Tr)
}
示例10: settingLocales
func settingLocales() {
// load locales with locale_LANG.ini files
langs := "en-US|zh-CN"
for _, lang := range strings.Split(langs, "|") {
lang = strings.TrimSpace(lang)
files := []string{"conf/" + "locale_" + lang + ".ini"}
if fh, err := os.Open(files[0]); err == nil {
fh.Close()
} else {
files = nil
}
if err := i18n.SetMessage(lang, "conf/global/"+"locale_"+lang+".ini", files...); err != nil {
beego.Error("Fail to set message file: " + err.Error())
os.Exit(2)
}
}
Langs = i18n.ListLangs()
}
示例11: initLocale
func initLocale() {
langs := []string{"zh-CN", "en-US"}
names := []string{"中文", "English"}
config.LangTypes = make([]*LangType, 0, len(langs))
for i, v := range langs {
config.LangTypes = append(config.LangTypes, &LangType{
Lang: v,
Name: names[i],
})
}
for _, lang := range langs {
beego.Trace("Loading language: " + lang)
if err := i18n.SetMessage(lang, "conf/"+"index_"+lang+".ini"); err != nil {
beego.Error("Fail to set message file: " + err.Error())
return
}
}
}
示例12: 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
}
}
}
示例13: InitLocales
func InitLocales() {
// 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, "conf/"+"locale_"+lang+".ini"); err != nil {
beego.Error("Fail to set message file: " + err.Error())
return
}
}
}
示例14: initLanguage
// 注册本地化文件
func initLanguage() error {
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{
Name: names[i],
Lang: v,
})
}
for _, lang := range langs {
err := i18n.SetMessage(lang, "languages/"+lang+".ini")
if err != nil {
return err
}
}
return nil
}
示例15: initialize
// We have to call a initialize function manully
// because we use `bee bale` to pack static resources
// and we cannot make sure that which init() execute first.
func initialize() {
// Load configuration, set app version and log level.
utils.LoadConfig("conf/app.ini")
// Load locale files.
langs := strings.Split(utils.Cfg.MustValue("lang", "types"), "|")
// Skip en-US.
for i := 1; i < len(langs); i++ {
err := i18n.SetMessage(langs[i], "conf/locale_"+langs[i]+".ini")
if err != nil {
panic("Fail to set message file: " + err.Error())
}
}
// Trim 4th part.
routers.AppVer = strings.Join(strings.Split(APP_VER, ".")[:3], ".")
beego.AppName = utils.Cfg.MustValue("beego", "app_name")
beego.RunMode = utils.Cfg.MustValue("beego", "run_mode")
beego.HttpPort = utils.Cfg.MustInt("beego", "http_port_"+beego.RunMode)
routers.IsBeta = utils.Cfg.MustBool("server", "beta")
routers.IsProMode = beego.RunMode == "prod"
if routers.IsProMode {
beego.SetLevel(beego.LevelInfo)
beego.Info("Product mode enabled")
os.Mkdir("./log", os.ModePerm)
beego.BeeLogger.SetLogger("file", `{"filename": "log/log"}`)
}
// Initialize data.
models.InitDb()
routers.InitRouter()
doc.SetGithubCredentials(utils.Cfg.MustValue("github", "client_id"),
utils.Cfg.MustValue("github", "client_secret"))
}