<p>This isn't perfect by any means and might need tweaking but to get you on your way: </p>

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

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

<p>Or if you have set the user:</p>

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

CC BY-SA 4.0
2019-02-14T13:20:39.747Z
2019-02-14T13:26:45.523Z
2019-02-14T13:26:45.523Z
Oli
<p>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?</p>

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

<p></p>

CC BY-SA 4.0
2019-02-14T12:03:04.337Z
Do your directory pages just break? If so, what is the error? You can't translate users so I'm guessing you would still want to translate the UI on directory pages but stay on the current page? What is the definition for `langSwitcher`?
Oli
CC BY-SA 4.0
2019-02-14T12:13:59.553Z
I don't get an error, I get re-directed to the homepage (of the language).

Code updated with definition for langSwitcher
sarah3585
CC BY-SA 4.0
2019-02-14T12:38:39.470Z
So you want all your languages to show in the switcher but when the user chooses to change language, they stay on the user page but the UI around translates? Can you show the format of your url for a directory entry page please?
Oli
CC BY-SA 4.0
2019-02-14T13:00:08.523Z
Basically they need to be redirected from http://website.com/membership/directory/1227(en) to http://website.com/ru/membership/directory/1227 (ru)
sarah3585
<users><localization><multi-site><language>
Language Switcher with Users
# Language Switcher with Users

(Asked by: username_0 on 2019-02-14)

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


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

 
   
 {{lang.name|upper}}
 

{% endfor %}

**Tags:** users, localization, multi-site, language

> **Comments:**
> **username_1**: Do your directory pages just break? If so, what is the error? You can't translate users so I'm guessing you would still want to translate the UI on directory pages but stay on the current page? What is the definition for `langSwitcher`?  
> **username_0**: I don't get an error, I get re-directed to the homepage (of the language).  Code updated with definition for langSwitcher  
> **username_1**: So you want all your languages to show in the switcher but when the user chooses to change language, they stay on the user page but the UI around translates? Can you show the format of your url for a directory entry page please?  
> **username_0**: Basically they need to be redirected from http://website.com/membership/directory/1227(en) to http://website.com/ru/membership/directory/1227 (ru)  

---

## 1 answers

### Answer by username_1 on 2019-02-14. Score: 2 | Accepted answer

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


---

