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.

link|improve this question
feedback

2 Answers

up vote 0 down vote accepted

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

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

This effectively solves your problem.

link|improve this answer
How can I implement this? Do I need to pull it from the URL? – FFish Dec 2 '10 at 21:15
It mostly depends on your code. Do you use a framework? Most frameworks support this kind of thing easily by modifying their routing settings. Look in Google for "clean urls" for some introduction to this, or ask on StackOverflow ;-) – john Dec 2 '10 at 21:45
John, I know how to use mod_rewrite, actually I am already re-writing that's why I would avoid going with your suggestion... but I am going to have to I guess. Just been reading 2 interesting articles: googlewebmastercentral.blogspot.com/2010/03/… , googlewebmastercentral.blogspot.com/2010/03/… Now I just need to wrap my head around how I am going to add the GET parameter to all my links. – FFish Dec 2 '10 at 22:04
And I don't use a framework, just Apache/mySQL/PHP – FFish Dec 2 '10 at 22:06
You could try using php 's auto_prepend ini setting (if I understood correctly what you want to do). – john Dec 2 '10 at 22:59
show 1 more comment
feedback

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.

link|improve this answer
feedback

Your Answer

 
or
required, but never shown

Not the answer you're looking for? Browse other questions tagged or ask your own question.