| 1 |
--- |
| 2 |
title: Configure languages |
| 3 |
linkTitle: Languages |
| 4 |
description: Configure the languages in your multilingual project. |
| 5 |
categories: [] |
| 6 |
keywords: [] |
| 7 |
--- |
| 8 |
|
| 9 |
## Base settings |
| 10 |
|
| 11 |
Configure the following base settings: |
| 12 |
|
| 13 |
{{< code-toggle file=hugo >}} |
| 14 |
defaultContentLanguage = 'en' |
| 15 |
defaultContentLanguageInSubdir = false |
| 16 |
disableDefaultLanguageRedirect = false |
| 17 |
disableLanguages = [] |
| 18 |
{{< /code-toggle >}} |
| 19 |
|
| 20 |
`defaultContentLanguage` |
| 21 |
: (`string`) The projects's default content language, conforming to the syntax described in [RFC 5646][]. This value must match one of the defined [language keys][]. Default is `en`. |
| 22 |
|
| 23 |
`defaultContentLanguageInSubdir` |
| 24 |
: (`bool`) Whether to publish the default content language to a subdirectory matching the [`defaultContentLanguage`](#defaultcontentlanguage). Default is `false`. |
| 25 |
|
| 26 |
`disableDefaultLanguageRedirect` |
| 27 |
: {{< new-in 0.140.0 />}} |
| 28 |
: (`bool`) Whether to disable generation of the alias redirect for the default content language. When [`defaultContentLanguageInSubdir`](#defaultcontentlanguageinsubdir) is `true`, this setting prevents the root directory from redirecting to the language subdirectory. Conversely, when `defaultContentLanguageInSubdir` is `false`, this setting prevents the language subdirectory from redirecting to the root directory. This is superseded by the more general [`disableDefaultSiteRedirect`][] setting. Default is `false`. |
| 29 |
|
| 30 |
`disableLanguages` |
| 31 |
: (`[]string]`) A slice of language keys representing the languages to disable during the build process. Although this is functional, consider using the [`disabled`](#disabled) key under each language instead. |
| 32 |
|
| 33 |
## Language settings |
| 34 |
|
| 35 |
Configure each language under the `languages` key: |
| 36 |
|
| 37 |
{{< code-toggle config=languages />}} |
| 38 |
|
| 39 |
In the above, `en` is the [language key](#language-keys). |
| 40 |
|
| 41 |
`direction` |
| 42 |
: (`string`) The language direction, either left-to-right (`ltr`) or right-to-left (`rtl`). Use this value in your templates with the global [`dir`][] HTML attribute. Access this value from a template using the [`Language.Direction`][] method on a `Site` or `Page` object. Default is `ltr`. |
| 43 |
|
| 44 |
`disabled` |
| 45 |
: (`bool`) Whether to disable this language when building the site. Default is `false`. |
| 46 |
|
| 47 |
`label` |
| 48 |
: (`string`) The language name, typically used when rendering a language switcher. Access this value from a template using the [`Language.Label`][] method on a `Site` or `Page` object. |
| 49 |
|
| 50 |
`languageCode` |
| 51 |
: {{<deprecated-in 0.158.0 />}} |
| 52 |
: Use [`locale`](#locale) instead. |
| 53 |
|
| 54 |
`languageDirection` |
| 55 |
: {{<deprecated-in 0.158.0 />}} |
| 56 |
: Use [`direction`](#direction) instead. |
| 57 |
|
| 58 |
`languageName` |
| 59 |
: {{<deprecated-in 0.158.0 />}} |
| 60 |
: Use [`label`](#label) instead. |
| 61 |
|
| 62 |
{{% include "/_common/configuration/locale.md" %}} |
| 63 |
|
| 64 |
`title` |
| 65 |
: (`string`) The site title for this language. Access this value from a template using the [`Title`][] method on a `Site` object. |
| 66 |
|
| 67 |
`weight` |
| 68 |
: (`int`) The language [weight](g). When set to a non-zero value, this is the primary sort criteria for this language. |
| 69 |
|
| 70 |
## Sort order |
| 71 |
|
| 72 |
Hugo sorts languages by weight in ascending order, then lexicographically in ascending order. This affects build order and complement selection. |
| 73 |
|
| 74 |
## Localized settings |
| 75 |
|
| 76 |
Some configuration settings can be defined separately for each language. For example: |
| 77 |
|
| 78 |
{{< code-toggle file=hugo >}} |
| 79 |
[languages.en] |
| 80 |
label = 'English' |
| 81 |
locale = 'en-US' |
| 82 |
timeZone = 'America/New_York' |
| 83 |
title = 'Project Documentation' |
| 84 |
weight = 1 |
| 85 |
[languages.en.pagination] |
| 86 |
path = 'page' |
| 87 |
[languages.en.params] |
| 88 |
subtitle = 'Reference, Tutorials, and Explanations' |
| 89 |
{{< /code-toggle >}} |
| 90 |
|
| 91 |
The following configuration keys can be defined separately for each language: |
| 92 |
|
| 93 |
{{< per-lang-config-keys >}} |
| 94 |
|
| 95 |
Any key not defined in a `languages` object will fall back to the global value in the root of your project configuration. |
| 96 |
|
| 97 |
## Language keys |
| 98 |
|
| 99 |
Language keys must conform to the syntax described in [RFC 5646][]. For example: |
| 100 |
|
| 101 |
{{< code-toggle file=hugo >}} |
| 102 |
defaultContentLanguage = 'de' |
| 103 |
[languages.de] |
| 104 |
weight = 1 |
| 105 |
[languages.en-US] |
| 106 |
weight = 2 |
| 107 |
[languages.pt-BR] |
| 108 |
weight = 3 |
| 109 |
{{< /code-toggle >}} |
| 110 |
|
| 111 |
Artificial languages with private use subtags as defined in [RFC 5646 § 2.2.7][] are also supported. Omit the `art-x-` prefix from the language key. For example: |
| 112 |
|
| 113 |
{{< code-toggle file=hugo >}} |
| 114 |
defaultContentLanguage = 'en' |
| 115 |
[languages.en] |
| 116 |
weight = 1 |
| 117 |
[languages.hugolang] |
| 118 |
weight = 2 |
| 119 |
{{< /code-toggle >}} |
| 120 |
|
| 121 |
> [!NOTE] |
| 122 |
> Private use subtags must not exceed 8 alphanumeric characters. |
| 123 |
|
| 124 |
## Example |
| 125 |
|
| 126 |
{{< code-toggle file=hugo >}} |
| 127 |
defaultContentLanguage = 'de' |
| 128 |
defaultContentLanguageInSubdir = true |
| 129 |
disableDefaultLanguageRedirect = false |
| 130 |
|
| 131 |
[languages.de] |
| 132 |
contentDir = 'content/de' |
| 133 |
direction = 'ltr' |
| 134 |
disabled = false |
| 135 |
label = 'Deutsch' |
| 136 |
locale = 'de-DE' |
| 137 |
title = 'Projekt Dokumentation' |
| 138 |
weight = 1 |
| 139 |
|
| 140 |
[languages.de.params] |
| 141 |
subtitle = 'Referenz, Tutorials und Erklärungen' |
| 142 |
|
| 143 |
[languages.en] |
| 144 |
contentDir = 'content/en' |
| 145 |
direction = 'ltr' |
| 146 |
disabled = false |
| 147 |
label = 'English' |
| 148 |
locale = 'en-US' |
| 149 |
title = 'Project Documentation' |
| 150 |
weight = 2 |
| 151 |
|
| 152 |
[languages.en.params] |
| 153 |
subtitle = 'Reference, Tutorials, and Explanations' |
| 154 |
{{< /code-toggle >}} |
| 155 |
|
| 156 |
> [!NOTE] |
| 157 |
> In the example above, omit `contentDir` if [translating by file name][]. |
| 158 |
|
| 159 |
## Multihost |
| 160 |
|
| 161 |
Hugo supports multiple languages in a multihost configuration. This means you can configure a `baseURL` per `language`. |
| 162 |
|
| 163 |
> [!NOTE] |
| 164 |
> If you define a `baseURL` for one language, you must define a unique `baseURL` for all languages. |
| 165 |
|
| 166 |
For example: |
| 167 |
|
| 168 |
{{< code-toggle file=hugo >}} |
| 169 |
defaultContentLanguage = 'fr' |
| 170 |
[languages.en] |
| 171 |
baseURL = 'https://en.example.org/' |
| 172 |
label = 'English' |
| 173 |
title = 'In English' |
| 174 |
weight = 2 |
| 175 |
[languages.fr] |
| 176 |
baseURL = 'https://fr.example.org' |
| 177 |
label = 'Français' |
| 178 |
title = 'En Français' |
| 179 |
weight = 1 |
| 180 |
{{</ code-toggle >}} |
| 181 |
|
| 182 |
With the above, Hugo publishes two sites, each with their own root: |
| 183 |
|
| 184 |
```tree |
| 185 |
public |
| 186 |
├── en |
| 187 |
└── fr |
| 188 |
``` |
| 189 |
|
| 190 |
[RFC 5646 § 2.2.7]: https://datatracker.ietf.org/doc/html/rfc5646#section-2.2.7 |
| 191 |
[RFC 5646]: https://datatracker.ietf.org/doc/html/rfc5646#section-2.1 |
| 192 |
[`Language.Direction`]: /methods/site/language/#direction |
| 193 |
[`Language.Label`]: /methods/site/language/#label |
| 194 |
[`Title`]: /methods/site/title/ |
| 195 |
[`dir`]: https://developer.mozilla.org/en-US/docs/Web/HTML/Global_attributes/dir |
| 196 |
[`disableDefaultSiteRedirect`]: /configuration/all/#disabledefaultsiteredirect |
| 197 |
[language keys]: /configuration/languages/#language-keys |
| 198 |
[translating by file name]: /content-management/multilingual/#translation-by-file-name |