Language
Returns the Language object for the given site.
- Syntax
- SITE.Language
- Returns
- langs.Language
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
Use these methods on the Language object.
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 thedirectionfrom the language definition.{{ .Site.Language.Direction }} → ltr FormatAccounting- New in v0.168.0
- (
string) Formats a number as currency in accounting notation for this language. Seelang.FormatAccounting.{{ .Site.Language.FormatAccounting 2 "EUR" -12.3 }} → -12,30 € FormatCurrency- New in v0.168.0
- (
string) Formats a number as currency for this language. Seelang.FormatCurrency.{{ .Site.Language.FormatCurrency 2 "EUR" 12.3 }} → 12,30 € FormatNumber- New in v0.168.0
- (
string) Formats a number for this language. Seelang.FormatNumber.{{ .Site.Language.FormatNumber 2 1234.5 }} → 1.234,50 FormatPercent- New in v0.168.0
- (
string) Formats a number as a percentage for this language. Seelang.FormatPercent.{{ .Site.Language.FormatPercent 1 12.3 }} → 12,3 % IsDefault- New in v0.153.0
- (
bool) Reports whether this is the default language.{{ .Site.Language.IsDefault }} → true Label- New in v0.158.0
- (
string) Returns thelabelfrom the language definition.{{ .Site.Language.Label }} → Deutsch Lang- Deprecated in v0.158.0
- Use
Nameinstead. LanguageCode- Deprecated in v0.158.0
- Use
Localeinstead. LanguageDirection- Deprecated in v0.158.0
- Use
Directioninstead. LanguageName- Deprecated in v0.158.0
- Use
Labelinstead. Locale- New in v0.158.0
- (
string) Returns thelocalefrom the language definition, falling back toName.{{ .Site.Language.Locale }} → de-DE Name- 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 }} → de Translate- New in v0.168.0
- (
string) Translates a string using the translation table for this language. Seelang.Translate.{{ .Site.Language.Translate "hello" }} → HalloUse this to translate a string into each configured language:
{{ range .Site.Languages }} {{ .Translate "hello" }} {{ end }} Weight- Deprecated in v0.158.0
Example
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` }}"
>