【问题标题】:Zend Framework 2 translate using gettext a text with variablesZend Framework 2 使用 gettext 翻译带有变量的文本
【发布时间】:2013-05-08 11:59:58
【问题描述】:

我必须如何翻译这样的字符串,其中 $user 包含用户名?

    $message = 'Hello ' . $user . ', how are you';

如果我使用下面的代码翻译,它不起作用。

    $message = $translator->translate('Hello ' . $user . ', how are you');

在我的 en_EN.po 文件中,我有:

    msgid "Hello %s, how are you"
    msgstr ""

在我的 es_ES.po 文件中,我有:

    msgid "Hello %s, how are you"
    msgstr "Hola %s, como estas"

提前致谢。

【问题讨论】:

    标签: zend-framework2 gettext zend-translate xgettext


    【解决方案1】:

    在你的视图中试试这个:

    echo sprintf($this->translate("Hello %s, how are you"), $user);
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2013-06-28
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多