absLangURL for BaseURL

I have opened an issue on Git about localising BaseURL

From the feedback I got there it seems I’m doing something wrong.
Neither {{.Site.BaseURL}} nor {{ .Site.BaseURL | absLangURL}} seem to return the base url localised with the current language.

{{ "/" | absLangURL}} Does work as expected. But shouldn’t {{ .Site.BaseURL | absLangURL}} work as well? One of the resources I found online seem to point in that direction: https://jibecfed.fedorapeople.org/blog-hugo/en/2018/11/building-a-multilingual-static-website-with-hugo/

If I understand correctly what you mean: correct way to do this is using

defaultContentLanguageInSubdir: true

See a working example here:

PS. Please share your code in a repo so we could help without playing the Q&A game.

Hi there @martignoni

Thank you for your reply.
I checked the docs and it says the following:

If the default language needs to be rendered below its own language code ( /en ) like the others, set defaultContentLanguageInSubdir: true .

I’m not sure if this is the problem I have. I also tried it and it didn’t seem to fix the issue.
Here are the current scenarios:

  1. If I’m at http://localhost:1313/pt-pt/about and click {{ .Site.BaseURL | absLangURL}} I expect to be forwarded to http://localhost:1313/pt-pt

  2. If I’m at http://localhost:1313/about and click {{ .Site.BaseURL | absLangURL}}, I expect to be forwarded to http://localhost:1313/

The behaviour works just as I described if I use {{ "/" | absLangURL}} but not if I have:

baseURL = "/"

and do {{ .Site.BaseURL | absLangURL}}

I mean I can currently go around this easily, but I feel that this is a bug and maybe should be considered for fix. But the issue has been closed on the premise that it’s expected behaviour, and I wonder if there’s something that I’m overlooking.

I hope this clarifies the issue, and thank you again for your reply :slight_smile:

Edit: A bit more clarification on why your proposed solution didn’t work for me, this is what happens:
If I’m at http://localhost:1313/pt-pt/about and click {{ .Site.BaseURL | absLangURL}} I expect to be forwarded to http://localhost:1313/pt-pt but I get forwarded to http://localhost:1313/en-gb/ instead