1

I have a email template onecode.mail.php

Which I call from

$body = $view->render(
    'template',
    compact('users','oneCode','username'),
    array(
        'controller' => 'users',
        'template'=>'onecode',
        'type' => 'mail',
        'layout' => false
    )
);
$transport = Swift_MailTransport::newInstance();
$mailer = Swift_Mailer::newInstance($transport);
$message = Swift_Message::newInstance();
$message->setSubject("Sign in password");
$message->setFrom(array(NOREPLY => 'Sign in password'));
$message->setTo($email);
$message->setBody($body,'text/html');
$mailer->send($message);

onecode.mail.php contains

<?=$t('Login Email Password')?>
<?=$oneCode?>

I get an error while processing this request as:

<b>Fatal error</b>:  Function name must be a string in <b>app\resources
\tmp\cache\templates
\template_views_users_onecode.mail_0_1460392715_2266.php</b> on line <b>1</b><br/>

Translation works perfect in all the .html.php files but not in the template of .email.php

What should be done? Any suggestions, thanks for the help.

Nilam Doctor
  • 491
  • 7
  • 18
  • It means that the value of `$t` is not a function name. Try `echo $t;` in onecode.mail.php to see what it is. Where do you initialize it? – Kenney Apr 11 '16 at 16:59
  • I tried as per your suggestion, did not change the error. I never initialized it when I used in .html.php files, so for .mail.php also I did not initialize it. It is initialized in one of the lithium libraries \lithium\g11n\Message.php. I tried calling that library use \lithium\gmm1\Message; No help! – Nilam Doctor Apr 11 '16 at 17:09
  • 1
    Ok, thanks for trying. I'm not familar with the Lithium library. Perhaps it's due to `'type' => 'mail'` if that's different from your other files. Maybe prepending `` to your onecode.mail.php fixes it? (found it [here](http://li3.me/docs/manual/common-tasks/globalization.md)). Anyway, good luck! – Kenney Apr 11 '16 at 17:22
  • Thanks!!! By adding these two lines to the template email.php it worked. use lithium\g11n\Message; extract(Message::aliases()); – Nilam Doctor Apr 11 '16 at 17:36

1 Answers1

1

Please add the following lines in your template:

<?php
use lithium\g11n\Message;
extract(Message::aliases());
?>
<?=$t('Login Email Password')?>

You should be able to get the translation in your desired language

Nilam Doctor
  • 491
  • 7
  • 18