Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Variables in PHP gettext [duplicate]

Possible Duplicate:
How does gettext handle dynamic content?

I'm using PHP's gettext. I want to translate a sentence which has a variable in it. Is this possible?

For example, in English:

Are you sure you want to block Alice?

(Where "Alice" is the user's name.)

But, in German, the subject does not appear at the end of the sentence.

Sind Sie sicher, dass Sie Alice blockieren?

In messages.po, I have

msgid "BLOCK"
msgstr "Are you sure you want to block"

But I see no way to pass one or more variables. Is this possible?

like image 481
Terence Eden Avatar asked Oct 12 '12 14:10

Terence Eden


1 Answers

poedit recognizes the vars.

msgid "Are you sure you want to block %s?"
msgstr "Sind Sie sicher, dass Sie %s blockieren?"

and in PHP

sprintf(_('Are you sure you want to block %s?'),'Alice');
like image 132
Luca Rainone Avatar answered Oct 10 '22 22:10

Luca Rainone