<p>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! </p>

<pre><code>        &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 %}
</code></pre>

CC BY-SA 4.0
2018-07-28T09:03:13.453Z
Made a blogpost about a bit more flexible language switcher. You can find it here: https://www.thebasement.be/language-switcher-for-craft-3/
Jan_dh
CC BY-SA 3.0
2018-04-09T15:40:31.393Z
2018-04-09T18:39:50.580Z
2018-04-09T18:39:50.580Z
Danielle Frappier
<p>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? </p>

<pre><code>{% 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 %}
</code></pre>

CC BY-SA 3.0
2018-04-07T22:36:14.257Z
I'll have a look at this in detail in a bit, but something you can do is do a `{{ dump(localizedUrlsArray) }}` to look at the data that's being returned to you from `seomatic.helper.getLocalizedUrls()` to make sure it is what you think it is. Also you don't mention what is _wrong_ or not working as expected with the code you've shown?
andrew.welch
CC BY-SA 3.0
2018-04-08T20:05:12.743Z
I tried your code... it seemed to work fine here, it outputted a link to the entry in another localization in the same Site Group. What is not working as you're expecting it to?
andrew.welch
CC BY-SA 3.0
2018-04-09T12:59:05.673Z
@andrew.welch What I would like to happen is if you go to an english entry, but that entry is not set to live on another site/language then not show the link. My code it shows the link regardless. I am 100% positive I'm not using enabledForSite for site correctly.
Danielle Frappier
CC BY-SA 3.0
2018-04-09T16:42:00.167Z
Oh... maybe you want to check on the `.status` to make sure it's `live` then?
andrew.welch
<localization><craft3><multi-site>
Struggling with language switcher for Craft 3
# Struggling with language switcher for Craft 3

(Asked by: username_0 on 2018-04-06)

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 %}

             {{ localizedUrls['language'] }}

        {% endif %}


    {% else %}

         {{ localizedUrls['language'] }}

    {% endif %}

{% endif %}

{% endfor %}

**Tags:** localization, craft3, multi-site
> **Comments:**
> **username_1**: I'll have a look at this in detail in a bit, but something you can do is do a `{{ dump(localizedUrlsArray) }}` to look at the data that's being returned to you from `seomatic.helper.getLocalizedUrls()` to make sure it is what you think it is. Also you don't mention what is _wrong_ or not working as expected with the code you've shown?  
> **username_1**: I tried your code... it seemed to work fine here, it outputted a link to the entry in another localization in the same Site Group. What is not working as you're expecting it to?  
> **username_0**: @andrew.welch What I would like to happen is if you go to an english entry, but that entry is not set to live on another site/language then not show the link. My code it shows the link regardless. I am 100% positive I'm not using enabledForSite for site correctly.  
> **username_1**: Oh... maybe you want to check on the `.status` to make sure it's `live` then?  

---

## 1 answers

### Answer by username_0 on 2018-04-09. Score: 1

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! 
        
        {% 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 %}

                        {{ site.name }}

                    {% endif %}

                {% endif %}

            {% endfor %}

        
        {% 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 %}

                    {{ site.name }}

                {% endif %}

            {% endfor %}

        
        {% else %}

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

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

            {% for site in sites %}

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

                    {{ site.name }}

                {% endif %}

            {% endfor %}

        {% endif %}

> **Comments:**
> **username_2**: Made a blogpost about a bit more flexible language switcher. You can find it here: https://www.thebasement.be/language-switcher-for-craft-3/  

---

