Is it possible to set {{ .Site.LanguageCode }}?

The majority of my posts are in Swedish. Is it possible to set the Hugo language code for a blog so that it can be used throughout the templates with the built-in variable {{ .Site.LanguageCode }}?

It would be great from an accessibility point of view so that screen readers use the correct language when reading/parsing the content on the page.

Ideally I would love to have the option to set the language on every post (or through micropub) so that I can mix multiple languages on the same blog. Additionally, it would be great if “Discover” could surface blog posts from specific languages. I would love to connect to other Swedish users.

Hej! Yes, you can set languageCode to sv in config.json using a custom theme. But that variable is intended for use only by the RSS template. So you might want to use {{ .Site.Language.Lang }} instead by setting defaultContentLanguage in config.json.

@manton is the only one who can give us official support for multilanguage blogs and timeline entries. But you could hack something together if you really want to. For example, you could have separate categories for each language. Or invent a magic shortcode. Or look for the presence of the :sweden: emoji or a #sv tag or similar in your posts. And implement logic in the templates to set the lang attribute accordingly.

1 Like