/**
  * 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));
                 }
             }
         }
     }
 }
예제 #3
0
/**
 * 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);
 }
예제 #5
0
 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;
 }
예제 #6
0
 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;
 }
예제 #7
0
$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');
$t->is($n->isValid(10000000, '[0,Inf]'), true, '->isValid() determines if a given number belongs to the given set');
$t->is($n->isValid(-10000000, '[-Inf,+Inf]'), true, '->isValid() determines if a given number belongs to the given set');
try {
    $n->isValid(1, '[1');
    $t->fail('->isValid() throw an exception if the set is not valid');
} catch (sfException $e) {
    $t->pass('->isValid() throw an exception if the set is not valid');
}
// ->format()
$t->diag('->format()');
$t->is($n->format($strings[0][0], 1), $strings[0][1][1][0], '->format() returns the string that match the number');
$t->is($n->format($strings[0][0], 4), false, '->format() returns the string that match the number');
$t->is($n->format($strings[4][0], 0), $strings[4][1][1][0], '->format() returns the string that match the number');
$t->is($n->format($strings[4][0], 1), $strings[4][1][1][1], '->format() returns the string that match the number');
$t->is($n->format($strings[4][0], 12), $strings[4][1][1][2], '->format() returns the string that match the number');
// test set notation
// tests adapted from Prado unit test suite
$t->diag('set notation');
$string = '{n: n%2 == 0} are even numbers |{n: n >= 5} are not even and greater than or equal to 5';
$t->is($n->format($string, 0), 'are even numbers', '->format() can takes a set notation in the format string');
$t->is($n->format($string, 2), 'are even numbers', '->format() can takes a set notation in the format string');
$t->is($n->format($string, 4), 'are even numbers', '->format() can takes a set notation in the format string');
$t->is(!$n->format($string, 1), 'are even numbers', '->format() can takes a set notation in the format string');
$t->is($n->format($string, 5), 'are not even and greater than or equal to 5', '->format() can takes a set notation in the format string');
$t->diag('set notation for polish');
$string = '[1] plik |{2,3,4} pliki |[5,21] pliko\'w |{n: n % 10 > 1 && n %10 < 5} pliki |{n: n%10 >= 5 || n%10 <=1} pliko\'w';
예제 #8
0
$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');
$t->is($n->isValid(10000000, '[0,Inf]'), true, '->isValid() determines if a given number belongs to the given set');
$t->is($n->isValid(-10000000, '[-Inf,+Inf]'), true, '->isValid() determines if a given number belongs to the given set');
try {
    $n->isValid(1, '[1');
    $t->fail('->isValid() throw an exception if the set is not valid');
} catch (sfException $e) {
    $t->pass('->isValid() throw an exception if the set is not valid');
}
// ->format()
$t->diag('->format()');
$t->is($n->format($strings[0][0], 1), $strings[0][1][1][0], '->format() returns the string that match the number');
$t->is($n->format($strings[0][0], 4), false, '->format() returns the string that match the number');
$t->is($n->format($strings[4][0], 0), $strings[4][1][1][0], '->format() returns the string that match the number');
$t->is($n->format($strings[4][0], 1), $strings[4][1][1][1], '->format() returns the string that match the number');
$t->is($n->format($strings[4][0], 12), $strings[4][1][1][2], '->format() returns the string that match the number');
// test strings with some set notation
$t->is($n->format("[0]Some text|[1,Inf] Some text (10)", 12), 'Some text (10)', '->format() does not take into account ranges that are not prefixed with |');
// test set notation
// tests adapted from Prado unit test suite
$t->diag('set notation');
$string = '{n: n%2 == 0} are even numbers |{n: n >= 5} are not even and greater than or equal to 5';
$t->is($n->format($string, 0), 'are even numbers', '->format() can takes a set notation in the format string');
$t->is($n->format($string, 2), 'are even numbers', '->format() can takes a set notation in the format string');
$t->is($n->format($string, 4), 'are even numbers', '->format() can takes a set notation in the format string');
$t->is(!$n->format($string, 1), 'are even numbers', '->format() can takes a set notation in the format string');
$t->is($n->format($string, 5), 'are not even and greater than or equal to 5', '->format() can takes a set notation in the format string');
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');
$t->is($n->isValid(10000000, '[0,Inf]'), true, '->isValid() determines if a given number belongs to the given set');
$t->is($n->isValid(-10000000, '[-Inf,+Inf]'), true, '->isValid() determines if a given number belongs to the given set');
try {
    $n->isValid(1, '[1');
    $t->fail('->isValid() throw an exception if the set is not valid');
} catch (sfException $e) {
    $t->pass('->isValid() throw an exception if the set is not valid');
}
// ->format()
$t->diag('->format()');
$t->is($n->format($strings[0][0], 1), $strings[0][1][1][0], '->format() returns the string that match the number');
$t->is($n->format($strings[0][0], 4), false, '->format() returns the string that match the number');
$t->is($n->format($strings[4][0], 0), $strings[4][1][1][0], '->format() returns the string that match the number');
$t->is($n->format($strings[4][0], 1), $strings[4][1][1][1], '->format() returns the string that match the number');
$t->is($n->format($strings[4][0], 12), $strings[4][1][1][2], '->format() returns the string that match the number');