Zend Framework 2使用gettext将带有变量的文本转换为

jos*_*mra 2 gettext xgettext zend-translate zend-framework2

我如何翻译字符串,其中$ user包含用户名?

    $message = 'Hello ' . $user . ', how are you';
Run Code Online (Sandbox Code Playgroud)

如果我使用以下代码进行翻译,则无效.

    $message = $translator->translate('Hello ' . $user . ', how are you');
Run Code Online (Sandbox Code Playgroud)

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

    msgid "Hello %s, how are you"
    msgstr ""
Run Code Online (Sandbox Code Playgroud)

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

    msgid "Hello %s, how are you"
    msgstr "Hola %s, como estas"
Run Code Online (Sandbox Code Playgroud)

提前致谢.

And*_*rew 8

在你的视图中尝试这个:

echo sprintf($this->translate("Hello %s, how are you"), $user);
Run Code Online (Sandbox Code Playgroud)