当前位置: 首页>>代码示例>>PHP>>正文


PHP Translator::setLocale方法代码示例

本文整理汇总了PHP中Symfony\Bundle\FrameworkBundle\Translation\Translator::setLocale方法的典型用法代码示例。如果您正苦于以下问题:PHP Translator::setLocale方法的具体用法?PHP Translator::setLocale怎么用?PHP Translator::setLocale使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Symfony\Bundle\FrameworkBundle\Translation\Translator的用法示例。


在下文中一共展示了Translator::setLocale方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。

示例1: sendEmail

 /**
  * (non-PHPdoc)
  * @see Azine\EmailBundle\Services.TemplateTwigSwiftMailerInterface::sendEmail()
  * @param array $failedRecipients
  * @param string $subject
  * @param String $from
  * @param String $fromName
  * @param array|String $to
  * @param String $toName
  * @param array|String $cc
  * @param String $ccName
  * @param array|String $bcc
  * @param String $bccName
  * @param $replyTo
  * @param $replyToName
  * @param array $params
  * @param $template
  * @param array $attachments
  * @param null $emailLocale
  * @param \Swift_Message $message
  * @return int
  */
 public function sendEmail(&$failedRecipients, $subject, $from, $fromName, $to, $toName, $cc, $ccName, $bcc, $bccName, $replyTo, $replyToName, array $params, $template, $attachments = array(), $emailLocale = null, \Swift_Message &$message = null)
 {
     // create the message
     if ($message == null) {
         $message = \Swift_Message::newInstance();
     }
     $message->setSubject($subject);
     // set the from-Name & -Emali to the default ones if not given
     if ($from == null) {
         $from = $this->noReplyEmail;
     }
     if ($fromName == null) {
         $fromName = $this->noReplyName;
     }
     // add the from-email for the footer-text
     if (!array_key_exists('fromEmail', $params)) {
         $params['sendMailAccountName'] = $this->noReplyName;
         $params['sendMailAccountAddress'] = $this->noReplyEmail;
     }
     // get the baseTemplate. => templateId without the ending.
     $templateBaseId = substr($template, 0, strrpos($template, ".", -6));
     // check if this email should be stored for web-view
     if ($this->templateProvider->saveWebViewFor($templateBaseId)) {
         // keep a copy of the vars for the web-view
         $webViewParams = $params;
         // add the web-view token
         $params[$this->templateProvider->getWebViewTokenId()] = SentEmail::getNewToken();
     } else {
         $webViewParams = array();
     }
     // recursively add all template-variables for the wrapper-templates and contentItems
     $params = $this->templateProvider->addTemplateVariablesFor($templateBaseId, $params);
     // recursively attach all messages in the array
     $this->embedImages($message, $params);
     // change the locale for the email-recipients
     if ($emailLocale !== null && strlen($emailLocale) > 0) {
         $currentUserLocale = $this->translator->getLocale();
         // change the router-context locale
         $this->routerContext->setParameter("_locale", $emailLocale);
         // change the translator locale
         $this->translator->setLocale($emailLocale);
     } else {
         $emailLocale = $this->translator->getLocale();
     }
     // recursively add snippets for the wrapper-templates and contentItems
     $params = $this->templateProvider->addTemplateSnippetsWithImagesFor($templateBaseId, $params, $emailLocale);
     // add the emailLocale (used for web-view)
     $params['emailLocale'] = $emailLocale;
     // render the email parts
     $twigTemplate = $this->loadTemplate($template);
     $textBody = $twigTemplate->renderBlock('body_text', $params);
     $message->addPart($textBody, 'text/plain');
     $htmlBody = $twigTemplate->renderBlock('body_html', $params);
     $campaignParams = $this->templateProvider->getCampaignParamsFor($templateBaseId, $params);
     if (sizeof($campaignParams) > 0) {
         $htmlBody = $this->emailTwigExtension->addCampaignParamsToAllUrls($htmlBody, $campaignParams);
     }
     // if email-tracking is enabled
     if ($this->emailOpenTrackingCodeBuilder) {
         // add an image at the end of the html tag with the tracking-params to track email-opens
         $imgTrackingCode = $this->emailOpenTrackingCodeBuilder->getTrackingImgCode($templateBaseId, $campaignParams, $params, $message->getId(), $to, $cc, $bcc);
         if ($imgTrackingCode && strlen($imgTrackingCode) > 0) {
             $htmlCloseTagPosition = strpos($htmlBody, "</body>");
             $htmlBody = substr_replace($htmlBody, $imgTrackingCode, $htmlCloseTagPosition, 0);
         }
     }
     $message->setBody($htmlBody, 'text/html');
     // remove unused/unreferenced embeded items from the message
     $message = $this->removeUnreferecedEmbededItemsFromMessage($message, $params, $htmlBody);
     // change the locale back to the users locale
     if (isset($currentUserLocale) && $currentUserLocale != null) {
         $this->routerContext->setParameter("_locale", $currentUserLocale);
         $this->translator->setLocale($currentUserLocale);
     }
     // add attachments
     foreach ($attachments as $fileName => $file) {
         // add attachment from existing file
         if (is_string($file)) {
//.........这里部分代码省略.........
开发者ID:azine,项目名称:email-bundle,代码行数:101,代码来源:AzineTwigSwiftMailer.php


注:本文中的Symfony\Bundle\FrameworkBundle\Translation\Translator::setLocale方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。