Language Switcher with Users I have the following setup for a language switcher. I have Member Directory pages which are using Users (rather than Entires or Categories). How can I update this to get it working on these pages?

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

&lt;div class="flag"&gt;
 {% for lang in langSwitcher %}
 {# Set homepage as default #}
 {% set url = alias(lang.baseUrl) %}

 {# Entry is defined #}
 {% if entry is defined %}
  {# Check if that entry exists in other locale #}
  {% set otherLocaleEntry = craft.entries.siteId(lang.id).id(entry.id).one() %}
  {% if otherLocaleEntry %}
    {% set url = otherLocaleEntry.url %}
  {% endif %}

{# Category is defined #}
{% elseif category is defined %}
  {# Check if that entry exists in other locale #}
  {% set otherLocaleCat = craft.categories.siteId(lang.id).id(category.id).one() %}
  {% if otherLocaleCat %}
    {% set url = otherLocaleCat.url %}
  {% endif %}
{% endif %}

 &lt;div {% if lang.id == currentSite.id %}class="active"{% endif %}&gt;
  &lt;a href="{{url}}" &gt; &lt;img src="/assets/images/site/flag-{{lang.name|lower}}.svg" alt="{{lang.name|upper}}"&gt;&lt;/a&gt;
 &lt;p class="small-hide"&gt;&lt;a href="{{url}}" &gt;{{lang.name|upper}}&lt;/a&gt;&lt;/p&gt;
 &lt;/div&gt;

{% endfor %}
This isn't perfect by any means and might need tweaking but to get you on your way: 

Assuming that on a user page, you are doing {% set user = ... %} somewhere (as you would do {% set entry = ... %} on an entry page), You just add another clause to your if statement, after checking for category, you check for user:

{# User is defined #}
{% elseif user is defined %}
  {% set url = lang.baseUrl ~ 'membership/directory/' ~ craft.app.request.segments|last %}
{% endif %}


Or if you have set the user:

{# User is defined #}
{% elseif user is defined %}
  {% set url = lang.baseUrl ~ 'membership/directory/' ~ user.id %}
{% endif %}