/**
  * @param EmailModel $emailModel
  * @param EmailTemplate $template
  * @param Email $email
  */
 protected function applyTemplate(EmailModel $emailModel, EmailTemplate $template, Email $email)
 {
     $locales = array_merge($email->getAcceptedLocales(), [$this->defaultLocale]);
     $flippedLocales = array_flip($locales);
     $translatedSubjects = [];
     $translatedContents = [];
     foreach ($template->getTranslations() as $translation) {
         switch ($translation->getField()) {
             case 'content':
                 $translatedContents[$translation->getLocale()] = $translation->getContent();
                 break;
             case 'subject':
                 $translatedSubjects[$translation->getLocale()] = $translation->getContent();
                 break;
         }
     }
     $comparator = ArrayUtil::createOrderedComparator($flippedLocales);
     uksort($translatedSubjects, $comparator);
     uksort($translatedContents, $comparator);
     $validContents = array_intersect_key($translatedContents, $flippedLocales);
     $validsubjects = array_intersect_key($translatedSubjects, $flippedLocales);
     $content = reset($validContents);
     $subject = reset($validsubjects);
     $emailModel->setSubject($subject === false ? $template->getSubject() : $subject)->setBody($content === false ? $template->getContent() : $content)->setType($template->getType());
 }