Language specific url of current page

I want to make a language switcher, which looks like this

    <ul class="shadow">
        {{ range $.Site.Home.AllTranslations }}
        <li class="dropdown_link"><a href="{{ .Permalink | absLangURL }}" target="_self" rel="noopener noreferrer">{{ .Site.Language.Params.flag }} {{ .Language.LanguageName }}</a></li>
        {{ end }}
    </ul>

So when I am on page http://localhost:1313/docs/prologue/introduction/ and switch to “Deutsch” I want the page switching to http://localhost:1313/de/docs/prologue/introduction/. However the .Permalink used gives me a href to href="//localhost:1313/de/"

What do I miss?

What do I miss?

Something in the frontmatter of the english and german articles for that URL. Please post and someone will dive into it :slight_smile: I don’t have much knowledge of the whole i18n-thing (yet), but IF there is a link it means Hugo knows there is a german translation, so the error will be in the permalink generation for either post.

It could also just be some context issue with the . not being what you assume it is inside of the range. But to me it looks like proper code and it should work as expected.

On a second look: you range the HOME page translations and Hugo does what you want. You want to range the translations of that specific page.

{{ range $.Translations }}
2 Likes

Cool man, thanks for the quick help! Final solution looks like this:

...
    <ul class="shadow">
        {{ range $.AllTranslations }}
        <li class="dropdown_link"><a href="{{ .RelPermalink }}" target="_self" rel="noopener noreferrer">{{ .Site.Language.Params.flag }} {{ .Language.LanguageName }}</a></li>
        {{ end }}
    </ul>
...

image

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