Page 5 of 7
Re: Multiple Languages
Posted: Thu Aug 25, 2016 10:59 am
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
Re: Multiple Languages
Posted: Thu Aug 25, 2016 11:34 am
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.
Re: Multiple Languages
Posted: Thu Aug 25, 2016 12:11 pm
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.
Re: Multiple Languages
Posted: Thu Aug 25, 2016 4:07 pm
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)
Re: Multiple Languages
Posted: Thu Aug 25, 2016 8:42 pm
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.
Re: Multiple Languages
Posted: Fri Aug 26, 2016 11:19 am
by admin
Can you show http headers plz ?
Re: Multiple Languages
Posted: Fri Aug 26, 2016 12:09 pm
by happydg
I sent them to you via pm.
Re: Multiple Languages
Posted: Mon Aug 29, 2016 11:23 am
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;
}
}
Re: Multiple Languages
Posted: Mon Aug 29, 2016 12:03 pm
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.
Re: Multiple Languages
Posted: Mon Aug 29, 2016 12:06 pm
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.