Multiple Languages

happydg
Posts: 412
Joined: Mon Jul 08, 2013 2:22 pm

Re: Multiple Languages

Post by happydg »

If i add:

Code: Select all

if (strstr($_SERVER['HTTP_ACCEPT_LANGUAGE'], 'fr')) {
  $lang = $my_keywords['fr'];
} elseif (strstr($_SERVER['HTTP_ACCEPT_LANGUAGE'], 'de')) {
  $lang = $my_keywords['de'];
} else $lang = $my_keywords['en'];

if ($_GET['force_lng'] and isset($my_keywords[$_GET['force_lng']])) {
  setcookie('force_lng', $_GET['set_lng'], time() + 86400);
  $lang = $my_keywords['en'];
} elseif ($_COOKIE['force_lng'] and isset($my_keywords[$_COOKIE['force_lng']])){
  $lang = $my_keywords[$_COOKIE['force_lng']];
}
http://www.domain.com/ will be in french but http://www.domain.com/fr/ or http://www.domain.com/de/ will be in english
admin
Site Admin
Posts: 37242
Joined: Wed Sep 10, 2008 11:43 am

Re: Multiple Languages

Post by admin »

Try it w\o rewrites to see where the error it.

As you can see the entire code in in your hands: short language template and a few lines in .htaccess
it should be easy.
Don't forget to run script update
happydg
Posts: 412
Joined: Mon Jul 08, 2013 2:22 pm

Re: Multiple Languages

Post by happydg »

About traffic rules let' say i want to redirect to fr language. I go to Traffic Rules - Incoming:

Select Language
Contains this value: FR

About Redirect to This URL: I can't put this url ( like in multilingual settings ) http://{DOMAIN}/{LANGUAGE}/{ORIGINAL_REQUEST}

Because i don't want to create a redirect for each groups, sponsors etc... This would be thousands of pages to add in traffic rules.
admin
Site Admin
Posts: 37242
Joined: Wed Sep 10, 2008 11:43 am

Re: Multiple Languages

Post by admin »

You only need to redirect "root" requests as all other requests are gonna be handled by category redirects (If I understand the issue correctly)
Don't forget to run script update
happydg
Posts: 412
Joined: Mon Jul 08, 2013 2:22 pm

Re: Multiple Languages

Post by happydg »

I found the code for those who wants it:

Code: Select all

if ($_GET['force_lng'] and isset($my_keywords[$_GET['force_lng']])) {
  $lang = $my_keywords[$_GET['force_lng']];
} else $lang = $my_keywords['en'];
Now i have a last problem: without traffic rules http://www.domain.com/fr/ is working

If i add Traffic Rules - Incoming:

If this field: HTTP_ACCEPT_LANGUAGE
Contains this value: fr
Redirect to This URL: http://www.domain.com/fr/

When i go to http://www.domain.com/ it redirects to http://www.domain.com/fr/ which is good.

But http://www.domain.com/fr/ doesn't work anymore. A firefox error says: the page isn't redirected correctly.
admin
Site Admin
Posts: 37242
Joined: Wed Sep 10, 2008 11:43 am

Re: Multiple Languages

Post by admin »

Can you show http headers plz ?
Don't forget to run script update
happydg
Posts: 412
Joined: Mon Jul 08, 2013 2:22 pm

Re: Multiple Languages

Post by happydg »

I sent them to you via pm.
admin
Site Admin
Posts: 37242
Joined: Wed Sep 10, 2008 11:43 am

Re: Multiple Languages

Post by admin »

Yes, you are right. There's an issue with incoming redirects in this case caz this URL this triggers the same index.php which redirects to the same url.

Basically you need a bit more complex redirect rule then what you can setup in traffic rules
Luckily you can do that in common.php

here's an example

Code: Select all


if (!strstr($_SERVER['HTTP_REFERER'], 'yourdomain.com') and !$_GET['force_lng']) {

	if (strstr($_SERVER['HTTP_ACCEPT_LANGUAGE'], 'fr')) {
		header('Location: http://your_domain/fr/');
		exit;
	} elseif (strstr($_SERVER['HTTP_ACCEPT_LANGUAGE'], 'de')) {
		header('Location: http://your_domain/de/');
		exit;
	}

}
Don't forget to run script update
happydg
Posts: 412
Joined: Mon Jul 08, 2013 2:22 pm

Re: Multiple Languages

Post by happydg »

It works but the problem is it redirects http://www.domain.com/category/lesbian/ to http://www.domain.com/fr/ instead of http://www.domain.com/fr/category/lesbian/

I tried to modify common.php a bit:

Code: Select all

Location: http://www.domain.com/fr<?php $str = $_SERVER['REQUEST_URI']; $str2 = substr($str, 3); echo $str2; ?>
But this doesn't work fine.
admin
Site Admin
Posts: 37242
Joined: Wed Sep 10, 2008 11:43 am

Re: Multiple Languages

Post by admin »

That's because you have

RewriteRule ^([^/]{2})/(.*)$ $2?force_lng=$1&%{QUERY_STRING} [L]


You should have URLs like

http://www.domain.com/fr/category/lesbian/

to avoid that redirect.
Don't forget to run script update
Post Reply