]> git.maquefel.me Git - brevno-suite/hugo/commitdiff
langs/i18n: Improve reserved key error message
authorJoe Mooring <joe.mooring@veriphor.com>
Sat, 18 Oct 2025 18:10:05 +0000 (11:10 -0700)
committerBjørn Erik Pedersen <bjorn.erik.pedersen@gmail.com>
Sun, 19 Oct 2025 11:47:04 +0000 (13:47 +0200)
Closes #14061

langs/i18n/i18n_integration_test.go
langs/i18n/translationProvider.go

index c078bc241bdae161280fc806cf96beed10315495..6406cb9727fe635397231f01cb4270b181792ed6 100644 (file)
@@ -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")
+}
index 9bc0de2e6389b03bf88990bae003a112d1cb67a5..5932fe1f08a0d908e52370c33f1dcf1ca56cf910 100644 (file)
@@ -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