Problem/Motivation

If "Interface text language detection" sets "Account administration pages" as the primary, a field title isn't translated.

Steps to reproduce:

1. Install Drupal with the standard profile in English.
2. After installation, login as an administrator (uid 1).
3. Enable the following modules: Configuration Translation, Interface Translation, Language.
4. Add Japanese language.
5. On the "Detection and selection" page, enable "Account administration pages" and disable others except the grayed-out "Selected language".
6. Check if a Japanese translation is shown on the "Edit Japanese translation for Picture" page.
7. Change the "Administration pages language" settings from "- No preference -" to "Japanese" on the logged-in user edit page.
8. Go to the logged-in user edit page.
9. Picture field title isn't changed to the Japanese translation. Any other field titles such as "Current Password" and "Roles" are changed to Japanese translation.

I installed Drupal 8.8.x-dev and followed the steps above.
If "Selected language" is set as the primary instead of the "Account administration pages" and Site language settings are changed to the same as the step 7 above, Picture field title is changed to the Japanese translation.

Support from Acquia helps fund testing for Drupal Acquia logo

Comments

Tom Konda created an issue. See original summary.

tetranz’s picture

I can reproduce the problem.

tetranz’s picture

I think I see the problem. I should have a patch tomorrow.

tetranz’s picture

I spoke too soon on this. It didn't quite work out as I expected. I will get back to it as time permits.

I think it is somewhat related to this: https://www.drupal.org/project/drupal/issues/2189267

On earlier versions (I think before that patch) it worked except that the first GET of the profile form (i.e., the redirect after form submit) did not detect language properly. The next GET (i.e., a refresh) did work.

Now on 8.8, it doesn't work at all. I think this only affects bundle fields, not base fields.

Berdir’s picture

Does this happen only with user entities or can you reproduce the same for example with the body field on nodes?

Interestingly, the static cache in \Drupal\Core\Entity\EntityFieldManager::getFieldDefinitions() does not depend on the language, but the persistent one does. You could try to add another key for the language code there, could be that the field definitions are loaded before language negotiation and then ignore the language change.

tetranz’s picture

Status: Active » Needs review
FileSize
1.81 KB

@bendir It only happens with the user entity.

This patch with your suggestion fixes it.

The issue is related to how the language negotiation happens recursively when rendering the user. It tries to get the language but as part of that it needs to access the current user to get the admin language setting. I haven't really followed it all but it gets field config for the default language first. The extra key in the static cache separates them.

I know it would be nice to have a test for this. I guess we could add user as a special case to ConfigurableLanguageManagerTest. Unfortunately I can't seem to get that test to pass unchanged on my local environment so ... I may not get that that.

Tom Konda’s picture

Thanks @tetranz for your work.
Patch #6 works for me.

tetranz’s picture

Here's a test only patch, without the fix. This should fail.

I'll wait for this result and post a combined test and fix.

There is something a little weird happening with the two existing tests in ConfigurableLanguageManagerTest. They fail on my local environment (Vagrant, basically DrupalVM). I can "fix" that by adding drupal_flush_all_caches(); before the Spanish GETs. The drupal.org testbot obviously doesn't need that so I haven't included it but I don't know why I need that on my local environment.

Status: Needs review » Needs work

The last submitted patch, 8: translate-by-admin-3048196-8.patch, failed testing. View results

tetranz’s picture

tetranz’s picture

Status: Needs work » Needs review
amateescu’s picture

Version: 8.8.x-dev » 8.7.x-dev
Status: Needs review » Reviewed & tested by the community

This looks great to me! Since the change is only affecting the static cache of the field definitions, we don't need an update function.

Status: Reviewed & tested by the community » Needs work

The last submitted patch, 10: translate-by-admin-3048196-10.patch, failed testing. View results

Berdir’s picture

Status: Needs work » Reviewed & tested by the community

Status: Reviewed & tested by the community » Needs work

The last submitted patch, 10: translate-by-admin-3048196-10.patch, failed testing. View results

Berdir’s picture

Component: language system » entity system
Status: Needs work » Reviewed & tested by the community

Another random fail.

alexpott’s picture

Status: Reviewed & tested by the community » Fixed

Crediting @Tom Konda for filing the issue with great instructions on our to reproduce the bug and @Berdir for coming up with the fix.

I ran the new test locally without the fix and can confirm it fixes the patch.

Committed and pushed d9519bae25 to 8.8.x and 9940ccf048 to 8.7.x. Thanks!

  • alexpott committed d9519ba on 8.8.x
    Issue #3048196 by tetranz, Tom Konda, Berdir: A field title isn't...

  • alexpott committed 9940ccf on 8.7.x
    Issue #3048196 by tetranz, Tom Konda, Berdir: A field title isn't...

Status: Fixed » Closed (fixed)

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