i18n.go
func initLocales(opt Options) language.Matcher {
	tags := make([]language.Tag, len(opt.Langs))
	for i, lang := range opt.Langs {
		tags[i] = language.Raw.Make(lang)
		fname := fmt.Sprintf(opt.Format, lang)
		// Append custom locale file.
		custom := []interface{}{}
		customPath := path.Join(opt.CustomDirectory, fname)
		if com.IsFile(customPath) {
			custom = append(custom, customPath)
		}

		var locale interface{}
		if data, ok := opt.Files[fname]; ok {
			locale = data
		} else {
			locale = path.Join(opt.Directory, fname)
		}

		err := i18n.SetMessageWithDesc(lang, opt.Names[i], locale, custom...)
		if err != nil && err != i18n.ErrLangAlreadyExist {
			panic(fmt.Errorf("fail to set message file(%s): %v", lang, err))
		}
	}
	return language.NewMatcher(tags)
}
func initLocales(opt Options) language.Matcher {
	tags := make([]language.Tag, len(opt.Langs))
	for i, lang := range opt.Langs {
		tags[i] = language.Raw.Make(lang)
		fname := fmt.Sprintf(opt.Format, lang)
		// Append custom locale file.
		custom := []interface{}{}
		customPath := path.Join(opt.CustomDirectory, fname)
		if com.IsFile(customPath) {
			custom = append(custom, customPath)
		}

		var locale interface{}
		if data, ok := opt.Files[fname]; ok {
			locale = data
		} else {
			locale = path.Join(opt.Directory, fname)
		}

		err := i18n.SetMessageWithDesc(lang, opt.Names[i], locale, custom...)
		if err != nil && err != i18n.ErrLangAlreadyExist {
			panic(fmt.Errorf("fail to set message file(%s): %v", lang, err))
		}
	}
	return language.NewMatcher(tags)
}
func initLocales ( opt Options ) language . Matcher { tags := make ( [ ] language . Tag , len ( opt . Langs ) ) for i , lang := range opt . Langs { tags [ i ] = language . Raw . Make ( lang ) fname := fmt . Sprintf ( opt . Format , lang ) // Append custom locale file. custom := [ ] interface { } { } customPath := path . Join ( opt . CustomDirectory , fname ) if com . IsFile ( customPath ) { custom = append ( custom , customPath ) } var locale interface { } if data , ok := opt . Files [ fname ] ; ok { locale = data } else { locale = path . Join ( opt . Directory , fname ) } err := i18n . SetMessageWithDesc ( lang , opt . Names [ i ] , locale , custom ... ) if err != nil && err != i18n . ErrLangAlreadyExist { panic ( fmt . Errorf ( " " , lang , err ) ) } } return language . NewMatcher ( tags ) }
// initLocales initializes language type list and Accept-Language header matcher.
initLocales initializes language type list and Accept - Language header matcher .