docs: List multilingual tpl vars and show menu creation

Fixes #2436
This commit is contained in:
digitalcraftsman 2016-09-16 15:35:19 +02:00
parent 9dab62c559
commit 3410007dca
3 changed files with 48 additions and 1 deletions

View file

@ -142,6 +142,48 @@ To track down missing translation strings, run Hugo with the `--i18n-warnings` f
i18n|MISSING_TRANSLATION|en|wordCount
```
### Menus
You can define your menus for each language independently. The [creation of a menu]({{< relref "extras/menus.md" >}}) works analogous to earlier versions of Hugo, except that they have to be defined in their language-specific block in the configuration file:
```toml
DefaultContentLanguage = "en"
[languages.en]
weight = 0
languageName = "English"
[[languages.en.menu.main]]
url = "/"
name = "Home"
weight = 0
[languages.de]
weight = 10
languageName = "Deutsch"
[[languages.de.menu.main]]
url = "/"
name = "Startseite"
weight = 0
```
The rendering of the main navigation works as usual. `.Site.Menus` will just contain the menu of the current language. Pay attention to the generation of the menu links. `absLangURL` takes care that you link to the correct locale of your website. Otherwise, both menu entries would link to the English version because it's the default content language that resides in the root directory.
```html
<ul>
{{- $currentNode := . -}}
{{ range .Site.Menus.main -}}
<li class="{{ if $currentNode.IsMenuCurrent "main" . }}active{{ end }}">
<a href="{{ .URL | absLangURL }}">{{ .Name }}</a>
</li>
{{- end }}
</ul>
```
### Multilingual Themes support
To support Multilingual mode in your themes, some considerations must be taken for the URLs in the templates. If there are more than one language, URLs must either come from the built-in `.Permalink` or `.URL`, be constructed with `relLangURL` or `absLangURL` template funcs -- or prefixed with `{{.LanguagePrefix }}`.

View file

@ -178,7 +178,10 @@ Also available is `.Site` which has the following:
**.Site.BuildDrafts** A boolean (Default: false) to indicate whether to build drafts. Defined in the site configuration.<br>
**.Site.Data** Custom data, see [Data Files](/extras/datafiles/).<br>
**.Site.IsMultiLingual** Whether there are more than one language in this site.<br> See [Multilingual]({{< relref "content/multilingual.md" >}}) for more info.<br>
**.Site.Language** This indicates which language you are currently rendering the website for. This is an object with the attributes set in your language definition in your site config. For the language code, use `.Site.Language.Lang`.<br>
**.Site.Language** This indicates which language you are currently rendering the website for. This is an object with the attributes set in your language definition in your site config.<br>
**.Site.Language.Lang** The language code of the current locale, e.g. `en`.<br>
**.Site.Language.Weight** The weight that defines the order in the `.Site.Languages` list.<br>
**.Site.Language.LanguageName** The full language name, e.g. `English`.<br>
**.Site.LanguagePrefix** This can be used to prefix theURLs with whats needed to point to the correct language. It will even work when only one language defined. See also the functions [absLangURL and relLangURL]({{< relref "templates/functions.md#abslangurl-rellangurl" >}}).<br>
**.Site.Languages** An ordered list (ordered by defined weight) of languages.<br>

View file

@ -11,6 +11,8 @@ title: Create a Multilingual Site
weight: 10
---
> **Note:** Since v0.17 Hugo has built-in support for the creation of multilingual website. [Read more about it]({{< relref "content/multilingual.md" >}}).
## Introduction
Hugo allows you to create a multilingual site from its built-in tools. This tutorial will show one way to do it, and assumes: