/**
  * Translates a string based on the number parameter passed
  *
  * @param string  $strings Strings to choose from
  * @param integer $number The umber of items
  * @param array   $parameters An array of parameters
  * 
  * @throws InvalidArgumentException
  *
  * @return string Translated string
  */
 public function choose(array $strings, $number, array $parameters = array())
 {
     if (count($strings) < 2) {
         throw new InvalidArgumentException('Choose method requires at least 2 strings to choose from');
     }
     $choice = KTranslatorPluralizationrules::get($number, $this->_locale);
     if ($choice > count($strings) - 1) {
         $choice = count($strings) - 1;
     }
     return $this->translate($strings[$choice], $parameters);
 }
示例#2
0
 /**
  * Translates a string based on the number parameter passed
  *
  * @param array   $strings    Strings to choose from
  * @param integer $number     The umber of items
  * @param array   $parameters An array of parameters
  *
  * @throws InvalidArgumentException
  * @return string Translated string
  */
 public function choose(array $strings, $number, array $parameters = array())
 {
     if (count($strings) < 2) {
         throw new InvalidArgumentException('Choose method requires at least 2 strings to choose from');
     }
     $choice = KTranslatorPluralizationrules::get($number, $this->_locale);
     if ($choice === 0) {
         return $this->translate($strings[0], $parameters);
     }
     $key = $this->getKey($strings[1]);
     $found = null;
     while ($choice > 0) {
         $looking_for = $key . ($choice === 1 ? '' : '_' . $choice);
         if ($this->_translation_helper->hasKey($looking_for)) {
             $found = $looking_for;
             break;
         }
         $choice--;
     }
     return $this->translate($found ? $found : $strings[1], $parameters);
 }