/**
  * Implements Drupal\Component\Gettext\PoMetadataInterface::setHeader().
  *
  * Sets the header and configure Drupal accordingly.
  *
  * Before being able to process the given header we need to know in what
  * context this database write is done. For this the options must be set.
  *
  * A langcode is required to set the current header's PluralForm.
  *
  * @param \Drupal\Component\Gettext\PoHeader $header
  *   Header metadata.
  *
  * @throws Exception
  */
 public function setHeader(PoHeader $header)
 {
     $this->header = $header;
     $locale_plurals = \Drupal::state()->get('locale.translation.plurals') ?: array();
     // Check for options.
     $options = $this->getOptions();
     if (empty($options)) {
         throw new \Exception('Options should be set before assigning a PoHeader.');
     }
     $overwrite_options = $options['overwrite_options'];
     // Check for langcode.
     $langcode = $this->langcode;
     if (empty($langcode)) {
         throw new \Exception('Langcode should be set before assigning a PoHeader.');
     }
     if (array_sum($overwrite_options) || empty($locale_plurals[$langcode]['plurals'])) {
         // Get and store the plural formula if available.
         $plural = $header->getPluralForms();
         if (isset($plural) && ($p = $header->parsePluralForms($plural))) {
             list($nplurals, $formula) = $p;
             $locale_plurals[$langcode] = array('plurals' => $nplurals, 'formula' => $formula);
             \Drupal::state()->set('locale.translation.plurals', $locale_plurals);
         }
     }
 }