Answers.Body: <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>
  
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2019-02-14T13:20:39.747Z
Answers.LastActivityDate: 2019-02-14T13:26:45.523Z
Answers.LastEditDate: 2019-02-14T13:26:45.523Z
Answers.UserDisplayName: Oli
Body: <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>
  
Comments.ContentLicense: CC BY-SA 4.0
Comments.CreationDate: 2019-02-14T12:03:04.337Z
Comments.Text: 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`?
Comments.UserDisplayName: Oli
Comments.ContentLicense: CC BY-SA 4.0
Comments.CreationDate: 2019-02-14T12:13:59.553Z
Comments.Text: I don't get an error, I get re-directed to the homepage (of the language).
  
  Code updated with definition for langSwitcher
Comments.UserDisplayName: sarah3585
Comments.ContentLicense: CC BY-SA 4.0
Comments.CreationDate: 2019-02-14T12:38:39.470Z
Comments.Text: 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?
Comments.UserDisplayName: Oli
Comments.ContentLicense: CC BY-SA 4.0
Comments.CreationDate: 2019-02-14T13:00:08.523Z
Comments.Text: Basically they need to be redirected from http://website.com/membership/directory/1227(en) to http://website.com/ru/membership/directory/1227 (ru)
Comments.UserDisplayName: sarah3585
Tags: <users><localization><multi-site><language>
Title: Language Switcher with Users
ThreadText: # 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() %}
  
  <div class="flag">
   {% 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 %}
  
   <div {% if lang.id == currentSite.id %}class="active"{% endif %}>
    <a href="{{url}}" > <img src="/assets/images/site/flag-{{lang.name|lower}}.svg" alt="{{lang.name|upper}}"></a>
   <p class="small-hide"><a href="{{url}}" >{{lang.name|upper}}</a></p>
   </div>
  
  {% 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 %}
  
  ```
  
  
  ---
  
  