[ Index ]

PHP Cross Reference of Limb3

title

Body

[close]

/i18n/src/locale/ -> lmbLocaleSpec.class.php (source)

   1  <?php
   2  /*
   3   * Limb PHP Framework
   4   *
   5   * @link http://limb-project.com 
   6   * @copyright  Copyright &copy; 2004-2007 BIT(http://bit-creative.com)
   7   * @license    LGPL http://www.gnu.org/copyleft/lesser.html 
   8   */
   9  
  10  /**

  11   * class lmbLocaleSpec.

  12   *

  13   * @package i18n

  14   * @version $Id: lmbLocaleSpec.class.php 5945 2007-06-06 08:31:43Z pachanga $

  15   */
  16  class lmbLocaleSpec
  17  {
  18    const REGEX = "~^([a-zA-Z]+)           #language identifier
  19                    ([_]([a-zA-Z]+))?     #separator and the country
  20                    (\.([-a-zA-Z0-9]+))?   #separator and the charset
  21                    (@([a-zA-Z0-9]+))?     #separator and the variation
  22                    \$~x";
  23  
  24    protected $language = '';
  25    protected $country = '';
  26    protected $country_variation = '';
  27    protected $charset = '';
  28    protected $locale = '';
  29    protected $locale_string = '';
  30  
  31    function __construct($locale_string)
  32    {
  33      $this->locale_string = $locale_string;
  34      $this->_parse($locale_string);
  35    }
  36  
  37    function getLocaleString()
  38    {
  39      return $this->locale_string;
  40    }
  41  
  42    function getLanguage()
  43    {
  44      return $this->language;
  45    }
  46  
  47    function getCountry()
  48    {
  49      return $this->country;
  50    }
  51  
  52    function getCountryVariation()
  53    {
  54      return $this->country_variation;
  55    }
  56  
  57    function getCharset()
  58    {
  59      return $this->charset;
  60    }
  61  
  62    function getLocale()
  63    {
  64      return $this->locale;
  65    }
  66  
  67    protected function _parse($locale_string)
  68    {
  69      if(preg_match(self :: REGEX, $locale_string, $regs))
  70      {
  71        $this->language = strtolower($regs[1]);
  72  
  73        if(isset($regs[3]))
  74          $this->country = strtoupper($regs[3]);
  75  
  76        if(isset($regs[5]))
  77          $this->charset = strtolower($regs[5]);
  78  
  79        if(isset($regs[7]))
  80          $this->country_variation = strtolower($regs[7]);
  81  
  82        $this->locale = $this->language;
  83        if($this->country !== '')
  84          $this->locale .= '_' . $this->country;
  85      }
  86      else
  87      {
  88        $this->locale = strtolower($locale_string);
  89        $this->language = $this->locale;
  90      }
  91    }
  92  }
  93  
  94  ?>


Generated: Sat Nov 22 03:48:54 2008 Cross-referenced by PHPXref 0.7