Answers.Body: <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>
  
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2018-07-28T09:03:13.453Z
Answers.Text: Made a blogpost about a bit more flexible language switcher. You can find it here: https://www.thebasement.be/language-switcher-for-craft-3/
Answers.UserDisplayName: Jan_dh
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2018-04-09T15:40:31.393Z
Answers.LastActivityDate: 2018-04-09T18:39:50.580Z
Answers.LastEditDate: 2018-04-09T18:39:50.580Z
Answers.UserDisplayName: Danielle Frappier
Body: <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>
  
Comments.ContentLicense: CC BY-SA 3.0
Comments.CreationDate: 2018-04-07T22:36:14.257Z
Comments.Text: 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?
Comments.UserDisplayName: andrew.welch
Comments.ContentLicense: CC BY-SA 3.0
Comments.CreationDate: 2018-04-08T20:05:12.743Z
Comments.Text: 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?
Comments.UserDisplayName: andrew.welch
Comments.ContentLicense: CC BY-SA 3.0
Comments.CreationDate: 2018-04-09T12:59:05.673Z
Comments.Text: @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.
Comments.UserDisplayName: Danielle Frappier
Comments.ContentLicense: CC BY-SA 3.0
Comments.CreationDate: 2018-04-09T16:42:00.167Z
Comments.Text: Oh... maybe you want to check on the `.status` to make sure it's `live` then?
Comments.UserDisplayName: andrew.welch
Tags: <localization><craft3><multi-site>
Title: Struggling with language switcher for Craft 3
ThreadText: # 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 %}
  
              <a href="{{ localizedUrls['url'] }}"> {{ localizedUrls['language'] }}</a>
  
          {% endif %}
  
      {% else %}
  
          <a href="{{ localizedUrls['url'] }}"> {{ localizedUrls['language'] }}</a>
  
      {% 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**: @username_1 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!
  
  ```
          <!-- 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 %}
  
                          <li><a href="{{ entryForOtherSite.getUrl() }}">{{ site.name }}</a></li>
  
                      {% endif %}
  
                  {% endif %}
  
              {% endfor %}
  
          <!-- category -->
          {% 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 %}
  
                      <li><a href="{{ site.baseUrl }}blog/category/{{craft.request.getLastSegment()}}">{{ site.name }}</a></li>
  
                  {% endif %}
  
              {% endfor %}
  
          <!-- index and tags -->
          {% else %}
  
              {% set currentSite = craft.app.sites.currentSite %}
  
              {% set sites = craft.app.sites.getAllSites() %}
  
              {% for site in sites %}
  
                  {% if site.id != currentSite.id %}
  
                      <li><a href="{{ site.baseUrl }}{% for segment in craft.request.getSegments() %}{{segment}}/{% endfor %}">{{ site.name }}</a></li>
  
                  {% 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/  
  
  ---
  
  