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}}
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.
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!