× Home
i18n - Get the language of the current web page for an if/else.

Hugo - Multilingual - Determine language of the web page

Hugo - Multilingual - Determine web page language

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

|
One minute to read
0
This post was created with Hugo version 0.109.0.

With the German language setting, comments are not displayed in the English version of the website and vice versa.

© 2023 - Frank Kunert  -  About me
A service from webdienste-kunert.de