1
0
mirror of https://github.com/osmarks/mycorrhiza.git synced 2024-12-15 06:20:27 +00:00
mycorrhiza/viewutil/chain.go

34 lines
770 B
Go
Raw Normal View History

package viewutil
import "text/template"
// Chain represents a chain of different language versions of the same template.
type Chain struct {
en *template.Template
ru *template.Template
}
// En returns a new Chain. This is the only constructor of the type, so every view is forced to have an English representation.
func En(en *template.Template) Chain {
return Chain{
en: en,
}
}
// Ru adds a Russian translation to the Chain.
func (c Chain) Ru(ru *template.Template) Chain {
c.ru = ru
return c
}
// Get returns an appropriate language representation for the given locale in meta.
func (c Chain) Get(meta Meta) *template.Template {
switch meta.Locale() {
case "en":
return c.en
case "ru":
return c.ru
}
panic("unknown language " + meta.Locale())
}