summaryrefslogtreecommitdiffstats
path: root/langs
diff options
context:
space:
mode:
authorBjørn Erik Pedersen <bjorn.erik.pedersen@gmail.com>2023-05-17 09:59:57 +0200
committerBjørn Erik Pedersen <bjorn.erik.pedersen@gmail.com>2023-05-17 22:13:29 +0200
commit5d857165fed4649c3aa639a1555a15b8b1c75bab (patch)
tree9eafd7d8b85ec4c9bc9a16c83172c3a2b1d57e41 /langs
parent0106cf1a6db73f76b7f26744fcee6ce7f41cdf07 (diff)
Deprecate site.Language.Params and some other fixes
Updates #10947
Diffstat (limited to 'langs')
-rw-r--r--langs/language.go26
1 files changed, 26 insertions, 0 deletions
diff --git a/langs/language.go b/langs/language.go
index c904b0c6b..5bf80274d 100644
--- a/langs/language.go
+++ b/langs/language.go
@@ -23,6 +23,7 @@ import (
"golang.org/x/text/language"
"github.com/gohugoio/hugo/common/htime"
+ "github.com/gohugoio/hugo/common/maps"
"github.com/gohugoio/locales"
translators "github.com/gohugoio/localescompressed"
)
@@ -42,6 +43,9 @@ type Language struct {
tag language.Tag
collator *Collator
location *time.Location
+
+ // This is just an alias of Site.Params.
+ params maps.Params
}
// NewLanguage creates a new language.
@@ -76,7 +80,25 @@ func NewLanguage(lang, defaultContentLanguage, timeZone string, languageConfig L
}
return l, l.loadLocation(timeZone)
+}
+
+// This is injected from hugolib to avoid cirular dependencies.
+var DeprecationFunc = func(item, alternative string, err bool) {}
+
+const paramsDeprecationWarning = `.Language.Params is deprecated and will be removed in a future release. Use site.Params instead.
+
+Also, for all but custom parameters, you need to use the built in Hugo variables, e.g. site.Title, site.LanguageCode; site.Language.Params.Title will not work.
+See https://gohugo.io/content-management/multilingual/#changes-in-hugo-01120
+
+`
+
+// Params returns the language params.
+// Note that this is the same as the Site.Params, but we keep it here for legacy reasons.
+// Deprecated: Use the site.Params instead.
+func (l *Language) Params() maps.Params {
+ DeprecationFunc(".Language.Params", paramsDeprecationWarning, false)
+ return l.params
}
func (l *Language) loadLocation(tzStr string) error {
@@ -113,6 +135,10 @@ func (l Languages) AsOrdinalSet() map[string]int {
// Internal access to unexported Language fields.
// This construct is to prevent them from leaking to the templates.
+func SetParams(l *Language, params maps.Params) {
+ l.params = params
+}
+
func GetTimeFormatter(l *Language) htime.TimeFormatter {
return l.timeFormatter
}