Problem/Motivation

User should be able to translate the profile.

Proposed resolution

Make Profile entity translatable

Remaining tasks

Review and discussion.

User interface changes

User will be able translate the profile

API changes

Profile entity will have a revision data table as well to store the translation of the revision.

Data model changes

Profile entity will properly utilize the field data table.

Support from Acquia helps fund testing for Drupal Acquia logo

Comments

jibran’s picture

Here is a WIP patch.

bojanz’s picture

Status: Needs review » Active

I explicitly removed translatability for two reasons:

1) Translating profiles doesn't make a lot of sense.
Your name, address, gender don't change between languages.

2) It would be very hard to provide decent UX.
Our entity translation UIs cover the admin use case, there's no UI designed to be used by the end-user in the non-admin theme.
Your patch provides no UI either, we'd need a translate tab, an edit form, the ability to view different translations... All for a very non-defined use case.

Your revisioning changes make sense, please provide another issue for that.

jibran’s picture

Status: Active » Closed (won't fix)

I was working on https://github.com/bojanz/profile/pull/23 and I realized EntityViewData doesn't use field data table if entity is not translatable so I think about making profile translatable.
After discussion on IRC @bojanz agrees to remove profile_field_data because it is only used for storing the translations. I'll create a follow up issue for that.

jefuri’s picture

Category: Task » Bug report
Priority: Normal » Major

Sorry to reopen this. But why is there a langcode in the entity if it is not translatable? I experience issues because of it because the entity takes the active language of the visitor into regard when rendering an entity with a different language. Resulting in fields not showing because the language does not match.

bojanz’s picture

Status: Closed (won't fix) » Needs work
mglaman’s picture

Title: Make Profile entity translatable » Remove langcode entity key

Updating. We can remove the leftover entity key.

  • mglaman committed 0c864b3 on 8.x-1.x
    Issue #2634230 by jibran, mglaman: Remove langcode entity key
    
mglaman’s picture

Status: Needs work » Fixed
steveoriol’s picture

FileSize
15.86 KB

Hello,
After Updating drupal/profile (1.0.0-alpha5 => 1.0.0-alpha6)
I get this error...
error

and after

drush entity-updates
The following updates are pending:

profile entity type : 
  The Language field needs to be uninstalled.
Do you wish to run all pending updates? (y/n): y
Drupal\Core\Entity\Exception\FieldStorageDefinitionUpdateForbiddenException: Unable to delete a field (langcode in profile entity) with data that cannot be       [error]
purged. in Drupal\Core\Entity\Sql\SqlContentEntityStorageSchema->onFieldStorageDefinitionDelete() (line 419 of
/home/sites/KEY2/web/core/lib/Drupal/Core/Entity/Sql/SqlContentEntityStorageSchema.php).
Failed: Drupal\Core\Entity\Exception\FieldStorageDefinitionUpdateForbiddenException: !message in                                                                  [error]
Drupal\Core\Entity\Sql\SqlContentEntityStorageSchema->onFieldStorageDefinitionDelete() (line 419 of
/home/sites/KEY2/web/core/lib/Drupal/Core/Entity/Sql/SqlContentEntityStorageSchema.php).
mglaman’s picture

Status: Fixed » Needs work

Argh, yeah. Forgot the need for an update hook.

mglaman’s picture

Status: Needs work » Needs review
FileSize
1.74 KB

Here is an upgrade patch to fix errors

jibran’s picture

Status: Needs review » Needs work
  1. +++ b/profile.install
    @@ -0,0 +1,55 @@
    +    $profile->get('langcode')->setValue(NULL);
    

    This should be done using query.

  2. +++ b/profile.install
    @@ -0,0 +1,55 @@
    +  $sandbox['#finished'] = empty($sandbox['max']) ? 1 : ($sandbox['current'] / $sandbox['max']);
    

    All the code above this line should be in separate update hook.

mglaman’s picture

Status: Needs work » Needs review
FileSize
1.45 KB

That last patch didn't work. Here is a different approach which just using direct SQL queries to set `langcode` to NULL so that the entity definition updater will delete the field. Does not use sandbox as we cannot load the profile and set to NULL.

mglaman’s picture

I've run #13 against all of my Drupal Commerce test sites, and a local production version of a client's site. It seems to be working fine. The biggest issue is that the field original spec says not null: TRUE, so we have to alter schema.

jibran’s picture

Status: Needs review » Reviewed & tested by the community

I added new tests to the patch. I don't know those will pass or not but changes looks good to me. Thanks for the fixes.

czigor’s picture

I applied the patch and ran the updates successfully. I could still open my existing profiles for view and edit. The {profile} and {profile_revision} tables have no more langcode column. So it looks good to me.

finne’s picture

I could not get it to work on my installation because the langcode field cannot be null.

Attached a patch that
- alters schema to allow null
- sets the field to null
- removes the field.

Using this version of profile.install I got my installation working again. Probably overlaps with the earlier patches - ymmv.

UPDATE: patch is almost identical to #13 - that should probably work too.

skyredwang’s picture

after updating to latest commerce and profile, site status shows "Profile: The Language field needs to be uninstalled.". Then, apply #13 patch, it fixed the problem.

czigor’s picture

@finne Which patch were you using? #13 already includes allowing NULL for langcode.
Ah ok, just saw your update.

finne’s picture

@czigor: It did not work when I updated Profile to the latest dev and did a drush entup. Then I created my own patch (#17) at about the same time as #13 was created. Got confused/did not check. They differ slightly in how they get their langcode definition when removing. But I think both work.
+1 on RTBC

agoradesign’s picture

@finne: does that mean, you can verify that it works also, when the langcode field was already removed? I only had a quick look at the patch and thought "hopefully this works, when the field is already gone", but haven't tried it

mglaman’s picture

Here's an updated patch which combines #13 and #17. Mostly checks if field exists, and if storage definition exists.

finne’s picture

@agoradesign: patch #22 has checks if the field exists, so that should work. I did not test it yet.

  • mglaman committed e6034a1 on 8.x-1.x
    Issue #2634230 by mglaman, jibran, finne, steveoriol, czigor, jefuri,...
mglaman’s picture

Status: Reviewed & tested by the community » Fixed

Thanks, everyone. Committed the fix and tagging new alpha.

Status: Fixed » Closed (fixed)

Automatically closed - issue fixed for 2 weeks with no activity.

bairlangga’s picture

Hi All, sorry for being newbie and jumping questions, please bear with me.

I've tried the patch #22, #17, #13 and have the profile.install file patched accordingly by first deleting the file and run the git apply command. All no avail, the error still persists. All cache clearance and cron jobs had been done.

However I must inform you that I encountered this when adding new user in Distro Open Social, running profile-8.x-1.0-alpha7. But I reckon this is module related issue, not distro issue. CMIIW.

minorOffense’s picture

Sorry I need to chime in here. Translatable user profiles makes sense in a lot of use cases. One specifically we have with a client right now is with their "Author" profile on the blog section. We store their name, department and a short bio about them (which individual users manage). These fields are displayed in english and french depending on the language of the site user.

Another example would be if you had a shipping profile where shipments needed to be sent to different locations depending on their language. You could have different instructions or shipment details (e.g. different attention field instructions).

Or if you had a "display email" field on your user profile. Some organizations have different domains for each language and you'd want to show the right domain email for the right language (e.g. info@healthpartners.ca vs info@partenairesante.ca).

Basically any site that requires information to be available in multiple languages would pretty much require user profiles to be translatable. And that's a big list of sites (e.g every canadian federal, provincial or municipal government site). It should work and translate like anything else in Drupal.

hexabinaer’s picture

To have the discussion in one place: I fully agree with minorOffense. Please have in mind that we're not only talking about translating from one language to another (bio, info about the author) but also translating from one alphabet to another. For the latter users should be able to transliterate their name, address e. g. from Arabic or Hebrew to Latin.

Furthermore, the UI should not be an excuse. We already have UI solutions for content translation ;-)

Deliberately not making profiles translatable feels odd to me in terms of international adaption and inclusion.

Acknowledging that this issue is closed and there is already an issue for this topic, I just wanted to add my arguments for the big picture. Sorry for the interruption.
https://www.drupal.org/project/profile/issues/2899744