HUGO

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.

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: