大家好)我有TYPO3版本7.6.18,并且在我的流动邮件模板中翻译不起作用。 这是我的控制器中的代码,用于呈现邮件模板:
$emailView = $this->objectManager->get('TYPO3\\CMS\\Fluid\\View\\StandaloneView');
$ext_path = \TYPO3\CMS\Core\Utility\ExtensionManagementUtility::extPath("feusersplus");
$templatePathAndFilename = $ext_path.'Resources/Private/Mail/Admin/updateInfo.html';
$emailView->setTemplatePathAndFilename($templatePathAndFilename);
$emailView->assignMultiple(
array(
'hash' => $hash,
'userDetailPid' => $userDetailPid,
'userUid' => $user->getUid(),
'username' => $user->getUsername(),
'image' => $userValues['image'],
'aboutmyself' => $userValues['aboutmyself'],
'aboutmypartner' => $userValues['aboutmypartner'],
'aboutmyselfSeconduser' => $this->pluginVariables['aboutmyselfSeconduser'],
'aboutmypartnerSeconduser' => $this->pluginVariables['aboutmypartnerSeconduser'],
'imprint' => $this->extConf['address'],
'backgroundimage' => $up->getBackgroundimage(),
'uploadFolder' => FileUtility::getUploadFolderFromTca()
)
);
$emailBody = $emailView->render();
$message = $this->objectManager->get('TYPO3\\CMS\\Core\\Mail\\MailMessage');
$message->setTo($adminemail)
->setFrom(array($adminemail => $this->extConf['mailtitle']))
->setSubject( \TYPO3\CMS\Extbase\Utility\LocalizationUtility::translate('request_to_update_profile', 'feusersplus'));
$message->setBody($emailBody, 'text/html');
$message->send();
这是流体的一小部分
<table class="twelve columns">
<tr>
<td><h1><f:translate key='want_to_update_profile_information'/></h1></td>
</tr>
<tr>
<td><p><f:translate key='user'/> {username} <f:translate key='want_to_update_profile_information'/><br>
<f:translate key='image'/>: {image} <br>
<img src="http://abenteuertreff.ihr-layout.eu/fileadmin/files/Avatars/{image}" width="30%" height="auto"/><br>
<f:translate key='backgroundimage'/>: <br>
<f:image image="{backgroundimage}" absolute="true"/><br>
<br>
</p>
<p> </p>
<p><f:translate key='about_myself'/>: {aboutmyself} <br>
<f:translate key='about_my_partner'/>: {aboutmypartner} <br>
<f:translate key='about_myself'/> (<f:translate key='second_user'/>): {aboutmyselfSeconduser} <br>
<f:translate key='about_my_partner'/> (<f:translate key='second_user'/>): {aboutmypartnerSeconduser}</p>
<p> </p>
<f:link.action pageUid="{userDetailPid}" absolute="true" arguments="{showUid: userUid}" additionalParams="{updateHash: hash}" extensionName="feuserfriends" pluginName="userlist" controller="Friend">
<f:translate key='accept'/> accept
</f:link.action>
<br />
<br />
<hr />
</td>
</tr>
</table>
请帮帮我)
答案 0 :(得分:2)
$emailView->getRequest()->setPluginName($requestPluginName);
$emailView->getRequest()->setControllerExtensionName($requestControllerExtensionName);
$emailView->getRequest()->setControllerName($requestControllerName);
$emailView->getRequest()->setControllerActionName($requestControllerActionName);
// if you have an extbase controller context you can set it too
$emailView->setControllerContext(...)
至少应该设置ControllerExtensionName,然后f:translate工作。
答案 1 :(得分:1)
我没有将任何ControllerContext传递给视图,而是使用
/**
* @param array $recipient recipient of the email in the format array('recipient@domain.tld' => 'Recipient Name')
* @param array $sender sender of the email in the format array('sender@domain.tld' => 'Sender Name')
* @param string $subject subject of the email
* @param string $templateName template name (UpperCamelCase)
* @param array $variables variables to be passed to the Fluid view
*/
protected function sendTemplateEmail(array $recipient, array $sender, $subject, $templateName, array $variables = array()) {
/** @var \TYPO3\CMS\Fluid\View\StandaloneView $emailView */
$emailView = $this->objectManager->get('TYPO3\\CMS\\Fluid\\View\\StandaloneView');
$extbaseFrameworkConfiguration = $this->configurationManager->getConfiguration(\TYPO3\CMS\Extbase\Configuration\ConfigurationManagerInterface::CONFIGURATION_TYPE_FRAMEWORK);
$emailRootPath = \TYPO3\CMS\Core\Utility\GeneralUtility::getFileAbsFileName($extbaseFrameworkConfiguration['view']['templateRootPaths'][1]);
$templatePathAndFilename = $emailRootPath . 'Emails/' . $templateName . '.html';
$emailView->setTemplatePathAndFilename($templatePathAndFilename);
$emailView->assignMultiple($variables);
$emailBody = $emailView->render();
/** @var $message \TYPO3\CMS\Core\Mail\MailMessage */
$message = $this->objectManager->get('TYPO3\\CMS\\Core\\Mail\\MailMessage');
$message->setTo($recipient)
->setFrom($sender)
->setSubject($subject);
// Plain text example
// $message->setBody($emailBody, 'text/plain');
// HTML Email
$message->setBody($emailBody, 'text/html');
$message->send();
return $message->isSent();
}
并在相应的Fluid-Template
中 {f:translate(key: "want_to_update_profile_information", extensionName: "EXTENSIONKEY")}
$variables
是一个PHP数组,其中包含电子邮件的流体模板所需的键值对。
当然,代码必须根据需要进行调整......(模板路径等)