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.