From 3410007dca4012d1dea3a9d953b4d0a180f43e70 Mon Sep 17 00:00:00 2001 From: digitalcraftsman Date: Fri, 16 Sep 2016 15:35:19 +0200 Subject: [PATCH] docs: List multilingual tpl vars and show menu creation Fixes #2436 --- docs/content/content/multilingual.md | 42 +++++++++++++++++++ docs/content/templates/variables.md | 5 ++- .../tutorials/create-a-multilingual-site.md | 2 + 3 files changed, 48 insertions(+), 1 deletion(-) diff --git a/docs/content/content/multilingual.md b/docs/content/content/multilingual.md index 188f0d500..a89b28108 100644 --- a/docs/content/content/multilingual.md +++ b/docs/content/content/multilingual.md @@ -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 + + +``` + ### 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 }}`. diff --git a/docs/content/templates/variables.md b/docs/content/templates/variables.md index e2cd4a7ce..b85387b46 100644 --- a/docs/content/templates/variables.md +++ b/docs/content/templates/variables.md @@ -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.
**.Site.Data** Custom data, see [Data Files](/extras/datafiles/).
**.Site.IsMultiLingual** Whether there are more than one language in this site.
See [Multilingual]({{< relref "content/multilingual.md" >}}) for more info.
-**.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`.
+**.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.
+**.Site.Language.Lang** The language code of the current locale, e.g. `en`.
+**.Site.Language.Weight** The weight that defines the order in the `.Site.Languages` list.
+**.Site.Language.LanguageName** The full language name, e.g. `English`.
**.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" >}}).
**.Site.Languages** An ordered list (ordered by defined weight) of languages.
diff --git a/docs/content/tutorials/create-a-multilingual-site.md b/docs/content/tutorials/create-a-multilingual-site.md index 322dfeb9c..c5d35379d 100644 --- a/docs/content/tutorials/create-a-multilingual-site.md +++ b/docs/content/tutorials/create-a-multilingual-site.md @@ -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: