【问题标题】:Zend_Translate translation of email templatesZend_Translate 电子邮件模板的翻译
【发布时间】:2011-07-03 22:19:24
【问题描述】:

使用 zend 框架,我和其他许多人一样,发送电子邮件。现在对于电子邮件,我使用视图模板。 f.x. 欢迎.phtml 欢迎来到我的网站

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

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

现在翻译这个有几种方法。 我可以将整个文本墙放在一个 translate();?> 中,所有的 html 都会跟随,所以这是一个愚蠢的想法。

其次,我可以将每个电子邮件模板放入语言文件夹 fx。 /languages/en_en/emails/welcome.phtml,然后翻译整个文件,html 仍然会跟随,但会更容易。缺点是如果我有 40 种语言,并且模板的 html 发生变化,我将不得不编辑 40 个文件。

第三,我可以把每一行放在一个 print $this->translate();但这会给出很多行。

还有其他方法吗?或者哪种方式最好?

一个小问题:如果我有一堵带有一点格式的文字墙,一般该怎么办?可能有 10 行文本,其中一些是粗体字,还有一些
字样? translate() 中的整个文本墙; ?> ?

问候

【问题讨论】:

    标签: php zend-framework translate zend-translate


    【解决方案1】:

    Zend_Translate 支持占位符,因此您也可以尝试在翻译源中创建消息,例如:

    // 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
    

    如果您的数据是:

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

    你可以调用 translate 方法

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

    和“%s”将被实际数据替换

    Hi John<br /> Welcome to my site.<br /><br /> Regards MySite.com
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2012-12-05
      • 2011-02-19
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多