Multi language site > redirect visitor to his own language

Guido

Avatar: Guido

2013-01-28 09:32

Hi,

I have a website with 3 lamguages. In settingspanel I can set default language.

But I want a visitor from Germany to be redirected to the German website (index page)and a visitor from the UK to the Engelish website (index page).

Is this possible?

Guido

» Quick.Cms v5.x

interkob

Avatar: interkob

2013-01-29 13:28

Unfortunately, I don't have a solution for this. But try to find something on Google, for example, using "Redirect GeoIp"

boboo

Avatar: boboo

2013-01-29 20:38

Guido,
try with $_SERVER['HTTP_ACCEPT_LANGUAGE']
This item contents the abreviation of the client browser language (en_EN, de_DE, etc.)
In QC the language is determined in general.php -> look for $sLang=...
You can build the query:
if $_SERVER['HTTP_ACCEPT_LANGUAGE'] == en_EN then $sLang = en
if $_SERVER['HTTP_ACCEPT_LANGUAGE'] == de_DE then $sLang = de
else $sLang = nl (if nl is your default)

this week i have no time to test it, but it should work, if you implement this correctly to general.php

www.kimla.de

Guido

Avatar: Guido

2013-01-30 18:47

Hi boboo,

Should I delete line in general.php: $config['default_lang'] = "nl";

And replace it with your code?

Guido

Avatar: Guido

2013-01-30 19:34

So delete that line and replace it with this code?


if ($_SERVER['HTTP_ACCEPT_LANGUAGE'] == 'en_EN')
{$sLang = 'en';
}
else if ($_SERVER['HTTP_ACCEPT_LANGUAGE'] == 'de_DE')
{$sLang = 'de';
}
else
{$sLang = 'nl';
}

Guido

Avatar: Guido

2013-01-30 20:04

Hmm, I guess not to delete that line, but only add this code?

Because if 'server http accept language' is not supported, visitor must go to nl (the default) index-page.

Guido

Guido

Avatar: Guido

2013-01-31 21:18

Not working.
I've stumbled upon the default language settings. Cannot remove them without getting errors or 'nothing found' when I visit homepage of website.
And there's also line in index.php: require DB_CONFIG_LANG

Guido

Avatar: Guido

2013-02-06 00:51

Boboo, do you have a solution?

Or anybody else?

boboo

Avatar: boboo

2013-02-07 09:03

Guido,
do you have some different (language) computers?
Or access to these?
Prepare 3 pieces: NL, DE and EN
I will try to write some code and put a test CMS on my webserver.
Hope, I get this today afternoon (i have really not so much time)

www.kimla.de

Guido

Avatar: Guido

2013-02-07 13:15

Hi,

Not different 'language computers', but I can use Tor to hide my ip/language. This way I can test it too I guess. Or ask a friend in another country.

Btw, I also added a htaccess file in root, but then whole site was not displayed anymore:
http://www.htaccesstools.com/redirection-by-language/

Guido

boboo

Avatar: boboo

2013-02-07 14:22

http://www.kimla.de/cmslangtest/
should be so: with PL computer polish pages will be shown,
with DE computer, german page,
with NL, dutch page,
with EN, englich pages.
If not in these 4 langs, then default (i suppose, i have set EN)

www.kimla.de

Guido

Avatar: Guido

2013-02-07 18:01

It's working.

Buddy of mine told me Opera has a language setting, so I used that to test your site.

How can I get this script from you?

Guido

boboo

Avatar: boboo

2013-02-07 19:49

Guido,
I'm glad that it works.
The solution:
in /database/config/general.php
over the line:

if( isset( $sLang ) && is_file$config['dir_lang'].$sLang.'.php' ) && strlen$sLang ) == ){


add:

if(defined('CUSTOMER_PAGE')&&!isset($sLang)&&isset($_SERVER['HTTP_ACCEPT_LANGUAGE']))
 
$sLang=strtolower(substr($_SERVER['HTTP_ACCEPT_LANGUAGE'],0,2));


That's all.
If you consider to give me something for this? then let me know :-)

www.kimla.de

Guido

Avatar: Guido

2013-02-07 23:24

@boboo

Thanks. PayPal?

So, delete line:

if( isset( $sLang ) && is_file$config['dir_lang'].$sLang.'.php' ) && strlen$sLang ) == 



(without: { )

And replace it with your line?

Did that, but getting error.

Guido

boboo

Avatar: boboo

2013-02-08 06:31

Not delete!!!
ADD this ABOVE the line.
But a small change is to make.
Don't do that from my first instruction, do as follows:
ABOVE the line:

if( isset( $sLang ) && is_file$config['dir_lang'].$sLang.'.php' ) && strlen$sLang ) == ){


ADD:

if(defined('CUSTOMER_PAGE')&&!isset($sLang)&&isset($_SERVER['HTTP_ACCEPT_LANGUAGE'])){
 $
$sLang=strtolower(substr($_SERVER['HTTP_ACCEPT_LANGUAGE'],0,2));
 if(
is_file($config['dir_lang'].$$sLang.'.php'))
  
$sLang=$sLang;
 else
  
$sLang=null;
}



Last time i'm a bit tired. We bought a house in Bestwig and we are moving. From Dortmund it is 80 km and we do it by ourselves. Maby we will meet there by ski in winter (its only 20 km from Winterberg) in our region there are a lot of ski parks and the Fort Fun we have 2,5 km from us :-)

www.kimla.de

boboo

Avatar: boboo

2013-02-08 06:33

Remove one "$" from the third line ".$$sLang."

www.kimla.de

Guido

Avatar: Guido

2013-02-09 01:04

Moving, but still time for helping me out > great!

I had to remove 1 $ in second line too ;-).

But works fine, thanks man.

PayPal?

Back to top
about us | contact