Is there a way to retrieve the value of defaultContentLanguage?

It can help to make more flexible default templates for multilanguage sites (e.g. hreflang link attributes in html headers).

No, but the langugages are sorted, so if you want ā€œthe firstā€ you can always do index .Site.Home.AllTranslations 0.

Great! Thanks.

I think of if we can get the value of ā€˜defaultContentLanguageā€™ will be better.

1 Like

If it can help you (in the context of multi-language sites), I did my hreflang this way, ranging over existing translations

1 Like

Thanks! @martignoni

      {{ if .Site.IsMultiLingual }}
  <a href="{{ .Site.BaseURL }}{{.Site.Language }}" class="link white">
     Jenkins X
     {{ .Page.Lang }}
  </a>
  {{ else }}
  <a href="{{ .Site.BaseURL }}" class="link white">
     Jenkins X
  </a>
  {{ end }}

This is what I want. But here is a problem, it will get 404 when current pageā€™s language is the defaultContentLanguage. So I need to know the default language.

Looking at your code, it seems what you want isnā€™t exactly related to hreflang, and seems instead like a language switch.

Did you have a look here: Language switcher in menu?

Thanks for your reply. Thatā€™s very good. Maybe you can contribute it to gohugoTheme.

This is planned, but I think my theme is not totally ready for publication yet. :blush:

Is this still the case: site.DefaultContentLanguage canā€™t be read from templates?

The defaultContentLanguage in the site configuration is not exposed to the templates.