mirror of
https://github.com/gohugoio/hugo.git
synced 2025-08-19 21:21:39 +02:00
Add IsTranslated to Node and Page
Makes the templates simpler. See #2309
This commit is contained in:
@@ -93,13 +93,12 @@ By having the same _base file name_, the content pieces are linked together as t
|
|||||||
To create a list of links to translated content, use a template similar to this:
|
To create a list of links to translated content, use a template similar to this:
|
||||||
|
|
||||||
```
|
```
|
||||||
{{ $translations := .Translations }}
|
{{ if .IsTranslated }}
|
||||||
{{ if gt (len $translations) 0 }}
|
|
||||||
<h4>{{ i18n "translations" }}</h4>
|
<h4>{{ i18n "translations" }}</h4>
|
||||||
<ul>
|
<ul>
|
||||||
{{ range $translations }}
|
{{ range .Translations }}
|
||||||
<li>
|
<li>
|
||||||
<a href="{{ .Permalink }}">{{ .Lang }}: {{ .Title }}</a>
|
<a href="{{ .Permalink }}">{{ .Lang }}: {{ .Title }}{{ if .IsPage }} ({{ i18n "wordCount" . }}){{ end }}</a>
|
||||||
</li>
|
</li>
|
||||||
{{ end}}
|
{{ end}}
|
||||||
</ul>
|
</ul>
|
||||||
|
@@ -271,10 +271,16 @@ func (n *Node) Translations() Nodes {
|
|||||||
translations = append(translations, t)
|
translations = append(translations, t)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return translations
|
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() {
|
func (n *Node) initTranslations() {
|
||||||
n.translationsInit.Do(func() {
|
n.translationsInit.Do(func() {
|
||||||
if n.translations != nil {
|
if n.translations != nil {
|
||||||
|
@@ -531,6 +531,12 @@ func (p *Page) AllTranslations() Pages {
|
|||||||
return p.translations
|
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.
|
// Translations returns the translations excluding the current Page.
|
||||||
func (p *Page) Translations() Pages {
|
func (p *Page) Translations() Pages {
|
||||||
translations := make(Pages, 0)
|
translations := make(Pages, 0)
|
||||||
|
Reference in New Issue
Block a user