Multiple files for configuration root objects

What I am trying to do

Multiple files for configuration setting like Menu, language etc. as per here.

Folder structure is:
config/

  • _default/
    • config.toml
    • languages.toml
    • menu.toml
    • params.toml
  • production
  • staging

Expected result

Configurations from all files within a folder ( like _default ) should merge together.

Result

Configuration from languages.toml is not loading. It seems Hugo is not even reading this file. Hugo is only reading config.toml in the _default directory

Stack

Hugo version: hugo v0.93.3+extended linux/amd64 BuildDate=unknown
OS: Fedora 36

This setup is very similar to the Hugo Docs site:

And Iโ€™m pretty sure it works there.

1 Like

How are you referencing fields in the language.toml in within your layouts?

Not sure how your file looks like but hereโ€™s a sample, from my languages.toml file:

### Info: https://gohugo.io/content-management/multilingual/#configure-languages

[en-ph]
  languageName = "English (PH)"
  languageCode = "en-PH"
  languageCodeCountry = "ph"              # custom
  languageFlag = "๐Ÿ‡ต๐Ÿ‡ญ"                     # custom
  timeZone = "Asia/Manila"
  tzOffset = "8h"                        # custom
  tzAbbr = "ACT"                          # custom
  tzAbbrTitle = "Asean Common Time"                        # custom
  weight = 111

[ja]
  languageName = "ๆ—ฅๆœฌ่ชž"
  languageCode = "ja"
  languageCodeCountry = "jp"              # custom
  languageFlag = "๐Ÿ‡ฏ๐Ÿ‡ต"                     # custom
  timeZone = "Asia/Tokyo"
  tzOffset = "9h"                        # custom
  tzAbbr = "JST"                          # custom
  tzAbbrTitle = "Japan Standard Time"                        # custom
  weight = 140
  title = "้›ชใฎไธ–็•Œ โ„๏ธ"

[ko]
  languageName = "ํ•œ๊ตญ์–ด"
  languageCode = "ko"
  languageCodeCountry = "kr"              # custom
  languageFlag = "๐Ÿ‡ฐ๐Ÿ‡ท"                     # custom
  timeZone = "Asia/Seoul"
  tzOffset = "9h"                        # custom
  tzAbbr = "KST"                          # custom
  tzAbbrTitle = "Korea Standard Time"                        # custom
  weight = 150
  title = "์Šค๋…ธ์šฐ ์›”๋“œ โ„๏ธ"

In my baseof.html files, I have:

{{/* Multilang support for lang attribute */}}
<html lang="{{ or (.Site.LanguageCode) (.Site.Language.Lang) }}" prefix="og: https://ogp.me/ns#{{ if in .Site.Params.mainTypes .Type }} article: https://ogp.me/ns/article#{{ end }}" class="h-feed">

In language selection, I have something like:

<menu id="lang-menu" class="flyout-menu menu">
  <a href="#" lang="{{ or (.Site.LanguageCode) (.Site.Language.Lang) }}" class="nav link active" title="{{ .Site.Language.LanguageName }}">{{ .Site.Language.Params.languageflag }} ({{ .Site.Language.LanguageName }})</a>
  {{ if .IsTranslated -}}
    {{ range .Translations }}
      <a href="{{ .Permalink }}" lang="{{ or (.Site.LanguageCode) (.Site.Language.Lang) }}" class="nav link" title="{{ .Site.Language.LanguageName }}">{{ .Site.Language.Params.languageflag }} ({{ .Language.LanguageName }})</a>
    {{ end }}
  {{ else }}
    {{ range .Site.Languages }}
      {{ if not (eq .Lang $.Site.Language.Lang) }}
        <span class="nav no-lang link" title="{{ .Params.LanguageName }}">{{ .Params.languageflag }} ({{ .Params.LanguageName }})</span>
      {{ end }}
    {{ end }}
  {{ end }}
</menu>

I use the other custom fields like so:

    {{ if not .PublishDate.IsZero }}<time datetime="{{ .PublishDate.UTC.Format "2006-01-02T15:04:05Z07:00" }}" class="dt-published">{{ time.Format $datetimeformat (.PublishDate.UTC.Add (time.ParseDuration $.Site.Language.Params.tzOffset)) }} <abbr{{ with $.Site.Language.Params.tzAbbrTitle }} title="{{ printf "%s" . }}"{{ end }}>{{ $.Site.Language.Params.tzAbbr }}</abbr></time>{{ end }}

You can see it live here: Snoworld โ„๏ธ (I customized the timezone abbreviation; and added auto-calculation of time.)

I hope it helps.

1 Like

Thanks. I was mistaking in using [languages.en] as the key. I used only the language name as the key , as per the Hugo docs repo, and it worked.

1 Like

Thanks. I was making the mistake in referencing the language key as `[languages.en]โ€™ . Fixed it by referencing Hugo docs repo.
Thank you for the detailed response on language menu.

2 Likes

This topic was automatically closed 2 days after the last reply. New replies are no longer allowed.