Make section permalinks multilingual

I’m looking on how to make sections and tags permalinks multilingual. I’ve been looking and experimenting a lot since yesterday, but haven’t found any clear answer or solution. Maybe someone here knows it?

Imagine the following tree structure:

+ content/
+-+ stories/
  +-+ my-story/
  | +-- index.md
  | +-- index.fr.md
  +-- _index.md
  +-- _index.fr.md

I know how to get the following, using slug in the front matter:

  • EN: mysite/stories/my-story
  • FR: mysite/stories/mon-histoire

What I’m looking for now is how to get the following FR URL: mysite/histoires/mon-histoire

I tried using the permalinks section of the configuration. It would be an almost perfect solution, but there are two limiting factors:

  • I need to set the url in the front matter of content/stories/_index.fr.md, though that’s not a blocker;
  • permalinks appear not to be taken into account in the multilingual settings: only the default language seems to be taken into account.

Does somebody have an idea about how to make this work?

The sources for my website are available at Gitlab. Anything Hugo-related is under the site directory.

Multilingual mode works at the project level not for selected sections and taxonomies.

Let me change the formulation: I have a multilingual project, but I did not find how to change the sections part of the URLs depending on the language. Does it sound better?

This seems a pretty common use case, and was requested several times in the issues. “About” is only valid in English. “Categories” would be “Kategorien” in German. Yet, in all those cases, when we are talking about a section or taxonomy, the documentation isn’t clear about how to make the URL reflect those translations.

Sure. Also I changed the topic title to clarify the issue.

Personally I had no need for this sort of configuration in my multilingual projects, so I cannot offer any insights.

Perhaps others can help.

But also note that if this permalink configuration is of paramount importance you can always set the url of a content file and section manually through front matter. Obviously this is less than ideal for a bigger project but for a smaller one, you just might be able to get away with it.

Thanks! :slight_smile:

Yes, I thought of it. I regularly write new pages on the site, so I fear this will grow impossible to maintain, as this must be applied to each and every single (non default language) page. I also fear this defeats the purpose of configuring permalinks in the config and slugs in the front matter.

bep said there were plenty of examples, but there again, I may have poorly expressed myself.

Actually you can do the following.

In your config configure the french language permalinks like so:

[languages.fr.permalinks]
stories = "/histoires/:slug"

And then in the front matter of fr/stories/_index.md set url = "histoires"

See more in this post and the replies below.

2 Likes

Wonderful! Thanks @alexandros!

This is precisely what I’ve been attempting but I used the configuration directory rather than a single file, and used permalinks.en.yml and permalinks.fr.yml. It works for menus and params, but, for an unexplained reason, only permalinks.yml is taken into account, not its variants.

So, I moved the permalinks section back into languages.yml and everything works as expected.

Thank you for your help and finding out the the other post. :slight_smile: