Multi language page

I have two languages english and german. The english language is the default
languauge. The content of the browser is displayed in But I would like to
see the content in and How do I change this?

In /content/en and content/de I have a All links, the German-speaking
and English-speaking pages are displayed in the browser, regardless of the
language. Please have a look at my page.

defaultcontentlanguageinsubdir: true in config does what is says.

This is my config.toml

Language configuration

defaultContentLanguage = "en"
defaultContentLanguageInSubdir = "true"

        languageName = "English"
        languageCode = "en-us"
        url = "/en/"

        languageName = "German"
        languageCode = "de-de"
        url = "/de/"

Had a few spare minutes, tried looking at the source but, it’s locked somehow.

Thank you Rick that you have a little time to check my code.

It’s working from what I can see. The language switch is fine, and is based on the baseURL config.toml parameter you have set.

I’m seeing:


… which is correct for the settings. The language switcher in the footer just goes to the top though, not to the equivalent URL. Like if you’re on Security in English, when you click the german button, it goes to the top of the German site.

Can you explain my how to switch to the correct site? But all content is in the root of the /content folder.

 <footer class="footer">
      <div class="container">
        <a class="brand" href="" target="_blank"></a>
        <input class="menu-btn" type="checkbox" id="footer-menu-btn" />
        <label class="menu-icon" for="footer-menu-btn"><span class="navicon"></span></label>
        <ul class="menu">
          {{- $currentPage := . -}}
          {{ range .Site.Menus.footer -}}
          <li class="{{ if $currentPage.IsMenuCurrent "footer" . }}active{{ end }}">
            <a href="{{ .URL }}">{{ .Name }}</a>
          {{- end }}
          {{ if .IsTranslated }}
          {{ range .Translations }}
            <a href="{{ .Permalink }}">{{ .Site.Language.Params.languageName }}</a>
          {{ end }}
          {{ else }}
          {{ $currentLang := .Site.Language.Lang }}
          {{ if eq $currentLang "en" }}
            <a href="/">German</a>
          {{ else }}
            <a href="/">Englisch</a>
          {{ end }}
          {{ end }}

Hmm. I’m just in the middle of setting up a similar one, with / for japanese and /en/ for the English, and, I have this kind of thing for my filenames in content:

I’m not sure if the name of the file has to be the same or not, to make Hugo recognize that is a translation of Maybe if you want the url path to be different, try making the filenames the same root, and specify the slug inside the frontmatter?

And specify slug in the one that is supposed to be German language.

The above is speculation; sorry, I have not tried it.

Yeah, pretty clear on this point here about the filename being the trigger to cause Hugo to treat something as translated content:

Thank you Rick. It works fine.


1 Like

Now I have two folder in the root dir. /en and /de. What I have to do that the content automatically switch to the one of the two languages? When I open the browser the webserver This site is currently under construction. But I need or

You have that because that’s the way you set up Hugo, but Hugo doesn’t forward in this case (edit 1). If you want a subfolder per language, yet still need to jump to (or /en), then you need to set forwarding on the webserver side. If Apache, you’d do this with an .htaccess (you can store it in your /static folder).

Forwarding rules in Apache are troublesome (can’t say for nginx or caddy), so I’d go for specifying one language as main, keeping its files in the root, and having the second language as the “sub” on in a subfolder. Or get another domain and do multi-host.

Edit 1 - except, yes, you can set an alias on an individual page. I have not tested if you can do this with / (in its attached and I doubt it would work.