mirror of
https://github.com/gohugoio/hugo.git
synced 2025-08-11 20:03:58 +02:00
@@ -17,6 +17,7 @@ import (
|
||||
"sort"
|
||||
"strings"
|
||||
"sync"
|
||||
"time"
|
||||
|
||||
translators "github.com/bep/gotranslators"
|
||||
"github.com/go-playground/locales"
|
||||
@@ -71,10 +72,13 @@ type Language struct {
|
||||
paramsMu sync.Mutex
|
||||
paramsSet bool
|
||||
|
||||
// Used for date formatting etc. We don't want this exported to the
|
||||
// Used for date formatting etc. We don't want these exported to the
|
||||
// templates.
|
||||
// TODO(bep) do the same for some of the others.
|
||||
translator locales.Translator
|
||||
|
||||
locationInit sync.Once
|
||||
location *time.Location
|
||||
}
|
||||
|
||||
func (l *Language) String() string {
|
||||
@@ -244,9 +248,25 @@ func (l *Language) IsSet(key string) bool {
|
||||
return l.Cfg.IsSet(key)
|
||||
}
|
||||
|
||||
func (l *Language) getLocation() *time.Location {
|
||||
l.locationInit.Do(func() {
|
||||
location, err := time.LoadLocation(l.GetString("timeZone"))
|
||||
if err != nil {
|
||||
location = time.UTC
|
||||
}
|
||||
l.location = location
|
||||
})
|
||||
|
||||
return l.location
|
||||
}
|
||||
|
||||
// Internal access to unexported Language fields.
|
||||
// This construct is to prevent them from leaking to the templates.
|
||||
|
||||
func GetTranslator(l *Language) locales.Translator {
|
||||
return l.translator
|
||||
}
|
||||
|
||||
func GetLocation(l *Language) *time.Location {
|
||||
return l.getLocation()
|
||||
}
|
||||
|
Reference in New Issue
Block a user