diff options
author | Bjørn Erik Pedersen <bjorn.erik.pedersen@gmail.com> | 2016-11-21 10:11:34 +0100 |
---|---|---|
committer | Bjørn Erik Pedersen <bjorn.erik.pedersen@gmail.com> | 2016-11-22 09:57:03 +0100 |
commit | 976f8f84bfe36f2c9e2ec6992b15dbb70c812af5 (patch) | |
tree | b010ca69184cc0a87558f70fbb9c98529b50326e /hugolib/translations.go | |
parent | aafbd3b4bfeef2db8edd50870affae164c172d92 (diff) |
node to page: Fixe index page translation issues
Updates #2297
Diffstat (limited to 'hugolib/translations.go')
-rw-r--r-- | hugolib/translations.go | 22 |
1 files changed, 18 insertions, 4 deletions
diff --git a/hugolib/translations.go b/hugolib/translations.go index e3df3acd1..36e79125d 100644 --- a/hugolib/translations.go +++ b/hugolib/translations.go @@ -13,6 +13,10 @@ 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. @@ -22,7 +26,7 @@ func pagesToTranslationsMap(ml *Multilingual, pages []*Page) map[string]Translat out := make(map[string]Translations) for _, page := range pages { - base := page.TranslationBaseName() + base := createTranslationKey(page) pageTranslation, present := out[base] if !present { @@ -41,10 +45,22 @@ func pagesToTranslationsMap(ml *Multilingual, pages []*Page) map[string]Translat return out } +func createTranslationKey(p *Page) string { + base := p.TranslationBaseName() + + if p.IsNode() { + // TODO(bep) see https://github.com/spf13/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 := page.TranslationBaseName() + base := createTranslationKey(page) trans, exist := allTranslations[base] if !exist { continue @@ -53,7 +69,5 @@ func assignTranslationsToPages(allTranslations map[string]Translations, pages [] for _, translatedPage := range trans { page.translations = append(page.translations, translatedPage) } - - pageBy(languagePageSort).Sort(page.translations) } } |