Ejemplo n.º 1
0
Archivo: i18n.go Proyecto: catgatp/gol
// Init tags
func initAfterParse(lang *Tlang, name string) {
	var (
		e   bool
		key string
	)
	// phrase loop
	for _, item := range lang.items {
		// tag loop
		for _, itemTag := range item.items {
			switch v := itemTag.(type) {
			case *tTagPlural:
				key = v.text[0]
				util.MaxSet(&item.contextCount, int(v.count))
				v.text, e = lang.Plural[key]
				err.PanicBool(e, "Err parse:"+name+" Not found plural key: "+key, 0)
			case tTagVar:
				util.MaxSet(&item.contextCount, int(v.id))
			case *tTagFunction:
				v.f, e = lang.F[v.fname]
				err.PanicBool(e, "Err parse:"+name+" Not found users function: "+v.fname, 0)
				for _, val := range v.vars {
					util.MaxSet(&item.contextCount, int(val))
				}
			}
		}
		// initially -1 because of len(n) = max(id)+1
		item.contextCount++
	}
}
Ejemplo n.º 2
0
// HumanByteLong from full name
func humanByteLong(lang *i18n.Tlang) func([]interface{}) []byte {
	list, ok := lang.Lists["+prefix1000"]
	err.PanicBool(ok, "i18n list '+prefix1000' not found", 0)
	pluralByte, ok := lang.Plural["byte"]
	err.PanicBool(ok, "i18n plural 'byte' not found", 0)

	return func(v []interface{}) []byte {
		r, ok := refl.Uint(v[0])
		if !ok {
			return nil
		}
		val, i, valf := human.Byten(r)
		if !(len(list) > int(i)) {
			return nil
		}
		return []byte(val + " " + list[i] + pluralByte[lang.PluralRule(valf)])
	}
}
Ejemplo n.º 3
0
// HumanBit short humanize bit
func humanBit(lang *i18n.Tlang) func([]interface{}) []byte {
	list, ok := lang.Lists["bitshort"]
	err.PanicBool(ok, "i18n list 'bit' not found", 0)
	return human1024(list)
}