aliroLanguage.php

Go to the documentation of this file.
00001 <?php
00007 class aliroLanguage extends cachedSingleton  {
00008     protected static $instance = __CLASS__;
00009 
00010     protected $languages = array();
00011     protected $default_language = '';
00012     protected $default_charset = '';
00013     protected $base_charset = 'utf-8';
00014     protected $current_language = '';
00015     
00016     protected function __construct () {
00017         $core = aliroCore::getInstance();
00018         $this->default_charset = $core->getCfg('charset');
00019         if (!$this->default_charset) $this->default_charset = $this->base_charset;
00020         $langspec = $core->getCfg('locale');
00021         if (!$this->setupLanguage($langspec) AND !$this->setupLanguage('en')) trigger_error(T_('Default language specification is invalid'), E_USER_ERROR);
00022         define ('_ALIRO_LANGUAGE', $this->default_language);
00023     }
00024     
00025     protected function setupLanguage ($langspec) {
00026         $language = new aliroLanguageBasic ($langspec, _ALIRO_CLASS_BASE.'/language/');
00027         if ($language->isValid) {
00028             $this->languages[$langspec] = $language;
00029             $this->languages[$langspec]->setCharset($this->default_charset);
00030             $this->default_language = $langspec;
00031             return true;
00032         }
00033         return false;
00034     }
00035 
00036     public static function getInstance () {
00037         if (!is_object(self::$instance)) {
00038             self::$instance = parent::getCachedSingleton(self::$instance);
00039             self::$instance->checkLanguage();
00040         }
00041         return self::$instance;
00042     }
00043     
00044     private function checkLanguage () {
00045         $this->current_language = empty($_REQUEST['lang']) ? $this->default_language : $_REQUEST['lang'];
00046         if (!isset($this->languages[$this->current_language])) {
00047             $this->languages[$this->current_language] = new aliroLanguageBasic ($this->current_language, _ALIRO_CLASS_BASE.'/language/');
00048             $this->languages[$this->current_language]->setCharset($this->default_charset);
00049             if (!$this->languages[$this->current_language]->isValid) $this->languages[$this->current_language] = 'Invalid';
00050         }
00051         if (!is_object($this->languages[$this->current_language])) $this->current_language = $this->default_language;
00052         define ('_ALIRO_LANGUAGE_CODE', $this->current_language);
00053         aliroCore::set('locale', $this->current_language);
00054         DEFINE('_ISO','charset='.$this->default_charset);
00055         $dateformat = $this->languages[$this->current_language]->date_format;
00056         DEFINE('_DATE_FORMAT_LC', $dateformat); //Uses PHP's strftime Command Format
00057         DEFINE('_DATE_FORMAT_LC2', $dateformat);
00058         define ('_JOOMLA_LANGUAGE', $this->languages[$this->current_language]->iso639.'-GB');
00059         $this->languages[$this->current_language]->startGettext();
00060     }
00061 
00062     public function getDate($format = null, $timestamp = null) {
00063         return $this->languages[$this->current_language]->getDate($format, $timestamp);
00064     }
00065 
00066     public function formatDate ($time=null, $format=null) {
00067         return $this->getDate($format, ($time ? strtotime($time) : time()));
00068     }
00069 
00070     public function getDateFormat() {
00071         return $this->languages[$this->current_language]->getDateFormat();
00072     }
00073     
00074     public function changeCharset ($value) {
00075         return $this->base_charset == $this->default_charset ? $value : $this->languages[$this->current_language]->changeCharset($value);
00076     }
00077     
00078     public function validCharset ($code) {
00079         return $this->languages[$this->current_language]->validCharset($code);
00080     }
00081 
00082 }

Generated on Thu Apr 17 13:03:26 2008 for ALIRO by  doxygen 1.5.5