Hugo not redirecting to default language

After the languages were set in config.toml with this:

defaultContentLanguage = "pt"

[Languages]
[Languages.pt]
LanguageName = "Português"

[Languages.en]
LanguageName = "English"

visiting localhost:1313 we still see the content in English and not the default Portuguese. What could be causing this?

I have no idea based on the little you’re showing us.

I’m unsure what else would be relevant … the site is using this theme: https://themes.gohugo.io/hugo-theme-bootstrap4-blog/

And the content is structured this way:

- posts
   |
   |_ post_1/index.pt.md
   |_ post_2/index.pt.md

Also tried with my own blog, and it’s still redirecting to /en instead of the defaultContentLanguage set in config.toml

I think you need to link to a “failing site”.

I was able to reproduce on a ‘clean’ version, without the original content:

lift every root level options (like: DefaultContentLanguage = "pt") to the top of your config.toml

You can’t have nested options, for example:

[params]
  # Site author
  author = "Marvin"

like this and then define root level options, for example:

DefaultContentLanguage = "pt"

Root level options has to be defined at the top, like this:

DefaultContentLanguage = "pt"

[params]
  # Site author
  author = "Marvin"

2 Likes

:man_facepalming:

Yeah that fixed it … thank you for your help!

Woah. Thanks for finding the issue. I had the same issue.

But why the heck do all root keys have to go first? Is that some TOML or hugo thing?

This is an old thread, but if I recall correctly, Hugo expects that to be at the root, so it’s both a Toml structure issue and Hugo’s expectation that we have defined those parameters in the right place.