/**
  * Find the translation and translate the template if translation is found.
  *
  * @param LayoutInterface|MailInterface $template The template
  * @param string                        $locale   The locale
  *
  * @return bool
  */
 public static function find($template, $locale)
 {
     $locale = strtolower($locale);
     foreach ($template->getTranslations() as $translation) {
         if ($locale === strtolower($translation->getLocale())) {
             static::injectValue($template, $translation, 'label');
             static::injectValue($template, $translation, 'description');
             static::injectValue($template, $translation, 'body');
             static::injectFile($template, $translation);
             if ($template instanceof MailInterface) {
                 static::injectValue($template, $translation, 'subject');
                 static::injectValue($template, $translation, 'htmlBody');
             }
             return true;
         }
     }
     return false;
 }
 /**
  * Render the template.
  *
  * @param string                        $template         The template string
  * @param LayoutInterface|MailInterface $templateInstance The template instance
  * @param array                         $variables        The variables of template
  *
  * @return string The rendered template
  *
  * @throws \Exception
  */
 protected function renderTemplate($template, $templateInstance, array $variables = array())
 {
     if (null !== $template) {
         if ($templateInstance instanceof TwigTemplateInterface) {
             $tpl = $this->renderer->loadTemplate($templateInstance->getFile());
             if ($tpl instanceof \Twig_Template) {
                 $template = $tpl->renderBlock($template, $variables);
                 $template = '' === $template ? null : $template;
             }
         } else {
             $tpl = $this->renderer->createTemplate($template);
             $template = $tpl->render($variables);
         }
     }
     return $template;
 }
 /**
  * Add the layout template.
  *
  * @param LayoutInterface $layout The layout template
  */
 public function addLayout(LayoutInterface $layout)
 {
     $this->layouts[$layout->getName()] = $layout;
 }