Hugo

Multilanguage for a homepage

I would like to make my homepage multilingual. In the folder content, I have two more folders / de and / en created. In these folders I have filed the corresponding pages. In the front office I made the following entries. Which entries do I still have to make?

     ---
     title: "Imprint"
     date: 2017-12-05T14:45:43+01:00
     draft: false
     menu:
       footer:
          name: Imprint
          url: /en/imprint/
          weight: 1
     ---


config.toml 
    # Language configuration
    defaultContentLanguage = "en"

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

        [languages.de]
            languageName = "Deutsch"
            languageCode = "de-de"
            linkedin = "de"

I have read the documentation. Unfortunately, I could not implement my idea. I ask for help again. I have in the directory content two more directories / de and / en. In these directories are the contents for each language. I want the browser to recognize that if the language is not German, it should switch to the English language. On the homepage itself, however, a switch for switching the language in the footer should be installed. I have inserted the following in front of each page. My questions are:

  1. What do I have to enter in /content/_index.md?
  2. Which entries do I have to enter in the config.toml?
  3. How do I implement the switch to toggle in the footer of the page?

 title: "Imprint"
 date: 2017-12-05T14:45:43+01:00
 draft: false
 menu:
   footer:
      name: Imprint
      url: /en/imprint/
      weight: 1


 title: "Impressum"
 date: 2017-12-05T14:45:43+01:00
 draft: false
 menu:
   footer:
      name: Impressum
      url: /de/impressum
      weight: 1
 ---

Have a look at my website for an idea on how I did it (3 languages: en, fr, de).

Hello,
i like your implementation.
Did you use translations managed by filename or by folder?
Can you tell some specs on how to start with?

I began managing translations by filename, then switched by folder (and renamed all my content files). I prefer this way since it keeps the file hierarchy tidy. See my content folder here:

Regarding specs, what do you need exactly?

Thank you for your reply.

At first I’d like to create just for some chosen content in /posts/ in another language. What would happen if there are no translated posts? Will the original file be shown?

Is there a possibility to choose the browser the proper language. For longterm I would create a language switcher as you have done on your site.

What is also unclear to me, whether links to other post have to be modified.

No, in my setup, when no translation exists, the language switcher do simply not display the missing language link.

I don’t know if I understand you correctly, but in my setup, the links to translated posts are automatic, provided the content file name is the same in all languages.

Does it fallback then to the original language?

I think I should create copy of the website for testing.

It is great that all content file names / links will remain. Otherwise it would begin very complicated

This has nothing to do with Hugo, but with your hosting server/service. It should detect the browser default language, and automatically serve the correct URL.

I’m testing. Hugo is so great!

Can you help me please with my config.toml
I don’t know how to set the language code “de”
[languages]
de:
languageName = German
weight = 1
en:
languageName = English
weight = 2

this produces no more errors but I still have both languages posts in my /posts/ folder

[languages]
[languages.de]
languageName = “German”
weight = 1
[languages.en]
languageName = “English”
weight = 2

Post a link to your code.

Good Morning,
I’ve tried it again today. Now it’s running :slight_smile:

TO-DO is the language switcher in the navigation bar.
edit: just the icon TO-DO. The menus are already working. It’s truly awesome!

I’ve pulled all sections in content/de/ and content/en (_index.md too).

Here’s what’s working for me:

config.toml

[languages]
[languages.de]
languageName = “German”
contentDir = “content/de”
weight = 1
[languages.en]
languageName = “English”
contentDir = “content/en”
weight = 2

Do you have a hint how to start with the language switcher?

Have a look at this discussion:

Here is another example.

Have a look here: https://www.netlify.com/docs/redirects/#geoip-and-language-based-redirects

1 Like

The canonical link is missing in each language.

There should be self canonical link of each language page too.

If the site is english, https://moodlebox.net/en/

It should be,

And the code to solve this for each language.

<link rel="canonical" href="{{ .Permalink }}">

1 Like