Configuring multilinguar mode to use different domains


I want to have two domains for two languages.

  • [topic].com/foo should display foo in English.
  • [topic].de/foo should display foo in German.

By following the guide and searching the forum I found two ideas on how to accomplish this, but both seem to lead to major disadvantages.

Either I configure both languages to be generated in their respective folders (defaultContentLanguageInSubdir:true), and configure my productive web servers to serve accordingly.
This means the .com domain serves from the /en root and the .de domain serves from the /de root.
But this means that global files like the robots.txt are generated outside of the actual web roots.

The other option is to set the baseURL in relation to the current language.

DefaultContentLanguage = "en"
baseURL: [topic].com

baseURL: [topic].de

This seems more like the intended way.

For both options I did not get links from one language to the other to work.

I am using the code from the multilang page:

{{ if .IsTranslated }}
  {{ range .Translations }}
    <a href="{{ .Permalink }}">{{ .Lang }}{{ end }}</a>
  {{ end}}
{{ end }}

For option one the links obviously fail, because they don’t know about the other domain name.
The second option will output links formatted like so:

  • [topic].com/en/foo
  • [topic].de/de/foo

These links look ugly to me. Also, calling one of the domains without the languge parameter at the end will link to the default language, which is a deal breaker. In this example, calling [topic].de will redirect to the english version. Confusing.

Thank you for your support!

Found a ticket that targets exactly what I need:

This just got merged so it is testable if you compile hugo. Otherwise it should be included in a near-future release.

1 Like