I18N
[ class tree: I18N ] [ index: I18N ] [ all elements ]

Source for file Format.php

Documentation is available at Format.php

  1. <?php
  2. /* vim: set expandtab tabstop=4 shiftwidth=4: */
  3. // +----------------------------------------------------------------------+
  4. // | PHP version 4.0                                                      |
  5. // +----------------------------------------------------------------------+
  6. // | Copyright (c) 1997, 1998, 1999, 2000, 2001, 2002, 2003 The PHP Group       |
  7. // +----------------------------------------------------------------------+
  8. // | This source file is subject to version 2.0 of the PHP license,       |
  9. // | that is bundled with this package in the file LICENSE, and is        |
  10. // | available at through the world-wide-web at                           |
  11. // | http://www.php.net/license/2_02.txt.                                 |
  12. // | If you did not receive a copy of the PHP license and are unable to   |
  13. // | obtain it through the world-wide-web, please send a note to          |
  14. // | license@php.net so we can mail you a copy immediately.               |
  15. // +----------------------------------------------------------------------+
  16. // | Authors: Wolfram Kriesing <wk@visionp.de>                            |
  17. // |                                                                      |
  18. // +----------------------------------------------------------------------+//
  19. // $Id: Format.php 134347 2003-07-07 12:50:43Z cain $
  20.  
  21. require_once 'PEAR.php';
  22.  
  23. // define those here, since the dateTime and currency 
  24. // use those constants too
  25. define'I18N_NUMBER_FLOAT' ,           );
  26. define'I18N_NUMBER_INTEGER' ,         );
  27.  
  28.  
  29. define'I18N_CURRENCY_LOCAL',          );
  30. define'I18N_CURRENCY_INTERNATIONAL',  );
  31.  
  32.                       
  33. // this is the offset for the custom index
  34. define'I18N_CUSTOM_FORMATS_OFFSET',   100);
  35.  
  36.  
  37. /**
  38. *
  39. *   @package    I18N
  40. *
  41. */
  42. class I18N_Format extends PEAR
  43. {
  44.      
  45.     /**
  46.     *   this var contains the current locale this instace works with
  47.     *
  48.     *   @access     protected
  49.     *   @var        string  this is a string like 'de_DE' or 'en_US', etc.
  50.     */
  51.     var $_locale;
  52.  
  53.     /**
  54.     *   the locale object which contains all the formatting specs
  55.     *
  56.     *   @access     protected
  57.     *   @var        object 
  58.     */
  59.     var $_localeObj = null;
  60.          
  61.                                   
  62.     /**          
  63.     *   do override this value !!!!
  64.     *   @abstract
  65.     */
  66.     var $_currentFormat = null;
  67.  
  68.     var $_customFormats = array();
  69.     
  70.     /**
  71.     *
  72.     *
  73.     *   @version    02/11/22
  74.     *   @author     Wolfram Kriesing <wolfram@kriesing.de>
  75.     *   @return     void 
  76.     *   @access     public
  77.     */
  78.     function I18N_Format($locale)
  79. // FIXXME if no locale is given try to use the local on of the system
  80. // if it cant be detected use english and the user probable will use setFormat anyway
  81.     {
  82.         parent::PEAR();
  83.         $this->_locale = $locale;
  84.  
  85. //FIXXME catch locales that we dont have a class for yet, and use default class, which
  86. // translates using google or something ...
  87.         ifinclude_once "I18N/Common/$locale.php){
  88.             $class = "I18N_Common_$locale";
  89.             $this->_localeObj = new $class();
  90.         }
  91.     }
  92.          
  93.     /**
  94.     *   This method creates a singleton instance for the given class.
  95.     *   This is here, just so the DateTime, Number and Currency dont have
  96.     *   to implement the same thing again, they only need to have a public method
  97.     *   singleton() which calls this method here.
  98.     *
  99.     *   @see    singleton()
  100.     *   @static
  101.     *   @access private
  102.     *   @param  string  the locale to use, i.e. 'de_DE'
  103.     *   @param  string  the name of the class to return an object for
  104.     *   @return object  an instance of this class
  105.     */
  106.     function &_singleton($locale,$class)
  107.     {
  108.         static $obj;
  109.         if (!isset($obj[$class])) {
  110.             $obj[$class= new $class($locale);
  111.         }
  112.         return $obj[$class];
  113.     }
  114.         
  115.     /**
  116.     *   define a custom format given by $format and return the $format-id
  117.     *   the format-id can be used to call format( x , format-id ) to
  118.     *   tell the method you want to use the format with that id
  119.     *
  120.     *   @see        format()
  121.     *   @version    02/11/20
  122.     *   @author     Wolfram Kriesing <wolfram@kriesing.de>
  123.     *   @param      string  defines a custom format
  124.     *   @return     int     the format-id, to be used with the format-method
  125.     */
  126.     function setFormat($format)
  127.     {
  128.         return $this->_setFormat($format);
  129.     }
  130.  
  131.     function _setFormat($format,$what='')
  132.     {
  133.         if((int)$format===$format{         // shall we only set the format to an already defined format?
  134.             return $this->{'_current'.ucfirst($what).'Format'$format;
  135.         }          
  136.  
  137.         // save a custom format and return the id of it, so the user can switch to it
  138.         // whenever needed
  139.         $index = (int)I18N_CUSTOM_FORMATS_OFFSET + sizeof($this->_customFormats);
  140.         $this->_customFormats[$index$format;
  141.         $this->{'_current'.ucfirst($what).'Format'$index;
  142.                              
  143.         return $index;
  144.     }
  145.  
  146.     /**
  147.     *
  148.     */
  149.     function getFormat()
  150.     {
  151.         return $this->_currentFormat;
  152.     }
  153.  
  154.  
  155.  
  156. }
  157. ?>

Documentation generated on Mon, 11 Mar 2019 15:36:11 -0400 by phpDocumentor 1.4.4. PEAR Logo Copyright © PHP Group 2004.