Multilanguage: what is the best way to create single English post in an otherwise mostly Finnish blog?

I have a blog that has defaultContentLanguage = 'fi' and all the posts in content/posts. I’ve written a single post in English, and I’d like the behaviour of the theme and the HTML metadata etc. to become English for that single post as well. I don’t want to the site to render separate /en/ and /fi/ subdirectories or have any other separation between the two languages. I don’t want any of my existing content to move or change.

How do I do this?

Then set defaultContentLanguageInSubdir = false (which is the default) in your site configuration.

There will still be a fi directory for the the fi sitemap and a redirect from /fi to the root of the public directory.

Disabling the rendering of /en can be done, but it’s messy, and I wouldn’t do it.

git clone --single-branch -b hugo-forum-topic-52231 https://github.com/jmooring/hugo-testing hugo-forum-topic-52231
cd hugo-forum-topic-52231
hugo server

First, your example fails:

hugo v0.111.3+extended linux/amd64 BuildDate=2023-03-16T08:41:31Z VendorInfo=debian:0.111.3-1
ERROR 2024/11/01 19:01:31 render of "section" failed: "/home/ronja/src/hugo-forum-topic-52231/layouts/_default/baseof.html:2:15": execute of template failed: template: _default/list.html:2:15: executing "_default/list.html" at <site>: can't evaluate field LanguageCode in type *langs.Language
ERROR 2024/11/01 19:01:31 render of "home" failed: "/home/ronja/src/hugo-forum-topic-52231/layouts/_default/baseof.html:2:15": execute of template failed: template: _default/home.html:2:15: executing "_default/home.html" at <site>: can't evaluate field LanguageCode in type *langs.Language
ERROR 2024/11/01 19:01:31 render of "taxonomy" failed: "/home/ronja/src/hugo-forum-topic-52231/layouts/_default/baseof.html:2:15": execute of template failed: template: _default/list.html:2:15: executing "_default/list.html" at <site>: can't evaluate field LanguageCode in type *langs.Language
Error: Error building site: failed to render pages: render of "page" failed: "/home/ronja/src/hugo-forum-topic-52231/layouts/_default/baseof.html:2:15": execute of template failed: template: _default/single.html:2:15: executing "_default/single.html" at <site>: can't evaluate field LanguageCode in type *langs.Language

Second, the example post files you made look like one is supposed to be a translation of the other. This is not my intention. The single English post I wrote is stand-alone content that is not intended to have a version in Finnish.

You’re running an older version of Hugo.

Please upgrade and then we can continue the conversation.

I see. It does work with the latest release.

Perhaps the key takeaway for my usecase is that I can override the /en/... url in the post’s front matter, and then I can just ignore the /en/ subdirectory even though it’s technically there? I can live with that.

Then remove the translation key from the front matter of both content files.

Pull changes from the repository above and test again. This is helpful to see the published structure:

rm -rf public && hugo && tree public

Everything looks reasonable with this setup, except post-2 doesn’t appear in the index alongside post-1. In fact, I don’t think post-2 is reachable from anywhere.

Change the page collections to use site.AllPages. Pull changes from the repository above and test again.

It’s likely you’re going to run into other details that you don’t like… which is why I initially responded:

I wouldn’t do it

Okay. I think today is the day I find an alternative to Hugo. Thank you for your time.

1 Like