Problem/Motivation
An exception is thrown on changing Site language
setting of a user under /user/<uid>/edit
if that user account is already translated to that target language.
Steps to reproduce:
- Install Drupal standard profile in default English language.
- Enable Language, Content Translation and Interface Translation modules.
- Add Language e.g. Hindi under /admin/config/regional/language.
- Enable translation for user accounts by checking Enable translation under admin/config/people/accounts.
- Translate user account to enabled language in step 3. In this case, Add Hindi translation at user/1/translations
- Now change Site language setting for user at user/1/edit. In this case, change it to Hindi. An uncaught exception will be thrown (mentioned below).
- If the translation of user account is not added (step 5) then you can change the Site language setting of the user. You can delete the translation added in step 5, now you can change the Site language of the user.
Error thrown:Uncaught PHP Exception InvalidArgumentException: "A translation already exists for the specified language (hi)." at core/lib/Drupal/Core/Entity/ContentEntityBase.php line 810
Proposed resolution
Added a check on syncing user entity language and user preferred language only when a user registers, but not when updating / translating the user.