[ Index ]
 

Code source de PRADO 3.0.6

Accédez au Source d'autres logiciels libresSoutenez Angelica Josefina !

title

Body

[fermer]

/framework/I18N/ -> TChoiceFormat.php (source)

   1  <?php
   2  /**
   3   * TChoiceFormat, I18N choice format component.
   4   *
   5   * @author Wei Zhuo <weizhuo[at]gmail[dot]com>
   6   * @link http://www.pradosoft.com/
   7   * @copyright Copyright &copy; 2005 PradoSoft
   8   * @license http://www.pradosoft.com/license/
   9   * @version $Id: TChoiceFormat.php 1397 2006-09-07 07:55:53Z wei $
  10   * @package System.I18N
  11   */
  12  
  13   /**
  14   * Get the ChoiceFormat class.
  15   */
  16  Prado::using('System.I18N.core.ChoiceFormat');
  17  Prado::using('System.I18N.TTranslate');
  18  
  19  /**
  20   * TChoiceFormat class.
  21   *
  22   * This component performs message/string choice translation. The translation
  23   * source is set in the TGlobalization module. The following example
  24   * demonstrates a simple 2 choice message translation.
  25   * <code>
  26   * <com:TChoiceFormat Value="1">[1] One Apple. |[2] Two Apples</com:TChoiceFormat>
  27   * </code>
  28   *
  29   * The Choice has <b>Value</b> "1" (one), thus the translated string
  30   * is "One Apple". If the <b>Value</b> is "2", then it will show
  31   * "Two Apples".
  32   *
  33   * The message/string choices are separated by the pipe "|" followed
  34   * by a set notation of the form
  35   *  # <tt>[1,2]</tt> -- accepts values between 1 and 2, inclusive.
  36   *  # <tt>(1,2)</tt> -- accepts values between 1 and 2, excluding 1 and 2.
  37   *  # <tt>{1,2,3,4}</tt> -- only values defined in the set are accepted.
  38   *  # <tt>[-Inf,0)</tt> -- accepts value greater or equal to negative infinity
  39   *                       and strictly less than 0
  40   * Any non-empty combinations of the delimiters of square and round brackets
  41   * are acceptable.
  42   *
  43   * The string choosen for display depends on the <b>Value</b> property.
  44   * The <b>Value</b> is evaluated for each set until the Value is found
  45   * to belong to a particular set.
  46   *
  47   * Properties
  48   * - <b>Value</b>, float,
  49   *   <br>Gets or sets the Value that determines which string choice to display.
  50   *
  51   * @author Xiang Wei Zhuo <weizhuo[at]gmail[dot]com>
  52   * @version v1.0, last update on Fri Dec 24 21:38:49 EST 2004
  53   * @package System.I18N
  54   */
  55  class TChoiceFormat extends TTranslate
  56  {
  57      /**
  58       * @return float the numerical value.
  59       */
  60  	public function getValue()
  61      {
  62          return $this->getViewState('Value','');
  63      }
  64  
  65      /**
  66       * Sets the numerical choice value
  67       * @param float the choice value
  68       */
  69  	public function setValue($value)
  70      {
  71          $this->setViewState('Value',$value,'');
  72      }
  73  
  74      /**
  75       * Display the choosen translated string.
  76       * Overrides the parent method, also calls parent's renderBody to
  77       * translate.
  78       */
  79  	protected function translateText($text, $subs)
  80      {
  81          $text = parent::translateText($text, $subs);
  82          $choice = new ChoiceFormat();
  83          $value = $this->getValue();
  84          $string = $choice->format($text, $value);
  85          if($string)
  86              return strtr($string, array('{Value}'=> $value));
  87      }
  88  }
  89  ?>


Généré le : Sun Feb 25 21:07:04 2007 par Balluche grâce à PHPXref 0.7