2

How I have to do for translate a string as this, where $user contains the user name?

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

If I translate using the follow code, it don't works.

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

In my en_EN.po file I have:

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

In my es_ES.po file I have:

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

Thanks in advance.

josepmra
  • 617
  • 9
  • 25

1 Answers1

8

Try this inside your view:

echo sprintf($this->translate("Hello %s, how are you"), $user);
Andrew
  • 12,617
  • 1
  • 34
  • 48