[Solar-talk] locale strings + replacements

Paul M Jones pmjones at ciaweb.net
Fri Mar 16 15:02:25 PDT 2007


On Nov 29, 2006, at 5:49 AM, Rodrigo Moraes wrote:

> On 11/29/06, Paul M Jones wrote:
>> My opinion on this is: if you need sprintf() formatting, you can keep
>> the format string as the locale string, then call sprintf() from the
>> view (instead of it being used in the locale() method when it's not
>> always needed).  For example, say your locale key/value pair is this:
>>
>>      'TEXT_FOO' => 'The %2$s contains %1$d monkeys.'
>>
>> Then in your view, you can do this:
>>
>>      echo sprintf(
>>          $this->getText('TEXT_FOO'),
>>          7,
>>          'house'
>>      );
>>
>> Then you get the benefits of sprintf() when you need them, and the
>> benefits of not using sprintf() when you don't.
>>
>> Have I missed anything here?
>
> I think this is a valid idea; I have implemented it in getTextRaw() as
> a shortcut and it is used *when* a replacements array is passed.
> Otherwise the locale string is returned as it is, without additional
> processing. This is an important point: it is only used when there are
> replacements to be done. This is the hack:
>
> http://dev.tipos.org/browser/trunk/Tipos/View/Helper/GetTextRaw.php

I have applied this in the new app-branch helper for GetTextRaw.   
Good idea.  :-)



--

Paul M. Jones  <http://paul-m-jones.com>

Solar: Simple Object Library and Application Repository
for PHP5.  <http://solarphp.com>

Join the Solar community wiki!  <http://solarphp.org>

Savant: The simple, elegant, and powerful solution for
templates in PHP.  <http://phpsavant.com>




More information about the solar-talk mailing list