This is a lot closer. The switcher now will not display the link if the entry is not enable for other site. The index part isn't perfect. If you go to /blog and change the language to for example german it will work: /blog/de. But then if you switch the language again to for example french it will go to /fr/de/blog
<!-- entry -->
{% if entry is defined %}
{% for siteForEntry in entry.getSupportedSites %}
{% set site = craft.app.getSites.getSiteById(siteForEntry.siteId) %}
{% if site.id != entry.siteId %}
{% set entryForOtherSite = craft.entries.id(entry.id).site(site).one() %}
{% if entryForOtherSite is not null %}
<a href="{{ entryForOtherSite.getUrl() }}">{{ site.language }}</a>
{% endif %}
{% endif %}
{% endfor %}
<!-- index -->
{% else %}
{% set localizedUrlsArray = seomatic.helper.getLocalizedUrls() %}
{% for localizedUrls in localizedUrlsArray %}
<a href="{{ localizedUrls['url'] }}"> {{ localizedUrls['language'] }}</a>
{% endfor %}
{% endif %}