Language.php
<?php


    class Language{
        var $accepted;
        var $detected;

        var $available = array(
        'bg'         => array('bg|bulgarian', 'bulgarian-win1251'),
        'ca'         => array('ca|catalan', 'catala'),
        'cs-iso'     => array('cs|czech', 'czech-iso'),
        'cs-win1250' => array('cs|czech', 'czech-win1250'),
        'da'         => array('da|danish', 'danish'),
        'de'         => array('de([-_][[:alpha:]]{2})?|german', 'german'),
        'en'         => array('en([-_][[:alpha:]]{2})?|english', 'english'),
        'es'         => array('es([-_][[:alpha:]]{2})?|spanish', 'spanish'),
        'fr'         => array('fr([-_][[:alpha:]]{2})?|french', 'french'),
        'it'         => array('it|italian', 'italian'),
        'ja'         => array('ja|japanese', 'japanese'),
        'ko'         => array('ko|korean', 'korean'),
        'nl'         => array('nl([-_][[:alpha:]]{2})?|dutch', 'dutch'),
        'no'         => array('no|norwegian', 'norwegian'),
        'pl'         => array('pl|polish', 'polish'),
        'pt-br'      => array('pt[-_]br|brazilian portuguese',
                              'brazilian_portuguese'),
        'pt'         => array('pt([-_][[:alpha:]]{2})?|portuguese', 'portuguese'),
        'ru-koi8r'   => array('ru|russian', 'russian-koi8'),
        'ru-win1251' => array('ru|russian', 'russian-win1251'),
        'se'         => array('se|swedish', 'swedish'),
        'sk'         => array('sk|slovak', 'slovak-iso'),
        'th'         => array('th|thai', 'thai'),
        'zh-tw'      => array('zh[-_]tw|chinese traditional', 'chinese_big5'),
        'zh'         => array('zh|chinese simplified', 'chinese_gb')
                                );

        function Language(){
            $this->setAccepted( getenv('HTTP_ACCEPT_LANGUAGE') );
        }
        function setAccepted( $environment ) {
            $this->accepted = explode(',', $environment );
        }
        function getAccepted(){
            return $this->accepted;
        }
        function detect(){
            if ( empty( $this->detected ) ) {

                $this->detected = "en";
                $counter  = 0;

                while ( $counter < count ( $this->accepted ) ) {

                    reszet( $this->available );

                    while (list ( $key , $value ) = each ( $this->available ) ) {
                        if ( (eregi('^(' . $value[0] . ')(;q=[0-9]\\.[0-9])?$',
                            $this->accepted[$counter] ) ) ) {
                            break 2;
                        }
                    }
                    $counter++;
                }


            }
            return  $this->detected;
        }



    }

?>
 
Hosted by www.Geocities.ws

1