Example #1
0
// load i18n
func loadI18n() error {
	filepath.Walk(vars.I18N_DIR, func(path string, info os.FileInfo, err error) error {
		// only parse ini
		if filepath.Ext(path) != ".ini" {
			return nil
		}
		langName := strings.ToLower(filepath.Base(path))
		langName = strings.TrimSuffix(langName, ".ini")
		if err = i18n.SetMessage(langName, path); err != nil {
			return err
		}
		return nil
	})
	return nil
}
Example #2
0
File: conf.go Project: jexm/wego
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 := []interface{}{"conf/" + "locale_" + lang + ".ini"}
		if fh, err := os.Open(files[0].(string)); err == nil {
			fh.Close()
		} else {
			files = nil
		}
		if err := i18n.SetMessage(lang, "conf/global/"+"locale_"+lang+".ini", files...); err != nil {
			log.Error("Fail to set message file: " + err.Error())
			os.Exit(2)
		}
	}
	Langs = i18n.ListLangs()
}
Example #3
0
func initLocales() {
	// Initialized language type list.
	langs := strings.Split(models.Cfg.MustValue("lang", "types"), "|")
	names := strings.Split(models.Cfg.MustValue("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 {
		log.Debug("Loading language: " + lang)
		if err := i18n.SetMessage(lang, "conf/"+"locale_"+lang+".ini"); err != nil {
			log.Error("Fail to set message file: " + err.Error())
			return
		}
	}
}
Example #4
0
func InitI18n(langs []string) error {
	for _, lang := range langs {
		i18n.SetMessage(lang, filepath.Join(*homeDir, fmt.Sprintf("langs/locale_%s.ini", strings.ToLower(lang))))
	}
	return i18n.ReloadLangs(langs...)
}