ref: 76108440043094b3841ef96cd1eda8274345430b
parent: 8b55bfc81438f33892611a8e828107791838ccdb
author: Bjørn Erik Pedersen <bjorn.erik.pedersen@gmail.com>
date: Tue Aug 9 10:26:55 EDT 2016
Add IsTranslated to Node and Page Makes the templates simpler. See #2309
--- a/docs/content/content/multilingual.md
+++ b/docs/content/content/multilingual.md
@@ -93,13 +93,12 @@
To create a list of links to translated content, use a template similar to this:
```
-{{ $translations := .Translations }} -{{ if gt (len $translations) 0 }}+{{ if .IsTranslated }} <h4>{{ i18n "translations" }}</h4><ul>
- {{ range $translations }}+ {{ range .Translations }}<li>
- <a href="{{ .Permalink }}">{{ .Lang }}: {{ .Title }}</a>+ <a href="{{ .Permalink }}">{{ .Lang }}: {{ .Title }}{{ if .IsPage }} ({{ i18n "wordCount" . }}){{ end }}</a></li>
{{ end}}</ul>
--- a/hugolib/node.go
+++ b/hugolib/node.go
@@ -271,8 +271,14 @@
translations = append(translations, t)
}
}
-
return translations
+}
+
+// IsTranslated returns whether this node is translated to
+// other language(s).
+func (n *Node) IsTranslated() bool {+ n.initTranslations()
+ return len(n.translations) > 1
}
func (n *Node) initTranslations() {--- a/hugolib/page.go
+++ b/hugolib/page.go
@@ -531,6 +531,12 @@
return p.translations
}
+// IsTranslated returns whether this content file is translated to
+// other language(s).
+func (p *Page) IsTranslated() bool {+ return len(p.translations) > 1
+}
+
// Translations returns the translations excluding the current Page.
func (p *Page) Translations() Pages {translations := make(Pages, 0)
--
⑨