diff --git a/hugolib/page.go b/hugolib/page.go index 759e4fe36..04be4428e 100644 --- a/hugolib/page.go +++ b/hugolib/page.go @@ -475,7 +475,7 @@ func (ps *pageState) String() string { // IsTranslated returns whether this content file is translated to // other language(s). func (ps *pageState) IsTranslated() bool { - return len(ps.Translations()) > 0 + return len(ps.AllTranslations()) > 1 } // TranslationKey returns the key used to identify a translation of this content. diff --git a/hugolib/page_test.go b/hugolib/page_test.go index 1d34df54c..b634b76ef 100644 --- a/hugolib/page_test.go +++ b/hugolib/page_test.go @@ -1991,3 +1991,28 @@ func content(c resource.ContentProvider) string { } return ccs } + +func BenchmarkIsTranslatedOneLanguage(b *testing.B) { + // Set it reasonably high to get a balance between cached and uncached calls to IsTranslated. + const numPages = 3000 + + files := ` +-- hugo.toml -- +disableKinds = ["taxonomy", "term"] +` + for i := range numPages { + files += fmt.Sprintf(` +-- content/sect/p%d.md --`, i) + } + + bb := Test(b, files, TestOptSkipRender()) + p := bb.H.Sites[0].RegularPages() + + b.ResetTimer() + + for i := range b.N { + if p[i%numPages].IsTranslated() { + b.Fatalf("Page %d should not be translated", i) + } + } +}