Multilanguage problem

Hello everyone, before posting i was trying to use chat gpt and of course i was searching solution on this forum and stackoverflow… I have problem with adding to theme language switcher.

simple code:

<ul>
{{ range $.Site.Home.AllTranslations }}
<li><a href="{{ .Permalink }}">{{ .Language.LanguageName }}</a></li>
{{ end }}
</ul>

generates:

<li><a href="//localhost:1313/pl/">Polish</a></li>
<li><a href="//localhost:1313/de/">Deutsch</a></li>
<li><a href="//localhost:1313/"></a></li>

That blank link should be defalul English.

I tried everything and im really tried. Maybe you can help me with this?

My env:

hugo v0.138.0+extended+withdeploy darwin/arm64 BuildDate=2024-11-06T11:22:34Z VendorInfo=brew
GOOS="darwin"
GOARCH="arm64"
GOVERSION="go1.23.2"
OptionParser::InvalidOption: invalid option: --embedded
  Use --trace for backtrace.
github.com/sass/libsass="3.6.6"
github.com/webmproject/libwebp="v1.3.2"

Please share your site configuration, or a link to your site’s public Git repository.

Here is my config.toml:

defaultContentLanguage = 'en-US'
defaultContentLanguageInSubdir = true

[languages]
  [languages.en]
    contentDir = 'content/en'
    languageCode = 'en-US'
    languageName = 'English'
    weight = 1
  [languages.pl]
    contentDir = 'content/pl'
    languageCode = 'pl-PL'
    languageName = 'Polish'
    weight = 2
  [languages.de]
    contentDir = 'content/de'
    languageCode = 'de-DE'
    languageName = 'Deutsch'
    weight = 3
[module]
  [module.hugoVersion]
    extended=true
    min = "0.41.0"
    
[markup]
  [markup.goldmark]
    [markup.goldmark.parser]
      [markup.goldmark.parser.attribute]
        block = true
        title = true
  [markup.highlight]
    anchorLineNos = false
    codeFences = true
    guessSyntax = false
    hl_Lines = ''
    hl_inline = false
    lineAnchors = ''
    lineNoStart = 1
    lineNos = false
    lineNumbersInTable = true
    noClasses = true
    noHl = false
    style = 'rrt'
    tabWidth = 4
  [markup.tableOfContents]
    startLevel = 2
    endLevel = 3
    ordered = false

[params]
  [params.theme_config]
    appearance = "retro"
    back_home_text = "↩︎ back"
    date_format = "2006-01-02"
    categories = true
    tags = true
    post_limit = 10
    show_more_url = "posts"

Also, if you’re transpiling Sass to CSS using the “dartsass” option, you’ll need to install Dart Sass instead of whatever sass executable is currently installed.

With the site configuration above Hugo throws an error, as expected:

failed to decode “languages”: config value “en-us” for defaultContentLanguage does not match any language definition

If I change this:

defaultContentLanguage = 'en-US'

To this:

defaultContentLanguage = 'en'

I get this:

<ul>
  <li><a href="http://localhost:1313/en/">English</a></li>
  <li><a href="http://localhost:1313/pl/">Polish</a></li>
  <li><a href="http://localhost:1313/de/">Deutsch</a></li>
</ul>

You’ll need to share your project if you need additional assistance.

can i share via wetransfer? Unique Download Link | WeTransfer
im total newbie in terms of git

I found this in your site config:

defaultContentLanguage = 'pl-PL'

Which causes Hugo to throw an error, as expected:

Error: failed to create config from result: failed to decode "languages": config value "pl-pl" for defaultContentLanguage does not match any language definition

When I change it to the correct value:

defaultContentLanguage = 'pl'

The site builds without error and the language switcher works great.

thanks for your answer, this really makes me wonder because according to what you write I measured the value to “pl” (and to “en”) and I still have the same thing. also I created a new directory with a clean hugo to check and all the time it doesn’t display my switcher correctly.

I’m not sure what to tell you; I cannot reproduce the problem with your site and the configuration correction that I described above. Maybe you can look at this simple working example to figure out what you’re doing differently/wrong:

git clone https://github.com/jmooring/hugo-multilingual-example
cd hugo-multilingual-example
hugo server

Thank you. The problem was of course stupid simple - I puted info about languages in config.toml instead of hugo.toml.

You can name the site configuration file either “config.toml” or “hugo.toml” (preferred). I’m not sure what you did, but the “fix” has nothing to do with the file name.

the problem was probably due to the fact that I had config.toml and hugo.toml - and the data from these two files overlapped