Based on the actual pages URL, it (the language-switcher) figures out, if the language is English ('/en/'-substring present in URL) or German (NO '/en/'-substring present in URL). Then it assembles the respective links for the switcher.
Both links ( {{ english }} and {{ german }} ) are assembled correctly. I have tested that by inserting them as text inside the respective links. ( <a href="{{ german }}">{{ german }}</a> ). Caching is also not the problem.
THE PROBLEM: The {{ german }}-var in href is NOT the {{ german }}-link. It diverges with the {{ german }}-var used as text. Actually the "/en/" part of the URL stays in place. And the really strange thing is, that it works on some pages and not on others (the pages are using the same global group).
EXAMPLE that works (You can switch back and forth):
Thank you for reaching out about this - I got wind of this situation and am looking into this internally.
Unfortunately, (from a looking into the issue perspective - glad you got it working ), I am not able to reproduce this using your same HubL logic. I know you noted it only was happening on some pages which may be part of the issue here.
Is there any chance you could maybe create a simplified example where the issue is present? If so, I am more than happy to dig into what is going on here.
Also, awesome looking language switcher, this is a really cool setup! I wonder if you may cosider using the string_startingwith or string_containing expression tests for this? If I have the full picture I think it could simplify the logic a bit (I think your logic is right, something funky seems up, but this may be simpler logic). This would look something like:
When trying to reproduce this, I built a simplified version with both your logic as well as using the string_startingwith expression test, and they both seem to work nicely.