On 26 Mar, 13:57, mouton <nos...@nospam. comwrote:
Hello,
I am a beginner. My website has 2 pages: one in English and one in
French. I would like non English people to be directed to the English
page. There I would like to display a particular sentence in 1 of 3
languages depending on the language of the visitor (this sentence would
be in Spanish or Italian or German and the rest of the page in English).
I have found this code to detect the language:
<SCRIPT language="javas cript">
<!--
function getlanguage(){
language=naviga tor.language;
if(language)
{language=langu age.substring(0 ,2);}}
switch (language){
case "en" :
window.location ="english.ht m";
break;
case "fr" :
window.location ="french.htm ";
break;
default :
window.location ="english.ht m";
}
}
// -->
</SCRIPT>
But then I do not know if this code is standards compliant and what to
do in the English page to display the sentence in one of the 3 languages...
Can you please help me.
Thank you.
do you have any control over your server at all - this is best done
server side. Do you have access use a scripting language like php?
server - apache: use Multiviews, saving your pages as dodah.html.en,
dodah.html.fr and .es
scripting - php: use the value of $_SERVER['HTTP_USER_AGEN T'] and look
through it to find the one at the start of the comma separated list.
Use that to return the strings you need within the doc sending
header( 'Content-Language: ' . $lang );
where $lang is en, fr or es and your script
the better way is to either use rewrites on apache and have you
content appear to the user to come from
http://server.com/lang/path/to/file
or since your site is small, actually separate your content.
if you use scripting the best way is to use a session to persist the
browsers choice and use that to send appropriate content, setting the
right lang attributes in your xhtml if needed as well. Also dont
forget to allow the user to override the setting, use a cookie in
apache setting prefered-lang or with a post to a script in php which
overrides the session preferred lang