Getting the below error when comparing revisions: Invalid translation language (en) specified. in Drupal\Core\Entity\ContentEntityBase->getTranslation() (line 905 of core/lib/Drupal/Core/Entity/ContentEntityBase.php).

Created on 25 October 2024, about 2 months ago

Problem/Motivation

Getting the below error when comparing revisions
InvalidArgumentException: Invalid translation language (en) specified. in Drupal\Core\Entity\ContentEntityBase->getTranslation() (line 905 of core/lib/Drupal/Core/Entity/ContentEntityBase.php).

This InvalidArgumentException error in getTranslation() suggests that the $langcode (in this case, en) may not be a valid translation for one or both of the entity revisions being compared.

Steps to reproduce

Go to a revision page like "/node/43151/revisions"
Click on "Compare Select Revisions". It will take to /node/43151/revisions/view/103781/725016/split_fields

Below error will show.
InvalidArgumentException: Invalid translation language (en) specified. in Drupal\Core\Entity\ContentEntityBase->getTranslation() (line 905 of core/lib/Drupal/Core/Entity/ContentEntityBase.php).

Proposed resolution

Check for Translation Existence Before Calling getTranslation(): Before attempting to fetch translations , use hasTranslation() to ensure the specified language is available.

Implement a Fallback for Missing Translations: If the translation doesnโ€™t exist, you can fall back to the default language.

Remaining tasks

User interface changes

API changes

Data model changes

๐Ÿ› Bug report
Status

Active

Version

1.8

Component

Code

Created by

๐Ÿ‡ฎ๐Ÿ‡ณIndia ashraf.hussain Bangalore

Live updates comments and jobs are added and updated live.
Sign in to follow issues

Comments & Activities

Production build 0.71.5 2024