2

I am building a multi-language site in a multi-users environment. For each user I want to assign several text fields that should be translatable for each language, similarly like in entries/categories etc.

But it seems that even if a field should be translatable for each language, in the user profile's tab where the relevant fields are, there is no possibility to switch between the different languages (sites).

What would be a good workaround for this limitation?

1 Answer 1

2

User fields are not translatable by design, see this question:

You're not missing anything; user content is currently not translatable. (It's up to each type of element whether it wants to support translatable content, and we felt that 99% of the time it would not be desirable for users to have translatable profiles.

There's a discussion thread on Github asking for translatable user fields – if you care about this feature, upvote it on Github so it gets some visibility.


As a workaround, move the user fields that need translating out of the user account and into a section. For example, you can create a section userProfiles and automatically create a new entry in that section for each newly created user account. Assign the new user account as the author of that entry. Then give that user group permission to edit their own entries in that section, but not create new entries or edit other's entries.

This way, the user profile can be translated. Anywhere you want to display the user's profile, simply query for the userProfile element:

{% set userProfile = craft.entries()
    .section('userProfile')
    .authorId(user.id)
    .one()
%}

If your users only interact with frontend forms, this doesn't change a whole lot. You can just build a profile form that posts to the entries/save-entry controller action. If you need to allow users to edit both 'native' user fields and their profile in a single form, you could use a custom controller endpoint or use JavaScript to split the form submission into two requests that call the respective endpoints.

If your users have access to the Control Panel, you might want to provide easy ways for them to find their profile entry. For example:

  • Create a custom widget showing the current user profile with a link to edit it (that goes directly to the entry edit page for the profile).
  • Use Template Hooks to include a link to the user profile on the user edit page. In this case, cp.users.edit.content would be a good place to put this.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.