mirror of
https://github.com/gohugoio/hugo.git
synced 2025-05-02 00:20:21 +03:00
hugolib: Fix .IsTranslated with identical filenames
This commit refines the key used to map translations: * Use `translationKey` set in front matter * Fall back to path + base filename (i.e. the filename without extension and language code) Note that the Page Kinde will be prepended to both cases above. It does not make sense to have a section as translation for the home page. Fixes #2699
This commit is contained in:
parent
df1677a6e8
commit
b3daa1f4bf
3 changed files with 48 additions and 18 deletions
|
@ -1440,6 +1440,29 @@ func TestKind(t *testing.T) {
|
|||
|
||||
}
|
||||
|
||||
func TestTranslationKey(t *testing.T) {
|
||||
t.Parallel()
|
||||
assert := require.New(t)
|
||||
cfg, fs := newTestCfg()
|
||||
|
||||
writeSource(t, fs, filepath.Join("content", filepath.FromSlash("sect/simple.no.md")), "---\ntitle: \"A1\"\ntranslationKey: \"k1\"\n---\nContent\n")
|
||||
writeSource(t, fs, filepath.Join("content", filepath.FromSlash("sect/simple.en.md")), "---\ntitle: \"A2\"\n---\nContent\n")
|
||||
|
||||
s := buildSingleSite(t, deps.DepsCfg{Fs: fs, Cfg: cfg}, BuildCfg{SkipRender: true})
|
||||
|
||||
require.Len(t, s.RegularPages, 2)
|
||||
|
||||
home, _ := s.Info.Home()
|
||||
assert.NotNil(home)
|
||||
assert.Equal("home", home.TranslationKey())
|
||||
assert.Equal("page/k1", s.RegularPages[0].TranslationKey())
|
||||
p2 := s.RegularPages[1]
|
||||
|
||||
// This is a single language setup
|
||||
assert.Equal("page/sect/simple.en", p2.TranslationKey())
|
||||
|
||||
}
|
||||
|
||||
func TestChompBOM(t *testing.T) {
|
||||
t.Parallel()
|
||||
const utf8BOM = "\xef\xbb\xbf"
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue