Changeset 8610
- Timestamp:
- 04/23/08 17:57:16 (1 year ago)
- Files:
-
- branches/1.1/lib/plugins/sfPropelPlugin/test/functional/fixtures/config (modified) (1 prop)
- branches/1.1/lib/widget/sfWidgetFormSchemaFormatter.class.php (modified) (6 diffs)
- branches/1.1/test/functional/fixtures/project/apps/i18n/modules/i18n/actions/actions.class.php (modified) (1 diff)
- branches/1.1/test/functional/fixtures/project/apps/i18n/modules/i18n/i18n/custom.fr.xml (added)
- branches/1.1/test/functional/fixtures/project/apps/i18n/modules/i18n/lib/I18nCustomCatalogueForm.class.php (added)
- branches/1.1/test/functional/i18nFormTest.php (modified) (1 diff)
- branches/1.1/test/unit/widget/sfWidgetFormSchemaFormatterTest.php (modified) (3 diffs)
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
branches/1.1/lib/plugins/sfPropelPlugin/test/functional/fixtures/config
- Property svn:ignore set to
*transformed.xml
- Property svn:ignore set to
branches/1.1/lib/widget/sfWidgetFormSchemaFormatter.class.php
r8463 r8610 30 30 $namedErrorRowFormatInARow = " <li>%name%: %error%</li>\n", 31 31 $decoratorFormat = '', 32 $widgetSchema = null; 32 $widgetSchema = null, 33 $translationCatalogue = null; 33 34 34 35 /** … … 58 59 * @param mixed $subject The subject to translate 59 60 * @param array $parameters Additional parameters to pass back to the callable 60 *61 61 * @return string 62 62 */ 63 staticpublic function translate($subject, $parameters = array())63 public function translate($subject, $parameters = array()) 64 64 { 65 65 if (false === $subject) … … 81 81 return strtr($subject, $parameters); 82 82 } 83 84 $catalogue = $this->getTranslationCatalogue(); 83 85 84 86 if (self::$translationCallable instanceof sfCallable) 85 87 { 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); 90 92 } 91 93 … … 124 126 } 125 127 126 return strtr($this->getHelpFormat(), array('%help%' => self::translate($help)));128 return strtr($this->getHelpFormat(), array('%help%' => $this->translate($help))); 127 129 } 128 130 … … 188 190 } 189 191 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 193 221 protected function unnestErrors($errors, $prefix = '') 194 222 { … … 205 233 if ($error instanceof sfValidatorError) 206 234 { 207 $err = self::translate($error->getMessageFormat(), $error->getArguments());235 $err = $this->translate($error->getMessageFormat(), $error->getArguments()); 208 236 } 209 237 else 210 238 { 211 $err = self::translate($error);239 $err = $this->translate($error); 212 240 } 213 241 branches/1.1/test/functional/fixtures/project/apps/i18n/modules/i18n/actions/actions.class.php
r8408 r8610 39 39 } 40 40 } 41 42 public function executeI18nCustomCatalogueForm(sfWebRequest $request) 43 { 44 $this->form = new I18nCustomCatalogueForm(); 45 $this->setTemplate('I18nForm'); 46 } 41 47 } branches/1.1/test/functional/i18nFormTest.php
r8462 r8610 51 51 ; 52 52 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 11 11 require_once(dirname(__FILE__).'/../../bootstrap/unit.php'); 12 12 13 $t = new lime_test(2 2, new lime_output_color());13 $t = new lime_test(25, new lime_output_color()); 14 14 15 15 class MyFormatter extends sfWidgetFormSchemaFormatter … … 114 114 115 115 $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'); 117 118 118 119 MyFormatter::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'); 120 121 121 122 $t->diag('->generateLabel() ->generateLabelName() ->setLabel() ->setLabels()'); … … 144 145 MyFormatter::setTranslationCallable('my__'); 145 146 $t->is($f->generateLabel('last_name'), '<label for="last_name">[Your Last Name]</label>', '->generateLabelName() returns a i18ned label tag'); 147 148 // ->setTranslationCatalogue() ->getTranslationCatalogue() 149 class 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()'); 158 try 159 { 160 $f->setTranslationCatalogue(array('foo')); 161 $t->fail('setTranslationCatalogue() does not throw an exception when catalogue name is incorrectly typed'); 162 } 163 catch (InvalidArgumentException $e) 164 { 165 $t->pass('setTranslationCatalogue() throws an exception when catalogue name is incorrectly typed'); 166 } 167 168 function ___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');

