Problem/Motivation

After saving the language overview form, languages sometimes end up with incorrect name translations.

Steps to reproduce

  1. On an English site, add a Spanish
  2. Visit /en/admin/config/regional/language
  3. See language names are English and Spanish
  4. Visit /es/admin/config/regional/language
  5. Click Save
  6. Visit /en/admin/config/regional/language
  7. See language names are now Inglés and Español.

This affects the language switcher everywhere on the site

Proposed resolution

Load the language entities without overrides before saving them to ensure the untranslated entities are not polluted.

Command icon Show commands

Start within a Git clone of the project using the version control instructions.

Or, if you do not have SSH keys set up on git.drupalcode.org:

Comments

bwaindwain created an issue. See original summary.

bwaindwain’s picture

Status: Active » Needs review
james.williams’s picture

Status: Needs review » Needs work

Oo this could be good, and yes, maybe it could solve #3355174: Native languanges aren't working, thank you! Is there any chance you could provide an automated test for this please, to demonstrate the issue & solution? Have you tried the patch on #3355174: Native languanges aren't working? It's not quite the same but looks to me be solving the same problem (so we shouldn't have both tickets open either). Your merge request does look more promising to me, as it doesn't treat language names as a special case in the config factory override class. (An automated test might also help us understand if that is still needed or not.)

---

Technical notes from my looking into this:

The language overview form is an extension of ConfigEntityListBuilder. That base class uses loadMultipleOverrideFree() in its load() method, but LanguageListBuilder overrides that method to use loadByProperties(['locked' => FALSE]) - so yes, overrides are unhelpfully included, which isn't normally correct for config entities.

bwaindwain’s picture

I've never done a test for Drupal (yet...)

bwaindwain’s picture

Status: Needs work » Needs review

test output before fix:

1) Drupal\Tests\language_hierarchy\Kernel\LanguagesFormSubmitTest::testSubmitHandlerPreservesNames
Failed asserting that two strings are identical.
--- Expected
+++ Actual
@@ @@
-'English'
+'Inglés'

after fix

OK (1 test, 1 assertion)

james.williams’s picture

Congratulations on your first test then, thank you!

The a pipeline in gitlab which runs the tests also has an additional tests-only job; could you run that please to demonstrate it failing for the current code?

I’ll try again myself once I’m at work later, but I think only you have access to run it as it’s your MR. (Though there might be an option you can tick to let others run pipelines.)

james.williams’s picture

Status: Needs review » Fixed

Turns out I did have permission to run that myself, and yep, it proves the bug. Thanks, great work!

Now that this issue is closed, review the contribution record.

As a contributor, attribute any organization that helped you, or if you volunteered your own time.

Maintainers, credit people who helped resolve this issue.

bwaindwain’s picture

Great! Kudos also to gemini and chatgpt for helping me with the test. ;)

Status: Fixed » Closed (fixed)

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