src/Normalizer/FieldNormalizer.php
public function normalize($field, $format = NULL, array $context = []) {

    $normalized_field_items = [];

    // Get the field definition.
    $entity = $field->getEntity();
    $field_name = $field->getName();
    $field_definition = $field->getFieldDefinition();

    // If this field is not translatable, it can simply be normalized without
    // separating it into different translations.
    if (!$field_definition->isTranslatable()) {
      $normalized_field_items = $this->normalizeFieldItems($field, $format, $context);
    }
    // Otherwise, the languages have to be extracted from the entity and passed
    // in to the field item normalizer in the context. The langcode is appended
    // to the field item values.
    else {
      foreach ($entity->getTranslationLanguages() as $language) {
        $context['langcode'] = $language->getId();
        $translation = $entity->getTranslation($language->getId());
        $translated_field = $translation->get($field_name);
        $normalized_field_items = array_merge($normalized_field_items, $this->normalizeFieldItems($translated_field, $format, $context));
      }
    }

    $normalized = NestedArray::mergeDeepArray($normalized_field_items);
    // I'm really not sure if this is the best approach
    // but in my defense, it works.
    if (!isset($normalized['@graph'])) {
      $normalized_in_context['@graph'][$context['current_entity_id']] = $normalized;
    }
    else {
      $normalized_in_context = $normalized;
    }
    return $normalized_in_context;
  }
public function normalize($field, $format = NULL, array $context = []) {

    $normalized_field_items = [];

    // Get the field definition.
    $entity = $field->getEntity();
    $field_name = $field->getName();
    $field_definition = $field->getFieldDefinition();

    // If this field is not translatable, it can simply be normalized without
    // separating it into different translations.
    if (!$field_definition->isTranslatable()) {
      $normalized_field_items = $this->normalizeFieldItems($field, $format, $context);
    }
    // Otherwise, the languages have to be extracted from the entity and passed
    // in to the field item normalizer in the context. The langcode is appended
    // to the field item values.
    else {
      foreach ($entity->getTranslationLanguages() as $language) {
        $context['langcode'] = $language->getId();
        $translation = $entity->getTranslation($language->getId());
        $translated_field = $translation->get($field_name);
        $normalized_field_items = array_merge($normalized_field_items, $this->normalizeFieldItems($translated_field, $format, $context));
      }
    }

    $normalized = NestedArray::mergeDeepArray($normalized_field_items);
    // I'm really not sure if this is the best approach
    // but in my defense, it works.
    if (!isset($normalized['@graph'])) {
      $normalized_in_context['@graph'][$context['current_entity_id']] = $normalized;
    }
    else {
      $normalized_in_context = $normalized;
    }
    return $normalized_in_context;
  }
{@inheritdoc}