Language Redirection according to visitator country

Post custom hacks and enhancements for phpwcms here only. Maybe some of these things will be included in official release later.
culda_a
Posts: 521
Joined: Tue 28. Feb 2006, 01:39
Contact:

Language Redirection according to visitator country

Post 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?
ImagePackging design,labels, catalogs,postcards,
culda_a
Posts: 521
Joined: Tue 28. Feb 2006, 01:39
Contact:

Re: Language Redirection according to visitator country

Post by culda_a »

well it seams that this is not a interesting topic ... or function to discuss about it
ImagePackging design,labels, catalogs,postcards,
User avatar
update
Moderator
Posts: 6455
Joined: Mon 10. Jan 2005, 17:29
Location: germany / outdoor

Re: Language Redirection according to visitator country

Post 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 ;)
It's mostly all about maintaining two or three customer's sites Still supporter for the band Mykket Morton. Visit Mykket Morton on FB. Listen Mykket Morton and live videos on youtube.
Now building a venue for young artists to get wet on stage, rehearsal rooms, a studio, a guitar shop - yes I'm going to build some guitars.
User avatar
update
Moderator
Posts: 6455
Joined: Mon 10. Jan 2005, 17:29
Location: germany / outdoor

Re: Language Redirection according to visitator country

Post 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 ;)
It's mostly all about maintaining two or three customer's sites Still supporter for the band Mykket Morton. Visit Mykket Morton on FB. Listen Mykket Morton and live videos on youtube.
Now building a venue for young artists to get wet on stage, rehearsal rooms, a studio, a guitar shop - yes I'm going to build some guitars.
User avatar
Jensensen
Posts: 3000
Joined: Tue 17. Oct 2006, 21:11
Location: auf der mlauer

Re: Language Redirection according to visitator country

Post 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?
{so_much} | Knick-Knack. | GitHub
Umlaute im URL sind meistens immer Kacke.
User avatar
Heiko H.
Posts: 868
Joined: Thu 27. Oct 2005, 11:41
Location: Dresden
Contact:

Re: Language Redirection according to visitator country

Post 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...
Not longer here - sorry...

Haubner-IT GbR Dresden
User avatar
update
Moderator
Posts: 6455
Joined: Mon 10. Jan 2005, 17:29
Location: germany / outdoor

Re: Language Redirection according to visitator country

Post by update »

I'm sending en_US and I'm getting the german page - so the set of cases has to be extended?
It's mostly all about maintaining two or three customer's sites Still supporter for the band Mykket Morton. Visit Mykket Morton on FB. Listen Mykket Morton and live videos on youtube.
Now building a venue for young artists to get wet on stage, rehearsal rooms, a studio, a guitar shop - yes I'm going to build some guitars.
User avatar
Heiko H.
Posts: 868
Joined: Thu 27. Oct 2005, 11:41
Location: Dresden
Contact:

Re: Language Redirection according to visitator country

Post 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]
Not longer here - sorry...

Haubner-IT GbR Dresden
User avatar
update
Moderator
Posts: 6455
Joined: Mon 10. Jan 2005, 17:29
Location: germany / outdoor

Re: Language Redirection according to visitator country

Post 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?
It's mostly all about maintaining two or three customer's sites Still supporter for the band Mykket Morton. Visit Mykket Morton on FB. Listen Mykket Morton and live videos on youtube.
Now building a venue for young artists to get wet on stage, rehearsal rooms, a studio, a guitar shop - yes I'm going to build some guitars.
User avatar
Heiko H.
Posts: 868
Joined: Thu 27. Oct 2005, 11:41
Location: Dresden
Contact:

Re: Language Redirection according to visitator country

Post 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...
Not longer here - sorry...

Haubner-IT GbR Dresden
culda_a
Posts: 521
Joined: Tue 28. Feb 2006, 01:39
Contact:

Re: Language Redirection according to visitator country

Post 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?
ImagePackging design,labels, catalogs,postcards,
User avatar
Heiko H.
Posts: 868
Joined: Thu 27. Oct 2005, 11:41
Location: Dresden
Contact:

Re: Language Redirection according to visitator country

Post 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...
Not longer here - sorry...

Haubner-IT GbR Dresden
culda_a
Posts: 521
Joined: Tue 28. Feb 2006, 01:39
Contact:

Re: Language Redirection according to visitator country

Post by culda_a »

thanks... and I can add how many languges i want no restriction?
ImagePackging design,labels, catalogs,postcards,
User avatar
Heiko H.
Posts: 868
Joined: Thu 27. Oct 2005, 11:41
Location: Dresden
Contact:

Re: Language Redirection according to visitator country

Post 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:
Not longer here - sorry...

Haubner-IT GbR Dresden
culda_a
Posts: 521
Joined: Tue 28. Feb 2006, 01:39
Contact:

Re: Language Redirection according to visitator country

Post by culda_a »

and write in the summary:
what do you mean by that? in the part where I add the text?
ImagePackging design,labels, catalogs,postcards,
Post Reply