mirror of
https://github.com/gohugoio/hugo.git
synced 2025-08-23 21:53:09 +02: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:
@@ -13,10 +13,6 @@
|
||||
|
||||
package hugolib
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
)
|
||||
|
||||
// Translations represent the other translations for a given page. The
|
||||
// string here is the language code, as affected by the `post.LANG.md`
|
||||
// filename.
|
||||
@@ -26,7 +22,7 @@ func pagesToTranslationsMap(pages []*Page) map[string]Translations {
|
||||
out := make(map[string]Translations)
|
||||
|
||||
for _, page := range pages {
|
||||
base := createTranslationKey(page)
|
||||
base := page.TranslationKey()
|
||||
|
||||
pageTranslation, present := out[base]
|
||||
if !present {
|
||||
@@ -45,22 +41,10 @@ func pagesToTranslationsMap(pages []*Page) map[string]Translations {
|
||||
return out
|
||||
}
|
||||
|
||||
func createTranslationKey(p *Page) string {
|
||||
base := p.TranslationBaseName()
|
||||
|
||||
if p.IsNode() {
|
||||
// TODO(bep) see https://github.com/gohugoio/hugo/issues/2699
|
||||
// Must prepend the section and kind to the key to make it unique
|
||||
base = fmt.Sprintf("%s/%s/%s", p.Kind, p.sections, base)
|
||||
}
|
||||
|
||||
return base
|
||||
}
|
||||
|
||||
func assignTranslationsToPages(allTranslations map[string]Translations, pages []*Page) {
|
||||
for _, page := range pages {
|
||||
page.translations = page.translations[:0]
|
||||
base := createTranslationKey(page)
|
||||
base := page.TranslationKey()
|
||||
trans, exist := allTranslations[base]
|
||||
if !exist {
|
||||
continue
|
||||
|
Reference in New Issue
Block a user