"text/template"
"git.earlybird.gay/today/include"
+ "git.earlybird.gay/today/localization/po"
"git.earlybird.gay/today/web/internal/compile"
"git.earlybird.gay/today/web/render"
"golang.org/x/text/language"
)
type Part struct {
- name string
- languages []language.Tag
- sources map[language.Tag]include.Opener
+ name string
+ languages []language.Tag
+ translations map[language.Tag]po.Entries
+ defaultLanguage language.Tag
+ sources map[language.Tag]include.Opener
noTag bool
includes []compile.Source
p := new(Part)
// Assign basic parameters
p.name = name
- p.languages = []language.Tag{language.English}
- p.sources = make(map[language.Tag]include.Opener)
- p.sources[language.English], p.err = include.File(source, "git.earlybird.gay/today/web/part")
+ sources, localeMeta, err := include.LocalizedFiles(source, "git.earlybird.gay/today/web/page")
+ if err != nil {
+ p.err = err
+ return p
+ }
+ p.languages = localeMeta.Languages
+ p.translations = localeMeta.Translations
+ p.defaultLanguage = localeMeta.DefaultLanguage
+ p.sources = sources
if p.err != nil {
return p
}
return p.languages
}
+func (p *Part) Translations() map[language.Tag]po.Entries {
+ return p.translations
+}
+
+func (p *Part) DefaultLanguage() language.Tag {
+ return p.defaultLanguage
+}
+
func (p *Part) Source(lang language.Tag) include.Opener {
- return p.sources[lang]
+ if source, ok := p.sources[lang]; ok {
+ return source
+ } else {
+ return p.sources[p.defaultLanguage]
+ }
}
// FileDependencies returns a list of absolute paths to files that are used in