Language Switcher with Users
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 %}