Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Zend_Translate translation of email templates

Using zend framework, i, as many others, send emails. Now for the email i use a view template. f.x. welcome.phtml Welcome to my site

Hi <?php print $this->name; ?><br />
Welcome to my site.<br /><br />

Regards <?php print $this->siteName; ?>

Now to translate this there would be several ways. I could put the whole wall of text in a translate();?>, the all the html would follow, so thats a dumb idea.

Secondly i could put each email template in the language folder, fx. /languages/en_en/emails/welcome.phtml, and translate the whole file, the html would still follow, but it would be easier. The downside is that if i have 40 languages, and the html for the template changes, i would have to edit 40 files.

Thirdly i could put each line in a print $this->translate(); but that would give a lot of lines.

Are there other ways? Or which way of doing this are the best?

A little question: What to do generally if i have a wall of text with a little formatting? maybe 10 lines of text, with some words in bold, and a few
's? The whole wall of text in a translate(); ?> ?

Regards

like image 610
Daniel Avatar asked Feb 24 '11 22:02

Daniel


1 Answers

Zend_Translate supports placeholders, so you can also try to create a messages in your translation source like:

// NOTE: this is only wireframe, working code depends on your translation adapter format
"message-id" => "Hi %s<br /> Welcome to my site.<br /><br /> Regards %s"     // en
"message-id" => "Hallo %s <br/>Willkommen auf meiner Website.<br/><br/>Regards %s" // de

and if your data is:

name => 'John'
siteName => 'MySite.com'

you just can call the translate method

$mailBody = $this->translate('message-id', $this->name, $this->siteName);

and "%s" will be replaced with actual data

Hi John<br /> Welcome to my site.<br /><br /> Regards MySite.com
like image 66
webdevbyjoss Avatar answered Oct 12 '22 11:10

webdevbyjoss