Jump to content
  • Checkout
  • Login
  • Get in touch

osCommerce

The e-commerce.

Redirection of home page needed (language-dependend)


Andreas2003

Recommended Posts

Posted

Hi there,

 

as you know, the default of osC is designed that way, that the language is detected through the browser language.

That is working for me and I don't want to change this.

 

But all languages are landing on the URL www.domain.com.

Language is set correctly for navigation, products etc., but the URL is www.domain.com, no matter what language is detected (not selected).

 

This changes only when you select a language or category.

Then in the URL, the parameter "language=xx" is being added.

 

What I need is a automatic redirection of the home page (and not only when you select a language or category) right from the beginning like this way:

www.domain.com                               => English
www.domain.com/index.php?language=de           => German
www.domain.com/index.php?language=es           => Spanish

 

Is there a chance to change that somewhere ??

 

Thanks in advance,

regards

Andreas

Posted

Is it even possible ?

Sure, it's possible! Although, I thought that osC was already written to behave that way (use the application_top language determination to set the language used). If it's not working in the way you'd like it to, you can try something like this. Find in includes/application_top.php:

   $language = $lng->language['directory'];
   $languages_id = $lng->language['id'];
 }

// include the language translations
 require(DIR_WS_LANGUAGES . $language . '.php');

and insert some code as follows:

   $language = $lng->language['directory'];
   $languages_id = $lng->language['id'];
 }

// if language is one of supported non-English, go there
 if ($language != 'english' && !isset($_GET['language'])) {
   switch ($language) {
     case 'spanish': $where = 'es'; break;
     case 'deutsche': $where = 'de'; break;
     default: $where = 'en';  // leave as English for any non-supported language
   }
   if ($where != 'en') {
     header("Location: /index.php?language=" . $where);
     exit;
   }
 }

// include the language translations
 require(DIR_WS_LANGUAGES . $language . '.php');

Now, this is just off the top of my head and is untested, so take it as a starting point, not as finished code! There are a number of possible trouble points that you'll have to investigate:

1) The available $language values (e.g., 'spanish' or 'espanol')

2) If you're not in index.php, you may need to grab the current path and page somewhere ($_SERVER['PHP_SELF'], perhaps?) and just append language=xx on to it (with ? or &, depending on whether there is already a Query String).

 

It will take some trial and error, but that should get you started. Note that if 'language=xx' is already in the URL, it won't do any redirecting. If English or an unsupported language is reported by the browser and other language code, use English. On the admin side, you can do the same if you wish, or just leave it as is.

 

You might even want to check what it's currently doing (without the added code) -- is it setting the expected $language? Maybe your browser is configured to always return English as the language? It's very common for users' browsers to be configured as English language, even in non-English speaking countries. This will keep osC from autoselecting the correct local language.

Posted

Mr.Phil, thank you very much for the answer and your code.

It seems to work, but...

 

Is there a way to test the function properly without to much fuzz ?

I'm using Firefox with the "Quick locale switcher". Test results are not clear enough, and the browser has to be restarted at every switch.

 

Is there another possibility to test this ?

 

Thanks in advance,

regards

Andreas

Posted

Sorry, I'm not familiar with switching languages on browsers. I'm not surprised that a restart would be needed with each change, though.

Archived

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

×
×
  • Create New...