Mobile app version of vmapp.org
Login or Join
Lengel546

: Can search engines change language and read the cookie? I am building a multi language website in PHP and prepared all my strings in English by default using gettext() My locale/it_IT/LC_MESSAGES/default.mo

@Lengel546

Posted in: #Cookie #Multilingual #SearchEngines

I am building a multi language website in PHP and prepared all my strings in English by default using gettext()
My locale/it_IT/LC_MESSAGES/default.mo file is working correctly and now I need to sort out the language detection and switching.

I was thinking about using the approach with the GET parameter:

<a href="?locale=en_US">English</a> | <a href="?locale=it_IT">Italian</a>


I also thought that writing the parameter in a cookie should be better than in PHP's $_SESSION

$locale = "it_IT"; // default in Italian
if (isset($_GET["locale"])) {
$locale = $_GET["locale"];
setcookie("locale", $locale, time()+60*60*24*365*10, "/"); // for 10 years
}
if (!$locale && isset($_COOKIE["locale"])) {
$locale = $_COOKIE["locale"];
}

// locales directory
$locales_root = $_SERVER['DOCUMENT_ROOT'] . "/locale";
$domain = "default";
// activate the locale setting
putenv("LC_ALL=$locale");
setlocale(LC_ALL, $locale);
// bind it, than activate
bindtextdomain($domain, $locales_root);
textdomain($domain);


OK so far, so good.
Now my actual question……
How can a search engine index the English content? It follows the "?locale=en_US" link, than what?
Does the cookie get written? The first page is translated fine, but I am not adding the GET parameter to all my links.
I saw this on some websites before; when you change the language the URL changes to somewebsite.com/it/ (mode_rewrite?) and the next click it's not added anymore.

10.02% popularity Vote Up Vote Down


Login to follow query

More posts by @Lengel546

2 Comments

Sorted by latest first Latest Oldest Best

 

@Kaufman445

Search engines do not parse any content hidden behind a cookie. Also, hardly ever do they read content presented by a javascript (sometimes Google does).

I suggest having a look at the Yii framework, it is pretty easy for beginners, it will answer many questions, and will save you lots of trouble.

10% popularity Vote Up Vote Down


 

@Nimeshi995

Why not pass the locale all the time in the url?

Like yousite.com/en/index.php and /it/index.php?

This effectively solves your problem.

10% popularity Vote Up Vote Down


Back to top | Use Dark Theme