Language
Syntax
SITE.Language
Returns
langs.Language
The Language
method on a Site
object returns the language object for the given site. The language object points to the language definition in the site configuration.
You can also use the Language
method on a Page
object. See details.
Methods
The examples below assume the following in your site configuration:
hugo.
languages:
de:
languageCode: de-DE
languageDirection: ltr
languageName: Deutsch
weight: 1
[languages]
[languages.de]
languageCode = 'de-DE'
languageDirection = 'ltr'
languageName = 'Deutsch'
weight = 1
{
"languages": {
"de": {
"languageCode": "de-DE",
"languageDirection": "ltr",
"languageName": "Deutsch",
"weight": 1
}
}
}
- Lang
- (
string
) The language tag as defined by RFC 5646.
{{ .Site.Language.Lang }} → de
- LanguageCode
- (
string
) The language code from the site configuration. Falls back toLang
if not defined.
{{ .Site.Language.LanguageCode }} → de-DE
- LanguageDirection
- (
string
) The language direction from the site configuration, eitherltr
orrtl
.
{{ .Site.Language.LanguageDirection }} → ltr
- LanguageName
- (
string
) The language name from the site configuration.
{{ .Site.Language.LanguageName }} → Deutsch
- Weight
- (
int
) The language weight from the site configuration which determines its order in the slice of languages returned by theLanguages
method on aSite
object.
{{ .Site.Language.Weight }} → 1
Example
Some of the methods above are commonly used in a base template as attributes for the html
element.
<html
lang="{{ .Site.Language.LanguageCode }}"
dir="{{ or .Site.Language.LanguageDirection `ltr` }}
>