Development

Changeset 24012 for branches

You must first sign up to be able to contribute.

Changeset 24012 for branches

Show
Ignore:
Timestamp:
11/16/09 14:06:31 (4 years ago)
Author:
bschussek
Message:

[1.3, 1.4] Options within optgroups are translated correctly, optgroup labels are translated as well (fixes #7591)

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • branches/1.3/lib/widget/sfWidgetFormChoiceBase.class.php

    r23994 r24012  
    5050    } 
    5151 
    52     return $this->translateAll($choices); 
     52    $results = array(); 
     53    foreach ($choices as $key => $choice) 
     54    { 
     55      if (is_array($choice)) 
     56      { 
     57        $results[$this->translate($key)] = $this->translateAll($choice); 
     58      } 
     59      else 
     60      { 
     61        $results[$key] = $this->translate($choice); 
     62      } 
     63    } 
     64 
     65    return $results; 
    5366  } 
    5467 
  • branches/1.3/test/unit/widget/sfWidgetFormSelectTest.php

    r23994 r24012  
    2121} 
    2222 
    23 $t = new lime_test(20); 
     23$t = new lime_test(22); 
    2424 
    2525$dom = new DomDocument('1.0', 'utf-8'); 
     
    8888$t->is($css->matchSingle('#foo option[value="foobar"]')->getValue(), 'translation[foo]', '->render() translates the options'); 
    8989 
     90// optgroup support with translated choices 
     91$t->diag('optgroup support with translated choices'); 
     92 
     93$ws = new sfWidgetFormSchema(); 
     94$ws->addFormFormatter('stub', new FormFormatterStub()); 
     95$ws->setFormFormatterName('stub'); 
     96$w = new sfWidgetFormSelect(array('choices' => array('group' => array('foo' => 'bar', 'foobar' => 'foo')))); 
     97$w->setParent($ws); 
     98$dom->loadHTML($w->render('foo')); 
     99$css = new sfDomCssSelector($dom); 
     100$t->is($css->matchSingle('#foo optgroup[label="translation[group]"] option[value="foo"]')->getValue(), 'translation[bar]', '->render() translates the options'); 
     101$t->is($css->matchSingle('#foo optgroup[label="translation[group]"] option[value="foobar"]')->getValue(), 'translation[foo]', '->render() translates the options'); 
     102 
    90103// choices as a callable 
    91104$t->diag('choices as a callable'); 
  • branches/1.4/lib/widget/sfWidgetFormChoiceBase.class.php

    r23994 r24012  
    5050    } 
    5151 
    52     return $this->translateAll($choices); 
     52    $results = array(); 
     53    foreach ($choices as $key => $choice) 
     54    { 
     55      if (is_array($choice)) 
     56      { 
     57        $results[$this->translate($key)] = $this->translateAll($choice); 
     58      } 
     59      else 
     60      { 
     61        $results[$key] = $this->translate($choice); 
     62      } 
     63    } 
     64 
     65    return $results; 
    5366  } 
    5467 
  • branches/1.4/test/unit/widget/sfWidgetFormSelectTest.php

    r23994 r24012  
    2121} 
    2222 
    23 $t = new lime_test(20); 
     23$t = new lime_test(22); 
    2424 
    2525$dom = new DomDocument('1.0', 'utf-8'); 
     
    8888$t->is($css->matchSingle('#foo option[value="foobar"]')->getValue(), 'translation[foo]', '->render() translates the options'); 
    8989 
     90// optgroup support with translated choices 
     91$t->diag('optgroup support with translated choices'); 
     92 
     93$ws = new sfWidgetFormSchema(); 
     94$ws->addFormFormatter('stub', new FormFormatterStub()); 
     95$ws->setFormFormatterName('stub'); 
     96$w = new sfWidgetFormSelect(array('choices' => array('group' => array('foo' => 'bar', 'foobar' => 'foo')))); 
     97$w->setParent($ws); 
     98$dom->loadHTML($w->render('foo')); 
     99$css = new sfDomCssSelector($dom); 
     100$t->is($css->matchSingle('#foo optgroup[label="translation[group]"] option[value="foo"]')->getValue(), 'translation[bar]', '->render() translates the options'); 
     101$t->is($css->matchSingle('#foo optgroup[label="translation[group]"] option[value="foobar"]')->getValue(), 'translation[foo]', '->render() translates the options'); 
     102 
    90103// choices as a callable 
    91104$t->diag('choices as a callable');