Select the linked Markdown file (multilingual mode)

Hello everyone,
I’ve been fiddling around with the Multilingual Mode in Hugo. Everything works fine now, except one thing. I don’t really know how to find the linked Markdown file to the current one.
I’m separating the languages by using different directories in my content folder. Example: content/english/general/SomeFile.md and content/german/general/EineDatei.md with a translationKey, so Hugo can link them together even though they have a different name. Now I want to be able to switch languages while being on the SomeFile.md page for example. If I select English, nothing should change, because it should load the same URL. If I select German however, it should load the linked German file with the same translationKey. How could I do that? I already tried a few things, but that all led to failure. I also read the entire documentation (Multilingual Mode | Hugo) but I couldn’t really find my answer there.

PS: This is the HTML code I’m currently using to generate the link-“buttons”:

{{ range $.Site.Home.AllTranslations }}
    <a href="{{ What should this contain? }}" class="topbar-buttons">{{ .Language.LanguageName }}</a>
{{end}}

look at this

{{ range .Translations }}
    <a href="{{ .Permalink }}" class="topbar-buttons">{{ .Language.LanguageName }}</a>
{{end}}

Hello, thank you for your answer. Why didn’t I think of that? I already came to a few solutions myself before I asked, but neither of them was elegant, they just didn’t satisfy me.
This solution is closer to that what I want, but there is one problem with this solution: It only loops through the other languages. I want to display the current language as well. Of course, I could just manually add another one for the current language, but that doesn’t really feel elegant. And I doubt I can just list all languages, because I won’t be able to use .Permalink to add the href in order to achieve the desired effect.

add page attribute .Language

<a href="{{ .Permalink }}" class="topbar-buttons">{{ .Language }}</a>
before of the range!

.Language

a language object that points to the language’s definition in the site config . .Language.Lang gives you the language code.

see at

1 Like

Thank you for your answer. I figured it out already, excuse the hasty question, but it just so happened that I managed to figure it out a while after I asked. It was just a small inconvenience with my way, which caused the code not to work properly, that’s why I decided to ask.

I appreciate your answer though, thank you very much!

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