/** * Get choice of translated string * * @param string $source Source key (catalogue.key) or simply text * @param integer $number Number of choice * @param array $params Replacements in text [optional] * @param boolean $useCase Using of external number case [optional] * @return string Translated string */ public static function __c($source, $number, $params = array(), $useCase = true) { $trans = self::__($source, $params); $choice = new sfChoiceFormat(); $retval = $choice->format($trans, $useCase ? self::ncase($number) : $number); return $retval === false ? $trans : $retval; }
public function configure() { $configs = Doctrine::getTable('NotificationMail')->getConfigs(); $app = 'mobile_frontend' == sfConfig::get('sf_app') ? 'mobile' : 'pc'; if (!isset($configs[$app])) { return; } $i18n = sfContext::getInstance()->getI18N(); $choices = array(1 => $i18n->__('Receive'), 0 => $i18n->__('Don\'t Receive')); foreach ($configs[$app] as $key => $value) { if (isset($value['member_configurable']) && $value['member_configurable']) { $notification = Doctrine::getTable('NotificationMail')->findOneByName($app . '_' . $key); $name = 'is_send_' . $app . '_' . $key . '_mail'; if (!$notification || $notification->getIsEnabled()) { if ('dailyNews' !== $key) { $this->setWidget($name, new sfWidgetFormChoice(array('choices' => $choices, 'expanded' => true))); $this->setValidator($name, new sfValidatorChoice(array('choices' => array_keys($choices), 'required' => true))); $this->widgetSchema->setLabel($name, $value['caption']); $this->setDefault($name, $this->member->getConfig($name, 1)); } else { $name = 'daily_news'; $i18n = sfContext::getInstance()->getI18N(); $choice = new sfChoiceFormat(); $count = count(opConfig::get('daily_news_day')); $translated = $choice->format($i18n->__('[1]Send once a week (%2%)|[2]Send twice a week (%2%)|(2,+Inf]Send %1% times a week (%2%)', array('%1%' => $count, '%2%' => implode(',', $this->generateDayList()))), $count); $dailyNewsChoices = array("Don't Send", $translated, "Send Everyday"); $this->setWidget($name, new sfWidgetFormChoice(array('choices' => $dailyNewsChoices, 'expanded' => true))); $this->setValidator($name, new sfValidatorChoice(array('choices' => array_keys($dailyNewsChoices), 'required' => true))); $this->widgetSchema->setLabel($name, $value['caption']); $this->setDefault($name, $this->member->getConfig($name, 2)); } } } } }
/** * Format a string according to a number. * * Every segment is separated with | * Each segment defines an intervale and a value. * * For example : * * * [0]Nobody is logged|[1]There is 1 person logged|(1,+Inf]There are %number persons logged * * @param string $text Text used for different number values * @param array $args Arguments to replace in the string * @param int $number Number to use to determine the string to use * @param string $catalogue Catalogue for translation * * @return string Result of the translation */ function format_number_choice($text, $args = array(), $number, $catalogue = 'messages') { $translated = __($text, $args, $catalogue); $choice = new sfChoiceFormat(); $retval = $choice->format($translated, $number); if ($retval === false) { throw new sfException(sprintf('Unable to parse your choice "%s".', $translated)); } return $retval; }
public function __construct(Member $member = null, $options = array(), $CSRFSecret = null) { parent::__construct($member, $options, $CSRFSecret); $count = count(opConfig::get('daily_news_day')); $i18n = sfContext::getInstance()->getI18N(); $translated = $i18n->__('[1]Send once a week (%2%)|[2]Send twice a week (%2%)|(2,+Inf]Send %1% times a week (%2%)', array('%1%' => $count, '%2%' => implode(',', $this->generateDayList()))); $choice = new sfChoiceFormat(); $retval = $choice->format($translated, $count); $options = $this->widgetSchema['daily_news']->getOptions(); $options['choices'][1] = $retval; $this->widgetSchema['daily_news']->setOptions($options); }
public function build(dmModuleSpace $space) { $this->ulClass('dm_modules')->children(array()); foreach ($space->getModules() as $key => $module) { if ($this->user->canAccessToModule($module)) { if ($nbRecords = $module->hasModel() ? $module->getTable()->count() : null) { $choice = new sfChoiceFormat(); $nbRecordsText = $choice->format($this->i18n->__('[0]no element|[1]1 element|(1,+Inf]%1% elements', array('%1%' => $nbRecords)), $nbRecords); } else { $nbRecordsText = ''; } $this->addChild($module->getName())->liClass('dm_module')->label($this->helper->link('@' . $module->getUnderscore())->text($this->i18n->__($module->getPlural()) . $this->helper->tag('span.infos', $nbRecordsText))->set('.dm_big_button')); } } return $this; }
public function build(dmModuleType $type) { $this->ulClass('dm_module_spaces dm_module_type mt10')->children(array()); foreach ($type->getSpaces() as $space) { $spaceMenu = $this->addChild($space->getPublicName())->ulClass('dm_modules dm_box_inner pl10 pr10')->liClass('dm_module_space dm_module_type_show dm_box fleft mr20 mb20')->label($this->helper->tag('h2.title', $this->helper->link($this->serviceContainer->getService('routing')->getModuleSpaceUrl($space))->text($this->i18n->__($space->getPublicName()))->set('.center'))); foreach ($space->getModules() as $key => $module) { if ($this->user->canAccessToModule($module)) { if ($nbRecords = $module->hasModel() ? $module->getTable()->count() : null) { $choice = new sfChoiceFormat(); $nbRecordsText = $choice->format($this->i18n->__('[0]no element|[1]1 element|(1,+Inf]%1% elements', array('%1%' => $nbRecords)), $nbRecords); } else { $nbRecordsText = ''; } $spaceMenu->addChild($module->getName())->liClass('dm_module')->label($this->helper->link('@' . $module->getUnderscore())->text($this->i18n->__($module->getPlural())) . $this->helper->tag('p.infos', $nbRecordsText)); } } if (!$spaceMenu->hasChildren()) { $this->removeChild($spaceMenu); } } return $this; }
<?php /* * This file is part of the symfony package. * (c) 2004-2006 Fabien Potencier <*****@*****.**> * * For the full copyright and license information, please view the LICENSE * file that was distributed with this source code. */ require_once dirname(__FILE__) . '/../../bootstrap/unit.php'; $t = new lime_test(89, new lime_output_color()); $n = new sfChoiceFormat(); $strings = array(array('[1,2] accepts values between 1 and 2, inclusive', array(array('[1,2]'), array('accepts values between 1 and 2, inclusive'))), array('(1,2) accepts values between 1 and 2, excluding 1 and 2', array(array('(1,2)'), array('accepts values between 1 and 2, excluding 1 and 2'))), array('{1,2,3,4} only values defined in the set are accepted', array(array('{1,2,3,4}'), array('only values defined in the set are accepted'))), array('[-Inf,0) accepts value greater or equal to negative infinity and strictly less than 0', array(array('[-Inf,0)'), array('accepts value greater or equal to negative infinity and strictly less than 0'))), array('[0] no file|[1] one file|(1,Inf] {number} files', array(array('[0]', '[1]', '(1,Inf]'), array('no file', 'one file', '{number} files')))); // ->parse() $t->diag('->parse()'); foreach ($strings as $string) { $t->is($n->parse($string[0]), $string[1], '->parse() takes a choice strings as its first parameters'); } // ->isValid() $t->diag('->isValid()'); $t->is($n->isValid(1, '[1]'), true, '->isValid() determines if a given number belongs to the given set'); $t->is($n->isValid(2, '[1]'), false, '->isValid() determines if a given number belongs to the given set'); $t->is($n->isValid(1, '(1)'), false, '->isValid() determines if a given number belongs to the given set'); $t->is($n->isValid(1, '(1,10)'), false, '->isValid() determines if a given number belongs to the given set'); $t->is($n->isValid(10, '(1,10)'), false, '->isValid() determines if a given number belongs to the given set'); $t->is($n->isValid(4, '(1,10)'), true, '->isValid() determines if a given number belongs to the given set'); $t->is($n->isValid(1, '{1,2,4,5}'), true, '->isValid() determines if a given number belongs to the given set'); $t->is($n->isValid(3, '{1,2,4,5}'), false, '->isValid() determines if a given number belongs to the given set'); $t->is($n->isValid(4, '{1,2,4,5}'), true, '->isValid() determines if a given number belongs to the given set'); $t->is($n->isValid(1, '[0,+Inf]'), true, '->isValid() determines if a given number belongs to the given set'); $t->is($n->isValid(10000000, '[0,+Inf]'), true, '->isValid() determines if a given number belongs to the given set');
<?php /* * This file is part of the symfony package. * (c) 2004-2006 Fabien Potencier <*****@*****.**> * * For the full copyright and license information, please view the LICENSE * file that was distributed with this source code. */ require_once dirname(__FILE__) . '/../../bootstrap/unit.php'; $t = new lime_test(24, new lime_output_color()); $n = new sfChoiceFormat(); $strings = array(array('[1,2] accepts values between 1 and 2, inclusive', array(array('[1,2]'), array('accepts values between 1 and 2, inclusive'))), array('(1,2) accepts values between 1 and 2, excluding 1 and 2', array(array('(1,2)'), array('accepts values between 1 and 2, excluding 1 and 2'))), array('{1,2,3,4} only values defined in the set are accepted', array(array('{1,2,3,4}'), array('only values defined in the set are accepted'))), array('[-Inf,0) accepts value greater or equal to negative infinity and strictly less than 0', array(array('[-Inf,0)'), array('accepts value greater or equal to negative infinity and strictly less than 0'))), array('[0] no file|[1] one file|(1,Inf] {number} files', array(array('[0]', '[1]', '(1,Inf]'), array('no file', 'one file', '{number} files')))); // ->parse() $t->diag('->parse()'); foreach ($strings as $string) { $t->is($n->parse($string[0]), $string[1], '->parse() takes a choice strings as its first parameters'); } // ->isValid() $t->diag('->isValid()'); $t->is($n->isValid(1, '[1]'), true, '->isValid() determines if a given number belongs to the given set'); $t->is($n->isValid(2, '[1]'), false, '->isValid() determines if a given number belongs to the given set'); $t->is($n->isValid(1, '(1)'), false, '->isValid() determines if a given number belongs to the given set'); $t->is($n->isValid(1, '(1,10)'), false, '->isValid() determines if a given number belongs to the given set'); $t->is($n->isValid(10, '(1,10)'), false, '->isValid() determines if a given number belongs to the given set'); $t->is($n->isValid(4, '(1,10)'), true, '->isValid() determines if a given number belongs to the given set'); $t->is($n->isValid(1, '{1,2,4,5}'), true, '->isValid() determines if a given number belongs to the given set'); $t->is($n->isValid(3, '{1,2,4,5}'), false, '->isValid() determines if a given number belongs to the given set'); $t->is($n->isValid(4, '{1,2,4,5}'), true, '->isValid() determines if a given number belongs to the given set'); $t->is($n->isValid(1, '[0,+Inf]'), true, '->isValid() determines if a given number belongs to the given set'); $t->is($n->isValid(10000000, '[0,+Inf]'), true, '->isValid() determines if a given number belongs to the given set');