Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/gohugoio/hugo.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBjørn Erik Pedersen <bjorn.erik.pedersen@gmail.com>2016-08-09 15:26:55 +0300
committerBjørn Erik Pedersen <bjorn.erik.pedersen@gmail.com>2016-09-06 18:32:19 +0300
commit76108440043094b3841ef96cd1eda8274345430b (patch)
tree9be50c884ed875c8b6920d36cf4d3ffc18309b3c /hugolib
parent8b55bfc81438f33892611a8e828107791838ccdb (diff)
Add IsTranslated to Node and Page
Makes the templates simpler. See #2309
Diffstat (limited to 'hugolib')
-rw-r--r--hugolib/node.go8
-rw-r--r--hugolib/page.go6
2 files changed, 13 insertions, 1 deletions
diff --git a/hugolib/node.go b/hugolib/node.go
index 53c22af13..780190ec6 100644
--- a/hugolib/node.go
+++ b/hugolib/node.go
@@ -271,10 +271,16 @@ func (n *Node) Translations() Nodes {
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() {
n.translationsInit.Do(func() {
if n.translations != nil {
diff --git a/hugolib/page.go b/hugolib/page.go
index 74f51c0bb..b09e2b1f7 100644
--- a/hugolib/page.go
+++ b/hugolib/page.go
@@ -531,6 +531,12 @@ func (p *Page) AllTranslations() Pages {
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)