aliroLanguageBasic Class Reference

Inheritance diagram for aliroLanguageBasic:

aliroLanguageExtended

List of all members.

Public Member Functions

 __construct ($lang, $path=null, $load_catalogs=false)
 setCharset ($code)
 validCharset ($code)
 startGettext ()
 getDate ($format=null, $timestamp=null)
 formatDate ($time=null, $format=null)
 getDateFormat ()
 changeCharset ($value)

Public Attributes

 $isValid = false
 $name = ''
 $path = ''
 $version = '2.0'
 $title = ''
 $description = ''
 $creationdate = ''
 $author = ''
 $authorurl = ''
 $authoremail = ''
 $copyright = ''
 $license = ''
 $territory = ''
 $text_direction = ''
 $date_format = ''
 $iso639 = ''
 $iso3166_2 = ''
 $iso3166_3 = ''
 $locale = ''
 $charset = ''
 $plural_form = array()
 $days = array('sun'=>'','mon'=>'','tue'=>'','wed'=>'','thu'=>'','fri'=>'','sat'=>'')
 $months = array('jan'=>'','feb'=>'','mar'=>'','apr'=>'','may'=>'','jun'=>'','jul'=>'','aug'=>'','sep'=>'','oct'=>'','nov'=>'','dec'=>'')
 $files = array()

Protected Member Functions

 getFileName ()
 iconvert ($fromcharset, $tocharset, $source)

Protected Attributes

 $base_charset = 'utf-8'
 $codesets = array()
 $xmlfile = ''
 $convertor = null

Private Member Functions

 getSystemLocale ()
 load ($load_catalogs=false)
 extprops ($xobj)
 locale ($xobj)
 plural ($xobj)
 codesets ($xobj)
 dayget ($xobj)
 monthget ($xobj)
 fileget ($xobj)
 onefile ($file)


Detailed Description

Language Class for Aliro See top level index.php for Copyright etc.

Definition at line 7 of file aliroLanguageBasic.php.


Constructor & Destructor Documentation

aliroLanguageBasic::__construct ( lang,
path = null,
load_catalogs = false 
)

Reimplemented in aliroLanguageExtended.

Definition at line 39 of file aliroLanguageBasic.php.

References $path, load(), name, and T_().

00039                                                                          {
00040         $this->name = $lang;
00041         $this->path = $path ? $path : _ALIRO_CLASS_BASE.'/language/';
00042         $this->xmlfile = $this->path.$this->name.'/'.$this->name.'.xml';
00043         if (strpos($this->name, '..')) trigger_error(T_('Language name contains illegal ".."'));
00044         elseif ($this->load($load_catalogs)) $this->isValid = true;
00045     }


Member Function Documentation

aliroLanguageBasic::setCharset ( code  ) 

Definition at line 47 of file aliroLanguageBasic.php.

References $name, changeCharset(), and validCharset().

00047                                        {
00048         $exclude = array('xmlfile', 'path', 'files');
00049         if ($this->base_charset != $code) {
00050             if ($this->validCharset($code)) {
00051                 $this->charset = $code;
00052                 foreach (get_object_vars($this) as $name=>$value) if (!in_array($name, $exclude)) $this->$name = $this->changeCharset($value);
00053             }
00054             else $this->isValid = false;
00055         }
00056     }

aliroLanguageBasic::validCharset ( code  ) 

Definition at line 58 of file aliroLanguageBasic.php.

References codesets().

Referenced by setCharset().

00058                                          {
00059         return in_array($code, $this->codesets);
00060     }

aliroLanguageBasic::startGettext (  ) 

Definition at line 62 of file aliroLanguageBasic.php.

References aliroCore::getInstance(), getSystemLocale(), and name.

00062                                     {
00063         $core = aliroCore::getInstance();
00064         $gettext =PHPGettext::getInstance();
00065         $gettext->debug = intval($core->getCfg('locale_debug'));
00066         $gettext->has_gettext = intval($core->getCfg('locale_use_gettext'));
00067         $gettext->setlocale($this->name, $this->getSystemLocale());
00068         $gettext->bindtextdomain($this->name, _ALIRO_CLASS_BASE.'/language');
00069         $gettext->bind_textdomain_codeset($this->name, $this->charset);
00070         $gettext->textdomain($this->name);
00071     }

aliroLanguageBasic::getDate ( format = null,
timestamp = null 
)

Definition at line 73 of file aliroLanguageBasic.php.

References $days, and $months.

Referenced by formatDate().

00073                                                                {
00074         if (is_null($format)) $format = $this->date_format;
00075         if (is_null($timestamp)) $timestamp = time();
00076         $days = array_values($this->days);
00077         $months = array_values($this->months);
00078         $date = preg_replace('/%[aA]/', $days[(int)strftime('%w', $timestamp)], $format);
00079         $date = preg_replace('/%[bB]/', $months[(int)strftime('%m', $timestamp)-1], $date);
00080         return strftime($date, $timestamp);
00081     }

aliroLanguageBasic::formatDate ( time = null,
format = null 
)

Definition at line 83 of file aliroLanguageBasic.php.

References getDate().

00083                                                           {
00084         return $this->getDate($format, ($time ? strtotime($time) : time()));
00085     }

aliroLanguageBasic::getDateFormat (  ) 

Definition at line 87 of file aliroLanguageBasic.php.

00087                                     {
00088         return $this->date_format;
00089     }

aliroLanguageBasic::getFileName (  )  [protected]

Definition at line 99 of file aliroLanguageBasic.php.

Referenced by aliroLanguageExtended::save().

00099                                      {
00100         return $this->iso639.(2 == strlen($this->iso3166_2) ? '-'.$this->iso3166_2 : '');
00101     }

aliroLanguageBasic::iconvert ( fromcharset,
tocharset,
source 
) [protected]

Definition at line 103 of file aliroLanguageBasic.php.

Referenced by changeCharset(), and aliroLanguageExtended::save().

00103                                                                   {
00104         if (strtolower($fromcharset)==strtolower($tocharset)) return $source;
00105         if (!is_object($this->convertor)) $this->convertor = new ConvertCharset();
00106         return $this->convertor->Convert($source, $fromcharset, $tocharset, false);
00107     }

aliroLanguageBasic::changeCharset ( value  ) 

Definition at line 110 of file aliroLanguageBasic.php.

References iconvert().

Referenced by setCharset().

00110                                            {
00111         if (is_array($value)) foreach ($value as &$element) $element = $this->changeCharset($element);
00112         if (is_string($value)) $value = $this->iconvert($this->base_charset, $this->charset, $value);
00113         return $value;
00114     }

aliroLanguageBasic::getSystemLocale (  )  [private]

Definition at line 116 of file aliroLanguageBasic.php.

References locale().

Referenced by startGettext().

00116                                       {
00117         if (substr(strtoupper(PHP_OS), 0, 3) == 'WIN') return strtolower($this->title).($this->iso3166_3?'_'.strtolower($this->iso3166_3):'');
00118         else return $this->locale;
00119     }

aliroLanguageBasic::load ( load_catalogs = false  )  [private]

Definition at line 121 of file aliroLanguageBasic.php.

References codesets(), dayget(), extprops(), fileget(), aliroErrorRecorder::getInstance(), locale(), monthget(), name, and plural().

Referenced by __construct().

00121                                                    {
00122         if (!is_readable($this->xmlfile)) return false;
00123         try {
00124             $xmlobject = new aliroXML;
00125             $xmlobject->loadFile($this->xmlfile);
00126             $this->extprops ($xmlobject);
00127             $this->locale($xmlobject);
00128             $this->plural($xmlobject);
00129             $this->codesets($xmlobject);
00130             $this->dayget($xmlobject);
00131             $this->monthget($xmlobject);
00132             if ($load_catalogs) $this->fileget($xmlobject);
00133             $this->date_format = (string) $xmlobject->getXML('locale->date_format');
00134         }
00135         catch (aliroXMLException $exception) {
00136             $message = $exception->getMessage();
00137             var_dump($this->name);
00138             aliroErrorRecorder::getInstance()->recordError($message, $message, $message, $exception);
00139             die($message);
00140         }
00141         return true;
00142     }

aliroLanguageBasic::extprops ( xobj  )  [private]

Definition at line 144 of file aliroLanguageBasic.php.

Referenced by load().

00144                                       {
00145         $extension = new aliroExtension;
00146         $extension->populateFromXML($xobj);
00147         foreach (get_object_vars($extension) as $key=>$value) if (isset($this->$key)) $this->$key = $value;
00148     }

aliroLanguageBasic::locale ( xobj  )  [private]

Definition at line 150 of file aliroLanguageBasic.php.

Referenced by aliroLanguageExtended::createLanguage(), getSystemLocale(), load(), and aliroLanguageExtended::toXML().

00150                                     {
00151         $attrs = array('name', 'title','territory','locale','text_direction','iso639','iso3166_2','iso3166_3','charset');
00152         foreach ($attrs as $attr) $this->$attr = (string) $xobj->getXML("locale->[$attr]");
00153     }

aliroLanguageBasic::plural ( xobj  )  [private]

Definition at line 155 of file aliroLanguageBasic.php.

Referenced by load().

00155                                     {
00156         $this->plural_form = array();
00157         $attrs = array('nplurals', 'plural','expression');
00158         foreach ($attrs as $attr) $this->plural_form[$attr] = (string) $xobj->getXML("locale->plural_form->[$attr]");
00159     }

aliroLanguageBasic::codesets ( xobj  )  [private]

Definition at line 161 of file aliroLanguageBasic.php.

Referenced by aliroLanguageExtended::extractOneLocale(), load(), aliroLanguageExtended::toXML(), and validCharset().

00161                                       {
00162         $this->codesets = array();
00163         $sets = $xobj->getXML('locale->codesets->charset');
00164         foreach ($sets as $set) $this->codesets[] = (string) $set;
00165         $this->codesets = array_unique($this->codesets);
00166     }

aliroLanguageBasic::dayget ( xobj  )  [private]

Definition at line 168 of file aliroLanguageBasic.php.

Referenced by load().

00168                                     {
00169         foreach (array_keys($this->days) as $day) {
00170             $this->days[$day] = (string) $xobj->getXML("locale->days->[$day]");
00171         }
00172     }

aliroLanguageBasic::monthget ( xobj  )  [private]

Definition at line 174 of file aliroLanguageBasic.php.

Referenced by load().

00174                                       {
00175         foreach (array_keys($this->months) as $month) {
00176             $this->months[$month] = (string) $xobj->getXML("locale->months->[$month]");
00177         }
00178     }

aliroLanguageBasic::fileget ( xobj  )  [private]

Definition at line 180 of file aliroLanguageBasic.php.

References onefile().

Referenced by load().

00180                                      {
00181         $this->files = array();
00182         foreach ($xobj->getXML('files->filename') as $file) if ($new = $this->onefile($file)) $this->files[] = $new;
00183     }

aliroLanguageBasic::onefile ( file  )  [private]

Definition at line 185 of file aliroLanguageBasic.php.

Referenced by fileget().

00185                                      {
00186         $newfile['filename'] = (string)$file;
00187         // Ignore where domain not set
00188         $info = array('domain','strings','translated','fuzzy','percent','filetype');
00189         foreach ($info as $fi) $newfile[$fi] = (string) $file[$fi];
00190         return empty($newfile['domain']) ? null : $newfile;
00191     }


Member Data Documentation

aliroLanguageBasic::$base_charset = 'utf-8' [protected]

Definition at line 8 of file aliroLanguageBasic.php.

aliroLanguageBasic::$codesets = array() [protected]

Definition at line 9 of file aliroLanguageBasic.php.

Referenced by aliroLanguageExtended::oldGetLocales().

aliroLanguageBasic::$xmlfile = '' [protected]

Definition at line 10 of file aliroLanguageBasic.php.

Referenced by aliroLanguageExtended::oldGetLocales().

aliroLanguageBasic::$convertor = null [protected]

Definition at line 11 of file aliroLanguageBasic.php.

aliroLanguageBasic::$isValid = false

Definition at line 13 of file aliroLanguageBasic.php.

aliroLanguageBasic::$name = ''

aliroLanguageBasic::$path = ''

aliroLanguageBasic::$version = '2.0'

Definition at line 17 of file aliroLanguageBasic.php.

aliroLanguageBasic::$title = ''

Definition at line 18 of file aliroLanguageBasic.php.

aliroLanguageBasic::$description = ''

Definition at line 19 of file aliroLanguageBasic.php.

aliroLanguageBasic::$creationdate = ''

Definition at line 20 of file aliroLanguageBasic.php.

aliroLanguageBasic::$author = ''

Definition at line 21 of file aliroLanguageBasic.php.

aliroLanguageBasic::$authorurl = ''

Definition at line 22 of file aliroLanguageBasic.php.

aliroLanguageBasic::$authoremail = ''

Definition at line 23 of file aliroLanguageBasic.php.

aliroLanguageBasic::$copyright = ''

Definition at line 24 of file aliroLanguageBasic.php.

aliroLanguageBasic::$license = ''

Definition at line 25 of file aliroLanguageBasic.php.

aliroLanguageBasic::$territory = ''

Definition at line 26 of file aliroLanguageBasic.php.

Referenced by aliroLanguageExtended::getLocales().

aliroLanguageBasic::$text_direction = ''

Definition at line 27 of file aliroLanguageBasic.php.

aliroLanguageBasic::$date_format = ''

Definition at line 28 of file aliroLanguageBasic.php.

aliroLanguageBasic::$iso639 = ''

aliroLanguageBasic::$iso3166_2 = ''

Definition at line 30 of file aliroLanguageBasic.php.

aliroLanguageBasic::$iso3166_3 = ''

Definition at line 31 of file aliroLanguageBasic.php.

Referenced by aliroLanguageExtended::createLanguage().

aliroLanguageBasic::$locale = ''

aliroLanguageBasic::$charset = ''

aliroLanguageBasic::$plural_form = array()

Definition at line 34 of file aliroLanguageBasic.php.

aliroLanguageBasic::$days = array('sun'=>'','mon'=>'','tue'=>'','wed'=>'','thu'=>'','fri'=>'','sat'=>'')

Definition at line 35 of file aliroLanguageBasic.php.

Referenced by getDate(), and aliroLanguageExtended::toXML().

aliroLanguageBasic::$months = array('jan'=>'','feb'=>'','mar'=>'','apr'=>'','may'=>'','jun'=>'','jul'=>'','aug'=>'','sep'=>'','oct'=>'','nov'=>'','dec'=>'')

Definition at line 36 of file aliroLanguageBasic.php.

Referenced by getDate(), and aliroLanguageExtended::toXML().

aliroLanguageBasic::$files = array()

Definition at line 37 of file aliroLanguageBasic.php.


The documentation for this class was generated from the following file:

Generated on Wed May 14 13:01:59 2008 for ALIRO by  doxygen 1.5.5