Struggling with language switcher for Craft 3 I am using SEOmatic helper class to get localizedUrls which is making life much easier! I would like to only display the localizedurl if the current entry is enable on that site. Below is what I have, has anyone successful done this for craft 3? 

{% set currentSite = craft.app.sites.currentSite %}

{% set currentSiteLanguage = currentSite['language'] %}

{% set localizedUrlsArray = seomatic.helper.getLocalizedUrls() %}


{% for localizedUrls in localizedUrlsArray %}

{% if currentSiteLanguage != localizedUrls['language'] %}

    {% if entry is defined %}

        {% if entry.enabledForSite %}

            &lt;a href="{{ localizedUrls['url'] }}"&gt; {{ localizedUrls['language'] }}&lt;/a&gt;

        {% endif %}


    {% else %}

        &lt;a href="{{ localizedUrls['url'] }}"&gt; {{ localizedUrls['language'] }}&lt;/a&gt;

    {% endif %}

{% endif %}

{% endfor %}
I think I might finally have it working. If someone has a more elegant way to handle the index, tag and category I would love to see it! 

        &lt;!-- entry --&gt;
        {% 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 %}

                        &lt;li&gt;&lt;a href="{{ entryForOtherSite.getUrl() }}"&gt;{{ site.name }}&lt;/a&gt;&lt;/li&gt;

                    {% endif %}

                {% endif %}

            {% endfor %}

        &lt;!-- category --&gt;
        {% elseif category is defined %}

            {% set currentSite = craft.app.sites.currentSite %}

            {% set sites = craft.app.sites.getAllSites() %}

            {% for site in sites %}

                {% if site.id != currentSite.id %}

                    &lt;li&gt;&lt;a href="{{ site.baseUrl }}blog/category/{{craft.request.getLastSegment()}}"&gt;{{ site.name }}&lt;/a&gt;&lt;/li&gt;

                {% endif %}

            {% endfor %}

        &lt;!-- index and tags --&gt;
        {% else %}

            {% set currentSite = craft.app.sites.currentSite %}

            {% set sites = craft.app.sites.getAllSites() %}

            {% for site in sites %}

                {% if site.id != currentSite.id %}

                    &lt;li&gt;&lt;a href="{{ site.baseUrl }}{% for segment in craft.request.getSegments() %}{{segment}}/{% endfor %}"&gt;{{ site.name }}&lt;/a&gt;&lt;/li&gt;

                {% endif %}

            {% endfor %}

        {% endif %}