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 The examples below assume the following language definition.
19
20 {{< code-toggle file=hugo >}}
21 [languages.de]
22 direction = 'ltr'
23 label = 'Deutsch'
24 locale = 'de-DE'
25 weight = 2
26 {{< /code-toggle >}}
27
28 ### Direction
29
30 {{< new-in 0.158.0 />}}
31
32 (`string`) Returns the [`direction`][] from the language definition.
33
34 ```go-html-template
35 {{ .Site.Language.Direction }} → ltr
36 ```
37
38 ### IsDefault
39
40 {{< new-in 0.153.0 />}}
41
42 (`bool`) Reports whether this is the [default language](g).
43
44 ```go-html-template
45 {{ .Site.Language.IsDefault }} → true
46 ```
47
48 ### Label
49
50 {{< new-in 0.158.0 />}}
51
52 (`string`) Returns the [`label`][] from the language definition.
53
54 ```go-html-template
55 {{ .Site.Language.Label }} → Deutsch
56 ```
57
58 ### Lang
59
60 {{<deprecated-in 0.158.0 />}}
61
62 Use [`Name`](#name) instead.
63
64 ### LanguageCode
65
66 {{<deprecated-in 0.158.0 />}}
67
68 Use [`Locale`](#locale) instead.
69
70 ### LanguageDirection
71
72 {{<deprecated-in 0.158.0 />}}
73
74 Use [`Direction`](#direction) instead.
75
76 ### LanguageName
77
78 {{<deprecated-in 0.158.0 />}}
79
80 Use [`Label`](#label) instead.
81
82 ### Locale
83
84 {{< new-in 0.158.0 />}}
85
86 (`string`) Returns the [`locale`][] from the language definition, falling back to [`Name`](#name).
87
88 ```go-html-template
89 {{ .Site.Language.Locale }} → de-DE
90 ```
91
92 ### Name
93
94 {{< new-in 0.153.0 />}}
95
96 (`string`) Returns the language tag as defined by [RFC 5646][]. This is the lowercased key from the language definition.
97
98 ```go-html-template
99 {{ .Site.Language.Name }} → de
100 ```
101
102 ### Weight
103
104 {{<deprecated-in 0.158.0 />}}
105
106 ## Example
107
108 Some of the methods above are commonly used in a base template as attributes for the `html` element.
109
110 ```go-html-template
111 <html
112 lang="{{ .Site.Language.Locale }}"
113 dir="{{ or .Site.Language.Direction `ltr` }}"
114 >
115 ```
116
117 [RFC 5646]: https://datatracker.ietf.org/doc/html/rfc5646
118 [`direction`]: /configuration/languages/#direction
119 [`label`]: /configuration/languages/#label
120 [`locale`]: /configuration/languages/#locale
121 [details]: /methods/page/language/