Variables in PHP gettext
11,669
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');
Comments
-
Terence Eden almost 2 years
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?
-
Terence Eden over 11 yearsWell that was easy! Thanks. Have edited to show sprintf. printf just shows the length.
-
Luca Rainone over 11 yearsSprintf? Why? Printf print the string and sprintf return it. Maybe you write
echo sprintf
. -
TommyAutoMagically almost 11 years@chumkiu -
sprintf()
is probably used here for reasons that are irrelevant to gettext and localization. (The app itself probably needed to store/manipulate the resulting string, not output it directly to stdout.) -
Thomas Rbt almost 7 yearsCan do do something like this with
<?= __('key') ?>
?