[Solar-talk] locale

Paul M Jones pmjones at ciaweb.net
Fri Mar 16 15:11:34 PDT 2007


On Mar 8, 2007, at 2:38 PM, Jeff Surgeson wrote:

> On Thursday 08 March 2007 19:32, Jeff Surgeson wrote:
>> On Thursday 08 March 2007 09:15, Jeff Surgeson wrote:
>>>>> Just downloaded latest branch changes, my app locale files are no
>>>>> longer found
>>>>> by solar, it does however find the Solar locale files.
>>>>>
>>>>> Has something changed that I dont know about?
>>>>
>>>> Don't think so; can you give some more details?
>>>
>>> Paul I also replaced my branch download with an older solar branch
>>> version I had lying about, it is about 2 weeks old, I should have  
>>> kept
>>> the previous one but I did not.
>>>
>>> With this older download all locale stuff works ok again! dont  
>>> know if
>>> that tells you anything!
>>
>> Paul the probelm is one of the helper files in Solar_View_Helper  
>> directory,
>> trying to find which one will let you know when I do.
>
> Paul the getTextRaw() helper is very different to what it was and  
> that is why
> my locale files are no longer found, something to do with the $this- 
> >_class
>
> How is it supposed to be used now?

Ah yes, I see the trouble now.  Here's the problem.

Previously, you could call $this->getText('Some_Class::LOCALE_KEY')  
to get the locale-key translation for Some_Class, where Some_Class  
was something other than the default class for the GetText helper.

The problem shows up when you have an anchor, or an action, or any  
user-entered text that has :: in it.  This is because those helpers  
use the GetText helper internally.  Say you have  
"ThisPage::ThatPage::Index" as the display text for the link; it will  
look for a class called "ThisPage" and then try to access the  
"ThatPage::Index" locale key.  The display text for those links are  
often user-supplied text values.

Basically, I hadn't realized the implications of using the  
translation string itself to load or access data from another class.   
(At worst, it might be a security issue, but that may just be paranoia.)

So in the newer versions of the helpers, you have to explicitly set  
the class for locale strings.  You do so by getting the helper object  
directly and using its setClass() method.

     $gettext_helper = $this->getHelper('getText');
     $gettext_helper->setClass('SomeClass);

     echo $this->getText('LOCALE_KEY'); // uses SomeClass::LOCALE_KEY

Technically, the class-name is being set in GetTextRaw, which GetText  
uses (then it escapes the returned value).

I hope this helps explain why I made the change, and how to get  
around it.  If you have other ideas about to handle this, please let  
me know, and I'm very sorry for the trouble.




--

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