[ Index ]

PHP Cross Reference of osCMax 2.0.4

title

Body

[close]

/admin/includes/classes/ -> language.php (source)

   1  <?php
   2  /*

   3  $Id: language.php 3 2006-05-27 04:59:07Z user $

   4  

   5    osCMax Power E-Commerce

   6    http://oscdox.com

   7  

   8    Copyright 2006 osCMax

   9  

  10    Released under the GNU General Public License

  11  

  12    browser language detection logic Copyright phpMyAdmin (select_lang.lib.php3 v1.24 04/19/2002)

  13                                     Copyright Stephane Garin <[email protected]> (detect_language.php v0.1 04/02/2002)

  14  */
  15  
  16    class language {
  17      var $languages, $catalog_languages, $browser_languages, $language;
  18  
  19      function language($lng = '') {
  20        $this->languages = array('ar' => 'ar([-_][[:alpha:]]{2})?|arabic',
  21                                 'bg' => 'bg|bulgarian',
  22                                 'br' => 'pt[-_]br|brazilian portuguese',
  23                                 'ca' => 'ca|catalan',
  24                                 'cs' => 'cs|czech',
  25                                 'da' => 'da|danish',
  26                                 'de' => 'de([-_][[:alpha:]]{2})?|german',
  27                                 'el' => 'el|greek',
  28                                 'en' => 'en([-_][[:alpha:]]{2})?|english',
  29                                 'es' => 'es([-_][[:alpha:]]{2})?|spanish',
  30                                 'et' => 'et|estonian',
  31                                 'fi' => 'fi|finnish',
  32                                 'fr' => 'fr([-_][[:alpha:]]{2})?|french',
  33                                 'gl' => 'gl|galician',
  34                                 'he' => 'he|hebrew',
  35                                 'hu' => 'hu|hungarian',
  36                                 'id' => 'id|indonesian',
  37                                 'it' => 'it|italian',
  38                                 'ja' => 'ja|japanese',
  39                                 'ko' => 'ko|korean',
  40                                 'ka' => 'ka|georgian',
  41                                 'lt' => 'lt|lithuanian',
  42                                 'lv' => 'lv|latvian',
  43                                 'nl' => 'nl([-_][[:alpha:]]{2})?|dutch',
  44                                 'no' => 'no|norwegian',
  45                                 'pl' => 'pl|polish',
  46                                 'pt' => 'pt([-_][[:alpha:]]{2})?|portuguese',
  47                                 'ro' => 'ro|romanian',
  48                                 'ru' => 'ru|russian',
  49                                 'sk' => 'sk|slovak',
  50                                 'sr' => 'sr|serbian',
  51                                 'sv' => 'sv|swedish',
  52                                 'th' => 'th|thai',
  53                                 'tr' => 'tr|turkish',
  54                                 'uk' => 'uk|ukrainian',
  55                                 'tw' => 'zh[-_]tw|chinese traditional',
  56                                 'zh' => 'zh|chinese simplified');
  57  
  58        $this->catalog_languages = array();
  59        $languages_query = tep_db_query("select languages_id, name, code, image, directory from " . TABLE_LANGUAGES . " order by sort_order");
  60        while ($languages = tep_db_fetch_array($languages_query)) {
  61          $this->catalog_languages[$languages['code']] = array('id' => $languages['languages_id'],
  62                                                               'name' => $languages['name'],
  63                                                               'image' => $languages['image'],
  64                                                               'directory' => $languages['directory']);
  65        }
  66  
  67        $this->browser_languages = '';
  68        $this->language = '';
  69  
  70        $this->set_language($lng);
  71      }
  72  
  73      function set_language($language) {
  74        if ( (tep_not_null($language)) && (isset($this->catalog_languages[$language])) ) {
  75          $this->language = $this->catalog_languages[$language];
  76        } else {
  77          $this->language = $this->catalog_languages[DEFAULT_LANGUAGE];
  78        }
  79      }
  80  
  81      function get_browser_language() {
  82        $this->browser_languages = explode(',', getenv('HTTP_ACCEPT_LANGUAGE'));
  83  
  84        for ($i=0, $n=sizeof($this->browser_languages); $i<$n; $i++) {
  85          reset($this->languages);
  86          while (list($key, $value) = each($this->languages)) {
  87            if (eregi('^(' . $value . ')(;q=[0-9]\\.[0-9])?$', $this->browser_languages[$i]) && isset($this->catalog_languages[$key])) {
  88              $this->language = $this->catalog_languages[$key];
  89              break 2;
  90            }
  91          }
  92        }
  93      }
  94    }
  95  ?>


Generated: Fri Jan 1 13:43:16 2010 Cross-referenced by PHPXref 0.7