Debian Codegraph @

docs/content/en/methods/page/Translations.md

raw
1 ---
2 title: Translations
3 description: Returns all translations of the given page, excluding the current language, sorted by language weight then language name.
4 categories: []
5 keywords: []
6 params:
7 functions_and_methods:
8 returnType: page.Pages
9 signatures: [PAGE.Translations]
10 ---
11
12 With this project configuration:
13
14 {{< code-toggle file=hugo >}}
15 defaultContentLanguage = 'en'
16
17 [languages.en]
18 contentDir = 'content/en'
19 label = 'English'
20 locale = 'en-US'
21 weight = 1
22
23 [languages.de]
24 contentDir = 'content/de'
25 label = 'Deutsch'
26 locale = 'de-DE'
27 weight = 2
28
29 [languages.fr]
30 contentDir = 'content/fr'
31 label = 'Français'
32 locale = 'fr-FR'
33 weight = 3
34 {{< /code-toggle >}}
35
36 And this content:
37
38 ```tree
39 content/
40 ├── de/
41 │ ├── books/
42 │ │ ├── book-1.md
43 │ │ └── book-2.md
44 │ └── _index.md
45 ├── en/
46 │ ├── books/
47 │ │ ├── book-1.md
48 │ │ └── book-2.md
49 │ └── _index.md
50 ├── fr/
51 │ ├── books/
52 │ │ └── book-1.md
53 │ └── _index.md
54 └── _index.md
55 ```
56
57 And this template:
58
59 ```go-html-template
60 {{ with .Translations }}
61 <ul>
62 {{ range . }}
63 <li>
64 <a href="{{ .RelPermalink }}" hreflang="{{ .Language.Locale }}">{{ .LinkTitle }} ({{ or .Language.Label .Language.Name }})</a>
65 </li>
66 {{ end }}
67 </ul>
68 {{ end }}
69 ```
70
71 Hugo will render this list on the `book-1` page of the English site:
72
73 ```html
74 <ul>
75 <li><a href="/de/books/book-1/" hreflang="de-DE">Book 1 (Deutsch)</a></li>
76 <li><a href="/fr/books/book-1/" hreflang="fr-FR">Book 1 (Français)</a></li>
77 </ul>
78 ```
79
80 Hugo will render this list on the `book-2` page of the English site:
81
82 ```html
83 <ul>
84 <li><a href="/de/books/book-1/" hreflang="de-DE">Book 1 (Deutsch)</a></li>
85 </ul>
86 ```