Language
Syntax
Returns
The Language method on a Site object returns the Language object for the given site, derived from the language definition in your project configuration.
You can also use the Language method on a Page object. See details.
Methods
The examples below assume the following language definition.
languages:
de:
direction: ltr
label: Deutsch
locale: de-DE
weight: 2
[languages]
[languages.de]
direction = 'ltr'
label = 'Deutsch'
locale = 'de-DE'
weight = 2
{
"languages": {
"de": {
"direction": "ltr",
"label": "Deutsch",
"locale": "de-DE",
"weight": 2
}
}
}
Direction
New in v0.158.0(string) Returns the direction from the language definition.
{{ .Site.Language.Direction }} → ltrIsDefault
New in v0.153.0(bool) Reports whether this is the default language.
{{ .Site.Language.IsDefault }} → trueLabel
New in v0.158.0(string) Returns the label from the language definition.
{{ .Site.Language.Label }} → DeutschLang
Deprecated in v0.158.0Use Name instead.
LanguageCode
Deprecated in v0.158.0Use Locale instead.
LanguageDirection
Deprecated in v0.158.0Use Direction instead.
LanguageName
Deprecated in v0.158.0Use Label instead.
Locale
New in v0.158.0(string) Returns the locale from the language definition, falling back to Name.
{{ .Site.Language.Locale }} → de-DEName
New in v0.153.0(string) Returns the language tag as defined by RFC 5646. This is the lowercased key from the language definition.
{{ .Site.Language.Name }} → deWeight
Deprecated in v0.158.0Example
Some of the methods above are commonly used in a base template as attributes for the html element.
<html
lang="{{ .Site.Language.Locale }}"
dir="{{ or .Site.Language.Direction `ltr` }}"
>