2

I'm trying to add "fa" language in a Drupal 8 installation. I added it from admin/config/regional/language. Everything is OK and the language added successfully and added in language switcher in front-end. But when I click on it, I get this error:

InvalidArgumentException: Invalid translation language (fa) specified. in Drupal\Core\Entity\ContentEntityBase->getTranslation() (line 748 of core/lib/Drupal/Core/Entity/ContentEntityBase.php). 

Note: This is not a clean installation. The Drupal I have is a working site with some modules which I want to add Persian as its 6th language. Any suggestions?

Thanks.

  • This happened for me and was caused by Inline Entity Form for a field using referenced entities. Changing it to Autocomplete fixes it, and Entity Browser should be fine too. (Was attempting to translate from EN->DE, and the field was referencing a FI node with no EN translation.) The next lines in the traceback points the finger at IEF: Drupal\inline_entity_form\TranslationHelper::prepareEntity(Object, Object) (Line: 338) Drupal\inline_entity_form\Plugin\Field\FieldWidget\InlineEntityFormBase->prepareFormState(Object, Object, 1) (Line: 215) Drupal\inline_entity_form\Plugin\Field\Fie... – Hugo Sep 13 '17 at 13:39
  • 1
    Reported to IEF here: drupal.org/node/2908780 – Hugo Sep 14 '17 at 11:26
2

Basically, this error appears when some translation methods like $entity->getTranslation('LANGUAGE_CODE') or $entity->addTranslation('LANGUAGE_CODE') are called and there is no translation of the entity in the specified language.

The solution is to check if the entity hasTranslation using $entity->hasTranslation('fa') before calling the getTranslation or addTranslation like this:

if ($entity->hasTranslation('fa')) {
  $translation = $entity->getTranslation('fa');
}

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.