views:

533

answers:

3

Hi, we are in admin generator in filters in field. What is the most clearest way to translate is empty label under form fields?

I've solve it by own setWidgets and setWidgets in BaseFormFilterDoctrine witch extend the parent methods by translating that is empty( empty_label ).

  • setWidgets - translate all *empty_label*s in form filter( for base filter class )
  • setWidget - translate *empty_label* for one filter field( for the extending filter class )

It works, but i think it's nasty. I am looking for something more clean

A: 

why do you think it's nasty ? I think that hacking the BaseFormFilterDoctrine class it's the way to go. I usually do something like this:

abstract class BaseFormFilterDoctrine extends sfFormFilterDoctrine
{
  public function setup()
  {
    parent::setup();
    foreach ($this->widgetSchema->getFields() as $name => $widget) {
      if ($widget->getOption('empty_label')) {
        $widget->setOption('empty_label', 'my internationalized string');
      }
    }
  }
}
gpilotino
Thats +/- my code:) But as you sad it's hack. I want to do it clear. BTW: I think your solution will not translate filter field defined in the extending class => myTableFormFilter will not be translated but baseMytableFormFilter will
Mailo
i don't think there's another way. that's because the string it's not passed to the symfony localization system (and this will never be fixed as stated in trac.symfony-project.org/ticket/5651), so it's a design problem and afaik there's no way around this hack
gpilotino
update: it looks it's somewhat fixed in symfony 1.3: http://www.symfony-project.org/tutorial/1_4/en/whats-new (default errror message)
gpilotino
A: 

You can do it this way:

$translated_text = $this->widgetSchema->getFormFormatter()->translate('String to translate');
David
A: 

Now (Symfony 1.4) you can do this just by adding

<trans-unit>
  <source>is empty</source>
  <target>my translation</target>
</trans-unit>

into the messages.xx.xml

Tom