Language selector - Printable Version
-Shoutbox (https://shoutbox.menthix.net)
+-- Forum: MsgHelp Archive (/forumdisplay.php?fid=58)
+--- Forum: Skype & Technology (/forumdisplay.php?fid=9)
+---- Forum: Tech Talk (/forumdisplay.php?fid=17)
+----- Thread: Language selector (/showthread.php?tid=51506)
Language selector by wohow on 10-07-2005 at 08:59 PM
Hi ya!
I just registered a couple of hours ago as a member of this community (a friend of mine told me about MP! yesterday...) and I've come across a tech problem lol.
I'm sure it should be kinda easy to work out, but, honestly, I have no idea about webpage programming so... I guess I've been wasting more than enough time on this. Anyway, here it goes:
I'm trying to make some kind of script (I don't mind using PHP, JavaScript... as long as it works ) which would get the user's navigator language. There'd be 2 possibilities: Spanish or non-Spanish (English). As a result, the script would "embed" or "include" (dunno how you'd refer to that in English...) the appropiate page (ie: indexsp.htm) into the script page (index.htm).
I've already found a couple of examples on the Internet, in JavaScript... but they relocate the URL, which is something I don't wanna do...
I know this sounds extremely stupid/rubbish, but I haven't got a clue....
Nice to join ya and thank you so much!
Luis
RE: Language selector by rav0 on 10-08-2005 at 01:52 AM
I'm not really sure of this, but since nobody else has replied, I'll add this.
It checks if the user agent (browser) accepts Spanish, and if so, includes indexsp.htm, otherwise includes index.htm. It also sets the content language HTTP header to Spanish or English depending on which file was included.
I've tested it on my computer and the English half works, but I don't know about the Spanish part because I don't have a computer in Spanish.
code: <?php
if($_SERVER['HTTP_ACCEPT_LANGUAGE']=='es')
{
header('content-language:es');
include 'indexsp.htm';
}
else
{
header('content-language:en');
include 'index.htm';
}
?>
Hopefully somebody with better knowledge can take a look at this and modify or improve this where it needs to be.
Update:
Changed sp to es in line two of code.
RE: Language selector by wohow on 10-08-2005 at 08:16 AM
It works like a dream!
I just modified the 'sp' (should be 'es', to determine whether the computer accepts Spanish or not).
Cheers mate!
RE: Language selector by rav0 on 10-11-2005 at 08:49 AM
Yay, it works!
That's the most complex PHP I've ever written, so I'm proud .
PS I has es as the language code in my local version (it took ages to find out what it should be as well), I don't know why the version I posted had sp in it.
|