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 example.com/. But I would like to
see the content in example.com/en. and example.com/de How do I change this?

In /content/en and content/de I have a _index.md 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"

[languages]
    [languages.en]
        languageName = "English"
        languageCode = "en-us"
        url = "/en/"

    [languages.de]
        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:

http://localhost:1313/homepage/en/
http://localhost:1313/homepage/de/

… 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="http://example.com" 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 }}
          </li>
          <li>
          {{ 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 }}
          </li>
        </ul>
      </div>
    </footer>

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:

about.md
about.en.md

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

security.de.md
security.en.md

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.

Jörg

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 https://example.com the webserver This site is currently under construction. But I need example.com/en or example.com/de

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 http://mydomain.com/ to jump to http://mydomain.com/de (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 _index.md) and I doubt it would work.