How could I do this without a hard-coded language but a dynamic logic? Whenever there is a translation available other than the currently active language?
Regarding the svg or emoji I wasn’t sure where and if to include in the mentioned code.
You need a way to assign available icons to your languages. If you want this to be dynamic, i.e. have icons for all possible languages, then you need of course a lot of icons.
You can create a connection between languages and icons by filename, e.g. en_US.svg or create an array of matching language code values/icon names in your config, for example.
Then grab the icon from this information in your loop. Again, as @pixelijn already pointed out, I don’t think it’s a good idea.
If you have a look at large companies, none of them uses flags anymore these days.
Sorry, but the question was related to the code snippet of @pixelijn which is a hard-coded for English. I would like to know how to do this universally (whenever there is a a translation available other than the active language).
Thanks, that did the trick but how would I show a Headline “Languages” only once and only if there are other languages available?
As the if clause is now part of the foreach loop it would appear as many times as there are languages available.
You would have to filter your languages collection by whether a translation exists first, then check if the collection has items, and only then go into the loop.