Problem/Motivation

On a site with multiple languages, using English as the default, when changing the order of the languages and moving English below another non-default language, this order causes language fallbacks to prioritize order over default status. E.g. English and Chinese Simplified translation exist, when trying to access a non-existent translation via URL prefix, the Chinese Simplified translation is shown instead of the English original source.

Steps to reproduce

  1. Enable Content Translation and Language
  2. Go to/admin/config/regional/language
  3. Add Languages: Chinese, Simplified, Chinese, Traditional, Spanish
  4. Reorder Languages to be alphabetical (Chinese systems first, English, Spanish)
  5. Set English as Default
  6. Go to /admin/config/regional/language/detection
  7. Customize Content language detection to differ from Interface
  8. Enable URL
  9. Configure URL
  10. Add “en” path prefix for English
  11. Go to /admin/structure/taxonomy
  12. Edit Tags vocab and Enable translation
  13. Under Tags, add a couple terms
  14. Translate one term in Chinese, Simplified and change name to differ from source
  15. Go to Tags vocab listing, edit the prefix in the URL from “en” to “es”

Result:
The taxonomy term that has Chinese translation shows the name value from that translation.

Expectation:
I would’ve expected it to use the default language, English. But I assume it’s taking the first value in the existing translations list and displaying it instead? Is this how it’s supposed to work, or does anyone know of a core issue about it?

Proposed resolution

Remaining tasks

User interface changes

API changes

Data model changes

Release notes snippet

Issue fork drupal-3315245

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

brittany.huntzberry created an issue. See original summary.

brittany.huntzberry’s picture

Adding a note, when reordering the Languages so that English is the first one in the list, then the issue is resolved. I'm thinking this is due to getTranslationFromContext, looking for fallbacks and selecting the first valid translation in the list instead of default language.

You can also reproduce the issue with translations on content types like Article, Basic page.

tom verhaeghe’s picture

Assigned: Unassigned » tom verhaeghe

I have encountered this issue myself as well. The default language should be checked first as opposed to the first valid translation the system finds.

tom verhaeghe’s picture

Assigned: tom verhaeghe » Unassigned
Status: Active » Needs review
tom verhaeghe’s picture

Version: 9.4.x-dev » 9.5.x-dev

tom verhaeghe’s picture

Status: Needs review » Needs work

I'm so sorry for the mess, it seems like there is a delay of 2 days between creating a merge request and the MR to appear in this overview. I didn't know, since this is my first go with gitlab merge requests. I made the mistake of creating multiple merge requests and that caused several jobs to run. Eitherway, the last build is the one that should be looked at, and quite a lot of tests fail. I'm unsure if my approach is the good one and i will check this.

dieterholvoet’s picture

Using the MR from this issue, we're getting a bunch of warnings like this:

Warning: Undefined array key "fr" in Drupal\Core\Entity\EntityRepository->getTranslationFromContext()

I'll push a fix to the MR.

Version: 9.5.x-dev » 11.x-dev

Drupal core is moving towards using a “main” branch. As an interim step, a new 11.x branch has been opened, as Drupal.org infrastructure cannot currently fully support a branch named main. New developments and disruptive changes should now be targeted for the 11.x branch. For more information, see the Drupal core minor version schedule and the Allowed changes during the Drupal core release cycle.

Version: 11.x-dev » main

Drupal core is now using the main branch as the primary development branch. New developments and disruptive changes should now be targeted to the main branch.

Read more in the announcement.