Skip to content

Commit

Permalink
Improve muiltilingual configuration examples
Browse files Browse the repository at this point in the history
  • Loading branch information
jmooring committed May 12, 2023
1 parent 3383786 commit c0e8a49
Showing 1 changed file with 47 additions and 28 deletions.
75 changes: 47 additions & 28 deletions content/en/content-management/multilingual.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,47 +19,66 @@ Also See [Hugo Multilingual Part 1: Content translation].

## Configure Languages

The following is an example of a site configuration for a multilingual Hugo project:
The following is an example of a site configuration for a multilingual project.Ank key not defined in a `languages` object will fall back to the global value.

{{< code-toggle file="config" >}}
defaultContentLanguage = "en"
copyright = "Everything is mine"
baseURL = 'https://example.org/'

[params]
[params.navigation]
help = "Help"
defaultContentLanguage = 'de'
defaultContentLanguageInSubdir = true

[languages]
[languages.en]
title = "My blog"
[languages.de]
contentDir = 'content/de'
languageCode = 'de-DE'
languageName = 'Deutsch'
title = 'Beispielseite'
weight = 1
[languages.en.params]
linkedin = "https://linkedin.com/whoever"

[languages.fr]
title = "Mon blogue"
weight = 2
[languages.fr.params]
linkedin = "https://linkedin.com/fr/whoever"
[languages.fr.params.navigation]
help = "Aide"

[languages.ar]
title = "مدونتي"
[languages.en]
contentDir = 'content/en'
languageCode = 'en-US'
languageName = 'English'
title = 'Example site'
weight = 2
languagedirection = "rtl"

[languages.pt-pt]
title = "O meu blog"
[languages.es]
contentDir = 'content/es'
languageCode = 'es_ES'
languageName = 'Español'
title = 'Sitio de ejemplo'
weight = 3
disabled = true

[languages.iw]
contentDir = 'content/iw'
languageCode = 'iw_IL'
languageDirection = 'rtl'
languageName = 'עִברִית'
title = 'אתר לדוגמה'
weight = 4
{{< /code-toggle >}}

Anything not defined in a `languages` block will fall back to the global value for that key (e.g., `copyright` for the English `en` language). This also works for `params`, as demonstrated with `help` above: You will get the value `Aide` in French and `Help` in all the languages without this parameter set.
To add language-specific site paramters:

With the configuration above, all content, sitemap, RSS feeds, pagination,
and taxonomy pages will be rendered below `/` in English (your default content language) and then below `/fr` in French.
{{< code-toggle file="config" >}}
[languages.de]
contentDir = 'content/de'
languageCode = 'de-DE'
languageName = 'Deutsch'
title = 'Beispielseite'
weight = 1
[languages.de.params]
phone = '+49 69 86 799 799'

When working with front matter `Params` in [single page templates], omit the `params` in the key for the translation.
[languages.en]
contentDir = 'content/en'
languageCode = 'en-US'
languageName = 'English'
title = 'Example site'
weight = 2
[languages.en.params]
phone = '+1 516 738 4422'
{{< /code-toggle >}}

`defaultContentLanguage` sets the project's default language. If not set, the default language will be `en`.

Expand Down

0 comments on commit c0e8a49

Please sign in to comment.