Localize all the GroupBy*Date methods

Fixes #9745
This commit is contained in:
Bjørn Erik Pedersen
2022-04-05 09:57:58 +02:00
parent e0a882fd3b
commit 658e11ebaa
13 changed files with 144 additions and 42 deletions

View File

@@ -28,7 +28,7 @@ func init() {
if d.Language == nil {
panic("Language must be set")
}
ctx := New(langs.GetTranslator(d.Language), langs.GetLocation(d.Language))
ctx := New(langs.GetTimeFormatter(d.Language), langs.GetLocation(d.Language))
ns := &internal.TemplateFuncsNamespace{
Name: name,

View File

@@ -21,15 +21,13 @@ import (
"github.com/gohugoio/hugo/common/htime"
"github.com/gohugoio/locales"
"github.com/spf13/cast"
)
// New returns a new instance of the time-namespaced template functions.
func New(translator locales.Translator, location *time.Location) *Namespace {
func New(timeFormatter htime.TimeFormatter, location *time.Location) *Namespace {
return &Namespace{
timeFormatter: htime.NewTimeFormatter(translator),
timeFormatter: timeFormatter,
location: location,
}
}

View File

@@ -20,6 +20,7 @@ import (
qt "github.com/frankban/quicktest"
"github.com/gohugoio/hugo/common/htime"
translators "github.com/gohugoio/localescompressed"
)
@@ -27,7 +28,7 @@ func TestTimeLocation(t *testing.T) {
t.Parallel()
loc, _ := time.LoadLocation("America/Antigua")
ns := New(translators.GetTranslator("en"), loc)
ns := New(htime.NewTimeFormatter(translators.GetTranslator("en")), loc)
for i, test := range []struct {
name string
@@ -86,7 +87,7 @@ func TestFormat(t *testing.T) {
c.Run("UTC", func(c *qt.C) {
c.Parallel()
ns := New(translators.GetTranslator("en"), time.UTC)
ns := New(htime.NewTimeFormatter(translators.GetTranslator("en")), time.UTC)
for i, test := range []struct {
layout string
@@ -129,7 +130,7 @@ func TestFormat(t *testing.T) {
loc, err := time.LoadLocation("America/Los_Angeles")
c.Assert(err, qt.IsNil)
ns := New(translators.GetTranslator("en"), loc)
ns := New(htime.NewTimeFormatter(translators.GetTranslator("en")), loc)
d, err := ns.Format(":time_full", "2020-03-09T11:00:00")
@@ -143,7 +144,7 @@ func TestFormat(t *testing.T) {
func TestDuration(t *testing.T) {
t.Parallel()
ns := New(translators.GetTranslator("en"), time.UTC)
ns := New(htime.NewTimeFormatter(translators.GetTranslator("en")), time.UTC)
for i, test := range []struct {
unit any