Sending Multiple Emails in Different Language Consequently with CakePHP
I am sending emails to multiple recipients through a loop. The email elements use language localization. When I send these emails, I would like to send these emails in the user's native开发者_如何学运维 language.
if you change Configure::write("Config.language")
to language which belongs to user to which the current e-mail is and after you use __d()
or __()
methods, you should have every email text in proper language
just translate via __dl()
instead of basics.php __d()
or __()
providing example from answer on SO question no.4294543
function __dl($domain, $str, $lang, $return = false) {
$original = Configure::read('Config.language');
Configure::write('Config.language', $lang);
$str = __d($domain, $str, true);
Configure::write('Config.language', $original);
if ($return) {
return $str;
}
echo $str;
}
__dl('domain', 'Foo bar', 'pt_BR');
or use parameter language
in __d()
see:
- Define the language when using gettext __d() on CakePHP
- https://github.com/cakephp/cakephp/blob/1.3/cake/libs/i18n.php (line 134)
精彩评论