Adding existing translation throws "Invalid translation language specified"

Created on 16 April 2021, about 4 years ago
Updated 13 March 2024, about 1 year ago

Problem/Motivation

Our QA team just found this one. It's possible for a default D8/9 site to throw an error 500 for content editors with very few steps: Attempt to add a translation that already exists.

Steps to reproduce

Deploy a standard D9.2.x-dev site using git clone https://github.com/drupal-composer/drupal-project.git
Enable Language and Content Translation modules.
Enable French as a second langauge
Modify Basic Page so that it can be translated.
Create a Basic Page in English.
Open Translation page and verify a translation exists in English, but not French.
Middle Click on the Add button for French.
In this new tab, create a French translation of the original content and save.
Close the new tab, and return to the already translation page.
Click "Add" on the French content again (e.g "http://drupal-project.lndo.site/fr/node/1/translations/add/en/fr")

The following error is thrown:

Uncaught PHP Exception InvalidArgumentException: "Invalid translation language (fr) specified." at /app/web/core/lib/Drupal/Core/Entity/ContentEntityBase.php line 955, referer: http://drupal-project.lndo.site/node/1/translations

This can be replicated with any translatable content. Just Add a translation, save it, then go back to the same Add URL.

Proposed resolution

While this is an edge case, it shouldn't be so easy for content editors to produce a PHP error. This should instead be caught and throw and error "This content has already been translated" - or perhaps redirect the user to the existing translated edit page.

Remaining tasks

Update target branch
Add tests
Review
Commit

User interface changes

API changes

Data model changes

Release notes snippet

πŸ› Bug report
Status

Needs work

Version

11.0 πŸ”₯

Component
Language systemΒ  β†’

Last updated about 14 hours ago

  • Maintained by
  • πŸ‡©πŸ‡ͺGermany @sun
Created by

πŸ‡¨πŸ‡¦Canada TrevorBradley

Live updates comments and jobs are added and updated live.
  • Needs tests

    The change is currently missing an automated test that fails when run with the original code, and succeeds when the bug has been fixed.

Sign in to follow issues

Comments & Activities

Not all content is available!

It's likely this issue predates Contrib.social: some issue and comment data are missing.

  • First commit to issue fork.
  • Status changed to Needs review about 2 years ago
  • πŸ‡§πŸ‡ͺBelgium dieterholvoet Brussels

    I changed the MR to redirect to the target translation edit form instead of the translation overview, this seems more user friendly.

    The same error happens when trying to add a translation for menu links

    The MR also fixes the issue for menu links.

  • Status changed to Needs work about 2 years ago
  • πŸ‡ΊπŸ‡ΈUnited States smustgrave

    Updated remaining tasks section.

  • πŸ‡ͺπŸ‡ΈSpain uridrupal

    I have tested and it works. I am not having issues translating block content anymore.

  • πŸ‡§πŸ‡ͺBelgium weseze

    Can confirm this error.
    Some of our content editors are getting stuck in this flow by mass translating in dozens of browser tabs and having some duplicates (already translated nodes) open.
    Very easy to get in to this problem, very hard te understand without technical knowledge why this is a problem...

    MR from DieterHolvoet fixes the issue nicely. Thanks!

Production build 0.71.5 2024