Files
hugo/docs/content/en/methods/site/Language.md
T
Bjørn Erik Pedersen 30a20122b7 Merge commit '8f3c066d23f431fb2c53d97ea489e4c28b42bd82'
# Conflicts:
#	docs/data/docs.yaml
2026-02-14 12:14:33 +01:00

2.4 KiB

title, description, categories, keywords, params
title description categories keywords params
Language Returns the language object for the given site.
functions_and_methods
returnType signatures
langs.Language
SITE.Language

The Language method on a Page object returns the language object for the given page. The language object is derived from 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 the site configuration:

{{< code-toggle file=hugo >}} [languages.de] languageCode = 'de-DE' languageDirection = 'ltr' languageName = 'Deutsch' weight = 1 {{< /code-toggle >}}

IsDefault

{{< new-in 0.153.0 />}}

(bool) Reports whether this is the default language object as defined by the defaultContentLanguage setting in the site configuration.

{{ .Site.Language.IsDefault }} → true

Lang

(string) The language tag as defined by RFC 5646. This is the lower cased key from the site configuration.

{{ .Site.Language.Lang }} → de

LanguageCode

(string) The language code from the site configuration. Falls back to Lang if not defined.

{{ .Site.Language.LanguageCode }} → de-DE

LanguageDirection

(string) The language direction from the site configuration, either ltr or rtl.

{{ .Site.Language.LanguageDirection }} → ltr

LanguageName

(string) The language name from the site configuration.

{{ .Site.Language.LanguageName }} → Deutsch

Name

(string) The language tag as defined by RFC 5646. This is the lower cased key from the site configuration. This is an alias for Lang.

{{ .Site.Language.Name }} → de

Weight

(int) The language weight from the site configuration which determines its order in the slice of languages returned by the Languages method on a Site 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` }}"
>