On Apr 17, 2011, at 21:11, Krissy Masters wrote:

> This might be rather dumb, but all the same…
>  
> <?php echo $var;?>  vs <?php  __($var); ?>
>  
> From reading __() is for l10n  i18n type translate type setup but if used 
> just to echo a var is there a downside? Performance issue, just plain wrong?

If $var contains a string that appears in your localized message catalogs, and 
you want the localized version printed, then __($var) is correct and echo $var 
is wrong.

If $var is just a variable that does not contain a localizable string, then 
echo $var is correct and __($var) is wrong.

__() is usually used with inline strings, like __('Hello') so that a parser can 
extract all the localizable strings from your sources and put them in your 
message catalog template, from which they can then be merged into all your 
message catalogs and then translated using tools like poEdit or, if you're 
careful, a plain text editor. Read gettext documentation for more information.

In CakePHP 1.3, __() has a second parameter, a boolean that says whether to 
return the data. The default is false, in which case it echoes the data. This 
default has always seemed peculiar to me, and in CakePHP 2.0, it's gone, and 
__() always returns data; if you want to echo it, you echo it using echo 
__(...).



-- 
Our newest site for the community: CakePHP Video Tutorials 
http://tv.cakephp.org 
Check out the new CakePHP Questions site http://ask.cakephp.org and help others 
with their CakePHP related questions.


To unsubscribe from this group, send email to
[email protected] For more options, visit this group at 
http://groups.google.com/group/cake-php

Reply via email to