Skip to content

Commit 559a029

Browse files
jmooringbep
authored andcommitted
langs/i18n: Improve reserved key error message
Closes #14061
1 parent 184b10e commit 559a029

File tree

2 files changed

+26
-1
lines changed

2 files changed

+26
-1
lines changed

‎langs/i18n/i18n_integration_test.go‎

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ package i18n_test
1616
import (
1717
"testing"
1818

19+
qt "github.com/frankban/quicktest"
1920
"github.com/gohugoio/hugo/hugolib"
2021
)
2122

@@ -144,3 +145,23 @@ description: {{ T "description" }}|
144145

145146
b.AssertFileContent("public/index.html", `description: This is a description from i18n.|`)
146147
}
148+
149+
// See issue #14061
150+
func TestI18nReservedKeyScalar(t *testing.T) {
151+
t.Parallel()
152+
153+
files := `
154+
-- hugo.toml --
155+
disableKinds = ['home','page','rss','section','sitemap','taxonomy','term']
156+
-- i18n/en.toml --
157+
a = 'a translated'
158+
description = 'description translated'
159+
b = 'b translated'
160+
161+
`
162+
163+
b, err := hugolib.TestE(t, files)
164+
165+
b.Assert(err, qt.IsNotNil)
166+
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")
167+
}

‎langs/i18n/translationProvider.go‎

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -114,7 +114,11 @@ func addTranslationFile(bundle *i18n.Bundle, r *source.File) error {
114114
return nil
115115
}
116116
}
117-
return errWithFileContext(fmt.Errorf("failed to load translations: %w", err), r)
117+
var guidance string
118+
if strings.Contains(err.Error(), "mixed with unreserved keys") {
119+
guidance = ": see the lang.Translate documentation for a list of reserved keys"
120+
}
121+
return errWithFileContext(fmt.Errorf("failed to load translations: %w%s", err, guidance), r)
118122
}
119123

120124
return nil

0 commit comments

Comments
 (0)