Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Passing variables to the __() function in CakePHP

I'm in the process of building a little project this weekend called Pirates Vs. Ninjas Vs. Zombies Vs. Robots ;)

The purpose is to learn some of the aspects of Cake that I've not yet used before - such as the __() function for translation.

I've got a message that I want to output along the lines of "The %s thank you", where %s would be 'Zombies'. If I was using normal PHP, I guess I would use:

$string = 'Zombies';
printf('The %s thank you', $string);

But as I'm trying to use the __() translate function, I don't know how to make this work.

Can anyone help me please? Thank you :)

like image 705
Daniel Avatar asked Jan 22 '11 14:01

Daniel


2 Answers

in cakephp 2.0+ it translates by default

$string = 'Zombies';
echo __('The %s thank you', $string);
like image 91
Omar S. Avatar answered Sep 29 '22 10:09

Omar S.


Set the second parameter of the __ function to true and it will return the translated string instead of echoing it:

$string = 'Zombies';
printf(__('The %s thank you', true), $string);
like image 33
dhofstet Avatar answered Sep 29 '22 08:09

dhofstet