Page 1 of 2

Language Redirection according to visitator country

Posted: Wed 18. Mar 2009, 15:42
by culda_a
is there a way to make Language Redirection when a visitator from England visit my site to be automaticly redirected to english version of my site?

http://www.mysite.com/index.php?en_home

or if he comes from germany to be redirected automaticly to : http://www.mysite.com/index.php?de_home

how can I do that?

Re: Language Redirection according to visitator country

Posted: Tue 24. Mar 2009, 20:26
by culda_a
well it seams that this is not a interesting topic ... or function to discuss about it

Re: Language Redirection according to visitator country

Posted: Tue 24. Mar 2009, 21:53
by update
well, this is an interesting question - indeed!
And there is a solution:
Please have a look at /template/inc_scripts/frontend_init/disabled/domaincheck.php
and edit it to your needs. In case you don't succeed just ask again - then instant relief will be yours ;)

Re: Language Redirection according to visitator country

Posted: Tue 24. Mar 2009, 22:43
by update
Ah- well, I just detected that you mean the country the visitor is coming from - hmmm, there should be a possibility to check the browser language for example... redirecting per browser language. This would mean that I'll never be able to visit your german part of the site because my browser language is en-US english by default.... hmmmm
Please forget my previous posting for a while ;)

Re: Language Redirection according to visitator country

Posted: Tue 24. Mar 2009, 22:57
by Jensensen
claus wrote:... would mean that I'll never be able to visit your german part of the site because my browser language is en-US english by default ...
so what is this i18n stuff all about?

Re: Language Redirection according to visitator country

Posted: Wed 25. Mar 2009, 10:05
by Heiko H.
Hi,

I made this like that:
Make a lang_redirect.php

Code: Select all

<?php
if(!$GLOBALS['aktion'][0]) { 
	 switch( strtolower( substr( $_SERVER['HTTP_ACCEPT_LANGUAGE'], 0, 2 ) ) ) {
	  	 //deutsch
		 case 'de': header('HTTP/1.1 301 Moved Permanently'); 
		            header('Location: '.$GLOBALS['phpwcms']['site'].$GLOBALS['phpwcms']['root'].'de_start.phtml');
		 exit();
		 break;
		 //tschechisch
		 case 'cs': header('HTTP/1.1 301 Moved Permanently'); 
		            header('Location: '.$GLOBALS['phpwcms']['site'].$GLOBALS['phpwcms']['root'].'cs_start.phtml');
		 exit();
		 break;
		 //französisch
		 case 'fr': header('HTTP/1.1 301 Moved Permanently'); 
		            header('Location: '.$GLOBALS['phpwcms']['site'].$GLOBALS['phpwcms']['root'].'fr_start.phtml');
		 exit();
		 break;
		 //japanisch
         case 'ja': header('HTTP/1.1 301 Moved Permanently'); 
		            header('Location: '.$GLOBALS['phpwcms']['site'].$GLOBALS['phpwcms']['root'].'ja_start.phtml');
		 exit();
		 break;
		 //italienisch
		 case 'it': header('HTTP/1.1 301 Moved Permanently'); 
		            header('Location: '.$GLOBALS['phpwcms']['site'].$GLOBALS['phpwcms']['root'].'it_start.phtml');
		 exit();
		 break;
		 //polnisch
		 case 'pl': header('HTTP/1.1 301 Moved Permanently'); 
		            header('Location: '.$GLOBALS['phpwcms']['site'].$GLOBALS['phpwcms']['root'].'pl_start.phtml');
		 exit();
		 break;
		 //spanisch
		 case 'es': header('HTTP/1.1 301 Moved Permanently'); 
		            header('Location: '.$GLOBALS['phpwcms']['site'].$GLOBALS['phpwcms']['root'].'es_start.phtml');
		 exit();
		 break;
		 //russisch
		 case 'ru': header('HTTP/1.1 301 Moved Permanently'); 
		            header('Location: '.$GLOBALS['phpwcms']['site'].$GLOBALS['phpwcms']['root'].'ru_start.phtml');
		 exit();
		 break;
		 //default -> englisch
		 default: header('HTTP/1.1 301 Moved Permanently');
		          header('Location: '.$GLOBALS['phpwcms']['site'].$GLOBALS['phpwcms']['root'].'en_start.phtml');
		 exit(); 
		 } 
	}
?>
fit it to your needs and place it where you want eg. /scripts.
Make a new article in the home category and write in the summary:

Code: Select all

{PHP:scripts/lang_redirect.php}
Enjoy... :wink:

This is working here.

Heiko...

Re: Language Redirection according to visitator country

Posted: Wed 25. Mar 2009, 10:18
by update
I'm sending en_US and I'm getting the german page - so the set of cases has to be extended?

Re: Language Redirection according to visitator country

Posted: Wed 25. Mar 2009, 10:30
by Heiko H.
claus wrote:I'm sending en_US and I'm getting the german page - so the set of cases has to be extended?
If I send en_US, I'm getting the english page.
Browser restartet after language change? Is en_US set as first in the priority?

Heiko

[EDIT]
I can see in phpmyvisites -> entrypages that it works...
[/EDIT]

Re: Language Redirection according to visitator country

Posted: Wed 25. Mar 2009, 10:48
by update
my fault - a simple reload of the kangaruuuh doesn't do it - you have to visit the page and it's working (because otherwise this start page with the script cannot be triggered anymore)
Wouldn't it be better then to push it into a frontend render script?

Re: Language Redirection according to visitator country

Posted: Wed 25. Mar 2009, 11:13
by Heiko H.
claus wrote:my fault - a simple reload of the kangaruuuh doesn't do it - you have to visit the page and it's working (because otherwise this start page with the script cannot be triggered anymore)
Wouldn't it be better then to push it into a frontend render script?
May be, but this is not soooo easy.
If the user is redirectet because of the language settings of the browser but this language is different to his native language (eg. in a internetcafe) he can't switch the language "by hand".
A frontend_render script should only run at the first access per client or should only work in the home-category - too much work :wink: .
Hey, this function is only a gimmick, or not?

I know my script is not 100%... too :wink:


Heiko...

Re: Language Redirection according to visitator country

Posted: Wed 25. Mar 2009, 15:24
by culda_a
is this script working also if I have the link like this:
index.php?en_home

do I have to put it like this in the script:

Code: Select all

 break;
       //default -> englisch
       default: header('HTTP/1.1 301 Moved Permanently');
                header('Location: '.$GLOBALS['phpwcms']['site'].$GLOBALS['phpwcms']['root'].'en_home');
       exit(); 

is that corect?

Re: Language Redirection according to visitator country

Posted: Wed 25. Mar 2009, 15:27
by Heiko H.
culda_a wrote:is that corect?
No!

That's it:

Code: Select all

       //default -> englisch
       default: header('HTTP/1.1 301 Moved Permanently');
                header('Location: '.$GLOBALS['phpwcms']['site'].$GLOBALS['phpwcms']['root'].'index.php?en_home');
       exit(); 
Good luck, Heiko...

Re: Language Redirection according to visitator country

Posted: Wed 25. Mar 2009, 15:37
by culda_a
thanks... and I can add how many languges i want no restriction?

Re: Language Redirection according to visitator country

Posted: Wed 25. Mar 2009, 15:49
by Heiko H.
culda_a wrote:no restriction?
No.
culda_a wrote:thanks... and I can add how many languges i want
Yes, as long you use the correct syntax... :wink:

Re: Language Redirection according to visitator country

Posted: Wed 25. Mar 2009, 22:25
by culda_a
and write in the summary:
what do you mean by that? in the part where I add the text?