From 559a029de7e856dd919e659e1a1386c2c3a58696 Mon Sep 17 00:00:00 2001 From: Joe Mooring Date: Sat, 18 Oct 2025 11:10:05 -0700 Subject: [PATCH] langs/i18n: Improve reserved key error message Closes #14061 --- langs/i18n/i18n_integration_test.go | 21 +++++++++++++++++++++ langs/i18n/translationProvider.go | 6 +++++- 2 files changed, 26 insertions(+), 1 deletion(-) diff --git a/langs/i18n/i18n_integration_test.go b/langs/i18n/i18n_integration_test.go index c078bc241..6406cb972 100644 --- a/langs/i18n/i18n_integration_test.go +++ b/langs/i18n/i18n_integration_test.go @@ -16,6 +16,7 @@ package i18n_test import ( "testing" + qt "github.com/frankban/quicktest" "github.com/gohugoio/hugo/hugolib" ) @@ -144,3 +145,23 @@ description: {{ T "description" }}| b.AssertFileContent("public/index.html", `description: This is a description from i18n.|`) } + +// See issue #14061 +func TestI18nReservedKeyScalar(t *testing.T) { + t.Parallel() + + files := ` +-- hugo.toml -- +disableKinds = ['home','page','rss','section','sitemap','taxonomy','term'] +-- i18n/en.toml -- +a = 'a translated' +description = 'description translated' +b = 'b translated' + +` + + b, err := hugolib.TestE(t, files) + + b.Assert(err, qt.IsNotNil) + b.Assert(err.Error(), qt.Contains, "failed to load translations: reserved keys [description] mixed with unreserved keys [a b]: see the lang.Translate documentation for a list of reserved keys") +} diff --git a/langs/i18n/translationProvider.go b/langs/i18n/translationProvider.go index 9bc0de2e6..5932fe1f0 100644 --- a/langs/i18n/translationProvider.go +++ b/langs/i18n/translationProvider.go @@ -114,7 +114,11 @@ func addTranslationFile(bundle *i18n.Bundle, r *source.File) error { return nil } } - return errWithFileContext(fmt.Errorf("failed to load translations: %w", err), r) + var guidance string + if strings.Contains(err.Error(), "mixed with unreserved keys") { + guidance = ": see the lang.Translate documentation for a list of reserved keys" + } + return errWithFileContext(fmt.Errorf("failed to load translations: %w%s", err, guidance), r) } return nil -- 2.39.5