Languages not working for me

I followed the instructions https://gohugo.io/content-management/multilingual/ and created a languages block like this

languages:
  - en:
    title: "English stuff"
    weight: 1
    contentDir: content
  - cy:
    title: "Cymraeg"
    weight: 2
    contentDir: content/cy

and there is _index.md content in both directories.

However, when I run Hugo it behaves as if all the pages are English, even the ones in content/cy.

Did I miss a step?

I think you are missing the indentation. Try

languages:
  en:
      title: "English stuff"
      weight: 1
      contentDir: content
  cy:
      title: "Cymraeg"
      weight: 2
      contentDir: content/cy

If you are going to define some custom parameters, add params: under language code.

EDIT: languages are objects, not list members.

1 Like

Thanks, that was a helpful suggestion but I am still having difficulties.

I put in a template {{.Language| jsonify}}

Now I look at the English and Welsh pages but I always see

{"Lang":"en","LanguageName":"","LanguageDirection":"","Title":"","Weight":0,"Disabled":false,"ContentDir":"","Cfg":{}}

What I would expect is to see “en” on English pages and “cy” on Welsh pages.

Any further suggestions?

DefaultContentLanguage: en
DefaultContentLanguageInSubdir: false
languages:
  en:
    contentDir: content/en
    languageName: English
    title: English stuff
    weight: 1
  cy:
    contentDir: content/cy
    languageName: Cymraeg
    title: Cymraeg stuff
    weight: 2

https://gohugo.io/content-management/multilingual/#translation-by-content-directory

The value of contentDir can be any valid path – even absolute path references. The only restriction is that the content directories cannot overlap.

2 Likes

Thanks for your help. Alas it didn’t work and I didn’t find a solution for my problem though.

I tested the configuration that I posted; no problems.

Please post a link to the public repository for your site. See:
https://discourse.gohugo.io/t/requesting-help/9132

Include a link to the source code repository of your project, because we really need the context of seeing your templates and partials to be able to help you. It is trivial to do a quick git clone on your repo, then run hugo server in your project, to help you out. On the other hand, recreating your code from screenshots, or sort of guessing at it, is not.

If you can’t share your repository for whatever reason, consider creating a dummy repo that you can share, which reproduces the problem you’re experiencing.