Hello! I wanto know How Do i do that when visitors from Spain enter in my website, they see the text in Spanish, bu when visitors from Portugal enter in my web, they see the text in portugues. I have entered in many international websites and they automatically open in portugues if I am in Portugal or in Spanish if I am in Spain. Any comments? Regards, Chewie.
Normally it is not based on where you are but what language you have set as default on your web browser. With .Net it is simply Request.UserLanguages(0) to get the language back
how about to tell us in which language you need that? Here is a piece of code PHP, but based on browser language. So if I will be Spanish with english browser, I will get it in english. $checklang = $_SERVER['HTTP_ACCEPT_LANGUAGE']; if(substr($checklang, 0, 2)=="es"){ $lang = "spanish"; }elseif(substr($checklang, 0, 2)=="en"){ $lang = "english"; } etc... substr for 2 first chars is only bcoz there are spanish in Peru, Mexico, Spain, etc, as well as English speaking poeple in USA, UK, ... all those have different language codes (e.g. en-gb , en-us, en-ca, ...) some codes are here: webmasterworld.com/forum24/320.htm
Hi! Thanks! I need it in Spanish (when people enter from Spain) and in Portuguese (When they enter from Portugal) In your code Goliathus, where I do set to what page redirect the visitors? I mean, I was thinking when the page detects you are from spain, automatically takes you to the root mywebsite/ESP/index.htm, but if you are from Portugal, takes you to mywebsite/PT/index.htm. Regards, Chewie.
if you need only those 2 languages, the best is do it like this. $checklang = $_SERVER['HTTP_ACCEPT_LANGUAGE']; if(substr($checklang, 0, 2)=="pt"){ header("Location: mywebsite/PT/index.htm"); }else{ header("Location: mywebsite/ESP/index.htm"); } It means guys from Portugal, Brazil, .. will get Portuguese, other will get Spanish, which is default. If you need Portuguese as default, change it like this: $checklang = $_SERVER['HTTP_ACCEPT_LANGUAGE']; if(substr($checklang, 0, 2)=="es"){ header("Location: mywebsite/ESP/index.htm"); }else{ header("Location: mywebsite/PT/index.htm"); } (reputation points appreciated )
index.php in ROOT directory should be like this: <?php $checklang = $_SERVER['HTTP_ACCEPT_LANGUAGE']; if(substr($checklang, 0, 2)=="es"){ header("Location: mywebsite/ESP/index.htm"); }else{ header("Location: mywebsite/PT/index.htm"); } ?> that's all...
You might want to also look into gettext if you want to have translated pages on your site. // I cannot post links yet: us2.php.net/manual/en/ref.gettext.php It is the most common way of having multiple language support on a website. (It's somewhat a pain at the beginning, but over time it is pretty useful) -Ben hab.la - Chat with visitors to your website for free using your existing IM client.
I don't understand. Do I create a PHP file just with that code or I put in in my index page and just rename it as a PHP ?? Thanks!