format() public method

For the choice string, and a number, find and return the string that satisfied the set within the choices.
public format ( $string, $number ) : string
return string the choosen string.
Ejemplo n.º 1
0
 function test_english()
 {
     $choice = new ChoiceFormat();
     $string = '[0] none |{n: n % 10 == 1} 1st |{n: n % 10 == 2} 2nd |{n: n % 10 == 3} 3rd |{n:n} th';
     $wants = array('none' => array(0), '1st' => array(1, 11, 21), '2nd' => array(2, 12, 22), '3rd' => array(3, 13, 23), 'th' => array(4, 5, 6, 7, 14, 15));
     foreach ($wants as $want => $numbers) {
         foreach ($numbers as $n) {
             $this->assertEquals($want, $choice->format($string, $n));
         }
     }
 }
Ejemplo n.º 2
0
 /**
  * Display the choosen translated string.
  * Overrides the parent method, also calls parent's renderBody to
  * translate.
  */
 protected function translateText($text, $subs)
 {
     $text = parent::translateText($text, $subs);
     $choice = new ChoiceFormat();
     $value = $this->getValue();
     $string = $choice->format($text, $value);
     if ($string) {
         return strtr($string, array('{Value}' => $value));
     }
 }