protected function createTranslatedInstance(FieldItemInterface $item, $langcode) {

    // Remove the untranslated item that was created for the default language
    // by FieldNormalizer::denormalize().
    $items = $item->getParent();
    $delta = $item->getName();
    unset($items[$delta]);

    // Instead, create a new item for the entity in the requested language.
    $entity = $item->getEntity();
    $entity_translation = $entity->hasTranslation($langcode) ? $entity->getTranslation($langcode) : $entity->addTranslation($langcode);
    $field_name = $item->getFieldDefinition()->getName();
    return $entity_translation->get($field_name)->appendItem();
  }
protected function createTranslatedInstance(FieldItemInterface $item, $langcode) {

    // Remove the untranslated item that was created for the default language
    // by FieldNormalizer::denormalize().
    $items = $item->getParent();
    $delta = $item->getName();
    unset($items[$delta]);

    // Instead, create a new item for the entity in the requested language.
    $entity = $item->getEntity();
    $entity_translation = $entity->hasTranslation($langcode) ? $entity->getTranslation($langcode) : $entity->addTranslation($langcode);
    $field_name = $item->getFieldDefinition()->getName();
    return $entity_translation->get($field_name)->appendItem();
  }
protected function createTranslatedInstance ( FieldItemInterface $ item , $ langcode ) { // Remove the untranslated item that was created for the default language // by FieldNormalizer::denormalize(). $ items = $ item -> getParent ( ) ; $ delta = $ item -> getName ( ) ; unset ( $ items [ $ delta ] ) ; // Instead, create a new item for the entity in the requested language. $ entity = $ item -> getEntity ( ) ; $ entity_translation = $ entity -> hasTranslation ( $ langcode ) ? $ entity -> getTranslation ( $ langcode ) : $ entity -> addTranslation ( $ langcode ) ; $ field_name = $ item -> getFieldDefinition ( ) -> getName ( ) ; return $ entity_translation -> get ( $ field_name ) -> appendItem ( ) ; }
Get a translated version of the field item instance.

To indicate that a field item applies to one translation of an entity and
not another, the property path must originate with a translation of the
entity. This is the reason for using target_instances, from which the
property path can be traversed up to the root.

@param \Drupal\Core\Field\FieldItemInterface $item
The untranslated field item instance.
@param string $langcode
The langcode.

@return \Drupal\Core\Field\FieldItemInterface
The translated field item instance.
Get a translated version of the field item instance .