Internationalization is a great feature in CakePHP 1.2, but one thing
bothers me. That is the "__()" function family calling convention.
Citing http://tempdocs.cakephp.org/#TOC137203
> Displaying localized content is done using the __() convenience function.
> [...] The localized content is echo()'d by default, but an optional second
> parameter causes the value be returned instead (handy for highlighting or
> linking using the TextHelper, for example).
So, the question is: is there any legal reason for it to be echoed,
not returned? OK, there are people who don't like short <?= ... ?>
tags and thus prefer <?php echo ... ?>, which is kinda lengty, but
there is a e() shortcut just for that case. Having an optional
$return parameter in "__()"-like functions, which is false by default,
contradicts to the rest of our lovely Helpers' behavior, which have
the same-purposed parameter set to true. This makes using __()
functions error-prone.
Consider an example when you first start with some static text
<?php e('translate me') ?>
and then decide to make it a part of a link. Back in the days of
CakePHP 1.1 you just wrapped your text in $html->link([...], '/') with
a simple cut-and-paste gesture, and it worked, just like following:
<?php e($html->link('translate me', '/')) ?>.
But now when we have __(), we write
<?php __('translate me') # no echo, sweet! ?>
for the static text, and, repeating cut-and-paste wrapping, just like
we always did, we get
<?php $html->link(__('translate me'), '/') ?>,
which doesn't work. What's even worse, it doesn't work for TWO
reasons: first, you have to wrap everything in e(), and second, you
have to supply a true as a second parameter, so you have to write:
<?php e($html->link(__('translate me', true), '/')) # kinda
cumbersome, yikes ?>.
What if i18n functions returned the translated text instead of
echoing, just like helpers do by default? Our habits would still
work, and the code would be shorter.
Before:
<?php e(__('translate me')) ?>
After:
<?php e($html->(__('translate me'), '/')) ?>
Or even:
<?= __('translate me') ?>
and
<?= $html->link(__('translate me'), '/') ?>
Considering this, I hope CakePHP core hackers would change their minds
and make __() family play nice with helpers. Objections?
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups "Cake
PHP" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at
http://groups.google.com/group/cake-php?hl=en
-~----------~----~----~----~------~----~------~--~---