Jump to content
  • Checkout
  • Login
  • Get in touch

osCommerce

The e-commerce.

Detecting languages


Tomcat

Recommended Posts

Posted

Hi,

 

My default language is English (GB).

I set up a new language as american to automatically switch american users to their currency ( USD instead of GBP ). I use switch to default currency=true, of course.

 

As far as I can see though Oscommerce language detection array is not made to make any dinstinction between english GB (en_gb) and english US (en_us ).

 

then I set up my browser language tu en_us to test, but no way the browser starts with en_us . I think I have to change the language detection string, but don't know how.

Any help ?

 

here is my code in catalog/icludes/classes/language.php :

<?php
/*
 $Id: language.php,v 1.1.1.1 2003/09/18 19:05:15 wilt Exp $

 osCommerce, Open Source E-Commerce Solutions
 http://www.oscommerce.com

 Copyright (c) 2003 osCommerce

 Released under the GNU General Public License

 browser language detection logic Copyright phpMyAdmin (select_lang.lib.php3 v1.24 04/19/2002)
                                  Copyright Stephane Garin <[email protected]> (detect_language.php v0.1 04/02/2002)
*/

 class language {
   var $languages, $catalog_languages, $browser_languages, $language;

   function language($lng = '') {
     $this->languages = array('ar' => 'ar([-_][[:alpha:]]{2})?|arabic',
                              'bg' => 'bg|bulgarian',
                              'br' => 'pt[-_]br|brazilian portuguese',
                              'ca' => 'ca|catalan',
                              'cs' => 'cs|czech',
                              'da' => 'da|danish',
                              'de' => 'de([-_][[:alpha:]]{2})?|german',
                              'el' => 'el|greek',
                              'en' => 'en([-_][[:alpha:]]{2})?|english',
         'us' => 'en[-_]us|american',
                              'es' => 'es([-_][[:alpha:]]{2})?|spanish',
                              'et' => 'et|estonian',
                              'fi' => 'fi|finnish',
                              'fr' => 'fr([-_][[:alpha:]]{2})?|french',
                              'gl' => 'gl|galician',
                              'he' => 'he|hebrew',
                              'hu' => 'hu|hungarian',
                              'id' => 'id|indonesian',
                              'it' => 'it|italian',
                              'ja' => 'ja|japanese',
                              'ko' => 'ko|korean',
                              'ka' => 'ka|georgian',
                              'lt' => 'lt|lithuanian',
                              'lv' => 'lv|latvian',
                              'nl' => 'nl([-_][[:alpha:]]{2})?|dutch',
                              'no' => 'no|norwegian',
                              'pl' => 'pl|polish',
                              'pt' => 'pt([-_][[:alpha:]]{2})?|portuguese',
                              'ro' => 'ro|romanian',
                              'ru' => 'ru|russian',
                              'sk' => 'sk|slovak',
                              'sr' => 'sr|serbian',
                              'sv' => 'sv|swedish',
                              'th' => 'th|thai',
                              'tr' => 'tr|turkish',
                              'uk' => 'uk|ukrainian',
                              'tw' => 'zh[-_]tw|chinese traditional',
                              'zh' => 'zh|chinese simplified');

     $this->catalog_languages = array();
     $languages_query = tep_db_query("select languages_id, name, code, image, directory from " . TABLE_LANGUAGES . " order by sort_order");
     while ($languages = tep_db_fetch_array($languages_query)) {
       $this->catalog_languages[$languages['code']] = array('id' => $languages['languages_id'],
                                                            'name' => $languages['name'],
                                                            'image' => $languages['image'],
                                                            'directory' => $languages['directory']);
     }

     $this->browser_languages = '';
     $this->language = '';

     $this->set_language($lng);
   }

   function set_language($language) {
     if ( (tep_not_null($language)) && (isset($this->catalog_languages[$language])) ) {
       $this->language = $this->catalog_languages[$language];
     } else {
       $this->language = $this->catalog_languages[DEFAULT_LANGUAGE];
     }
   }

   function get_browser_language() {
     $this->browser_languages = explode(',', getenv('HTTP_ACCEPT_LANGUAGE'));

     for ($i=0, $n=sizeof($this->browser_languages); $i<$n; $i++) {
       reset($this->languages);
       while (list($key, $value) = each($this->languages)) {
         if (eregi('^(' . $value . ')(;q=[0-9]\\.[0-9])?$', $this->browser_languages[$i]) && isset($this->catalog_languages[$key])) {
           $this->language = $this->catalog_languages[$key];
           break 2;
         }
       }
     }
   }
 }
 //echo $this;
 




?>

Outside links in signatures are not allowed!

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...