Debian Codegraph @

docs/content/en/methods/site/Language.md

raw
1 ---
2 title: Language
3 description: Returns the Language object for the given site.
4 categories: []
5 keywords: []
6 params:
7 functions_and_methods:
8 returnType: langs.Language
9 signatures: [SITE.Language]
10 ---
11
12 The `Language` method on a `Site` object returns the `Language` object for the given site, derived from the language definition in your project configuration.
13
14 You can also use the `Language` method on a `Page` object. See [details][].
15
16 ## Methods
17
18 Use these methods on the `Language` object.
19
20 The examples below assume the following language definition.
21
22 {{< code-toggle file=hugo >}}
23 [languages.de]
24 direction = 'ltr'
25 label = 'Deutsch'
26 locale = 'de-DE'
27 weight = 2
28 {{< /code-toggle >}}
29
30 `Direction`
31 : {{< new-in 0.158.0 />}}
32 : (`string`) Returns the [`direction`][] from the language definition.
33
34 ```go-html-template
35 {{ .Site.Language.Direction }} → ltr
36 ```
37
38 `IsDefault`
39 : {{< new-in 0.153.0 />}}
40 : (`bool`) Reports whether this is the [default language](g).
41
42 ```go-html-template
43 {{ .Site.Language.IsDefault }} → true
44 ```
45
46 `Label`
47 : {{< new-in 0.158.0 />}}
48 : (`string`) Returns the [`label`][] from the language definition.
49
50 ```go-html-template
51 {{ .Site.Language.Label }} → Deutsch
52 ```
53
54 `Lang`
55 : {{<deprecated-in 0.158.0 />}}
56 : Use [`Name`](#name) instead.
57
58 `LanguageCode`
59 : {{<deprecated-in 0.158.0 />}}
60 : Use [`Locale`](#locale) instead.
61
62 `LanguageDirection`
63 : {{<deprecated-in 0.158.0 />}}
64 : Use [`Direction`](#direction) instead.
65
66 `LanguageName`
67 : {{<deprecated-in 0.158.0 />}}
68 : Use [`Label`](#label) instead.
69
70 `Locale`
71 : {{< new-in 0.158.0 />}}
72 : (`string`) Returns the [`locale`][] from the language definition, falling back to [`Name`](#name).
73
74 ```go-html-template
75 {{ .Site.Language.Locale }} → de-DE
76 ```
77
78 `Name`
79 : {{< new-in 0.153.0 />}}
80 : (`string`) Returns the language tag as defined by [RFC 5646][]. This is the lowercased key from the language definition.
81
82 ```go-html-template
83 {{ .Site.Language.Name }} → de
84 ```
85
86 `Weight`
87 : {{<deprecated-in 0.158.0 />}}
88
89 ## Example
90
91 Some of the methods above are commonly used in a base template as attributes for the `html` element.
92
93 ```go-html-template
94 <html
95 lang="{{ .Site.Language.Locale }}"
96 dir="{{ or .Site.Language.Direction `ltr` }}"
97 >
98 ```
99
100 [RFC 5646]: https://datatracker.ietf.org/doc/html/rfc5646
101 [`direction`]: /configuration/languages/#direction
102 [`label`]: /configuration/languages/#label
103 [`locale`]: /configuration/languages/#locale
104 [details]: /methods/page/language/