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

Issue fork drupal-3209204

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

TrevorBradley created an issue. See original summary.

trevorbradley’s picture

Issue summary: View changes

Version: 9.2.x-dev » 9.3.x-dev

Drupal 9.2.0-alpha1 will be released the week of May 3, 2021, which means new developments and disruptive changes should now be targeted for the 9.3.x-dev branch. For more information see the Drupal core minor version schedule and the Allowed changes during the Drupal core release cycle.

randalv’s picture

I would like to second this, this is not okay behaviour.

At the very least, we shouldn't throw an exception but show a regular admin page saying the translation already exists, with perhaps a link to the edit page.

randalv’s picture

StatusFileSize
new1.95 KB
randalv’s picture

StatusFileSize
new1.95 KB

Typo in last patch file rendered it unable to apply.

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

Drupal 9.3.0-rc1 was released on November 26, 2021, which means new developments and disruptive changes should now be targeted for the 9.4.x-dev branch. For more information see the Drupal core minor version schedule and the Allowed changes during the Drupal core release cycle.

johnwebdev’s picture

I run into this problem as well, but for menus. I also noticed the behavior depends on which Browser you use.

Preparation:
1. Add a menu

With Chrome browser
2. Add a menu link
3. Translate that menu link
4. Press Back button
5. You end up on the Add translation page
6. Try Save, you will get the error "Invalid translation language specified"

In Edge
2. Add a menu link
3. Translate that menu link
4. Press Back button
5. You will get the Invalid translation language specified

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

Drupal 9.4.0-alpha1 was released on May 6, 2022, which means new developments and disruptive changes should now be targeted for the 9.5.x-dev branch. For more information see the Drupal core minor version schedule and the Allowed changes during the Drupal core release cycle.

mpp’s picture

Status: Active » Needs work

The same error happens when trying to add a translation for menu links e.g. /fr/admin/structure/menu/item/14/edit/translations/add/nl/fr

ikeigenwijs’s picture

we have the same error for untranslated content the node is translated, I saw it in the url,
but is listed as untranslated
just using the add button to add translation

InvalidArgumentException: Invalid translation language (en) specified. in Drupal\Core\Entity\ContentEntityBase->addTranslation() (line 956 of /core/lib/Drupal/Core/Entity/ContentEntityBase.php).

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

Drupal 9.5.0-beta2 and Drupal 10.0.0-beta2 were released on September 29, 2022, which means new developments and disruptive changes should now be targeted for the 10.1.x-dev branch. For more information see the Drupal core minor version schedule and the Allowed changes during the Drupal core release cycle.

DieterHolvoet made their first commit to this issue’s fork.

dieterholvoet’s picture

Status: Needs work » Needs review

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.

smustgrave’s picture

Issue summary: View changes
Status: Needs review » Needs work
Issue tags: +Needs Review Queue Initiative, +Needs tests

Updated remaining tasks section.

Version: 10.1.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, which currently accepts only minor-version allowed changes. For more information, see the Drupal core minor version schedule and the Allowed changes during the Drupal core release cycle.

uridrupal’s picture

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

weseze’s picture

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!

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.

dieterholvoet’s picture

@johnwebdev could you change the MR to target the main branch?

dieterholvoet changed the visibility of the branch 3209204-adding-existing-translation to hidden.

dieterholvoet’s picture

I started a new MR instead.

michaelsoetaert’s picture

StatusFileSize
new2.57 KB

Created patch based on current MR for usage with composer.

andras_szilagyi made their first commit to this issue’s fork.

andras_szilagyi’s picture

Status: Needs work » Needs review

I've added a test and fixed my concerns, in addition the pipeline was failing for unrelated, so I rebased the fork branch now its better but there is still an issue in the main branch, anyway, ready for review.

claudiu.cristea’s picture

Status: Needs review » Reviewed & tested by the community
Issue tags: -Needs tests

I came here after experiencing the same issue, randomly on macOS & Safari. It seems that, in some circumstances, the Mac touchpad is triggering a browser Back. But I've learned that the same error is triggered if, while adding a translation, other user adds the same translation and saves. Then, when you save, will get the same error. This is weird because in such scenario Drupal expected behavior is to invalidate your submission with the "The form has become outdated..."

The fix is simple and is just a defensive check. By patching my codebase I cannot reproduce anymore the bug. It has also tests, so from my POV is RTBC.

claudiu.cristea’s picture

  • catch committed f1e54b02 on 11.4.x
    fix: #3209204 Adding existing translation throws "Invalid translation...

  • catch committed c4638541 on 11.x
    fix: #3209204 Adding existing translation throws "Invalid translation...

  • catch committed e179038b on main
    fix: #3209204 Adding existing translation throws "Invalid translation...
catch’s picture

Version: main » 11.4.x-dev
Status: Reviewed & tested by the community » Fixed

Committed/pushed to main, 11.x and 11.4.x, thanks!

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.

Status: Fixed » Closed (fixed)

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