Hugo - Multilingual - Determine language of the web page

When programming a multilingual website, the language of the respective web page must be determined for some program parts. This is the only way to react accordingly and create different program code depending on the language.
There are several ways to determine the language of the current web page for an if/else in Hugo. This quick tip describes 2 possibilities.
if/else which language?
The main language on my website is German. The second language English. For this reason, an if/else is sufficient. If you use more languages, the query can be extended with else if
. Below is the “long” version of the query.
{{ if eq .Site.Language.Lang "de" }}
..
{{ else }}
..
{{ end }}
And here is the slightly “shorter” version. All a matter of taste.
{{ if eq (string .Lang) "de" }}
..
{{ else }}
..
{{ end }}
Conclusion
Nothing earth-shattering, but sometimes such a little tip helps to get further in the source code.
This might also interest you
- Hugo - i18n Multilingual - customize lastmod date for specific country
i18n - Adjust the country-specific notation of the lastmod date according to the language.
- Hugo - Tutorial Part 1 - Create i18n multilingual site
Part 1 describes initial configuration steps in hugo.toml, the Page Bundle structure of the web pages, and Front Matter entries in the Markdown files.
- ahrefs.com - free webmaster tools
Technical SEO support.
With the German language setting, comments are not displayed in the English version of the website and vice versa.