Development

Changeset 8610

You must first sign up to be able to contribute.

Changeset 8610

Show
Ignore:
Timestamp:
04/23/08 17:57:16 (1 year ago)
Author:
nicolas
Message:

fixed #3355 - added a translationCatalogue property in sfWidgetFormSchemaFormatter class to handle specific catalogue name to pass back to the translation catalogue. Example of use in a sfForm instance:

<?php
class I18nCustomCatalogueForm extends sfForm
{
  public function configure()
  {
    // [...] configure your form here
    $this->widgetSchema->getFormFormatter()->setTranslationCatalogue('custom');
  }
}
Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • branches/1.1/lib/plugins/sfPropelPlugin/test/functional/fixtures/config

    • Property svn:ignore set to
      *transformed.xml
  • branches/1.1/lib/widget/sfWidgetFormSchemaFormatter.class.php

    r8463 r8610  
    3030    $namedErrorRowFormatInARow = "    <li>%name%: %error%</li>\n", 
    3131    $decoratorFormat           = '', 
    32     $widgetSchema              = null; 
     32    $widgetSchema              = null, 
     33    $translationCatalogue      = null; 
    3334 
    3435  /** 
     
    5859   * @param  mixed  $subject     The subject to translate 
    5960   * @param  array  $parameters  Additional parameters to pass back to the callable 
    60    *  
    6161   * @return string 
    6262   */ 
    63   static public function translate($subject, $parameters = array()) 
     63  public function translate($subject, $parameters = array()) 
    6464  { 
    6565    if (false === $subject) 
     
    8181      return strtr($subject, $parameters); 
    8282    } 
     83     
     84    $catalogue = $this->getTranslationCatalogue(); 
    8385 
    8486    if (self::$translationCallable instanceof sfCallable) 
    8587    { 
    86       return self::$translationCallable->call($subject, $parameters); 
    87     } 
    88  
    89     return call_user_func(self::$translationCallable, $subject, $parameters); 
     88      return self::$translationCallable->call($subject, $parameters, $catalogue); 
     89    } 
     90 
     91    return call_user_func(self::$translationCallable, $subject, $parameters, $catalogue); 
    9092  } 
    9193 
     
    124126    } 
    125127 
    126     return strtr($this->getHelpFormat(), array('%help%' => self::translate($help))); 
     128    return strtr($this->getHelpFormat(), array('%help%' => $this->translate($help))); 
    127129  } 
    128130 
     
    188190    } 
    189191 
    190     return self::translate($label); 
    191   } 
    192  
     192    return $this->translate($label); 
     193  } 
     194   
     195  /** 
     196   * Get i18n catalogue name 
     197   * 
     198   * @return string 
     199   */ 
     200  public function getTranslationCatalogue() 
     201  { 
     202    return $this->translationCatalogue; 
     203  } 
     204   
     205  /** 
     206   * Set an i18n catalogue name 
     207   * 
     208   * @param  string  $catalogue 
     209   * @throws InvalidArgumentException 
     210   */ 
     211  public function setTranslationCatalogue($catalogue) 
     212  { 
     213    if (!is_string($catalogue)) 
     214    { 
     215      throw new InvalidArgumentException('Catalogue name must be a string'); 
     216    } 
     217     
     218    $this->translationCatalogue = $catalogue; 
     219  } 
     220   
    193221  protected function unnestErrors($errors, $prefix = '') 
    194222  { 
     
    205233        if ($error instanceof sfValidatorError) 
    206234        { 
    207           $err = self::translate($error->getMessageFormat(), $error->getArguments()); 
     235          $err = $this->translate($error->getMessageFormat(), $error->getArguments()); 
    208236        } 
    209237        else 
    210238        { 
    211           $err = self::translate($error); 
     239          $err = $this->translate($error); 
    212240        } 
    213241 
  • branches/1.1/test/functional/fixtures/project/apps/i18n/modules/i18n/actions/actions.class.php

    r8408 r8610  
    3939    } 
    4040  } 
     41   
     42  public function executeI18nCustomCatalogueForm(sfWebRequest $request) 
     43  { 
     44    $this->form = new I18nCustomCatalogueForm(); 
     45    $this->setTemplate('I18nForm'); 
     46  } 
    4147} 
  • branches/1.1/test/functional/i18nFormTest.php

    r8462 r8610  
    5151; 
    5252 
     53// forms label custoim catalogue test 
     54$b-> 
     55  get('/fr/i18n/i18nCustomCatalogueForm')-> 
     56  isStatusCode(200)-> 
     57  isRequestParameter('module', 'i18n')-> 
     58  isRequestParameter('action', 'i18nCustomCatalogueForm')-> 
     59  isUserCulture('fr')-> 
     60  checkResponseElement('label', 'PrĂ©nom!!!', array('position' => 0))-> 
     61  checkResponseElement('label', 'Nom!!!', array('position' => 1))-> 
     62  checkResponseElement('label', 'Adresse email!!!', array('position' => 2)) 
     63; 
  • branches/1.1/test/unit/widget/sfWidgetFormSchemaFormatterTest.php

    r8408 r8610  
    1111require_once(dirname(__FILE__).'/../../bootstrap/unit.php'); 
    1212 
    13 $t = new lime_test(22, new lime_output_color()); 
     13$t = new lime_test(25, new lime_output_color()); 
    1414 
    1515class MyFormatter extends sfWidgetFormSchemaFormatter 
     
    114114 
    115115$t->diag('->translate()'); 
    116 $t->is(MyFormatter::translate('label'), '[label]', 'translate() call i18n sfCallable as expected'); 
     116$f = new MyFormatter(new sfWidgetFormSchema()); 
     117$t->is($f->translate('label'), '[label]', 'translate() call i18n sfCallable as expected'); 
    117118 
    118119MyFormatter::setTranslationCallable(array('myI18n', '__')); 
    119 $t->is(MyFormatter::translate('label'), '[label]', 'translate() call i18n callable as expected'); 
     120$t->is($f->translate('label'), '[label]', 'translate() call i18n callable as expected'); 
    120121 
    121122$t->diag('->generateLabel() ->generateLabelName() ->setLabel() ->setLabels()'); 
     
    144145MyFormatter::setTranslationCallable('my__'); 
    145146$t->is($f->generateLabel('last_name'), '<label for="last_name">[Your Last Name]</label>', '->generateLabelName() returns a i18ned label tag'); 
     147 
     148// ->setTranslationCatalogue() ->getTranslationCatalogue() 
     149class MyFormatter2 extends sfWidgetFormSchemaFormatter 
     150{ 
     151   
     152} 
     153 
     154$f = new MyFormatter2(new sfWidgetFormSchema(array())); 
     155$f->setTranslationCatalogue('foo'); 
     156$t->is($f->getTranslationCatalogue(), 'foo', 'setTranslationCatalogue() has set the i18n catalogue correctly'); 
     157$t->diag('->setTranslationCatalogue() ->getTranslationCatalogue()'); 
     158try 
     159{ 
     160  $f->setTranslationCatalogue(array('foo')); 
     161  $t->fail('setTranslationCatalogue() does not throw an exception when catalogue name is incorrectly typed'); 
     162} 
     163catch (InvalidArgumentException $e) 
     164{ 
     165  $t->pass('setTranslationCatalogue() throws an exception when catalogue name is incorrectly typed'); 
     166} 
     167 
     168function ___my($s, $p, $c) 
     169{ 
     170  return $c; 
     171} 
     172 
     173$f = new MyFormatter2(new sfWidgetFormSchema()); 
     174$f->setTranslationCallable('___my'); 
     175$f->setTranslationCatalogue('bar'); 
     176$t->is($f->translate('foo', array()), 'bar', 'translate() passes back the catalogue to the translation callable'); 

The Sensio Labs Network

Since 1998, Sensio Labs has been promoting the Open-Source software movement by providing quality web application development, training, consulting, and supporting several large Open-Source projects.