Ok, some progres for getting i18n to 'just work' with the new form stuff 
is below.  It handles putting labels though i18n, and select options. 
It works for me... but....

I can't help but feel all of the below is just a big dirty hack though - 
and that the form system should work with i18n out of the box.

I think perhaps this could be done by having a method in sfForm that's 
used every time some text is used.. would need some reworking of the 
form stuff as it is at the moment though I imagine.

Feedback please :)


# cat apps/frontend/lib/forms/LoginForm.class.php
<?php


   class LoginForm extends sfForm
   {
     public function configure()
     {
       $schema =  new myWidgetFormSchema(array(
         'username' => new sfWidgetFormInput(),
         'password' => new sfWidgetFormInputPassword(),
         'test'     => new myWidgetFormSelect(array('choices' =>
                              array(1 => 'Username:',
                                    2 => 'Password:'))),
       ));

       $schema->setLabel('username', 'Username:');
       $schema->setLabel('password', 'Password:');

       $this->setWidgetSchema($schema);

       $this->setValidatorSchema(
         new sfValidatorSchema(array(
           'username' => new sfValidatorString(),
           'password' => new sfValidatorString(),
         )));
     }

   }

   class myWidgetFormSelect extends sfWidgetFormSelect
   {
     public function __construct($options = array(), $attributes = array())
     {
       if ($options['choices'])
       {
         $i18n = sfContext::getInstance()->getI18N();
         foreach($options['choices'] as $k => $v)
         {
           $options['choices'][$k] = $i18n->__($v);
         }
       }
       parent::__construct($options, $attributes);
     }
   }

   class myWidgetFormSchema extends sfWidgetFormSchema
   {
     private $i18n;

     public function __construct($fields = null, $options = array(), 
$attributes = array(), $labels = array(), $helps = array())
     {
       $this->i18n = sfContext::getInstance()->getI18N();
       parent::__construct($fields, $options, $attributes, $labels, $helps);
     }

     public function generateLabelName($name)
     {
       return $this->i18n->__(parent::generateLabelName($name));
     }

   }



-- 

Ian P. Christian ~ http://pookey.co.uk

--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"symfony developers" group.
To post to this group, send email to symfony-devs@googlegroups.com
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/symfony-devs?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to